Parcourir la source

Added externals and put to trace

gbeurier il y a 7 ans
Parent
commit
a3a14adf1a

+ 12 - 0
src/artis/kernel/AbstractAtomicModel.hpp

@@ -110,6 +110,18 @@ public:
                 utils::Trace < utils::DoubleTime >::trace().flush();
             }
         }
+
+        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 >("KERNEL", t,
+                                                                 utils::KERNEL)
+                    << "*" << Externals < T, U, V >::name(i) << " = "
+                    << Externals < T, U, V >::get(i).to_string(
+                        dynamic_cast < const T* >(this));
+                utils::Trace < utils::DoubleTime >::trace().flush();
+            }
+        }
 #else
         (void) t;
 #endif

+ 72 - 26
src/artis/kernel/AbstractCoupledModel.hpp

@@ -55,9 +55,13 @@ public:
         unsigned int index;
         type* model;
         int sub_index;
+        std::string var_name;
+        std::string sub_var_name;
 
-        Var (unsigned int index, type* model, int sub_index) :
-            index(index), model(model), sub_index(sub_index)
+        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)
         { }
     };
 
@@ -145,6 +149,18 @@ public:
                 utils::Trace < utils::DoubleTime >::trace().flush();
             }
         }
+
+        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 >("KERNEL", t,
+                                                                 utils::KERNEL)
+                    << "*" << Externals < T, U, V >::name(i) << " = "
+                    << Externals < T, U, V >::get(i).to_string(
+                        dynamic_cast < const T* >(this));
+                utils::Trace < utils::DoubleTime >::trace().flush();
+            }
+        }
 #else
         (void) t;
 #endif
@@ -368,28 +384,43 @@ public:
     }
 
 protected:
-     void change_internal(unsigned int index, double T::* var)
-     {
-         submodel_internals.erase(index);
-         Internals < T, U, V >::internal(index, var);
-     }
-
-     void change_internal(unsigned int index, int T::* var)
-     {
-         submodel_internals.erase(index);
-         Internals < T, U, V >::internalI(index, var);
-     }
-
-     void change_internal(unsigned int index, bool T::* var)
-     {
-         submodel_internals.erase(index);
-         Internals < T, U, V >::internalB(index, var);
-     }
-
-    void internal_(unsigned int index, type* model, int sub_index)
+//     void change_internal(unsigned int index, double T::* var)
+//     {
+//         submodel_internals.erase(index);
+//         Internals < T, U, V >::internal(index, var);
+//     }
+
+//     void change_internal(unsigned int index, int T::* var)
+//     {
+//         submodel_internals.erase(index);
+//         Internals < T, U, V >::internalI(index, var);
+//     }
+
+//     void change_internal(unsigned int index, bool T::* var)
+//     {
+//         submodel_internals.erase(index);
+//         Internals < T, U, V >::internalB(index, var);
+//     }
+
+    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 >("KERNEL", -1,
+                                                                     utils::KERNEL)
+                        << "LINK INTERNAL "
+                        << AbstractCoupledModel < T, U, V, W >::path(this)
+                        << ":"
+                        << var_name
+                        << " to "
+                        << AbstractCoupledModel < T, U, V, W >::path(model)
+                        << ":"
+                        << sub_var_name;
+                utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
     }
 
     void I_(std::initializer_list < Var > internals)
@@ -399,6 +430,21 @@ protected:
 
             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 >("KERNEL", -1,
+                                                                     utils::KERNEL)
+                        << "LINK INTERNAL "
+                        << AbstractCoupledModel < T, U, V, W >::path(this)
+                        << ":"
+                        << it->var_name
+                        << " to "
+                        << AbstractCoupledModel < T, U, V, W >::path(it->model)
+                        << ":"
+                        << it->sub_var_name;
+                utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
         }
     }
 
@@ -415,7 +461,7 @@ protected:
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
                                                          utils::KERNEL)
-            << "ADD SUBMODEL - "
+            << "SUBMODEL - "
             << AbstractCoupledModel < T, U, V, W >::path(it->second)
             << " to "
             << AbstractCoupledModel < T, U, V, W >::path(this);
@@ -437,9 +483,9 @@ protected:
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
                                                          utils::KERNEL)
-            << "ADD SUBMODEL - "
+            << "SUBMODEL - "
             << AbstractCoupledModel < T, U, V, W >::path(model)
-            << " to "
+            << " added to "
             << AbstractCoupledModel < T, U, V, W >::path(this);
         utils::Trace < utils::DoubleTime >::trace().flush();
 #endif
@@ -451,9 +497,9 @@ private:
     Setsubmodels setsubmodels;
 };
 
-#define InternalS(index, var, sub_index) internal_(index, var, sub_index)
 
-#define ITEM_S(index, var, sub_index) Var(index, var, sub_index)
+#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)))
 #define UNWRAP_ITEM_S(...) ITEM_S __VA_ARGS__
 #define LIST_S_16(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15, L16) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12), UNWRAP_ITEM_S(L13), UNWRAP_ITEM_S(L14), UNWRAP_ITEM_S(L15), UNWRAP_ITEM_S(L16) }
 #define LIST_S_15(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12), UNWRAP_ITEM_S(L13), UNWRAP_ITEM_S(L14), UNWRAP_ITEM_S(L15) }

+ 17 - 0
src/artis/kernel/Externals.hpp

@@ -54,6 +54,12 @@ public:
     virtual ~Externals()
     { }
 
+    const Any& get(unsigned int index) const
+    { return externals.at(index).second; }
+
+    const std::string& name(unsigned int index) const
+    { return external_names.at(index); }
+
     bool check(typename U::type t) const
     {
         bool OK = true;
@@ -113,6 +119,17 @@ public:
                 updated = true;
             }
         }
+
+#ifdef WITH_TRACE
+            utils::Trace < utils::DoubleTime >::trace()
+                    << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
+                                                                 utils::KERNEL)
+                    << "PUT - "
+                    << external_names[index] << " = " << get(index).to_string(dynamic_cast < const T* >(this))
+                    << " in "
+                    << typeid(T).name();
+            utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
     }
 
     virtual void restore(AbstractModel < U, V >* model,

+ 27 - 4
src/artis/kernel/Internals.hpp

@@ -60,14 +60,26 @@ public:
     void I_(std::initializer_list < element < W > > list)
     {
         for (typename std::initializer_list <element < W > >::iterator it =
-                 list.begin(); it != list.end(); ++it) {
+             list.begin(); it != list.end(); ++it) {
             if (internals.size() <= it->index) {
                 internals.resize(it->index + 1);
                 internal_names.resize(it->index + 1, std::string());
             }
             internals[it->index] = it->var;
             internal_names[it->index] = it->name;
+
+#ifdef WITH_TRACE
+            utils::Trace < utils::DoubleTime >::trace()
+                    << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
+                                                                 utils::KERNEL)
+                    << "INTERNAL - "
+                    << typeid(T).name()
+                    << " declare "
+                    << it->name;
+            utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
         }
+
     }
 
     template < typename W >
@@ -79,6 +91,17 @@ public:
         }
         internals[index] = Any(var);
         internal_names[index] = name;
+
+#ifdef WITH_TRACE
+            utils::Trace < utils::DoubleTime >::trace()
+                    << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
+                                                                 utils::KERNEL)
+                    << "INTERNAL - "
+                    << typeid(T).name()
+                    << " declare "
+                    << name;
+            utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
     }
 
     const std::string& name(unsigned int index) const
@@ -105,7 +128,7 @@ public:
         unsigned int index = 0;
 
         for (typename std::vector < Any >::const_iterator it =
-                 internals.begin(); it != internals.end(); ++it) {
+             internals.begin(); it != internals.end(); ++it) {
             if (not it->is_null()) {
                 state.add_internal(index,
                                    it->save < T >(
@@ -119,12 +142,12 @@ public:
     { return internals.size(); }
 
 private:
-    std::vector < Any > internals;
     std::vector < std::string > internal_names;
+    std::vector < Any > internals;
 };
 
 #define Internal(index, var)                                    \
-        internal_(index, std::string(ESCAPEQUOTE(index)), var)
+    internal_(index, std::string(ESCAPEQUOTE(index)), var)
 
 #define Internals(W,L) I_< W >(UNWRAP2 L)
 

+ 2 - 2
src/artis/utils/Trace.hpp

@@ -124,8 +124,8 @@ public:
         for (typename TraceElements < Time >::const_iterator it =
                  TraceElements < Time >::begin();
              it != TraceElements < Time >::end(); ++it) {
-            std::string date = it->get_time() == -1 ? "Start" :
-                                    it->get_time() == 0 ? "End" :
+            std::string date = it->get_time() == -1 ? "start" :
+                                    it->get_time() == 0 ? "end" :
                                                  utils::DateTime::toJulianDay(it->get_time());
             ss << "TRACE: " << it->get_model_name() << " at "
                << date << " <";

+ 7 - 2
src/test/models.hpp

@@ -95,7 +95,7 @@ class BModel : public AtomicModel < BModel >
 {
 public:
     enum externals { IX, BX, DX };
-    enum internals { IY, BY, DY, IZ };
+    enum internals { IY, IZ, BY, DY };
     enum states { N };
 
     BModel()
@@ -159,7 +159,7 @@ class RootModel : public CoupledModel < RootModel >
 {
 public:
     enum submodels { A, B };
-    enum internals { IY, BY, DY, IZ };
+    enum internals { IY, BY, DY, IZ, DX };
     enum states { N };
 
     RootModel() : _a(new AModel), _b(new BModel)
@@ -168,6 +168,7 @@ public:
         Submodels(((A, _a.get()), (B, _b.get())));
 
         // internals
+        Internal(DX, &RootModel::_dx);
         InternalsS(((IY, _b.get(), BModel::IY), (IZ, _b.get(), BModel::IZ)));
         InternalS(BY, _b.get(), BModel::BY);
 
@@ -199,6 +200,7 @@ public:
         _a->init(t, parameters);
         _b->init(t, parameters);
         _n = 0;
+        _dx = 0;
     }
 
 private:
@@ -206,6 +208,9 @@ private:
     std::unique_ptr < AModel > _a;
     std::unique_ptr < BModel > _b;
 
+    //internals
+    double _dx;
+
     // states
     int _n;
 };