votca 2026-dev
Loading...
Searching...
No Matches
ewaldparameters.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20// Standard includes
21#include <stdexcept>
22#include <string>
23
24// Local VOTCA includes
26
27namespace votca {
28namespace xtp {
29
30namespace {
31// The shape travels as a string rather than as the enum's integer value.
32// An integer would silently change meaning if an enumerator were ever
33// inserted ahead of another, and a checkpoint written by an older build
34// would then be read back as a different shape with no error -- the
35// kind of mismatch that produces a plausible wrong answer.
36std::string ShapeToString(EwaldShape shape) {
37 switch (shape) {
39 return "cube";
41 return "slab";
42 }
43 throw std::runtime_error("EwaldParameters: unhandled EwaldShape");
44}
45
46EwaldShape ShapeFromString(const std::string& name) {
47 if (name == "cube") {
48 return EwaldShape::Cube;
49 }
50 if (name == "slab") {
51 return EwaldShape::Slab;
52 }
53 throw std::runtime_error("EwaldParameters: unknown shape '" + name +
54 "' in checkpoint");
55}
56} // namespace
57
59 w(alpha, "alpha");
60 w(k_max, "k_max");
61 w(r_min, "r_min");
62 w(field_tol, "field_tol");
63 w(thole_a, "thole_a");
64 w(screening_factor, "screening_factor");
65 w(ShapeToString(shape), "shape");
66 w(box, "box");
67}
68
70 r(alpha, "alpha");
71 r(k_max, "k_max");
72 r(r_min, "r_min");
73 r(field_tol, "field_tol");
74 r(thole_a, "thole_a");
75 r(screening_factor, "screening_factor");
76 std::string shape_name;
77 r(shape_name, "shape");
78 shape = ShapeFromString(shape_name);
79 r(box, "box");
80
81 if (!(alpha > 0.0) || !(k_max > 0.0) || !(box.determinant() > 0.0)) {
82 throw std::runtime_error(
83 "EwaldParameters: checkpoint holds implausible Ewald parameters "
84 "(alpha, k_max and the box volume must all be positive). The "
85 "checkpoint is either from an incompatible version or corrupt.");
86 }
87}
88
89} // namespace xtp
90} // namespace votca
Charge transport classes.
Definition ERIs.h:28
Provides a means for comparing floating point numbers.
Definition basebead.h:33
void ReadFromCpt(CheckpointReader &r)
void WriteToCpt(CheckpointWriter &w) const