IFEM  90A354
SIMCoupled.h
Go to the documentation of this file.
1 // $Id$
2 //==============================================================================
12 //==============================================================================
13 
14 #ifndef _SIM_COUPLED_H_
15 #define _SIM_COUPLED_H_
16 
17 #include "Property.h"
18 #include "matrix.h"
19 #include <map>
20 
21 class SIMdependency;
22 class ASMbase;
23 class ProcessAdm;
24 class DataExporter;
25 class VecFunc;
26 class TimeStep;
27 class VTF;
28 
29 
34 template<class T1, class T2> class SIMCoupled
35 {
36 public:
38  SIMCoupled(T1& s1, T2& s2) : S1(s1), S2(s2) {}
39 
41  virtual ~SIMCoupled() { S2.setVTF(nullptr); }
42 
44  virtual void setupDependencies() {}
45 
47  bool preprocess()
48  {
49  return S1.preprocess() && S2.preprocess();
50  }
51 
53  const ProcessAdm& getProcessAdm() const { return S1.getProcessAdm(); }
54 
56  int getRefined() const { return S1.getRefined(); }
57 
59  std::string getName(int substep = 1) const
60  {
61  if (substep == 1)
62  return S1.getName();
63  else if (substep == 2)
64  return S2.getName();
65 
66  return "SIMCoupled<" + S1.getName() +","+ S2.getName() +">";
67  }
68 
70  virtual bool advanceStep(TimeStep& tp)
71  {
72  return S1.advanceStep(tp) && S2.advanceStep(tp);
73  }
74 
76  virtual void enableStaggering(bool = true) {}
77 
79  virtual bool solveStep(TimeStep& tp, bool firstS1 = true)
80  {
81  if (firstS1)
82  return S1.solveStep(tp) && S2.solveStep(tp);
83  else
84  return S2.solveStep(tp) && S1.solveStep(tp);
85  }
86 
88  virtual bool saveStep(const TimeStep& tp, int& nBlock)
89  {
90  return S2.saveStep(tp,nBlock) && S1.saveStep(tp,nBlock);
91  }
92 
94  virtual bool saveModel(char* fileName, int& geoBlk, int& nBlock)
95  {
96  if (!S1.saveModel(fileName,geoBlk,nBlock))
97  return false;
98 
99  S2.setVTF(S1.getVTF());
100  return true;
101  }
102 
104  VTF* getVTF() const { return S1.getVTF(); }
105 
107  virtual bool init(const TimeStep& tp)
108  {
109  return S1.init(tp) && S2.init(tp);
110  }
111 
113  virtual void registerDependency(SIMdependency* sim, const std::string& name,
114  short int nvc,
115  const std::vector<ASMbase*>& patches,
116  char diffBasis = 0, int component = 1)
117  {
118  S1.registerDependency(sim, name, nvc, patches, diffBasis, component);
119  S2.registerDependency(sim, name, nvc, patches, diffBasis, component);
120  }
121 
123  virtual void registerDependency(SIMdependency* sim, const std::string& name,
124  short int nvc = 1)
125  {
126  S1.registerDependency(sim, name, nvc);
127  S2.registerDependency(sim, name, nvc);
128  }
129 
131  int getUniquePropertyCode(const std::string& setName, int comp = 0)
132  {
133  return S1.getUniquePropertyCode(setName, comp);
134  }
135 
137  bool createPropertySet(const std::string& setName, int pc)
138  {
139  return S1.createPropertySet(setName, pc);
140  }
141 
143  size_t setVecProperty(int code, Property::Type ptype,
144  VecFunc* field = nullptr, int pflag = -1)
145  {
146  return S1.setVecProperty(code, ptype, field, pflag);
147  }
148 
150  void registerFields(DataExporter& exporter)
151  {
152  S1.registerFields(exporter);
153  S2.registerFields(exporter);
154  }
155 
158  {
159  return S1.setInitialConditions() && S2.setInitialConditions();
160  }
161 
163  bool hasIC(const std::string& name) const
164  {
165  return S1.hasIC(name) || S2.hasIC(name);
166  }
167 
169  utl::vector<double>* getField(const std::string& name)
170  {
171  utl::vector<double>* result = S1.getField(name);
172  if (!result)
173  result = S2.getField(name);
174 
175  return result;
176  }
177 
180  bool serialize(std::map<std::string,std::string>& data)
181  {
182  return S1.serialize(data) && S2.serialize(data);
183  }
184 
187  bool deSerialize(const std::map<std::string,std::string>& data)
188  {
189  return S1.deSerialize(data) && S2.deSerialize(data);
190  }
191 
192 protected:
193  T1& S1;
194  T2& S2;
195 };
196 
197 #endif
Representation of a distributed physical property.
static const double T1[2]
1-point rule coordinates.
Definition: TriangleQuadrature.C:19
Base class for spline-based finite element (FE) assembly drivers.
Definition: ASMbase.h:70
Administer and write data using DataWriters.
Definition: DataExporter.h:38
Class for administration of MPI processes in IFEM library.
Definition: ProcessAdm.h:33
Template class for coupled simulators.
Definition: SIMCoupled.h:35
utl::vector< double > * getField(const std::string &name)
Returns the nodal vector of named field in this SIM.
Definition: SIMCoupled.h:169
int getUniquePropertyCode(const std::string &setName, int comp=0)
Returns a unique integer code for a Property set.
Definition: SIMCoupled.h:131
bool deSerialize(const std::map< std::string, std::string > &data)
Set internal state from a serialized state.
Definition: SIMCoupled.h:187
virtual bool solveStep(TimeStep &tp, bool firstS1=true)
Computes the solution for the current time step.
Definition: SIMCoupled.h:79
virtual ~SIMCoupled()
The destructor nullifies the VTF pointer for the second simulator.
Definition: SIMCoupled.h:41
SIMCoupled(T1 &s1, T2 &s2)
The constructor initializes the references to the two simulators.
Definition: SIMCoupled.h:38
bool serialize(std::map< std::string, std::string > &data)
Serialize internal state for restarting purposes.
Definition: SIMCoupled.h:180
T1 & S1
First substep.
Definition: SIMCoupled.h:193
virtual bool advanceStep(TimeStep &tp)
Advances the time step one step forward.
Definition: SIMCoupled.h:70
virtual bool saveStep(const TimeStep &tp, int &nBlock)
Saves the converged results to VTF-file of a given time step.
Definition: SIMCoupled.h:88
int getRefined() const
Returns current refinement status.
Definition: SIMCoupled.h:56
T2 & S2
Second substep.
Definition: SIMCoupled.h:194
virtual void registerDependency(SIMdependency *sim, const std::string &name, short int nvc=1)
Registers a dependency on a field from another SIM object.
Definition: SIMCoupled.h:123
virtual void setupDependencies()
Sets up field dependencies.
Definition: SIMCoupled.h:44
virtual bool saveModel(char *fileName, int &geoBlk, int &nBlock)
Opens a new VTF-file and writes the model geometry to it.
Definition: SIMCoupled.h:94
const ProcessAdm & getProcessAdm() const
Returns the parallel process administrator.
Definition: SIMCoupled.h:53
std::string getName(int substep=1) const
Returns the name of this (or a substep) simulator.
Definition: SIMCoupled.h:59
virtual void enableStaggering(bool=true)
Enables/disables staggering iteration cycles.
Definition: SIMCoupled.h:76
bool preprocess()
Performs some pre-processing tasks on the FE model.
Definition: SIMCoupled.h:47
bool setInitialConditions()
Sets the initial conditions for the simulators.
Definition: SIMCoupled.h:157
bool hasIC(const std::string &name) const
Checks whether a named initial condition is present.
Definition: SIMCoupled.h:163
VTF * getVTF() const
Returns the current VTF-file object.
Definition: SIMCoupled.h:104
size_t setVecProperty(int code, Property::Type ptype, VecFunc *field=nullptr, int pflag=-1)
Defines a vector field property.
Definition: SIMCoupled.h:143
virtual bool init(const TimeStep &tp)
Initializes for time-dependent simulation.
Definition: SIMCoupled.h:107
void registerFields(DataExporter &exporter)
Registers the field vectors for storage on HDF5 output.
Definition: SIMCoupled.h:150
bool createPropertySet(const std::string &setName, int pc)
Creates a set of Property objects.
Definition: SIMCoupled.h:137
virtual void registerDependency(SIMdependency *sim, const std::string &name, short int nvc, const std::vector< ASMbase * > &patches, char diffBasis=0, int component=1)
Registers a dependency on a field from another SIM object.
Definition: SIMCoupled.h:113
Class administering inter-SIM field dependencies.
Definition: SIMdependency.h:30
Class for encapsulation of general time stepping parameters.
Definition: TimeStep.h:31
Class for output of FE model and results to VTF file.
Definition: VTF.h:58
Vector-valued unary function of a spatial point.
Definition: Function.h:242
A vector class with some added algebraic operations.
Definition: matrix.h:64
Simple template classes for dense rectangular matrices and vectors.
Type
The available property types.
Definition: Property.h:32