42template <
typename CoreClass>
71 system.on_thermostat_param_change();
77 system.on_thermostat_param_change();
83 throw std::domain_error(
"Parameter '" +
name +
"' cannot be negative");
88 std::string
const &
name)
const {
90 throw std::domain_error(
"Parameter '" +
name +
"' cannot be negative");
100 virtual std::shared_ptr<CoreThermostat> &
106 throw std::invalid_argument(
"Parameter 'seed' is needed on first "
107 "activation of the thermostat");
113 if (
key ==
"is_active") {
123 template <
typename T>
137 template <
typename T>
146#ifdef PARTICLE_ANISOTROPY
147 static_assert(std::is_same_v<T, Utils::Vector3d>);
171 for (
auto key : {std::string(
"seed"), std::string(
"philox_counter")}) {
182 if (
name ==
"override_philox_counter") {
224 return {std::nullopt};
228 auto lock = std::make_shared<bool>(
false);
238 auto const seed =
m_handle->rng_seed();
239 assert(seed <=
static_cast<uint32_t>(std::numeric_limits<int>::max()));
240 return static_cast<int>(seed);
244 auto const counter =
m_handle->rng_counter();
245 assert(counter <=
static_cast<uint64_t>(std::numeric_limits<int>::max()));
246 return static_cast<int>(counter);
252 throw std::domain_error(
"Parameter 'seed' must be a positive integer");
255 static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()));
263 std::numeric_limits<uint64_t>::max());
268 m_handle = std::make_shared<CoreThermostat>();
271 set_new_parameters(
params);
276 std::shared_ptr<::System::System>
system) {
282 m_handle = std::make_shared<CoreThermostat>();
299 std::shared_ptr<CoreThermostat> &
331 std::shared_ptr<CoreThermostat> &
364 std::shared_ptr<CoreThermostat> &
383 std::shared_ptr<CoreThermostat> &
385 return thermostat.
lb;
430 std::shared_ptr<CoreThermostat> &
432 return thermostat.
dpd;
440#ifdef STOKESIAN_DYNAMICS
442 std::shared_ptr<CoreThermostat> &
453 std::shared_ptr<CoreThermostat> &
463 std::shared_ptr<Langevin> langevin;
464 std::shared_ptr<Brownian> brownian;
466 std::shared_ptr<IsotropicNpt> npt_iso;
469 std::shared_ptr<LBThermostat> lb;
472 std::shared_ptr<DPDThermostat> dpd;
474#ifdef STOKESIAN_DYNAMICS
475 std::shared_ptr<Stokesian> stokesian;
477 std::shared_ptr<ThermalizedBond> thermalized_bond;
478 std::shared_ptr<::Thermostat::Thermostat> m_handle;
479 std::unique_ptr<VariantMap> m_params;
481 template <
typename Fun>
void apply(
Fun fun) {
493#ifdef STOKESIAN_DYNAMICS
496 fun(*thermalized_bond);
500 template <
typename T>
505 auto &thermostat = this->*
member;
507 throw WriteError{
name};
514 template <
typename T>
518 std::optional<double>
new_kT;
521 auto const thermo_flag = thermostat->get_thermo_flag();
526 auto const was_active = thermostat->is_activated();
542 thermostat->bind_system(
m_system.lock());
548 "An exception occurred when setting up the thermostat. "
549 "An exception also occurred when attempting to restore the "
550 "original thermostat. The system is now in an invalid state.");
558 auto const thermo_flag = thermostat.get_thermo_flag();
560 thermostat.detach_system();
562 if (m_handle->thermo_switch == 0) {
571 auto const thermo_switch = m_handle->thermo_switch;
574 throw std::runtime_error(
575 "Cannot set parameter 'kT' to " + std::to_string(
new_kT) +
576 ": there are currently active thermostats with kT=" +
592 return (m_handle->kT >= 0.) ?
Variant{m_handle->kT}
606#ifdef STOKESIAN_DYNAMICS
615 if (
params.contains(
"act_on_virtual")) {
617 throw std::runtime_error(
618 name +
"() got an unexpected keyword argument 'act_on_virtual'");
621 if (
name ==
"set_langevin") {
625 if (
name ==
"set_brownian") {
630 if (
name ==
"set_npt") {
636 if (
name ==
"set_lb") {
642 if (
name ==
"set_dpd") {
647#ifdef STOKESIAN_DYNAMICS
648 if (
name ==
"set_stokesian") {
653 if (
name ==
"set_thermalized_bond") {
657 if (
name ==
"turn_off") {
667 m_params = std::make_unique<VariantMap>(
params);
671 assert(m_params !=
nullptr);
672 m_handle =
system.thermostat;
673 auto const &
params = *m_params;
675 reload_checkpointed_thermostats(
params);
683 make_default_constructed_thermostats();
700 apply([
this](
auto &thermostat) {
702 thermostat.bind_system(m_system.lock());
703 m_handle->thermo_switch |= thermostat.get_thermo_flag();
713 void make_default_constructed_thermostats() {
729#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::shared_ptr< CoreThermostat > & get_member_handle(::Thermostat::Thermostat &thermostat) 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::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::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::shared_ptr< CoreThermostat > & get_member_handle(::Thermostat::Thermostat &thermostat) override
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
::ThermostatFlags get_thermo_flag() const final
::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