ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
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 ESPRESSO_NPT
54 case TRANS_LANGEVIN_NPT:
55 return force_code_coverage(true);
56#endif
57#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
58 case TRANS_VS_CENTER_OF_MASS:
59 return force_code_coverage(true);
60#endif
61#ifdef ESPRESSO_ROTATION
62 case ROT_EULER:
63 return force_code_coverage(true);
64 case ROT_BROWNIAN:
65 return force_code_coverage(true);
66 case ROT_LANGEVIN:
67 return force_code_coverage(true);
68#endif // ESPRESSO_ROTATION
69 case TRANS_LB_MOMENTUM_EXCHANGE:
70 return force_code_coverage(true);
71#ifdef ESPRESSO_VIRTUAL_SITES_INERTIALESS_TRACERS
72 case TRANS_LB_TRACER:
73 return force_code_coverage(true);
74#endif
75#ifdef ESPRESSO_ROTATION
76 // same mode for translation and rotation
77 case TRANS_NEWTON | ROT_EULER:
78 return force_code_coverage(true);
79 case TRANS_LANGEVIN | ROT_LANGEVIN:
80 return force_code_coverage(true);
81 case TRANS_BROWNIAN | ROT_BROWNIAN:
82 return force_code_coverage(true);
83#ifdef ESPRESSO_STOKESIAN_DYNAMICS
84 case TRANS_STOKESIAN | ROT_STOKESIAN:
85 return force_code_coverage(true);
86#endif
87 // other mode combinations
88 case TRANS_LB_MOMENTUM_EXCHANGE | ROT_EULER:
89 return force_code_coverage(true);
90 case TRANS_LB_MOMENTUM_EXCHANGE | ROT_LANGEVIN:
91 return force_code_coverage(true);
92#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
93 case TRANS_VS_RELATIVE | ROT_VS_RELATIVE:
94 return force_code_coverage(true);
95 case TRANS_VS_RELATIVE | ROT_VS_INDEPENDENT:
96 return force_code_coverage(true);
97 case TRANS_VS_RELATIVE | ROT_VS_RELATIVE | TRANS_LB_MOMENTUM_EXCHANGE:
98 return force_code_coverage(true);
99 case TRANS_VS_RELATIVE | ROT_VS_RELATIVE | TRANS_LANGEVIN | ROT_LANGEVIN:
100 return force_code_coverage(true);
101 case TRANS_VS_RELATIVE | ROT_VS_RELATIVE | TRANS_LB_MOMENTUM_EXCHANGE |
102 ROT_LANGEVIN:
103 return force_code_coverage(true);
104#endif // ESPRESSO_VIRTUAL_SITES_RELATIVE
105#endif // ESPRESSO_ROTATION
106 }
107 return force_code_coverage(false);
108}
109
110std::unordered_map<std::string, int> propagation_flags_map() {
111 using namespace PropagationMode;
112 std::unordered_map<std::string, int> enum_values{};
113 enum_values["NONE"] = NONE;
114 enum_values["SYSTEM_DEFAULT"] = SYSTEM_DEFAULT;
115 enum_values["TRANS_NEWTON"] = TRANS_NEWTON;
116 enum_values["TRANS_LANGEVIN"] = TRANS_LANGEVIN;
117 enum_values["TRANS_LANGEVIN_NPT"] = TRANS_LANGEVIN_NPT;
118 enum_values["TRANS_VS_RELATIVE"] = TRANS_VS_RELATIVE;
119 enum_values["TRANS_LB_MOMENTUM_EXCHANGE"] = TRANS_LB_MOMENTUM_EXCHANGE;
120 enum_values["TRANS_LB_TRACER"] = TRANS_LB_TRACER;
121 enum_values["TRANS_BROWNIAN"] = TRANS_BROWNIAN;
122 enum_values["TRANS_STOKESIAN"] = TRANS_STOKESIAN;
123 enum_values["TRANS_VS_CENTER_OF_MASS"] = TRANS_VS_CENTER_OF_MASS;
124 enum_values["ROT_EULER"] = ROT_EULER;
125 enum_values["ROT_LANGEVIN"] = ROT_LANGEVIN;
126 enum_values["ROT_VS_RELATIVE"] = ROT_VS_RELATIVE;
127 enum_values["ROT_VS_INDEPENDENT"] = ROT_VS_INDEPENDENT;
128 enum_values["ROT_BROWNIAN"] = ROT_BROWNIAN;
129 enum_values["ROT_STOKESIAN"] = ROT_STOKESIAN;
130 return enum_values;
131}
132
133std::string propagation_bitmask_to_string(int propagation) {
134 std::string serialized{""};
135 for (auto const &[name, flag] : propagation_flags_map()) {
136 if (propagation & flag) {
137 serialized += "|" + name;
138 }
139 }
140 if (serialized.empty()) {
141 serialized = "NONE";
142 } else {
143 serialized = serialized.substr(1);
144 }
145 return serialized;
146}
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
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.