HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ensemble_simulations.h
Go to the documentation of this file.
1 
6 #ifndef _ENSEMBLE_SIM_H_
7 #define _ENSEMBLE_SIM_H_
8 
9 #include <stdio.h>
10 #include <vector>
11 #include <simulation.h>
12 
13 #define _ENSEMBLE_SIM_INP_FNAME_ "simulation.inp"
14 
31 {
32  public:
33 
36  {
37  m_is_defined = false;
38  m_sims.clear();
39  m_nsims = 0;
40  m_nproc = -1;
41  m_rank = -1;
42  }
43 
46  {
47  int err = Cleanup((void*) m_sims.data(), m_nsims);
48  if (err) {
49  printf( "Error: CleanUp() returned with status %d on process %d.\n",
50  err, m_rank );
51  }
52  m_sims.clear();
53  }
54 
56  int define(int, int);
57 
59  inline int ReadInputs()
60  {
61  int retval = ::ReadInputs( (void*) m_sims.data(),
62  m_nsims,
63  m_rank );
64  ::WriteInputs( (void*) m_sims.data(),
65  m_nsims,
66  m_rank );
67  return retval;
68  }
69 
71  inline int Initialize()
72  {
73  int retval = ::Initialize( (void*) m_sims.data(),
74  m_nsims );
75  return retval;
76  }
77 
79  inline int InitialSolution()
80  {
81  int retval = ::InitialSolution( (void*) m_sims.data(),
82  m_nsims );
83  return retval;
84  }
85 
87  inline int InitializeBoundaries()
88  {
89  int retval = ::InitializeBoundaries( (void*) m_sims.data(),
90  m_nsims );
91  return retval;
92  }
93 
96  {
97  int retval = ::InitializeImmersedBoundaries( (void*) m_sims.data(),
98  m_nsims );
99  return retval;
100  }
101 
103  inline int InitializePhysics()
104  {
105  int retval = ::InitializePhysics( (void*) m_sims.data(),
106  m_nsims );
107  return retval;
108  }
109 
112  {
113  for (int ns = 0; ns < m_nsims; ns++) {
114  int retval = ::InitializePhysicsData( (void*) &(m_sims[ns]),
115  ns, m_nsims, NULL );
116  if (retval) {
117  fprintf(stderr, "Error in EnsembleSimulations::InitializePhysicsData()\n");
118  fprintf(stderr, " InitializePhysicsData returned with error code %d on rank %d.\n",
119  retval, m_sims[ns].mpi.rank);
120  return retval;
121  }
122  }
123  return 0;
124  }
125 
127  inline int InitializeSolvers()
128  {
129  int retval = ::InitializeSolvers( (void*) m_sims.data(),
130  m_nsims );
131  return retval;
132  }
133 
135  inline int Solve()
136  {
137  int retval = ::Solve( (void*) m_sims.data(),
138  m_nsims,
139  m_rank,
140  m_nproc );
141  return retval;
142  }
143 
145  inline void WriteErrors(double a_wt_solver,
146  double a_wt_total )
147  {
148  ::SimWriteErrors( (void*) m_sims.data(),
149  m_nsims,
150  m_rank,
151  a_wt_solver,
152  a_wt_total );
153  return;
154  }
155 
157  inline bool isDefined() const { return m_is_defined; }
158 
159 #ifndef serial
160 
161  inline int mpiCommDup()
162  {
163  for (int n = 0; n < m_nsims; n++) {
164  MPI_Comm_dup(MPI_COMM_WORLD, &(m_sims[n].mpi.world));
165  }
166  return 0;
167  }
168 #endif
169 
170 #ifdef with_petsc
171 
172  inline void usePetscTS(PetscBool a_flag)
173  {
174  for (int n = 0; n < m_nsims; n++) {
175  m_sims[n].solver.use_petscTS = a_flag;
176  }
177  }
178 
180  inline int SolvePETSc()
181  {
182  int retval = ::SolvePETSc( (void*) m_sims.data(),
183  m_nsims,
184  m_rank,
185  m_nproc );
186  return retval;
187  }
188 #endif
189 
190  protected:
191 
193  int m_nsims;
194  int m_rank,
195  m_nproc;
197  std::vector<SimulationObject> m_sims;
199  private:
200 
201 };
202 
203 #endif
int Cleanup(void *, int)
Definition: Cleanup.c:39
Base class for simulation and declarations for C functions.
Class describing ensemble simulations.
std::vector< SimulationObject > m_sims
int WriteInputs(void *, int, int)
Definition: WriteInputs.c:15
void WriteErrors(double a_wt_solver, double a_wt_total)
void usePetscTS(PetscBool a_flag)
void SimWriteErrors(void *, int, int, double, double)
Base class for a simulation.
Definition: simulation.h:46