43template <
typename CoreClass>
72 system.on_thermostat_param_change();
78 system.on_thermostat_param_change();
84 throw std::domain_error(
"Parameter '" +
name +
"' cannot be negative");
89 std::string
const &
name)
const {
91 throw std::domain_error(
"Parameter '" +
name +
"' cannot be negative");
101 virtual std::shared_ptr<CoreThermostat> &
107 throw std::invalid_argument(
"Parameter 'seed' is needed on first "
108 "activation of the thermostat");
110 check_required_parameters(
params);
115 if (
key ==
"is_active") {
130 throw std::runtime_error(
"Parameter '" +
name +
"' is missing");
136 template <
typename T>
150 template <
typename T>
159#ifdef PARTICLE_ANISOTROPY
160 static_assert(std::is_same_v<T, Utils::Vector3d>);
184 for (
auto key : {std::string(
"seed"), std::string(
"philox_counter")}) {
195 if (
name ==
"override_philox_counter") {
232 if (
params.contains(
"kT")) {
237 return {std::nullopt};
241 auto lock = std::make_shared<bool>(
false);
251 auto const seed =
m_handle->rng_seed();
252 assert(seed <=
static_cast<uint32_t>(std::numeric_limits<int>::max()));
253 return static_cast<int>(seed);
257 auto const counter =
m_handle->rng_counter();
258 assert(counter <=
static_cast<uint64_t>(std::numeric_limits<int>::max()));
259 return static_cast<int>(counter);
265 throw std::domain_error(
"Parameter 'seed' must be a positive integer");
268 static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()));
276 std::numeric_limits<uint64_t>::max());
281 m_handle = std::make_shared<CoreThermostat>();
284 set_new_parameters(
params);
289 std::shared_ptr<::System::System>
system) {
295 m_handle = std::make_shared<CoreThermostat>();
312 std::shared_ptr<CoreThermostat> &
318 static constexpr std::array
names{std::string_view(
"gamma")};
349 std::shared_ptr<CoreThermostat> &
355 static constexpr std::array
names{std::string_view(
"gamma")};
387 std::shared_ptr<CoreThermostat> &
393 static constexpr std::array
names{std::string_view(
"gamma0"),
394 std::string_view(
"gammav")};
412 std::shared_ptr<CoreThermostat> &
414 return thermostat.
lb;
456 static constexpr std::array
names{std::string_view(
"gamma")};
464 std::shared_ptr<CoreThermostat> &
466 return thermostat.
dpd;
478#ifdef STOKESIAN_DYNAMICS
480 std::shared_ptr<CoreThermostat> &
495 std::shared_ptr<CoreThermostat> &
509 std::shared_ptr<Langevin> langevin;
510 std::shared_ptr<Brownian> brownian;
512 std::shared_ptr<IsotropicNpt> npt_iso;
515 std::shared_ptr<LBThermostat> lb;
518 std::shared_ptr<DPDThermostat> dpd;
520#ifdef STOKESIAN_DYNAMICS
521 std::shared_ptr<Stokesian> stokesian;
523 std::shared_ptr<ThermalizedBond> thermalized_bond;
524 std::shared_ptr<::Thermostat::Thermostat> m_handle;
525 std::unique_ptr<VariantMap> m_params;
527 template <
typename Fun>
void apply(
Fun fun) {
539#ifdef STOKESIAN_DYNAMICS
542 fun(*thermalized_bond);
546 template <
typename T>
551 auto &thermostat = this->*
member;
553 throw WriteError{
name};
560 template <
typename T>
564 std::optional<double>
new_kT;
567 auto const thermo_flag = thermostat->get_thermo_flag();
572 auto const was_active = thermostat->is_activated();
588 thermostat->bind_system(
m_system.lock());
594 "An exception occurred when setting up the thermostat. "
595 "An exception also occurred when attempting to restore the "
596 "original thermostat. The system is now in an invalid state.");
604 auto const thermo_flag = thermostat.get_thermo_flag();
606 thermostat.detach_system();
608 if (m_handle->thermo_switch == 0) {
617 auto const thermo_switch = m_handle->thermo_switch;
620 throw std::runtime_error(
621 "Cannot set parameter 'kT' to " + std::to_string(
new_kT) +
622 ": there are currently active thermostats with kT=" +
638 return (m_handle->kT >= 0.) ?
Variant{m_handle->kT}
652#ifdef STOKESIAN_DYNAMICS
661 if (
params.contains(
"act_on_virtual")) {
663 throw std::runtime_error(
664 name +
"() got an unexpected keyword argument 'act_on_virtual'");
667 if (
name ==
"set_langevin") {
671 if (
name ==
"set_brownian") {
676 if (
name ==
"set_npt") {
682 if (
name ==
"set_lb") {
688 if (
name ==
"set_dpd") {
693#ifdef STOKESIAN_DYNAMICS
694 if (
name ==
"set_stokesian") {
699 if (
name ==
"set_thermalized_bond") {
703 if (
name ==
"turn_off") {
713 m_params = std::make_unique<VariantMap>(
params);
717 assert(m_params !=
nullptr);
718 m_handle =
system.thermostat;
719 auto const &
params = *m_params;
721 reload_checkpointed_thermostats(
params);
729 make_default_constructed_thermostats();
746 apply([
this](
auto &thermostat) {
748 thermostat.bind_system(m_system.lock());
749 m_handle->thermo_switch |= thermostat.get_thermo_flag();
759 void make_default_constructed_thermostats() {
775#ifdef STOKESIAN_DYNAMICS
ScriptInterface::Context decorates ScriptInterface::ObjectHandle objects with a context: a creation p...
ThermostatFlags
Thermostat flags.
Data structures for bonded interactions.
Bind parameters in the script interface.
void do_set_parameter(const std::string &name, const Variant &value) final
Variant get_parameter(const std::string &name) const final
void add_parameters(std::vector< AutoParameter > &¶ms)
auto const & get_parameter_insertion_order() const
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
virtual std::shared_ptr< ObjectHandle > make_shared(std::string const &name, const VariantMap ¶meters)=0
Get a new reference counted instance of a script interface by name.
Type to indicate no value in Variant.
boost::string_ref name() const
Context * context() const
Responsible context.
void set_parameter(const std::string &name, const Variant &value)
Set single parameter.
Script interface wrapper for a component of the system class.
auto const & get_system() const
std::weak_ptr<::System::System > m_system
void bind_system(std::shared_ptr<::System::System > const &system)
VariantMap extend_parameters(VariantMap const ¶meters) const override
::ThermostatFlags get_thermo_flag() const final
std::shared_ptr< CoreThermostat > & get_member_handle(::Thermostat::Thermostat &thermostat) override
std::span< std::string_view const > get_required_parameters() const override
std::shared_ptr< CoreThermostat > & get_member_handle(::Thermostat::Thermostat &thermostat) override
std::span< std::string_view const > get_required_parameters() const override
::ThermostatFlags get_thermo_flag() const final
void sanity_checks_positive(double value, std::string const &name) const
void update_and_bind(VariantMap const ¶ms, bool was_active, std::shared_ptr<::System::System > system)
void on_bind_system(::System::System &system) override
void set_rng_counter(Variant const &value)
void set_rng_seed(Variant const &value)
virtual ::ThermostatFlags get_thermo_flag() const =0
auto get_rng_counter() const
auto get_rng_seed() const
virtual std::shared_ptr< CoreThermostat > & get_member_handle(::Thermostat::Thermostat &thermostat)=0
void on_detach_system(::System::System &system) override
virtual bool invalid_rng_state(VariantMap const ¶ms) const
auto make_autoparameter(T CoreThermostat::*member, char const *name)
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
virtual std::span< std::string_view const > get_required_parameters() const =0
virtual std::optional< double > extract_kT(VariantMap const ¶ms) const
auto is_activated() const
auto make_autogamma(T CoreThermostat::*member, char const *name)
virtual VariantMap extend_parameters(VariantMap const ¶meters) const
std::weak_ptr< bool > m_edit_lock
Basic lock mechanism that follows RAII.
std::shared_ptr< CoreThermostat > m_handle
virtual bool is_seed_required() const
void sanity_checks_positive(Utils::Vector3d const &value, std::string const &name) const
void do_construct(VariantMap const ¶ms) override
std::span< std::string_view const > get_required_parameters() const override
std::shared_ptr< CoreThermostat > & get_member_handle(::Thermostat::Thermostat &thermostat) override
::ThermostatFlags get_thermo_flag() const final
bool invalid_rng_state(VariantMap const ¶ms) const override
::ThermostatFlags get_thermo_flag() const final
std::shared_ptr< CoreThermostat > & get_member_handle(::Thermostat::Thermostat &thermostat) override
std::optional< double > extract_kT(VariantMap const ¶ms) const override
std::span< std::string_view const > get_required_parameters() const override
std::shared_ptr< CoreThermostat > & get_member_handle(::Thermostat::Thermostat &thermostat) override
std::span< std::string_view const > get_required_parameters() const override
VariantMap extend_parameters(VariantMap const ¶meters) const override
::ThermostatFlags get_thermo_flag() const final
std::span< std::string_view const > get_required_parameters() const override
std::shared_ptr< CoreThermostat > & get_member_handle(::Thermostat::Thermostat &thermostat) override
::ThermostatFlags get_thermo_flag() const final
std::span< std::string_view const > get_required_parameters() const override
::ThermostatFlags get_thermo_flag() const final
std::shared_ptr< CoreThermostat > & get_member_handle(::Thermostat::Thermostat &thermostat) override
void update_global_kT(double old_kT, double new_kT, int thermo_flag)
void on_bind_system(::System::System &system) override
auto make_autoparameter(T Thermostat::*member, char const *name)
void turn_thermostat_off(T &thermostat)
void do_construct(VariantMap const ¶ms) override
void setup_thermostat(std::shared_ptr< T > &thermostat, VariantMap const ¶ms)
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
std::shared_ptr< BrownianThermostat > brownian
std::shared_ptr< ThermalizedBondThermostat > thermalized_bond
std::shared_ptr< LangevinThermostat > langevin
std::shared_ptr< DPDThermostat > dpd
std::shared_ptr< LBThermostat > lb
std::shared_ptr< IsotropicNptThermostat > npt_iso
std::shared_ptr< StokesianThermostat > stokesian
static DEVICE_QUALIFIER constexpr Vector< T, N > broadcast(typename Base::value_type const &value)
Create a vector that has all entries set to the same value.
Implementation in thermostat.cpp.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
bool is_none(Variant const &v)
bool are_kT_equal(double old_kT, double new_kT)
Check that two kT values are close up to a small tolerance.
constexpr GammaType gamma_null
Value for a null friction coefficient.
static SteepestDescentParameters params
Currently active steepest descent instance.
GammaType gamma
Translational friction coefficient .
GammaType gamma_rotation
Rotational friction coefficient .
double gamma0
Friction coefficient of the particles .
double gammav
Friction coefficient for the box .
GammaType gamma_rotation
Rotational friction coefficient .
GammaType gamma
Translational friction coefficient .
Description and getter/setter for a parameter.
static constexpr const ReadOnly read_only