|
@@ -77,6 +77,18 @@ public:
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
virtual void before(typename U::type t)
|
|
virtual void before(typename U::type t)
|
|
{
|
|
{
|
|
|
|
|
|
@@ -103,47 +115,75 @@ public:
|
|
|
|
|
|
virtual void compute(typename U::type t, bool update) = 0;
|
|
virtual void compute(typename U::type t, bool update) = 0;
|
|
|
|
|
|
- virtual double get(typename U::type t, unsigned int index) const
|
|
|
|
|
|
+ virtual const Any& get(typename U::type t, unsigned int index) const
|
|
{
|
|
{
|
|
typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
submodel_internals.find(index);
|
|
submodel_internals.find(index);
|
|
|
|
|
|
if (it == submodel_internals.end()) {
|
|
if (it == submodel_internals.end()) {
|
|
- return static_cast < const T* >(this)->*(
|
|
|
|
- Internals < T, U >::get(index));
|
|
|
|
|
|
+ if (type::last_time != t) {
|
|
|
|
+ throw utils::InvalidGet("Variable not computed");
|
|
|
|
+ }
|
|
|
|
+ return Internals < T, U >::get(index);
|
|
} else {
|
|
} else {
|
|
return it->second.first->get(t, it->second.second);
|
|
return it->second.first->get(t, it->second.second);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- virtual int getI(typename U::type t, unsigned int index) const
|
|
|
|
|
|
+ template < typename Z, typename K >
|
|
|
|
+ Z get(typename U::type t, unsigned int index) const
|
|
{
|
|
{
|
|
typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
submodel_internals.find(index);
|
|
submodel_internals.find(index);
|
|
|
|
|
|
if (it == submodel_internals.end()) {
|
|
if (it == submodel_internals.end()) {
|
|
- return static_cast < const T* >(this)->*(
|
|
|
|
- Internals < T, U >::getI(index));
|
|
|
|
|
|
+ if (type::last_time != t) {
|
|
|
|
+ throw utils::InvalidGet("Variable not computed");
|
|
|
|
+ }
|
|
|
|
+ const Any& value = Internals < T, U >::get(index);
|
|
|
|
+
|
|
|
|
+ return static_cast < const T* >(this)->*(value.get < T, Z >());
|
|
} else {
|
|
} else {
|
|
- return it->second.first->getI(t, it->second.second);
|
|
|
|
|
|
+ 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 >());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- virtual bool getB(typename U::type t, unsigned int index) const
|
|
|
|
|
|
+ virtual std::string get(const ValueType& value_type, typename U::type t,
|
|
|
|
+ unsigned int index) const
|
|
{
|
|
{
|
|
typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
submodel_internals.find(index);
|
|
submodel_internals.find(index);
|
|
|
|
|
|
if (it == submodel_internals.end()) {
|
|
if (it == submodel_internals.end()) {
|
|
- return static_cast < const T* >(this)->*(
|
|
|
|
- Internals < T, U >::getB(index));
|
|
|
|
|
|
+ Any value = Internals < T, U >::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 {
|
|
} else {
|
|
- return it->second.first->getB(t, it->second.second);
|
|
|
|
|
|
+ return it->second.first->get(value_type, t, it->second.second);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
virtual void init(typename U::type t, const V& parameters) = 0;
|
|
virtual void init(typename U::type t, const V& parameters) = 0;
|
|
|
|
|
|
|
|
+ virtual bool is_atomic() const
|
|
|
|
+ { return false; }
|
|
|
|
+
|
|
bool is_computed(typename U::type t, unsigned int index) const
|
|
bool is_computed(typename U::type t, unsigned int index) const
|
|
{
|
|
{
|
|
typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
typename AbstractCoupledModel::SubModelInternals::const_iterator it =
|
|
@@ -289,24 +329,17 @@ protected:
|
|
void internal(unsigned int index, double T::* var)
|
|
void internal(unsigned int index, double T::* var)
|
|
{ Internals < T, U >::internal(index, var); }
|
|
{ Internals < T, U >::internal(index, var); }
|
|
|
|
|
|
- void I(std::initializer_list < std::pair < unsigned int,
|
|
|
|
- bool T::* > > internals)
|
|
|
|
- { Internals < T, U >::I(internals); }
|
|
|
|
-
|
|
|
|
- void I(std::initializer_list < std::pair < unsigned int,
|
|
|
|
- int T::* > > internals)
|
|
|
|
- { Internals < T, U >::I(internals); }
|
|
|
|
-
|
|
|
|
- void I(std::initializer_list < std::pair < unsigned int,
|
|
|
|
- double T::* > > internals)
|
|
|
|
- { Internals < T, U >::I(internals); }
|
|
|
|
-
|
|
|
|
void internal(unsigned int index, type* model, int sub_index)
|
|
void internal(unsigned int index, type* model, int sub_index)
|
|
{
|
|
{
|
|
submodel_internals[index] =
|
|
submodel_internals[index] =
|
|
std::pair < type*, int >(model, sub_index);
|
|
std::pair < type*, int >(model, sub_index);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ template < typename Z >
|
|
|
|
+ void I(std::initializer_list < std::pair < unsigned int,
|
|
|
|
+ Z T::* > > list)
|
|
|
|
+ { Internals < T, U >::I(list); }
|
|
|
|
+
|
|
void I(std::initializer_list < Var > internals)
|
|
void I(std::initializer_list < Var > internals)
|
|
{
|
|
{
|
|
for (typename std::initializer_list < Var >::iterator it =
|
|
for (typename std::initializer_list < Var >::iterator it =
|
|
@@ -318,8 +351,12 @@ protected:
|
|
|
|
|
|
void submodel(unsigned int index, type* model)
|
|
void submodel(unsigned int index, type* model)
|
|
{
|
|
{
|
|
- submodels[index] = model;
|
|
|
|
- model->set_parent(this);
|
|
|
|
|
|
+ if (model) {
|
|
|
|
+ submodels[index] = model;
|
|
|
|
+ model->set_parent(this);
|
|
|
|
+ } else {
|
|
|
|
+ submodels[index] = 0;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void S(std::initializer_list < std::pair < unsigned int,
|
|
void S(std::initializer_list < std::pair < unsigned int,
|
|
@@ -348,184 +385,6 @@ private:
|
|
Setsubmodels setsubmodels;
|
|
Setsubmodels setsubmodels;
|
|
};
|
|
};
|
|
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-struct SC_t
|
|
|
|
-{
|
|
|
|
- SC_t(double t, AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index) : t(t), model(model), index(index)
|
|
|
|
- { }
|
|
|
|
-
|
|
|
|
- double t;
|
|
|
|
- AbstractCoupledModel < T, U, V, W >* model;
|
|
|
|
- unsigned int index;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-struct IN_SC_t : public SC_t < T, U, V , W >
|
|
|
|
-{
|
|
|
|
- IN_SC_t(double t, AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index) : SC_t < T, U, V, W >(t, model, index)
|
|
|
|
- { }
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-struct IN_SC_I_t : public IN_SC_t < T, U, V , W >
|
|
|
|
-{
|
|
|
|
- IN_SC_I_t(double t, AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index) : IN_SC_t < T, U, V, W >(t, model, index)
|
|
|
|
- { }
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-struct IN_SC_B_t : public IN_SC_t < T, U, V , W >
|
|
|
|
-{
|
|
|
|
- IN_SC_B_t(double t, AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index) : IN_SC_t < T, U, V, W >(t, model, index)
|
|
|
|
- { }
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-struct OUT_SC_t : public SC_t < T, U, V , W >
|
|
|
|
-{
|
|
|
|
- OUT_SC_t(double t, AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index) : SC_t < T, U, V, W >(t, model, index)
|
|
|
|
- { }
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-struct OUT_SC_I_t : public OUT_SC_t < T, U, V , W >
|
|
|
|
-{
|
|
|
|
- OUT_SC_I_t(double t, AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index) : OUT_SC_t < T, U, V, W >(t, model, index)
|
|
|
|
- { }
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-struct OUT_SC_B_t : public SC_t < T, U, V , W >
|
|
|
|
-{
|
|
|
|
- OUT_SC_B_t(double t, AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index) : OUT_SC_t < T, U, V, W >(t, model, index)
|
|
|
|
- { }
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-template < typename T >
|
|
|
|
-struct OUT_A_t
|
|
|
|
-{
|
|
|
|
- OUT_A_t(double t, T value) : t(t), value(value)
|
|
|
|
- { }
|
|
|
|
-
|
|
|
|
- double t;
|
|
|
|
- T value;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-template < typename T >
|
|
|
|
-struct OUT_A_I_t
|
|
|
|
-{
|
|
|
|
- OUT_A_I_t(int t, T value) : t(t), value(value)
|
|
|
|
- { }
|
|
|
|
-
|
|
|
|
- int t;
|
|
|
|
- T value;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-template < typename T >
|
|
|
|
-struct OUT_A_B_t
|
|
|
|
-{
|
|
|
|
- OUT_A_B_t(bool t, T value) : t(t), value(value)
|
|
|
|
- { }
|
|
|
|
-
|
|
|
|
- bool t;
|
|
|
|
- T value;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-IN_SC_t < T, U, V, W > IN(double t, AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index)
|
|
|
|
-{ return IN_SC_t < T, U, V, W >(t, model, index); }
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-IN_SC_I_t < T, U, V, W > IN_I(double t,
|
|
|
|
- AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index)
|
|
|
|
-{ return IN_SC_I_t < T, U, V, W >(t, model, index); }
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-IN_SC_B_t < T, U, V, W > IN_B(double t,
|
|
|
|
- AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index)
|
|
|
|
-{ return IN_SC_B_t < T, U, V, W >(t, model, index); }
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-OUT_SC_t < T, U, V, W > OUT(double t,
|
|
|
|
- AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index)
|
|
|
|
-{ return OUT_SC_t < T, U, V, W >(t, model, index); }
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-OUT_SC_I_t < T, U, V, W > OUT_I(double t,
|
|
|
|
- AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index)
|
|
|
|
-{ return OUT_SC_I_t < T, U, V, W >(t, model, index); }
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W >
|
|
|
|
-OUT_SC_B_t < T, U, V, W > OUT_B(double t,
|
|
|
|
- AbstractCoupledModel < T, U, V, W >* model,
|
|
|
|
- unsigned int index)
|
|
|
|
-{ return OUT_SC_B_t < T, U, V, W >(t, model, index); }
|
|
|
|
-
|
|
|
|
-template < typename T >
|
|
|
|
-OUT_A_t < T > OUT(double t, T value)
|
|
|
|
-{ return OUT_A_t < T >(t, value); }
|
|
|
|
-
|
|
|
|
-template < typename T >
|
|
|
|
-OUT_A_I_t < T > OUT_I(double t, T value)
|
|
|
|
-{ return OUT_A_I_t < T >(t, value); }
|
|
|
|
-
|
|
|
|
-template < typename T >
|
|
|
|
-OUT_A_B_t < T > OUT_B(double t, T value)
|
|
|
|
-{ return OUT_A_B_t < T >(t, value); }
|
|
|
|
-
|
|
|
|
-template < typename T1, typename U1, typename V1, typename W1,
|
|
|
|
- typename T2, typename U2, typename V2, typename W2 >
|
|
|
|
-void operator>>(OUT_SC_t < T2, U2, V2, W2 > out, IN_SC_t < T1, U1, V1, W1 > in)
|
|
|
|
-{
|
|
|
|
- if (out.model->is_computed(out.t, out.index)) {
|
|
|
|
- in.model->put(in.t, in.index, out.model->get(out.t, out.index));
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-template < typename T1, typename U1, typename V1, typename W1,
|
|
|
|
- typename T2, typename U2, typename V2, typename W2 >
|
|
|
|
-void operator>>(OUT_SC_I_t < T2, U2, V2, W2 > out,
|
|
|
|
- IN_SC_I_t < T1, U1, V1, W1 > in)
|
|
|
|
-{
|
|
|
|
- if (out.model->is_computed(out.t, out.index)) {
|
|
|
|
- in.model->put(in.t, in.index, out.model->getI(out.t, out.index));
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-template < typename T1, typename U1, typename V1, typename W1,
|
|
|
|
- typename T2, typename U2, typename V2, typename W2 >
|
|
|
|
-void operator>>(OUT_SC_B_t < T2, U2, V2, W2 > out,
|
|
|
|
- IN_SC_B_t < T1, U1, V1, W1 > in)
|
|
|
|
-{
|
|
|
|
- if (out.model->is_computed(out.t, out.index)) {
|
|
|
|
- in.model->put(in.t, in.index, out.model->getB(out.t, out.index));
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W, typename Z >
|
|
|
|
-void operator>>(OUT_A_t < Z > out, IN_SC_t < T, U, V, W > in)
|
|
|
|
-{ in.model->put(in.t, in.index, out.value); }
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W, typename Z >
|
|
|
|
-void operator>>(OUT_A_I_t < Z > out, IN_SC_I_t < T, U, V, W > in)
|
|
|
|
-{ in.model->put(in.t, in.index, out.value); }
|
|
|
|
-
|
|
|
|
-template < typename T, typename U, typename V, typename W, typename Z >
|
|
|
|
-void operator>>(OUT_A_B_t < Z > out, IN_SC_B_t < T, U, V, W > in)
|
|
|
|
-{ in.model->put(in.t, in.index, out.value); }
|
|
|
|
-
|
|
|
|
} }
|
|
} }
|
|
|
|
|
|
#endif
|
|
#endif
|