Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
propagation.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "propagation.hpp"
21
22#include "config/config.hpp"
23
24#include "PropagationMode.hpp"
25
26#include <cassert>
27#include <string>
28#include <unordered_map>
29
30// no-op function to generate a trace for code coverage
31static bool force_code_coverage(bool value) { return value; }
32
33/**
34 * Note for developers: when enabling new propagation mode combinations,
35 * make sure every single line of this function has code coverage.
36 */
37bool is_valid_propagation_combination(int propagation) {
38 using namespace PropagationMode;
39 assert(propagation >= 0);
40 // check allowlist
41 switch (propagation) {
42 // only one mode
43 case NONE: // NOLINT(bugprone-branch-clone)
44 return force_code_coverage(true);
45 case SYSTEM_DEFAULT:
46 return force_code_coverage(true);
47 case TRANS_NEWTON:
48 return force_code_coverage(true);
49 case TRANS_BROWNIAN:
50 return force_code_coverage(true);
51 case TRANS_LANGEVIN:
52 return force_code_coverage(true);
53#ifdef NPT
54 case TRANS_LANGEVIN_NPT:
55 return force_code_coverage(true);
56#endif
57#ifdef ROTATION
58 case ROT_EULER:
59 return force_code_coverage(true);
60 case ROT_BROWNIAN:
61 return force_code_coverage(true);
62 case ROT_LANGEVIN:
63 return force_code_coverage(true);
64#endif // ROTATION
65 case TRANS_LB_MOMENTUM_EXCHANGE:
66 return force_code_coverage(true);
67#ifdef VIRTUAL_SITES_INERTIALESS_TRACERS
68 case TRANS_LB_TRACER:
69 return force_code_coverage(true);
70#endif
71#ifdef ROTATION
72 // same mode for translation and rotation
73 case TRANS_NEWTON | ROT_EULER:
74 return force_code_coverage(true);
75 case TRANS_LANGEVIN | ROT_LANGEVIN:
76 return force_code_coverage(true);
77 case TRANS_BROWNIAN | ROT_BROWNIAN:
78 return force_code_coverage(true);
79#ifdef STOKESIAN_DYNAMICS
80 case TRANS_STOKESIAN | ROT_STOKESIAN:
81 return force_code_coverage(true);
82#endif
83 // other mode combinations
84 case TRANS_LB_MOMENTUM_EXCHANGE | ROT_EULER:
85 return force_code_coverage(true);
86 case TRANS_LB_MOMENTUM_EXCHANGE | ROT_LANGEVIN:
87 return force_code_coverage(true);
88#ifdef VIRTUAL_SITES_RELATIVE
89 case TRANS_VS_RELATIVE | ROT_VS_RELATIVE:
90 return force_code_coverage(true);
91 case TRANS_VS_RELATIVE | ROT_VS_RELATIVE | TRANS_LB_MOMENTUM_EXCHANGE:
92 return force_code_coverage(true);
93 case TRANS_VS_RELATIVE | ROT_VS_RELATIVE | TRANS_LANGEVIN | ROT_LANGEVIN:
94 return force_code_coverage(true);
95 case TRANS_VS_RELATIVE | ROT_VS_RELATIVE | TRANS_LB_MOMENTUM_EXCHANGE |
96 ROT_LANGEVIN:
97 return force_code_coverage(true);
98#endif // VIRTUAL_SITES_RELATIVE
99#endif // ROTATION
100 }
101 return force_code_coverage(false);
102}
103
104std::unordered_map<std::string, int> propagation_flags_map() {
105 using namespace PropagationMode;
106 std::unordered_map<std::string, int> enum_values{};
107 enum_values["NONE"] = NONE;
108 enum_values["SYSTEM_DEFAULT"] = SYSTEM_DEFAULT;
109 enum_values["TRANS_NEWTON"] = TRANS_NEWTON;
110 enum_values["TRANS_LANGEVIN"] = TRANS_LANGEVIN;
111 enum_values["TRANS_LANGEVIN_NPT"] = TRANS_LANGEVIN_NPT;
112 enum_values["TRANS_VS_RELATIVE"] = TRANS_VS_RELATIVE;
113 enum_values["TRANS_LB_MOMENTUM_EXCHANGE"] = TRANS_LB_MOMENTUM_EXCHANGE;
114 enum_values["TRANS_LB_TRACER"] = TRANS_LB_TRACER;
115 enum_values["TRANS_BROWNIAN"] = TRANS_BROWNIAN;
116 enum_values["TRANS_STOKESIAN"] = TRANS_STOKESIAN;
117 enum_values["ROT_EULER"] = ROT_EULER;
118 enum_values["ROT_LANGEVIN"] = ROT_LANGEVIN;
119 enum_values["ROT_VS_RELATIVE"] = ROT_VS_RELATIVE;
120 enum_values["ROT_BROWNIAN"] = ROT_BROWNIAN;
121 enum_values["ROT_STOKESIAN"] = ROT_STOKESIAN;
122 return enum_values;
123}
124
125std::string propagation_bitmask_to_string(int propagation) {
126 std::string serialized{""};
127 for (auto const &[name, flag] : propagation_flags_map()) {
128 if (propagation & flag) {
129 serialized += "|" + name;
130 }
131 }
132 if (serialized.empty()) {
133 serialized = "NONE";
134 } else {
135 serialized = serialized.substr(1);
136 }
137 return serialized;
138}
This file contains the defaults for ESPResSo.
static bool force_code_coverage(bool value)
std::string propagation_bitmask_to_string(int propagation)
Convert a propagation modes bitmask to a string.
bool is_valid_propagation_combination(int propagation)
Note for developers: when enabling new propagation mode combinations, make sure every single line of ...
std::unordered_map< std::string, int > propagation_flags_map()
Convert PropagationMode::PropagationMode to name/value pairs.