4 #include<boost/algorithm/string.hpp>
45 DoF(
const std::string &_name =
"",
Index _ID = -1) : m_type_name(_name), m_dof_ID(_ID), m_ID_lock(false) {}
54 std::vector<std::string> split_string;
55 boost::split(split_string,
type_name(), boost::is_any_of(
"_"), boost::token_compress_on);
56 if(split_string.size())
57 return split_string[0];
63 std::vector<std::string> split_string;
64 boost::split(split_string,
type_name(), boost::is_any_of(
"_"), boost::token_compress_on);
65 if(split_string.size())
66 return split_string.back();
99 jsonParser &
to_json(
const DoF *dof, jsonParser &json);
104 void from_json(DoF *dof,
const jsonParser &json,
const Lattice &lat);
124 m_current_state(_current_state),
125 m_remote_state(nullptr),
145 m_current_state = -1;
154 assert(m_remote_state &&
"In DiscreteDoF::remote_value() m_remote_state is nullptr.\n");
163 assert(handle.
i_ptr() &&
"In DiscreteDoF::register_remote(), attempting to register to nullptr!");
164 m_remote_state = handle.
i_ptr();
176 m_current_state = new_state;
190 void print(std::ostream &out)
const {
199 template<
typename T>
220 OccupantDoF(std::initializer_list<T> _domain,
int _current_state = 0) :
221 DiscreteDoF(
"occupation_occ", _current_state), m_domain(_domain.begin(), _domain.end()) {
237 if(
Index(new_state) >= m_domain.
size()) {
238 std::cerr <<
"In OccupantDoF::set_value(): Bad Assignment, new_state>=size Go check! EXITING \n";
242 m_current_state = new_state;
247 Index new_index = m_domain.
find(new_state);
248 if(new_index >= m_domain.
size()) {
249 std::cerr <<
"In OccupantDoF::set_current_state(const T &new_state): Bad Assignment, new_state not found in domain. Go check! EXITING \n";
253 m_current_state = new_index;
265 if((*
this)[i] != RHS[i])
278 if(new_dom.
size() == 1)
281 m_current_state = -1;
298 return m_domain.
size();
301 void print(std::ostream &out)
const {
304 out << m_domain[i].name;
306 out <<
' ' << m_domain[i].name;
327 jsonParser &
to_json(
const OccupantDoF<int> &dof, jsonParser &json);
329 void from_json(OccupantDoF<int> &dof,
const jsonParser &json);
332 jsonParser &
to_json(
const OccupantDoF<Molecule> &dof, jsonParser &json);
336 void from_json(OccupantDoF<Molecule> &dof,
const jsonParser &json);
349 current_min(NAN), current_max(NAN), m_remote_ptr(nullptr) {}
352 DoF(tname), min_val(tmin), max_val(tmax), current_val(NAN),
353 current_min(min_val), current_max(max_val), m_remote_ptr(nullptr) {}
356 DoF(tname, _ID), min_val(tmin), max_val(tmax), current_val(NAN),
357 current_min(min_val), current_max(max_val), m_remote_ptr(nullptr) {}
368 && (
ID() == RHS.
ID()));
373 && (
ID() == RHS.
ID())
378 assert(m_remote_ptr &&
"In ContinuousDoF::remote_value() m_remote_val is nullptr.\n");
387 assert(handle.
d_ptr() &&
"In ContinuousDoF::register_remote(), attempting to register to nullptr!");
388 m_remote_ptr = handle.
d_ptr();
401 json[
"DoF_type"] =
"ContinuousDoF";
411 void from_json(ContinuousDoF &dof,
const jsonParser &json);
413 jsonParser &
to_json(
const ContinuousDoF &dof, jsonParser &json);
void set_current_state(const T &new_state)
void set_domain(const Array< T > &new_dom)
void set_ID(Index new_ID)
void set_value(int new_state) override
virtual bool operator==(const DiscreteDoF &RHS) const
void print(std::ostream &out) const
const double * d_ptr() const
void from_json(ClexDescription &desc, const jsonParser &json)
bool is_specified() const
virtual jsonParser & to_json(jsonParser &json) const =0
DiscreteDoF(const std::string &_name, int _current_state=0, SymGroupRepID _id=SymGroupRepID::identity(0))
Type-safe ID object for communicating and accessing Symmetry representation info. ...
const int * i_ptr() const
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
DiscreteDoF * copy() const override
SymGroupRepID m_sym_rep_ID
const double * m_remote_ptr
Allows DoF to point to a remote value for faster/easier evaluation.
const std::string & type_name() const
void print_occ(std::ostream &out) const
virtual void set_value(int new_state)
jsonParser & to_json(jsonParser &json) const
SymGroupRepID sym_rep_ID() const
std::string type_name_suffix() const
virtual jsonParser & to_json(jsonParser &json) const =0
double remote_value() const
jsonParser & to_json(jsonParser &json) const override
void print(std::ostream &out) const
double const *const m_d_ptr
const int * m_remote_state
Allows DoF to point to a remote value for faster/easier evaluation.
EigenIndex Index
For long integer indexing:
OccupantDoF(const Array< T > &_domain, int _current_state=0)
bool operator==(const OccupantDoF &RHS) const
virtual DiscreteDoF * copy() const =0
const Array< T > & get_domain() const
Index size() const override
virtual Index size() const =0
DoF(const std::string &_name="", Index _ID=-1)
std::string type_name_prefix() const
Index find(const T &test_elem) const
const T & operator[](Index i) const
void set_sym_rep_ID(SymGroupRepID _id)
int m_current_state
index into domain of the current state, -1 if unspecified
const T & get_occ() const
bool compare(const ContinuousDoF &RHS, bool compare_value) const
jsonParser & put_obj()
Puts new empty JSON object.
ContinuousDoF(const std::string &tname, double tmin, double tmax)
Array< T > m_domain
Allowed values, assume class T has member 'T.name'.
RemoteHandle(const double &d)
ContinuousDoF * copy() const
OccupantDoF(const std::string &_name, const Array< T > &_domain, int _current_state=0)
int const * remote_ptr() const
double const * remote_ptr() const
OccupantDoF(std::initializer_list< T > _domain, int _current_state=0)
void register_remote(const RemoteHandle &handle)
ContinuousDoF(const std::string &tname, Index _ID, double tmin, double tmax)
void register_remote(const RemoteHandle &handle)
Basic std::vector like container (deprecated)
bool operator==(const ContinuousDoF &RHS) const
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)
bool compare(const OccupantDoF &RHS, bool compare_value) const
static SymGroupRepID identity(Index dim)
Static function to construct an ID for identity representations.
bool valid_index(Index i)
RemoteHandle(const int &i)