8 Commits a3a14adf1a ... 7c09b99b43

Author SHA1 Message Date
  gbeurier 7c09b99b43 Merge branch 'master' of https://gogs.univ-littoral.fr/devs-lab/artis into extended_trace 7 years ago
  gbeurier 225ca4fa17 Added missing externals trace + traceInfo 7 years ago
  Eric Ramat ec52f3530a Add vector to Any/Value 7 years ago
  Eric Ramat c44a18eeea Add new contributor 7 years ago
  Eric Ramat 5d873ea169 Merge remote-tracking branch 'origin/master' 7 years ago
  gbeurier b9d0330e50 Fixed internal (local) on CoupledModels 7 years ago
  Eric Ramat 243fe3d6e8 Remove const to GlobalParameters when simulator creation 7 years ago
  Eric Ramat 85bcd80f39 Change define section of Trace 7 years ago

+ 9 - 2
AUTHORS

@@ -6,10 +6,15 @@ Copyright
 =========
 
 - ULCO
-  - Copyright © 2013-2016
+  - Copyright © 2013-2017
   - Université du Littoral Côte d'Opale
   - http://www.univ-littoral.fr
 
+- Cirad
+  - Copyright © 2017
+  - Cirad
+  - http://www.cirad.fr
+
 Authors
 =======
 
@@ -26,4 +31,6 @@ Main programmer and founder
 
 
 Contributors
-------------
+------------
+
+- Grégory Beurier <beurier@cirad.fr>

+ 8 - 2
src/artis/context/Context.hpp

@@ -54,8 +54,14 @@ public:
     void end(double end)
     { _end = end; }
 
-    const Context& operator=(const Context& /* context */)
-    { assert(false); }
+    const Context& operator=(const Context& context)
+    {
+        _begin = context._begin;
+        _end = context._end;
+        _valid = context._valid;
+        _state = context._state;
+        return *this;
+    }
 
     void saved()
     { _valid = true; }

+ 26 - 0
src/artis/context/Value.hpp

@@ -32,6 +32,8 @@
 #if WIN32
 #include <string>
 #endif
+#include <vector>
+
 namespace artis { namespace context {
 
 class Value
@@ -99,6 +101,21 @@ public:
 
             get_content(v);
             return v ? "true" : "false";
+        } if (is_double_vector()) {
+            std::vector < double > v;
+
+            get_content(v);
+            return "";
+        } else if (is_int_vector()) {
+            std::vector < int > v;
+
+            get_content(v);
+            return "";
+        } else if (is_bool_vector()) {
+            std::vector < bool > v;
+
+            get_content(v);
+            return "";
         } else {
             assert(false);
         }
@@ -107,12 +124,21 @@ public:
     bool is_bool() const
     { return _type_id == typeid(bool).hash_code(); }
 
+    bool is_bool_vector() const
+    { return _type_id == typeid(std::vector < bool >).hash_code(); }
+
     bool is_int() const
     { return _type_id == typeid(int).hash_code(); }
 
+    bool is_int_vector() const
+    { return _type_id == typeid(std::vector < int >).hash_code(); }
+
     bool is_double() const
     { return _type_id == typeid(double).hash_code(); }
 
+    bool is_double_vector() const
+    { return _type_id == typeid(std::vector < double >).hash_code(); }
+
 private:
     void assign(const void* content, size_t size, size_t type_id)
     {

+ 2 - 3
src/artis/kernel/AbstractCoupledModel.hpp

@@ -167,11 +167,10 @@ public:
 
     }
 
-    virtual void build(const W& /* parameters */)
+    virtual void build(W& /* parameters */)
     { }
 
-    virtual void build(const W& /* parameters */,
-                       const std::string& /* json */)
+    virtual void build(W& /* parameters */, const std::string& /* json */)
     { }
 
     virtual bool check(typename U::type t) const

+ 41 - 0
src/artis/kernel/Any.hpp

@@ -26,6 +26,7 @@
 #include <artis/context/Value.hpp>
 
 #include <string>
+#include <vector>
 
 namespace artis { namespace kernel {
 
@@ -104,6 +105,21 @@ public:
         } else if (value.is_bool()) {
             bool v;
 
+            value.get_content(v);
+            put(o, v);
+        } else if (value.is_double_vector()) {
+            std::vector < double > v;
+
+            value.get_content(v);
+            put(o, v);
+        } else if (value.is_int_vector()) {
+            std::vector < int > v;
+
+            value.get_content(v);
+            put(o, v);
+        } else if (value.is_bool_vector()) {
+            std::vector < bool > v;
+
             value.get_content(v);
             put(o, v);
         } else {
@@ -132,6 +148,31 @@ public:
 
                     if (q_bool) {
                         return context::Value(o->*(q_bool->value_));
+                    } else {
+                        data < T, std::vector < double > >* q_double_v =
+                            dynamic_cast < data < T, std::vector <
+                                double > >* >(ptr_);
+
+                        if (q_double_v) {
+                            return context::Value(o->*(q_double_v->value_));
+                        } else {
+                            data < T, std::vector < int > >* q_int_v =
+                                dynamic_cast < data < T, std::vector <
+                                    int > >* >(ptr_);
+
+                            if (q_int_v) {
+                                return context::Value(o->*(q_int_v->value_));
+                            } else {
+                                data < T, std::vector < bool > >* q_bool_v =
+                                    dynamic_cast < data < T, std::vector <
+                                        bool > >* >(ptr_);
+
+                                if (q_bool_v) {
+                                    return context::Value(
+                                        o->*(q_bool_v->value_));
+                                }
+                            }
+                        }
                     }
                 }
             }

+ 24 - 2
src/artis/kernel/Externals.hpp

@@ -85,6 +85,17 @@ public:
             }
             externals[it->index] = std::make_pair(-1, it->var);
             external_names[it->index] = it->name;
+
+#ifdef WITH_TRACE
+            utils::Trace < utils::DoubleTime >::trace()
+                    << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
+                                                                 utils::KERNEL)
+                    << "EXTERNAL - "
+                    << typeid(T).name()
+                    << " declare "
+                    << it->name;
+            utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
         }
     }
 
@@ -97,6 +108,17 @@ public:
         }
         externals[index] = std::make_pair(-1, var);
         external_names[index] = name;
+
+#ifdef WITH_TRACE
+            utils::Trace < utils::DoubleTime >::trace()
+                    << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
+                                                                 utils::KERNEL)
+                    << "EXTERNAL - "
+                    << typeid(T).name()
+                    << " declare "
+                    << name;
+            utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
     }
 
     bool is_ready(typename U::type t, unsigned int index) const
@@ -125,9 +147,9 @@ public:
                     << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
                                                                  utils::KERNEL)
                     << "PUT - "
-                    << external_names[index] << " = " << get(index).to_string(dynamic_cast < const T* >(this))
+                    << get(index).to_string(dynamic_cast < const T* >(this))
                     << " in "
-                    << typeid(T).name();
+                    << typeid(T).name() << ":" << external_names[index];
             utils::Trace < utils::DoubleTime >::trace().flush();
 #endif
     }

+ 3 - 2
src/artis/kernel/Simulator.hpp

@@ -36,11 +36,11 @@ class Simulator
 {
 public:
     Simulator(artis::kernel::AbstractCoupledModel < T, U, V, W >* model,
-              const W& parameters) : _model(model), _observer(model)
+              W& parameters) : _model(model), _observer(model)
     { _model->build(parameters); }
 
     Simulator(artis::kernel::AbstractCoupledModel < T, U, V, W >* model,
-              const W& parameters, const std::string& json)
+              W& parameters, const std::string& json)
         : _model(model), _observer(model)
     { _model->build(parameters, json); }
 
@@ -54,6 +54,7 @@ public:
     {
         _model->init(time, parameters);
         _observer.init();
+
     }
 
     const observer::Observer < U, V >& observer() const

+ 24 - 5
src/artis/utils/Trace.hpp

@@ -20,8 +20,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef UTILS_TRACE
-#define UTILS_TRACE
+#ifndef ARTIS_UTILS_TRACE
+#define ARTIS_UTILS_TRACE
 
 #include <algorithm>
 #include <iterator>
@@ -32,11 +32,30 @@
 #include <vector>
 
 #include <artis/utils/DateTime.hpp>
+#include <artis/kernel/Any.hpp>
 
 namespace artis { namespace utils {
 
 enum TraceType { NONE = 0, CHECK, COMPUTE, INIT, KERNEL, PUT };
 
+enum InformationType { CONSTRUCTION, DESTRUCTION,
+                       BEFORE_COMPUTE, AFTER_COMPUTE, INTERNAL_VALUE,
+                       EXTERNAL_VALUE, PUT_TO_EXTERNAL, LINK_INTERNAL };
+
+struct TraceInfo
+{
+
+    std::string         _src_model_name;
+    artis::kernel::Any  _value;
+    InformationType     _type;
+    std::string         _tgt_model_model;
+
+    TraceInfo(const std::string& src_model_name, artis::kernel::Any value,
+                 InformationType type, const std::string& tgt_model_model = "") :
+        _src_model_name(src_model_name), _value(value), _type(type), _tgt_model_model(tgt_model_model)
+    { }
+};
+
 template < class Time >
 class TraceElement
 {
@@ -124,9 +143,9 @@ 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" :
-                                                 utils::DateTime::toJulianDay(it->get_time());
+            std::string date = it->get_time() == -1 ? "construction" :
+                                    it->get_time() == 0 ? "initialization" :
+                                         utils::DateTime::toJulianDay(it->get_time());
             ss << "TRACE: " << it->get_model_name() << " at "
                << date << " <";
             switch (it->get_type())