ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
VelocityVerletIsoNPT.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 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 "config/config.hpp"
21
22#ifdef ESPRESSO_NPT
23
25
27
30#include "core/npt.hpp"
31
32#include <utils/Vector.hpp>
33
34#include <memory>
35#include <string>
36
37namespace ScriptInterface {
38namespace Integrators {
39
42 {"ext_pressure", AutoParameter::read_only,
43 [this]() { return get_instance().p_ext; }},
44 {"piston", AutoParameter::read_only,
45 [this]() { return get_instance().piston; }},
46 {"direction", AutoParameter::read_only,
47 [this]() { return get_instance().get_direction(); }},
48 {"cubic_box", AutoParameter::read_only,
49 [this]() { return get_instance().cubic_box; }},
50 });
51}
52
54 auto const ext_pressure = get_value<double>(params, "ext_pressure");
55 auto const piston = get_value<double>(params, "piston");
56 auto const cubic_box = get_value_or<bool>(params, "cubic_box", false);
57 auto const direction = get_value_or<Utils::Vector3b>(
58 params, "direction", Utils::Vector3b::broadcast(true));
59 m_barostat = get_value_or<std::string>(params, "barostat", "Andersen");
60
61 context()->parallel_try_catch([&]() {
62 m_instance = std::make_shared<::NptIsoParameters>(ext_pressure, piston,
63 direction, cubic_box);
64 });
65}
66
68 context()->parallel_try_catch(
69 [this]() { m_instance->coulomb_dipole_sanity_checks(get_system()); });
70 get_system().nptiso = m_instance;
71 if (m_barostat == "Andersen") {
72 get_system().propagation->set_integ_switch(INTEG_METHOD_NPT_ISO_AND);
73 } else if (m_barostat == "MTK") {
74 get_system().propagation->set_integ_switch(INTEG_METHOD_NPT_ISO_MTK);
75 } else {
76 throw std::invalid_argument(
77 "Parameter 'barostat' must be 'Andersen' or 'MTK'.");
78 }
79 get_system().on_thermostat_param_change();
80}
81
82} // namespace Integrators
83} // namespace ScriptInterface
84
85#endif // ESPRESSO_NPT
@ INTEG_METHOD_NPT_ISO_AND
@ INTEG_METHOD_NPT_ISO_MTK
Vector implementation and trait types for boost qvm interoperability.
void do_construct(VariantMap const &params) override
std::shared_ptr< NptIsoParameters > nptiso
std::shared_ptr< Propagation > propagation
static DEVICE_QUALIFIER constexpr Vector< T, N > broadcast(typename Base::value_type const &value) noexcept
Create a vector that has all entries set to the same value.
Definition Vector.hpp:132
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:133
Exports for the NpT code.
static SteepestDescentParameters params
Currently active steepest descent instance.
double p_ext
desired pressure to which the algorithm strives to
Definition npt.hpp:59
bool cubic_box
Set this flag if you want all box dimensions to be identical.
Definition npt.hpp:81
Utils::Vector< bool, 3 > get_direction() const
Definition npt.cpp:94
double piston
mass of a virtual piston representing the shaken box
Definition npt.hpp:47
static constexpr const ReadOnly read_only