Parcourir la source

Added init and in depth trace

gbeurier il y a 7 ans
Parent
commit
131b2bc192

+ 33 - 35
src/artis/kernel/AbstractAtomicModel.hpp

@@ -72,17 +72,7 @@ public:
             << "AFTER - "
             << AbstractAtomicModel < T, U, V >::path(this);
         utils::Trace < utils::DoubleTime >::trace().flush();
-        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 >("KERNEL", t,
-                                                                 utils::KERNEL)
-                    << Internals < T, U, V >::name(i) << " = "
-                    << Internals < T, U, V >::get(i).to_string(
-                        dynamic_cast < const T* >(this));
-                utils::Trace < utils::DoubleTime >::trace().flush();
-            }
-        }
+        trace_model(t);
 #else
         (void) t;
 #endif
@@ -98,30 +88,7 @@ public:
                                                          utils::KERNEL)
             << "BEFORE - "
             << AbstractAtomicModel < T, U, V >::path(this);
-        utils::Trace < utils::DoubleTime >::trace().flush();
-        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 >("KERNEL", t,
-                                                                 utils::KERNEL)
-                    << Internals < T, U, V >::name(i) << " = "
-                    << Internals < T, U, V >::get(i).to_string(
-                        dynamic_cast < const T* >(this));
-                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();
-            }
-        }
+       trace_model(t);
 #else
         (void) t;
 #endif
@@ -210,6 +177,37 @@ public:
         state.last_time(type::last_time);
     }
 
+#ifdef WITH_TRACE
+    virtual void trace_model(typename U::type t) 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 >("KERNEL", t,
+                                                                 utils::KERNEL)
+                    << AbstractAtomicModel < T, U, V >::path(this) << ":"
+                    << Internals < T, U, V >::name(i) << " = "
+                    << Internals < T, U, V >::get(i).to_string(
+                        dynamic_cast < const T* >(this));
+                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)
+                    << AbstractAtomicModel < T, U, V >::path(this) << ":"
+                    << "*" << 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();
+            }
+        }
+    }
+#endif
+
     virtual void stable()
     { Externals < T, U, V >::updated = false; }
 };

+ 48 - 34
src/artis/kernel/AbstractCoupledModel.hpp

@@ -99,17 +99,7 @@ public:
             << "AFTER - "
             << AbstractCoupledModel < T, U, V, W >::path(this);
         utils::Trace < utils::DoubleTime >::trace().flush();
-        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 >("KERNEL", t,
-                                                                 utils::KERNEL)
-                    << Internals < T, U, V >::name(i) << " = "
-                    << Internals < T, U, V >::get(i).to_string(
-                        dynamic_cast < const T* >(this));
-                utils::Trace < utils::DoubleTime >::trace().flush();
-            }
-        }
+        trace_model(t, false);
 #else
         (void) t;
 #endif
@@ -138,29 +128,7 @@ public:
             << "BEFORE - "
             << AbstractCoupledModel < T, U, V, W >::path(this);
         utils::Trace < utils::DoubleTime >::trace().flush();
-        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 >("KERNEL", t,
-                                                                 utils::KERNEL)
-                    << Internals < T, U, V >::name(i) << " = "
-                    << Internals < T, U, V >::get(i).to_string(
-                        dynamic_cast < const T* >(this));
-                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();
-            }
-        }
+        trace_model(t, false);
 #else
         (void) t;
 #endif
@@ -369,6 +337,52 @@ public:
         Externals < T, U, V >::save(this, state);
     }
 
+#ifdef WITH_TRACE
+    virtual void trace_model(typename U::type t) const {
+        trace_model(t, true);
+    }
+    void trace_model(typename U::type t, bool in_depth) 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 >("KERNEL", t,
+                                                                 utils::KERNEL)
+                    << AbstractCoupledModel < T, U, V, W >::path(this) << ":"
+                    << Internals < T, U, V >::name(i) << " = "
+                    << Internals < T, U, V >::get(i).to_string(
+                        dynamic_cast < const T* >(this));
+                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)
+                    << AbstractCoupledModel < T, U, V, W >::path(this) << ":"
+                    << "*" << 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();
+            }
+        }
+
+
+        if(in_depth) {
+            typename AbstractCoupledModel::Submodels::const_iterator it =
+                submodels.begin();
+
+            while (it != submodels.end()) {
+                it->second->trace_model(t);
+                ++it;
+            }
+        }
+    }
+#endif
+
+
     virtual void stable()
     { Externals < T, U, V >::updated = false; }
 

+ 4 - 0
src/artis/kernel/AbstractModel.hpp

@@ -126,6 +126,10 @@ public:
 
     virtual void save(context::State < Time >& state) const = 0;
 
+#ifdef WITH_TRACE
+    virtual void trace_model(typename Time::type t) const = 0;
+#endif
+
     void set_parent(const AbstractModel < Time, Parameters >* p)
     { parent = p; }
 

+ 11 - 0
src/artis/kernel/Simulator.hpp

@@ -50,11 +50,22 @@ public:
     void attachView(const std::string& name, observer::View < U, V >* view)
     { _observer.attachView(name, view); }
 
+
     void init(double time, const V& parameters)
     {
+        std::cout << "LAUNCH INIT" << std::endl;
         _model->init(time, parameters);
         _observer.init();
 
+#ifdef WITH_TRACE
+        utils::Trace < utils::DoubleTime >::trace()
+            << utils::TraceElement < utils::DoubleTime >("KERNEL", 0,
+                                                         utils::KERNEL)
+            << "GLOBAL VALUES - "
+            << _model->path(_model);
+        utils::Trace < utils::DoubleTime >::trace().flush();
+        _model->trace_model(0);
+#endif
     }
 
     const observer::Observer < U, V >& observer() const

+ 14 - 0
src/test/models.hpp

@@ -69,11 +69,16 @@ public:
 
     void compute(double t, bool /* update */)
     {
+        ::Trace::trace() << ::TraceElement("A", t, artis::utils::COMPUTE);
+        ::Trace::trace() << "Start";
+        ::Trace::trace().flush();
+
         ++_ix;
         _bx = not _bx;
         ++_dx;
 
         ::Trace::trace() << ::TraceElement("A", t, artis::utils::COMPUTE);
+        ::Trace::trace() << "Stop";
         ::Trace::trace().flush();
 
     }
@@ -120,12 +125,17 @@ public:
 
     void compute(double t, bool /* update */)
     {
+        ::Trace::trace() << ::TraceElement("B", t, artis::utils::COMPUTE);
+        ::Trace::trace() << "Start";
+        ::Trace::trace().flush();
+
         _iy = _ix + 1;
         _by = not _bx;
         _dy = _dx + 1;
         ++_n;
 
         ::Trace::trace() << ::TraceElement("B", t, artis::utils::COMPUTE);
+        ::Trace::trace() << "Stop";
         ::Trace::trace().flush();
 
     }
@@ -182,6 +192,9 @@ public:
 
     void compute(double t, bool /* update */)
     {
+        ::Trace::trace() << ::TraceElement("ROOT", t, artis::utils::COMPUTE);
+        ::Trace::trace() << "Start";
+        ::Trace::trace().flush();
         (*_a)(t);
         _b->put < double >(t, BModel::DX, _a->get < double >(t, AModel::DX));
         _b->put < int >(t, BModel::IX, _a->get < int >(t, AModel::IX));
@@ -191,6 +204,7 @@ public:
         ++_n;
 
         ::Trace::trace() << ::TraceElement("ROOT", t, artis::utils::COMPUTE);
+        ::Trace::trace() << "Stop";
         ::Trace::trace().flush();
 
     }