espresso icon indicating copy to clipboard operation
espresso copied to clipboard

Refactor thermostat switches

Open KaiSzuttor opened this issue 4 years ago • 1 comments

The low-level handling of how thermostats are enabled or disabled should not be exposed to the developer. Something like the following could be implemented:

#include <bitset>
#include <cassert>
#include <iostream>

enum class Thermostat : unsigned int {
    LANGEVIN,
    DPD,
    NPT_ISP,
    NPT_ISO,
    LB,
    BROWNIAN,
    SD
};

template<std::size_t N>
struct ThermoSwitch {
  std::bitset<N> thermo_switch;
  void add(Thermostat thermostat) {
    assert(static_cast<unsigned int>(thermostat) < N);
    thermo_switch.set(static_cast<unsigned int>(thermostat), true);
  }

  void remove(Thermostat thermostat) {
    assert(static_cast<unsigned int>(thermostat) < N);
    thermo_switch.set(static_cast<unsigned int>(thermostat), false);
  }

  bool is_active(Thermostat thermostat) {
    assert(static_cast<unsigned int>(thermostat) < N);
    return thermo_switch[static_cast<unsigned int>(thermostat)];
  }

  void turn_off() {
    thermo_switch.reset();
  }
};

int main() {
   ThermoSwitch<7> thermo_switch;
   thermo_switch.add(Thermostat::LANGEVIN);
   std::cout << thermo_switch.thermo_switch << std::endl;
   thermo_switch.add(Thermostat::DPD);
   std::cout << thermo_switch.thermo_switch << std::endl;
   std::cout << thermo_switch.is_active(Thermostat::DPD) << std::endl;
   thermo_switch.turn_off();
   std::cout << thermo_switch.thermo_switch << std::endl;
   std::cout << thermo_switch.is_active(Thermostat::DPD) << std::endl;
}

KaiSzuttor avatar May 28 '21 08:05 KaiSzuttor

What you propose represents the current structure very clearly.

We have to decide whether to still do this refactoring before the propagation refactoring.

After that, the thermostats will no longer exist as independent concept, and each particle will be propagated according to exactly one scheme.

(DPD, like ThermalizedBond, will be just an interaction).

RudolfWeeber avatar May 28 '21 11:05 RudolfWeeber