|
@@ -4,7 +4,7 @@
|
|
|
*/
|
|
|
|
|
|
/*
|
|
|
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
|
|
|
+ * Copyright (C) 2012-2019 ULCO http://www.univ-littoral.fr
|
|
|
*
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
@@ -34,508 +34,500 @@
|
|
|
#include <functional>
|
|
|
#include <vector>
|
|
|
|
|
|
-namespace artis { namespace kernel {
|
|
|
-
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
-class Simulator;
|
|
|
-
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
-class AbstractCoupledModel : public AbstractModel < U, V >,
|
|
|
- public States < T, U, V >,
|
|
|
- public Internals < T, U, V >,
|
|
|
- public Externals < T, U, V >
|
|
|
-{
|
|
|
- typedef AbstractModel < U, V > type;
|
|
|
- typedef std::map < int, type* > Submodels;
|
|
|
- typedef std::map < int,
|
|
|
- std::vector < type* > > Setsubmodels;
|
|
|
- typedef std::map < int, std::pair < type*,
|
|
|
- int > > SubModelInternals;
|
|
|
-
|
|
|
- using Externals < T, U, V >::restore;
|
|
|
- using Internals < T, U, V >::restore;
|
|
|
- using States < T, U, V >::restore;
|
|
|
- using Externals < T, U, V >::save;
|
|
|
- using Internals < T, U, V >::save;
|
|
|
- using States < T, U, V >::save;
|
|
|
+namespace artis {
|
|
|
+ namespace kernel {
|
|
|
+
|
|
|
+ template<typename T, typename U, typename V, typename W>
|
|
|
+ class Simulator;
|
|
|
+
|
|
|
+ template<typename T, typename U, typename V, typename W>
|
|
|
+ class AbstractCoupledModel : public AbstractModel<U, V>,
|
|
|
+ public States<T, U, V>,
|
|
|
+ public Internals<T, U, V>,
|
|
|
+ public Externals<T, U, V> {
|
|
|
+ typedef AbstractModel<U, V> type;
|
|
|
+ typedef std::map<int, type*> Submodels;
|
|
|
+ typedef std::map<int,
|
|
|
+ std::vector<type*> > Setsubmodels;
|
|
|
+ typedef std::map<int, std::pair<type*,
|
|
|
+ int> > SubModelInternals;
|
|
|
+
|
|
|
+ using Externals<T, U, V>::restore;
|
|
|
+ using Internals<T, U, V>::restore;
|
|
|
+ using States<T, U, V>::restore;
|
|
|
+ using Externals<T, U, V>::save;
|
|
|
+ using Internals<T, U, V>::save;
|
|
|
+ using States<T, U, V>::save;
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
- friend class Simulator < T, U, V, W >;
|
|
|
+
|
|
|
+ friend class Simulator<T, U, V, W>;
|
|
|
+
|
|
|
#endif
|
|
|
|
|
|
-public:
|
|
|
- struct Var
|
|
|
- {
|
|
|
- unsigned int index;
|
|
|
- type* model;
|
|
|
- int sub_index;
|
|
|
- std::string var_name;
|
|
|
- std::string sub_var_name;
|
|
|
-
|
|
|
- Var (unsigned int index, std::string var_name,
|
|
|
- type* model, int sub_index, std::string sub_var_name) :
|
|
|
- index(index), model(model), sub_index(sub_index),
|
|
|
- var_name(var_name), sub_var_name(sub_var_name)
|
|
|
- { }
|
|
|
- };
|
|
|
-
|
|
|
- AbstractCoupledModel(const type* parent = 0) : type(parent)
|
|
|
- {
|
|
|
+ public:
|
|
|
+ struct Var {
|
|
|
+ unsigned int index;
|
|
|
+ type* model;
|
|
|
+ int sub_index;
|
|
|
+ std::string var_name;
|
|
|
+ std::string sub_var_name;
|
|
|
+
|
|
|
+ Var(unsigned int index, std::string var_name,
|
|
|
+ type* model, int sub_index, std::string sub_var_name)
|
|
|
+ :
|
|
|
+ index(index), model(model), sub_index(sub_index),
|
|
|
+ var_name(var_name), sub_var_name(sub_var_name) { }
|
|
|
+ };
|
|
|
+
|
|
|
+ AbstractCoupledModel(const type* parent = 0)
|
|
|
+ :type(parent)
|
|
|
+ {
|
|
|
#ifdef WITH_TRACE
|
|
|
- utils::Trace < utils::DoubleTime >::trace()
|
|
|
- << utils::TraceElement < utils::DoubleTime >(
|
|
|
- true,
|
|
|
- boost::core::demangle(typeid(T).name()),
|
|
|
- utils::DoubleTime::null,
|
|
|
- utils::CONSTRUCT);
|
|
|
- utils::Trace < utils::DoubleTime >::trace().flush();
|
|
|
+ utils::Trace<utils::DoubleTime>::trace()
|
|
|
+ << utils::TraceElement<utils::DoubleTime>(
|
|
|
+ true,
|
|
|
+ boost::core::demangle(typeid(T).name()),
|
|
|
+ utils::DoubleTime::null,
|
|
|
+ utils::CONSTRUCT);
|
|
|
+ utils::Trace<utils::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- virtual ~AbstractCoupledModel()
|
|
|
- {
|
|
|
+ virtual ~AbstractCoupledModel()
|
|
|
+ {
|
|
|
#ifdef WITH_TRACE
|
|
|
- trace_element(true, utils::DoubleTime::null,
|
|
|
- utils::DESTRUCT);
|
|
|
+ trace_element(true, utils::DoubleTime::null,
|
|
|
+ utils::DESTRUCT);
|
|
|
#endif
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- virtual void after(typename U::type t)
|
|
|
- {
|
|
|
+ virtual void after(typename U::type t)
|
|
|
+ {
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
- trace_element(true, t, utils::AFTER_COMPUTE);
|
|
|
- trace_internals(true, t, utils::AFTER_COMPUTE);
|
|
|
+ trace_element(true, t, utils::AFTER_COMPUTE);
|
|
|
+ trace_internals(true, t, utils::AFTER_COMPUTE);
|
|
|
#else
|
|
|
- (void) t;
|
|
|
+ (void) t;
|
|
|
#endif
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- virtual const Node < U >* atomic(unsigned int index) const
|
|
|
- {
|
|
|
- typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
- submodel_internals.find(index);
|
|
|
+ virtual const Node<U>* atomic(unsigned int index) const
|
|
|
+ {
|
|
|
+ typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
+ submodel_internals.find(index);
|
|
|
|
|
|
- if (it == submodel_internals.end()) {
|
|
|
- return this;
|
|
|
- } else {
|
|
|
- return it->second.first->atomic(it->second.second);
|
|
|
- }
|
|
|
- }
|
|
|
+ if (it == submodel_internals.end()) {
|
|
|
+ return this;
|
|
|
+ } else {
|
|
|
+ return it->second.first->atomic(it->second.second);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- virtual void before(typename U::type t)
|
|
|
- {
|
|
|
+ virtual void before(typename U::type t)
|
|
|
+ {
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
- trace_element(true, t, utils::BEFORE_COMPUTE);
|
|
|
- trace_internals(true, t, utils::BEFORE_COMPUTE);
|
|
|
- trace_externals(true, t, utils::BEFORE_COMPUTE);
|
|
|
+ trace_element(true, t, utils::BEFORE_COMPUTE);
|
|
|
+ trace_internals(true, t, utils::BEFORE_COMPUTE);
|
|
|
+ trace_externals(true, t, utils::BEFORE_COMPUTE);
|
|
|
#else
|
|
|
- (void) t;
|
|
|
+ (void) t;
|
|
|
#endif
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- virtual void build(W& /* parameters */)
|
|
|
- { }
|
|
|
+ virtual void build(W& /* parameters */) { }
|
|
|
|
|
|
- virtual void build(W& /* parameters */, const std::string& /* json */)
|
|
|
- { }
|
|
|
+ virtual void build(W& /* parameters */, const std::string& /* json */) { }
|
|
|
|
|
|
- virtual bool check(typename U::type t) const
|
|
|
- { return Externals < T, U, V >::check(t); }
|
|
|
+ virtual bool check(typename U::type t) const { return Externals<T, U, V>::check(t); }
|
|
|
|
|
|
- virtual void compute(typename U::type t, bool update) = 0;
|
|
|
+ virtual void compute(typename U::type t, bool update) = 0;
|
|
|
|
|
|
- virtual const Any& get(typename U::type t, unsigned int index) const
|
|
|
- {
|
|
|
- typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
- submodel_internals.find(index);
|
|
|
+ virtual const Any& get(typename U::type t, unsigned int index) const
|
|
|
+ {
|
|
|
+ typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
+ submodel_internals.find(index);
|
|
|
|
|
|
- if (it == submodel_internals.end()) {
|
|
|
- if (type::last_time != t) {
|
|
|
- throw utils::InvalidGet("Variable not computed");
|
|
|
+ if (it == submodel_internals.end()) {
|
|
|
+ if (type::last_time != t) {
|
|
|
+ throw utils::InvalidGet("Variable not computed");
|
|
|
+ }
|
|
|
+ return Internals<T, U, V>::get(index);
|
|
|
+ } else {
|
|
|
+ return it->second.first->get(t, it->second.second);
|
|
|
+ }
|
|
|
}
|
|
|
- return Internals < T, U, V >::get(index);
|
|
|
- } else {
|
|
|
- return it->second.first->get(t, it->second.second);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- template < typename Z, typename K >
|
|
|
- Z get(typename U::type t, unsigned int index) const
|
|
|
- {
|
|
|
- typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
- submodel_internals.find(index);
|
|
|
+ template<typename Z, typename K>
|
|
|
+ Z get(typename U::type t, unsigned int index) const
|
|
|
+ {
|
|
|
+ typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
+ submodel_internals.find(index);
|
|
|
+
|
|
|
+ if (it == submodel_internals.end()) {
|
|
|
+ if (type::last_time != t) {
|
|
|
+ throw utils::InvalidGet("Variable not computed");
|
|
|
+ }
|
|
|
+ const Any& value = Internals<T, U, V>::get(index);
|
|
|
+
|
|
|
+ return static_cast < const T* >(this)->*(value.get<T, Z>());
|
|
|
+ } else {
|
|
|
+ const Any& value = it->second.first->get(t, it->second.second);
|
|
|
+ const Node<U>* object = it->second.first->atomic(
|
|
|
+ it->second.second);
|
|
|
+
|
|
|
+ return static_cast < const K* >(object)->*(value.get<K, Z>());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (it == submodel_internals.end()) {
|
|
|
- if (type::last_time != t) {
|
|
|
- throw utils::InvalidGet("Variable not computed");
|
|
|
+ virtual std::string get(const ValueTypeID& value_type, typename U::type t,
|
|
|
+ unsigned int index) const
|
|
|
+ {
|
|
|
+ typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
+ submodel_internals.find(index);
|
|
|
+
|
|
|
+ if (it == submodel_internals.end()) {
|
|
|
+ Any value = Internals<T, U, V>::get(index);
|
|
|
+
|
|
|
+ switch (value_type) {
|
|
|
+ case DOUBLE:
|
|
|
+ return std::to_string(
|
|
|
+ static_cast < const T* >(this)->*(value.get<T,
|
|
|
+ double>()));
|
|
|
+ case INT:
|
|
|
+ return std::to_string(
|
|
|
+ static_cast < const T* >(this)->*(value.get<T, int>()));
|
|
|
+ case BOOL:
|
|
|
+ return std::to_string(
|
|
|
+ static_cast < const T* >(this)->*(value.get<T, bool>()));
|
|
|
+ default:
|
|
|
+ return "NA";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return it->second.first->get(value_type, t, it->second.second);
|
|
|
+ }
|
|
|
}
|
|
|
- const Any& value = Internals < T, U, V >::get(index);
|
|
|
|
|
|
- return static_cast < const T* >(this)->*(value.get < T, Z >());
|
|
|
- } else {
|
|
|
- const Any& value = it->second.first->get(t, it->second.second);
|
|
|
- const Node < U >* object = it->second.first->atomic(
|
|
|
- it->second.second);
|
|
|
+ virtual void init(typename U::type t, const V& parameters) = 0;
|
|
|
|
|
|
- return static_cast < const K* >(object)->*(value.get < K, Z >());
|
|
|
- }
|
|
|
- }
|
|
|
+ virtual bool is_atomic() const { return false; }
|
|
|
|
|
|
- virtual std::string get(const ValueTypeID& value_type, typename U::type t,
|
|
|
- unsigned int index) const
|
|
|
- {
|
|
|
- typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
- submodel_internals.find(index);
|
|
|
-
|
|
|
- if (it == submodel_internals.end()) {
|
|
|
- Any value = Internals < T, U, V >::get(index);
|
|
|
-
|
|
|
- switch (value_type) {
|
|
|
- case DOUBLE:
|
|
|
- return std::to_string(
|
|
|
- static_cast < const T* >(this)->*(value.get < T,
|
|
|
- double >()));
|
|
|
- case INT:
|
|
|
- return std::to_string(
|
|
|
- static_cast < const T* >(this)->*(value.get < T, int >()));
|
|
|
- case BOOL:
|
|
|
- return std::to_string(
|
|
|
- static_cast < const T* >(this)->*(value.get < T, bool >()));
|
|
|
- default: return "NA";
|
|
|
+ bool is_computed(typename U::type t, unsigned int index) const
|
|
|
+ {
|
|
|
+ typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
+ submodel_internals.find(index);
|
|
|
+
|
|
|
+ if (it == submodel_internals.end()) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return it->second.first->is_computed(t, it->second.second);
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
- return it->second.first->get(value_type, t, it->second.second);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- virtual void init(typename U::type t, const V& parameters) = 0;
|
|
|
+ bool is_stable(typename U::type t) const
|
|
|
+ {
|
|
|
+ typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
+ submodel_internals.begin();
|
|
|
+ bool stable = true;
|
|
|
|
|
|
- virtual bool is_atomic() const
|
|
|
- { return false; }
|
|
|
+ while (it != submodel_internals.end() and stable) {
|
|
|
+ stable = it->second.first->is_stable(t);
|
|
|
+ ++it;
|
|
|
+ }
|
|
|
+ return stable;
|
|
|
+ }
|
|
|
|
|
|
- bool is_computed(typename U::type t, unsigned int index) const
|
|
|
- {
|
|
|
- typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
- submodel_internals.find(index);
|
|
|
+ virtual bool is_updated() const { return Externals<T, U, V>::updated; }
|
|
|
|
|
|
- if (it == submodel_internals.end()) {
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- return it->second.first->is_computed(t, it->second.second);
|
|
|
- }
|
|
|
- }
|
|
|
+ virtual const Node<U>* get_submodel(unsigned int index) const
|
|
|
+ {
|
|
|
+ typename AbstractCoupledModel::Submodels::const_iterator it =
|
|
|
+ submodels.find(index);
|
|
|
|
|
|
- bool is_stable(typename U::type t) const
|
|
|
- {
|
|
|
- typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
|
- submodel_internals.begin();
|
|
|
- bool stable = true;
|
|
|
-
|
|
|
- while (it != submodel_internals.end() and stable) {
|
|
|
- stable = it->second.first->is_stable(t);
|
|
|
- ++it;
|
|
|
- }
|
|
|
- return stable;
|
|
|
- }
|
|
|
+ if (it != submodels.end()) {
|
|
|
+ return it->second;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- virtual bool is_updated() const
|
|
|
- { return Externals < T, U, V >::updated; }
|
|
|
+ virtual const Node<U>* get_submodel(unsigned int index,
|
|
|
+ unsigned int rank) const
|
|
|
+ {
|
|
|
+ typename AbstractCoupledModel::Setsubmodels::const_iterator it =
|
|
|
+ setsubmodels.find(index);
|
|
|
|
|
|
- virtual const Node < U >* get_submodel(unsigned int index) const
|
|
|
- {
|
|
|
- typename AbstractCoupledModel::Submodels::const_iterator it =
|
|
|
- submodels.find(index);
|
|
|
+ if (it != setsubmodels.end() and it->second.size() > rank) {
|
|
|
+ return it->second.at(rank);
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (it != submodels.end()) {
|
|
|
- return it->second;
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
+ virtual std::string path_index(const AbstractModel<U, V>* child,
|
|
|
+ int& index) const
|
|
|
+ {
|
|
|
+ typename Setsubmodels::const_iterator it = setsubmodels.begin();
|
|
|
+ bool found = false;
|
|
|
+
|
|
|
+ index = -1;
|
|
|
+ while (not found and it != setsubmodels.end()) {
|
|
|
+ typename std::vector<type*>::const_iterator itm =
|
|
|
+ it->second.begin();
|
|
|
+
|
|
|
+ index = 0;
|
|
|
+ while (not found and itm != it->second.end()) {
|
|
|
+ found = *itm == child;
|
|
|
+ if (not found) {
|
|
|
+ ++index;
|
|
|
+ ++itm;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ index = found ? index : -1;
|
|
|
+ ++it;
|
|
|
+ }
|
|
|
+ if (type::parent) {
|
|
|
+ int i;
|
|
|
+ std::string p = type::parent->path_index(this, i);
|
|
|
+
|
|
|
+ if (i >= 0) {
|
|
|
+ return p +
|
|
|
+ "/[" + std::to_string(i) + "]" +
|
|
|
+ boost::core::demangle(typeid(*this).name());
|
|
|
+ } else {
|
|
|
+ return p + "/" + boost::core::demangle(typeid(*this).name());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return boost::core::demangle(typeid(*this).name());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- virtual const Node < U >* get_submodel(unsigned int index,
|
|
|
- unsigned int rank) const
|
|
|
- {
|
|
|
- typename AbstractCoupledModel::Setsubmodels::const_iterator it =
|
|
|
- setsubmodels.find(index);
|
|
|
-
|
|
|
- if (it != setsubmodels.end() and it->second.size() > rank) {
|
|
|
- return it->second.at(rank);
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
+ virtual void restore(const context::State<U>& state)
|
|
|
+ {
|
|
|
+ typename AbstractCoupledModel::Submodels::const_iterator it =
|
|
|
+ submodels.begin();
|
|
|
|
|
|
- virtual std::string path_index(const AbstractModel < U, V >* child,
|
|
|
- int& index) const
|
|
|
- {
|
|
|
- typename Setsubmodels::const_iterator it = setsubmodels.begin();
|
|
|
- bool found = false;
|
|
|
-
|
|
|
- index = -1;
|
|
|
- while (not found and it != setsubmodels.end()) {
|
|
|
- typename std::vector < type* >::const_iterator itm =
|
|
|
- it->second.begin();
|
|
|
-
|
|
|
- index = 0;
|
|
|
- while (not found and itm != it->second.end()) {
|
|
|
- found = *itm == child;
|
|
|
- if (not found) {
|
|
|
- ++index;
|
|
|
- ++itm;
|
|
|
+ while (it != submodels.end()) {
|
|
|
+ it->second->restore(state.get_substate(it->first));
|
|
|
+ ++it;
|
|
|
}
|
|
|
+ States<T, U, V>::restore(this, state);
|
|
|
+ Internals<T, U, V>::restore(this, state);
|
|
|
+ Externals<T, U, V>::restore(this, state);
|
|
|
}
|
|
|
- index = found ? index : -1;
|
|
|
- ++it;
|
|
|
- }
|
|
|
- if (type::parent) {
|
|
|
- int i;
|
|
|
- std::string p = type::parent->path_index(this, i);
|
|
|
-
|
|
|
- if (i >= 0) {
|
|
|
- return p +
|
|
|
- "/[" + std::to_string(i) + "]" +
|
|
|
- boost::core::demangle(typeid(*this).name());
|
|
|
- } else {
|
|
|
- return p + "/" + boost::core::demangle(typeid(*this).name());
|
|
|
- }
|
|
|
- } else {
|
|
|
- return boost::core::demangle(typeid(*this).name());
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- virtual void restore(const context::State < U >& state)
|
|
|
- {
|
|
|
- typename AbstractCoupledModel::Submodels::const_iterator it =
|
|
|
- submodels.begin();
|
|
|
-
|
|
|
- while (it != submodels.end()) {
|
|
|
- it->second->restore(state.get_substate(it->first));
|
|
|
- ++it;
|
|
|
- }
|
|
|
- States < T, U, V >::restore(this, state);
|
|
|
- Internals < T, U, V >::restore(this, state);
|
|
|
- Externals < T, U, V >::restore(this, state);
|
|
|
- }
|
|
|
+ virtual void save(context::State<U>& state) const
|
|
|
+ {
|
|
|
+ typename AbstractCoupledModel::Submodels::const_iterator it =
|
|
|
+ submodels.begin();
|
|
|
|
|
|
- virtual void save(context::State < U >& state) const
|
|
|
- {
|
|
|
- typename AbstractCoupledModel::Submodels::const_iterator it =
|
|
|
- submodels.begin();
|
|
|
-
|
|
|
- while (it != submodels.end()) {
|
|
|
- context::State < U > substate;
|
|
|
-
|
|
|
- it->second->save(substate);
|
|
|
- state.add_substate(it->first, substate);
|
|
|
- ++it;
|
|
|
- }
|
|
|
- States < T, U, V >::save(this, state);
|
|
|
- Internals < T, U, V >::save(this, state);
|
|
|
- Externals < T, U, V >::save(this, state);
|
|
|
- }
|
|
|
+ while (it != submodels.end()) {
|
|
|
+ context::State<U> substate;
|
|
|
|
|
|
- virtual void stable()
|
|
|
- { Externals < T, U, V >::updated = false; }
|
|
|
-
|
|
|
- void submodel(unsigned int index, type* model)
|
|
|
- {
|
|
|
- if (model) {
|
|
|
- submodels[index] = model;
|
|
|
- model->set_parent(this);
|
|
|
- } else {
|
|
|
- submodels[index] = 0;
|
|
|
- }
|
|
|
- }
|
|
|
+ it->second->save(substate);
|
|
|
+ state.add_substate(it->first, substate);
|
|
|
+ ++it;
|
|
|
+ }
|
|
|
+ States<T, U, V>::save(this, state);
|
|
|
+ Internals<T, U, V>::save(this, state);
|
|
|
+ Externals<T, U, V>::save(this, state);
|
|
|
+ }
|
|
|
|
|
|
- virtual void trace_element(typename U::type t,
|
|
|
- utils::TraceType type = utils::NONE,
|
|
|
- std::string comment = "") const
|
|
|
- { trace_element(false, t, type, comment); }
|
|
|
-
|
|
|
- virtual void trace_internals(typename U::type t,
|
|
|
- utils::TraceType type) const
|
|
|
- { trace_internals(false, t, type); }
|
|
|
-
|
|
|
- virtual void trace_externals(typename U::type t,
|
|
|
- utils::TraceType type = utils::NONE) const
|
|
|
- { trace_externals(false, t, type); }
|
|
|
-
|
|
|
- virtual void trace_model(typename U::type t,
|
|
|
- utils::TraceType type = utils::NONE) const
|
|
|
- { trace_model(false, t, type); }
|
|
|
-
|
|
|
-private:
|
|
|
- void trace_element(bool from_kernel, typename U::type t,
|
|
|
- utils::TraceType type = utils::NONE,
|
|
|
- std::string comment = "") const
|
|
|
- {
|
|
|
- utils::Trace < utils::DoubleTime >::trace()
|
|
|
- << utils::TraceElement < utils::DoubleTime >(
|
|
|
- from_kernel,
|
|
|
- AbstractCoupledModel < T, U, V, W >::path(this),
|
|
|
- t, type)
|
|
|
- << comment;
|
|
|
- utils::Trace < utils::DoubleTime >::trace().flush();
|
|
|
- }
|
|
|
+ virtual void stable() { Externals<T, U, V>::updated = false; }
|
|
|
|
|
|
- void trace_internals(bool from_kernel, typename U::type t,
|
|
|
- utils::TraceType type) const
|
|
|
- {
|
|
|
- for (size_t i = 0; i < Internals < T, U, V >::size(); ++i) {
|
|
|
- if (not Internals < T, U, V >::get(i).is_null()) {
|
|
|
- utils::Trace < utils::DoubleTime >::trace()
|
|
|
- << utils::TraceElement < utils::DoubleTime >(
|
|
|
- from_kernel,
|
|
|
- AbstractCoupledModel < T, U, V, W >::path(this),
|
|
|
- t, type)
|
|
|
- << utils::KernelInfo(
|
|
|
- Internals < T, U, V >::name(i), true,
|
|
|
- Internals < T, U, V >::get(i).to_string(
|
|
|
- dynamic_cast < const T* >(this))
|
|
|
- );
|
|
|
- utils::Trace < utils::DoubleTime >::trace().flush();
|
|
|
+ void submodel(unsigned int index, type* model)
|
|
|
+ {
|
|
|
+ if (model) {
|
|
|
+ submodels[index] = model;
|
|
|
+ model->set_parent(this);
|
|
|
+ } else {
|
|
|
+ submodels[index] = 0;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- void trace_externals(bool from_kernel, typename U::type t,
|
|
|
- utils::TraceType type = utils::NONE) const
|
|
|
- {
|
|
|
- for (size_t i = 0; i < Externals < T, U, V >::size(); ++i) {
|
|
|
- if (not Externals < T, U, V >::get(i).is_null()) {
|
|
|
- utils::Trace < utils::DoubleTime >::trace()
|
|
|
- << utils::TraceElement < utils::DoubleTime >(
|
|
|
- from_kernel,
|
|
|
- AbstractCoupledModel < T, U, V, W >::path(this),
|
|
|
- t, type)
|
|
|
- << utils::KernelInfo(
|
|
|
- Externals < T, U, V >::name(i), false,
|
|
|
- Externals < T, U, V >::get(i).to_string(
|
|
|
- dynamic_cast < const T* >(this))
|
|
|
- );
|
|
|
- utils::Trace < utils::DoubleTime >::trace().flush();
|
|
|
+ virtual void trace_element(typename U::type t,
|
|
|
+ utils::TraceType type = utils::NONE,
|
|
|
+ std::string comment = "") const { trace_element(false, t, type, comment); }
|
|
|
+
|
|
|
+ virtual void trace_internals(typename U::type t,
|
|
|
+ utils::TraceType type) const { trace_internals(false, t, type); }
|
|
|
+
|
|
|
+ virtual void trace_externals(typename U::type t,
|
|
|
+ utils::TraceType type = utils::NONE) const { trace_externals(false, t, type); }
|
|
|
+
|
|
|
+ virtual void trace_model(typename U::type t,
|
|
|
+ utils::TraceType type = utils::NONE) const { trace_model(false, t, type); }
|
|
|
+
|
|
|
+ private:
|
|
|
+ void trace_element(bool from_kernel, typename U::type t,
|
|
|
+ utils::TraceType type = utils::NONE,
|
|
|
+ std::string comment = "") const
|
|
|
+ {
|
|
|
+ utils::Trace<utils::DoubleTime>::trace()
|
|
|
+ << utils::TraceElement<utils::DoubleTime>(
|
|
|
+ from_kernel,
|
|
|
+ AbstractCoupledModel<T, U, V, W>::path(this),
|
|
|
+ t, type)
|
|
|
+ << comment;
|
|
|
+ utils::Trace<utils::DoubleTime>::trace().flush();
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- void trace_model(bool from_kernel, typename U::type t,
|
|
|
- utils::TraceType type = utils::NONE) const
|
|
|
- {
|
|
|
- trace_element(from_kernel, t, type);
|
|
|
- trace_internals(from_kernel, t, type);
|
|
|
- trace_externals(from_kernel, t, type);
|
|
|
+ void trace_internals(bool from_kernel, typename U::type t,
|
|
|
+ utils::TraceType type) const
|
|
|
+ {
|
|
|
+ for (size_t i = 0; i < Internals<T, U, V>::size(); ++i) {
|
|
|
+ if (not Internals<T, U, V>::get(i).is_null()) {
|
|
|
+ utils::Trace<utils::DoubleTime>::trace()
|
|
|
+ << utils::TraceElement<utils::DoubleTime>(
|
|
|
+ from_kernel,
|
|
|
+ AbstractCoupledModel<T, U, V, W>::path(this),
|
|
|
+ t, type)
|
|
|
+ << utils::KernelInfo(
|
|
|
+ Internals<T, U, V>::name(i), true,
|
|
|
+ Internals<T, U, V>::get(i).to_string(
|
|
|
+ dynamic_cast < const T* >(this))
|
|
|
+ );
|
|
|
+ utils::Trace<utils::DoubleTime>::trace().flush();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // typename AbstractCoupledModel::Submodels::const_iterator it =
|
|
|
- // submodels.begin();
|
|
|
+ void trace_externals(bool from_kernel, typename U::type t,
|
|
|
+ utils::TraceType type = utils::NONE) const
|
|
|
+ {
|
|
|
+ for (size_t i = 0; i < Externals<T, U, V>::size(); ++i) {
|
|
|
+ if (not Externals<T, U, V>::get(i).is_null()) {
|
|
|
+ utils::Trace<utils::DoubleTime>::trace()
|
|
|
+ << utils::TraceElement<utils::DoubleTime>(
|
|
|
+ from_kernel,
|
|
|
+ AbstractCoupledModel<T, U, V, W>::path(this),
|
|
|
+ t, type)
|
|
|
+ << utils::KernelInfo(
|
|
|
+ Externals<T, U, V>::name(i), false,
|
|
|
+ Externals<T, U, V>::get(i).to_string(
|
|
|
+ dynamic_cast < const T* >(this))
|
|
|
+ );
|
|
|
+ utils::Trace<utils::DoubleTime>::trace().flush();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // while (it != submodels.end()) {
|
|
|
- // it->second->trace_model(from_kernel, t, type);
|
|
|
- // ++it;
|
|
|
- // }
|
|
|
- }
|
|
|
+ void trace_model(bool from_kernel, typename U::type t,
|
|
|
+ utils::TraceType type = utils::NONE) const
|
|
|
+ {
|
|
|
+ trace_element(from_kernel, t, type);
|
|
|
+ trace_internals(from_kernel, t, type);
|
|
|
+ trace_externals(from_kernel, t, type);
|
|
|
|
|
|
-protected:
|
|
|
- void link_internal_(unsigned int index, std::string var_name,
|
|
|
- type* model, int sub_index, std::string sub_var_name)
|
|
|
- {
|
|
|
- submodel_internals[index] =
|
|
|
- std::pair < type*, int >(model, sub_index);
|
|
|
+ // typename AbstractCoupledModel::Submodels::const_iterator it =
|
|
|
+ // submodels.begin();
|
|
|
+
|
|
|
+ // while (it != submodels.end()) {
|
|
|
+ // it->second->trace_model(from_kernel, t, type);
|
|
|
+ // ++it;
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected:
|
|
|
+ void link_internal_(unsigned int index, std::string var_name,
|
|
|
+ type* model, int sub_index, std::string sub_var_name)
|
|
|
+ {
|
|
|
+ submodel_internals[index] =
|
|
|
+ std::pair<type*, int>(model, sub_index);
|
|
|
#ifdef WITH_TRACE
|
|
|
- utils::Trace < utils::DoubleTime >::trace()
|
|
|
- << utils::TraceElement < utils::DoubleTime >(
|
|
|
- true,
|
|
|
- AbstractCoupledModel < T, U, V, W >::path(this),
|
|
|
- utils::DoubleTime::null,
|
|
|
- utils::INTERNAL_LINK)
|
|
|
- << utils::KernelInfo(
|
|
|
- var_name,
|
|
|
- AbstractCoupledModel < T, U, V, W >::path(model),
|
|
|
- sub_var_name);
|
|
|
- utils::Trace < utils::DoubleTime >::trace().flush();
|
|
|
+ utils::Trace<utils::DoubleTime>::trace()
|
|
|
+ << utils::TraceElement<utils::DoubleTime>(
|
|
|
+ true,
|
|
|
+ AbstractCoupledModel<T, U, V, W>::path(this),
|
|
|
+ utils::DoubleTime::null,
|
|
|
+ utils::INTERNAL_LINK)
|
|
|
+ << utils::KernelInfo(
|
|
|
+ var_name,
|
|
|
+ AbstractCoupledModel<T, U, V, W>::path(model),
|
|
|
+ sub_var_name);
|
|
|
+ utils::Trace<utils::DoubleTime>::trace().flush();
|
|
|
|
|
|
#endif
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- void I_(std::initializer_list < Var > internals)
|
|
|
- {
|
|
|
- for (typename std::initializer_list < Var >::iterator it =
|
|
|
- internals.begin(); it != internals.end(); ++it) {
|
|
|
+ void I_(std::initializer_list<Var> internals)
|
|
|
+ {
|
|
|
+ for (typename std::initializer_list<Var>::iterator it =
|
|
|
+ internals.begin(); it != internals.end(); ++it) {
|
|
|
|
|
|
- submodel_internals[it->index] =
|
|
|
- std::pair < type*, int >(it->model, it->sub_index);
|
|
|
+ submodel_internals[it->index] =
|
|
|
+ std::pair<type*, int>(it->model, it->sub_index);
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
- utils::Trace < utils::DoubleTime >::trace()
|
|
|
- << utils::TraceElement < utils::DoubleTime >(
|
|
|
- true,
|
|
|
- AbstractCoupledModel < T, U, V, W >::path(this),
|
|
|
- utils::DoubleTime::null,
|
|
|
- utils::INTERNAL_LINK)
|
|
|
- << utils::KernelInfo(
|
|
|
- it->var_name,
|
|
|
- AbstractCoupledModel < T, U, V, W >::path(it->model),
|
|
|
- it->sub_var_name);
|
|
|
- utils::Trace < utils::DoubleTime >::trace().flush();
|
|
|
+ utils::Trace<utils::DoubleTime>::trace()
|
|
|
+ << utils::TraceElement<utils::DoubleTime>(
|
|
|
+ true,
|
|
|
+ AbstractCoupledModel<T, U, V, W>::path(this),
|
|
|
+ utils::DoubleTime::null,
|
|
|
+ utils::INTERNAL_LINK)
|
|
|
+ << utils::KernelInfo(
|
|
|
+ it->var_name,
|
|
|
+ AbstractCoupledModel<T, U, V, W>::path(it->model),
|
|
|
+ it->sub_var_name);
|
|
|
+ utils::Trace<utils::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- void SM_(std::initializer_list < std::pair < unsigned int,
|
|
|
- type* > > models)
|
|
|
- {
|
|
|
- for (typename std::initializer_list < std::pair < unsigned int,
|
|
|
- type* > >::iterator it =
|
|
|
- models.begin(); it != models.end(); ++it) {
|
|
|
- submodels[it->first] = it->second;
|
|
|
- it->second->set_parent(this);
|
|
|
+ void SM_(std::initializer_list<std::pair<unsigned int,
|
|
|
+ type*> > models)
|
|
|
+ {
|
|
|
+ for (typename std::initializer_list<std::pair<unsigned int,
|
|
|
+ type*> >::iterator it =
|
|
|
+ models.begin(); it != models.end(); ++it) {
|
|
|
+ submodels[it->first] = it->second;
|
|
|
+ it->second->set_parent(this);
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
- utils::Trace < utils::DoubleTime >::trace()
|
|
|
- << utils::TraceElement < utils::DoubleTime >(
|
|
|
- true,
|
|
|
- AbstractCoupledModel < T, U, V, W >::path(this),
|
|
|
- utils::DoubleTime::null,
|
|
|
- utils::SUBMODEL_ADD)
|
|
|
- << utils::KernelInfo(
|
|
|
- AbstractCoupledModel < T, U, V, W >::path(it->second));
|
|
|
- utils::Trace < utils::DoubleTime >::trace().flush();
|
|
|
+ utils::Trace<utils::DoubleTime>::trace()
|
|
|
+ << utils::TraceElement<utils::DoubleTime>(
|
|
|
+ true,
|
|
|
+ AbstractCoupledModel<T, U, V, W>::path(this),
|
|
|
+ utils::DoubleTime::null,
|
|
|
+ utils::SUBMODEL_ADD)
|
|
|
+ << utils::KernelInfo(
|
|
|
+ AbstractCoupledModel<T, U, V, W>::path(it->second));
|
|
|
+ utils::Trace<utils::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- void setsubmodel(unsigned int index, type* model)
|
|
|
- {
|
|
|
- if (setsubmodels.find(index) == setsubmodels.end()) {
|
|
|
- setsubmodels[index] = std::vector < type* >();
|
|
|
- }
|
|
|
- setsubmodels[index].push_back(model);
|
|
|
- model->set_parent(this);
|
|
|
+ void setsubmodel(unsigned int index, type* model)
|
|
|
+ {
|
|
|
+ if (setsubmodels.find(index) == setsubmodels.end()) {
|
|
|
+ setsubmodels[index] = std::vector<type*>();
|
|
|
+ }
|
|
|
+ setsubmodels[index].push_back(model);
|
|
|
+ model->set_parent(this);
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
- utils::Trace < utils::DoubleTime >::trace()
|
|
|
- << utils::TraceElement < utils::DoubleTime >(
|
|
|
- true,
|
|
|
- AbstractCoupledModel < T, U, V, W >::path(this),
|
|
|
- utils::DoubleTime::null,
|
|
|
- utils::SUBMODEL_ADD)
|
|
|
- << utils::KernelInfo(
|
|
|
- AbstractCoupledModel < T, U, V, W >::path(model));
|
|
|
- utils::Trace < utils::DoubleTime >::trace().flush();
|
|
|
+ utils::Trace<utils::DoubleTime>::trace()
|
|
|
+ << utils::TraceElement<utils::DoubleTime>(
|
|
|
+ true,
|
|
|
+ AbstractCoupledModel<T, U, V, W>::path(this),
|
|
|
+ utils::DoubleTime::null,
|
|
|
+ utils::SUBMODEL_ADD)
|
|
|
+ << utils::KernelInfo(
|
|
|
+ AbstractCoupledModel<T, U, V, W>::path(model));
|
|
|
+ utils::Trace<utils::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
|
- }
|
|
|
-
|
|
|
-private:
|
|
|
- SubModelInternals submodel_internals;
|
|
|
- Submodels submodels;
|
|
|
- Setsubmodels setsubmodels;
|
|
|
-};
|
|
|
+ }
|
|
|
|
|
|
+ private:
|
|
|
+ SubModelInternals submodel_internals;
|
|
|
+ Submodels submodels;
|
|
|
+ Setsubmodels setsubmodels;
|
|
|
+ };
|
|
|
|
|
|
#define InternalS(index, var, sub_index) link_internal_(index, std::string(ESCAPEQUOTE(index)), var, sub_index, std::string(ESCAPEQUOTE(index)))
|
|
|
#define ITEM_S(index, var, sub_index) Var(index, std::string(ESCAPEQUOTE(index)), var, sub_index, std::string(ESCAPEQUOTE(index)))
|
|
@@ -587,6 +579,7 @@ private:
|
|
|
#define Submodels(L) SM_(UNWRAP_Sub_2 L)
|
|
|
|
|
|
|
|
|
-} }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
#endif
|