Browse Source

Add new operator for connection definition

Eric Ramat 8 years ago
parent
commit
0b03471242

+ 27 - 1
src/artis/kernel/AbstractAtomicModel.hpp

@@ -169,6 +169,18 @@ private:
     // std::vector < std::vector < double > T::* > externalsV;
 };
 
+template < typename T, typename U, typename V >
+struct IN_SA_t
+{
+    IN_SA_t(double t, AbstractAtomicModel < T, U, V >* model,
+             unsigned int index) : t(t), model(model), index(index)
+    { }
+
+    double t;
+    AbstractAtomicModel < T, U, V >* model;
+    unsigned int index;
+};
+
 template < typename T, typename U, typename V >
 struct OUT_SA_t
 {
@@ -181,6 +193,11 @@ struct OUT_SA_t
     unsigned int index;
 };
 
+template < typename T, typename U, typename V >
+IN_SA_t < T, U, V > IN(double t, AbstractAtomicModel < T, U, V >* model,
+                       unsigned int index)
+{ return IN_SA_t < T, U, V >(t, model, index); }
+
 template < typename T, typename U, typename V >
 OUT_SA_t < T, U, V > OUT(double t,
                             AbstractAtomicModel < T, U, V >* model,
@@ -189,13 +206,22 @@ OUT_SA_t < T, U, V > OUT(double t,
 
 template < typename T1, typename U1, typename V1, typename W1,
            typename T2, typename U2, typename V2 >
-void operator>>(OUT_SA_t < T2, U2, V2 > out, IN_t < T1, U1, V1, W1 > in)
+void operator>>(OUT_SA_t < T2, U2, V2 > out, IN_SA_t < T1, U1, V1 > in)
 {
     if (out.model->is_computed(out.t, out.index)) {
         in.model->put(out.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 >
+void operator>>(OUT_SA_t < T2, U2, V2 > out, IN_SC_t < T1, U1, V1, W1 > in)
+{
+  if (out.model->is_computed(out.t, out.index)) {
+    in.model->put(out.t, in.index, out.model->get(out.t, out.index));
+  }
+}
+
 } }
 
 #endif

+ 12 - 11
src/artis/kernel/AbstractCoupledModel.hpp

@@ -274,12 +274,13 @@ private:
 };
 
 template < typename T, typename U, typename V, typename W >
-struct IN_t
+struct IN_SC_t
 {
-    IN_t(AbstractCoupledModel < T, U, V, W >* model,
-         unsigned int index) : model(model), index(index)
+    IN_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;
 };
@@ -307,9 +308,9 @@ struct OUT_A_t
 };
 
 template < typename T, typename U, typename V, typename W >
-IN_t < T, U, V, W > IN(AbstractCoupledModel < T, U, V, W >* model,
+IN_SC_t < T, U, V, W > IN(double t, AbstractCoupledModel < T, U, V, W >* model,
                        unsigned int index)
-{ return IN_t < T, U, V, W >(model, index); }
+{ return IN_SC_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,
@@ -323,16 +324,16 @@ OUT_A_t < T > OUT(double 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_t < T1, U1, V1, W1 > in)
+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(out.t, in.index, out.model->get(out.t, out.index));
-    }
+  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 T, typename U, typename V, typename W, typename Z >
-void operator>>(OUT_A_t < Z > out, IN_t < T, U, V, W > in)
-{ in.model->put(out.t, in.index, out.value); }
+void operator>>(OUT_A_t < Z > out, IN_SC_t < T, U, V, W > in)
+{ in.model->put(in.t, in.index, out.value); }
 
 } }
 

+ 1 - 1
src/artis/kernel/Simulator.cpp

@@ -1,5 +1,5 @@
 /**
- * @file model/kernel/Simulator.cpp
+ * @file artis/kernel/Simulator.cpp
  * @author See the AUTHORS file
  */
 

+ 8 - 6
src/test/test.cpp

@@ -35,11 +35,13 @@ struct GlobalParameters
 struct ModelParameters
 { };
 
+using namespace artis::kernel;
+using namespace artis::utils;
+
 template < typename T >
-using AbstractAtomicModel = artis::kernel::AbstractAtomicModel <
-    T, artis::utils::DoubleTime, ModelParameters >;
+using AtomicModel = AbstractAtomicModel < T, DoubleTime, ModelParameters >;
 
-class AModel : public AbstractAtomicModel < AModel >
+class AModel : public AtomicModel < AModel >
 {
 public:
     enum externals { };
@@ -77,7 +79,7 @@ private:
     double _dx;
 };
 
-class BModel : public AbstractAtomicModel < BModel >
+class BModel : public AtomicModel < BModel >
 {
 public:
     enum externalsB { BX };
@@ -199,7 +201,7 @@ TEST_CASE("Simulator_tests", "simple")
 {
     GlobalParameters globalParameters;
     ModelParameters modelParameters;
-    Simulator simulator(new RootModel, globalParameters);
+    ::Simulator simulator(new RootModel, globalParameters);
 
     simulator.attachView("Root", new AView);
 
@@ -207,7 +209,7 @@ TEST_CASE("Simulator_tests", "simple")
     simulator.init(0, modelParameters);
     simulator.run(0, 10);
 
-    Output output(simulator.observer());
+    ::Output output(simulator.observer());
 
     output();
 }