HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
EnsembleSimulation Class Reference

Class describing ensemble simulations. More...

#include <ensemble_simulations.h>

Inheritance diagram for EnsembleSimulation:
Simulation

Public Member Functions

 EnsembleSimulation ()
 
 ~EnsembleSimulation ()
 
int define (int, int)
 
int ReadInputs ()
 
int Initialize ()
 
int InitialSolution ()
 
int InitializeBoundaries ()
 
int InitializeImmersedBoundaries ()
 
int InitializePhysics ()
 
int InitializePhysicsData ()
 
int InitializeSolvers ()
 
int Solve ()
 
void WriteErrors (double a_wt_solver, double a_wt_total)
 
bool isDefined () const
 
int mpiCommDup ()
 
void usePetscTS (PetscBool a_flag)
 
int SolvePETSc ()
 
- Public Member Functions inherited from Simulation
 Simulation ()
 
virtual ~Simulation ()
 
virtual int InitializationWrapup ()
 

Protected Attributes

bool m_is_defined
 
int m_nsims
 
int m_rank
 
int m_nproc
 
std::vector< SimulationObjectm_sims
 

Detailed Description

Class describing ensemble simulations.

Class describing ensemble simulations This class contains all data and functions needed to run ensemble simulations, i.e., multiple simulations of the same physics with the same numerical methods but on multiple grids.

This class contains all data and functions needed to run ensemble simulations, i.e., multiple simulations of the same physics with the same numerical methods but on multiple grids.

Definition at line 30 of file ensemble_simulations.h.

Constructor & Destructor Documentation

EnsembleSimulation ( )
inline

Constructor

Definition at line 35 of file ensemble_simulations.h.

36  {
37  m_is_defined = false;
38  m_sims.clear();
39  m_nsims = 0;
40  m_nproc = -1;
41  m_rank = -1;
42  }
std::vector< SimulationObject > m_sims
~EnsembleSimulation ( )
inline

Destructor

Definition at line 45 of file ensemble_simulations.h.

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  }
int Cleanup(void *, int)
Definition: Cleanup.c:39
std::vector< SimulationObject > m_sims

Member Function Documentation

int define ( int  a_rank,
int  a_nproc 
)
virtual

Define this object

Define the ensemble simulation object: This function also reads sparse grids inputs from the file simulation.inp. Rank 0 reads in the inputs and broadcasts them to all the processors.

The format of solver.inp is as follows:

begin
    <keyword>   <value>
    <keyword>   <value>
    ...
    <keyword>   <value>
end

where the list of keywords and their type are:

Keyword name Type Variable Default value
nsims int EnsembleSimulation::m_nsims -1
Parameters
a_rankMPI rank of this process
a_nprocTotal number of MPI ranks

Implements Simulation.

Definition at line 28 of file EnsembleSimulationsDefine.cpp.

31 {
32  if (m_is_defined) {
33  fprintf(stderr,"Error: object already defined on rank %d.\n", a_rank);
34  return 1;
35  }
36 
37  m_rank = a_rank;
38  m_nproc = a_nproc;
39 
40  /* default value */
41  m_nsims = -1;
42 
43  if (!m_rank) {
44 
45  FILE *in;
46  in = fopen(_ENSEMBLE_SIM_INP_FNAME_,"r");
47 
48  if (!in) {
49  fprintf(stderr, "Error in EnsembleSimulations::Define() - %s file not found.\n",
51  } else {
52 
53  int ferr;
54  char word[_MAX_STRING_SIZE_];
55  ferr = fscanf(in,"%s", word); if (ferr != 1) return(1);
56 
57  if (std::string(word) == "begin") {
58 
59  while (std::string(word) != "end") {
60 
61  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
62 
63  if (std::string(word) == "nsims") {
64  ferr = fscanf(in,"%d",&m_nsims); if (ferr != 1) return(1);
65  } else if (std::string(word) != "end") {
66  char useless[_MAX_STRING_SIZE_];
67  ferr = fscanf(in,"%s",useless);
68  printf("Warning: keyword %s in file \"%s\" with value %s not recognized or extraneous. Ignoring.\n",
69  _ENSEMBLE_SIM_INP_FNAME_, word, useless );
70  }
71 
72  if (ferr != 1) return(1);
73  }
74 
75  } else {
76  fprintf(stderr,"Error: Illegal format in file \"%s\". Word read is: %s\n",
78  return 1;
79  }
80 
81  fclose(in);
82 
83  }
84 
85  if (m_nsims < 1) {
86  fprintf(stderr,"Error in InitializeSimulation(): invalid value for nsims (%d)!\n", m_nsims);
87  return 1;
88  }
89 
90  printf("Number of simulation domains: %d\n", m_nsims);
91 
92  }
93 
94 #ifndef serial
95  MPI_Bcast(&m_nsims,1,MPI_INT,0,MPI_COMM_WORLD);
96 #endif
97 
98  if (m_nsims < 0) {
99  return 1;
100  }
101 
102  m_sims.resize(m_nsims);
103  for (int ns = 0; ns < m_nsims; ns++) {
104  m_sims[ns].solver.my_idx = ns;
105  m_sims[ns].solver.nsims = m_nsims;
106  m_sims[ns].mpi.rank = m_rank;
107  m_sims[ns].mpi.nproc = m_nproc;
108  }
109 
110  if (!m_rank) {
111  printf("Allocated simulation object(s).\n");
112  }
113 
114  m_is_defined = true;
115  return 0;
116 }
std::vector< SimulationObject > m_sims
#define _MAX_STRING_SIZE_
Definition: basic.h:14
#define _ENSEMBLE_SIM_INP_FNAME_
int ReadInputs ( )
inlinevirtual

Read solver inputs

Implements Simulation.

Definition at line 59 of file ensemble_simulations.h.

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  }
std::vector< SimulationObject > m_sims
int WriteInputs(void *, int, int)
Definition: WriteInputs.c:15
int Initialize ( )
inlinevirtual

Initialize the simulations

Implements Simulation.

Definition at line 71 of file ensemble_simulations.h.

72  {
73  int retval = ::Initialize( (void*) m_sims.data(),
74  m_nsims );
75  return retval;
76  }
std::vector< SimulationObject > m_sims
int InitialSolution ( )
inlinevirtual

Read initial solution for each simulation

Implements Simulation.

Definition at line 79 of file ensemble_simulations.h.

80  {
81  int retval = ::InitialSolution( (void*) m_sims.data(),
82  m_nsims );
83  return retval;
84  }
std::vector< SimulationObject > m_sims
int InitializeBoundaries ( )
inlinevirtual

Initialize the boundary conditions of the simulations

Implements Simulation.

Definition at line 87 of file ensemble_simulations.h.

88  {
89  int retval = ::InitializeBoundaries( (void*) m_sims.data(),
90  m_nsims );
91  return retval;
92  }
std::vector< SimulationObject > m_sims
int InitializeImmersedBoundaries ( )
inlinevirtual

Initialize the immersed boundary conditions of the simulations

Implements Simulation.

Definition at line 95 of file ensemble_simulations.h.

96  {
97  int retval = ::InitializeImmersedBoundaries( (void*) m_sims.data(),
98  m_nsims );
99  return retval;
100  }
std::vector< SimulationObject > m_sims
int InitializePhysics ( )
inlinevirtual

Initialize the physics of the simulations

Implements Simulation.

Definition at line 103 of file ensemble_simulations.h.

104  {
105  int retval = ::InitializePhysics( (void*) m_sims.data(),
106  m_nsims );
107  return retval;
108  }
std::vector< SimulationObject > m_sims
int InitializePhysicsData ( )
inlinevirtual

Initialize the physics data of the simulations

Implements Simulation.

Definition at line 111 of file ensemble_simulations.h.

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  }
std::vector< SimulationObject > m_sims
int InitializeSolvers ( )
inlinevirtual

Initialize the numerical solvers of the simulations

Implements Simulation.

Definition at line 127 of file ensemble_simulations.h.

128  {
129  int retval = ::InitializeSolvers( (void*) m_sims.data(),
130  m_nsims );
131  return retval;
132  }
std::vector< SimulationObject > m_sims
int Solve ( )
inlinevirtual

Run the simulation using native time integrators

Implements Simulation.

Definition at line 135 of file ensemble_simulations.h.

136  {
137  int retval = ::Solve( (void*) m_sims.data(),
138  m_nsims,
139  m_rank,
140  m_nproc );
141  return retval;
142  }
std::vector< SimulationObject > m_sims
void WriteErrors ( double  a_wt_solver,
double  a_wt_total 
)
inlinevirtual

Write simulation errors and wall times to file

Implements Simulation.

Definition at line 145 of file ensemble_simulations.h.

147  {
148  ::SimWriteErrors( (void*) m_sims.data(),
149  m_nsims,
150  m_rank,
151  a_wt_solver,
152  a_wt_total );
153  return;
154  }
std::vector< SimulationObject > m_sims
void SimWriteErrors(void *, int, int, double, double)
bool isDefined ( ) const
inlinevirtual

Return whether object is defined or not

Implements Simulation.

Definition at line 157 of file ensemble_simulations.h.

157 { return m_is_defined; }
int mpiCommDup ( )
inlinevirtual

Create duplicate MPI communicators

Implements Simulation.

Definition at line 161 of file ensemble_simulations.h.

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  }
std::vector< SimulationObject > m_sims
void usePetscTS ( PetscBool  a_flag)
inlinevirtual

Set flag whether to use PETSc time integration

Implements Simulation.

Definition at line 172 of file ensemble_simulations.h.

173  {
174  for (int n = 0; n < m_nsims; n++) {
175  m_sims[n].solver.use_petscTS = a_flag;
176  }
177  }
std::vector< SimulationObject > m_sims
int SolvePETSc ( )
inlinevirtual

Run the simulation using PETSc time integrators

Implements Simulation.

Definition at line 180 of file ensemble_simulations.h.

181  {
182  int retval = ::SolvePETSc( (void*) m_sims.data(),
183  m_nsims,
184  m_rank,
185  m_nproc );
186  return retval;
187  }
std::vector< SimulationObject > m_sims

Field Documentation

bool m_is_defined
protected

Boolean to show if this object is defined

Definition at line 192 of file ensemble_simulations.h.

int m_nsims
protected

Number of ensemble simulations

Definition at line 193 of file ensemble_simulations.h.

int m_rank
protected

MPI rank of this process

Definition at line 194 of file ensemble_simulations.h.

int m_nproc
protected

Total number of MPI ranks

Definition at line 194 of file ensemble_simulations.h.

std::vector<SimulationObject> m_sims
protected

vector of simulation objects

Definition at line 197 of file ensemble_simulations.h.


The documentation for this class was generated from the following files: