HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SparseGridsInitialize.cpp
Go to the documentation of this file.
1 
6 #include <basic.h>
7 #include <arrayfunctions.h>
9 
16 {
17  int ierr;
18 
19  /* find out the number of spatial dimensions */
21 
22  /* make sure full grid simulation object is allocated */
23  if (m_sim_fg == NULL) {
24  fprintf(stderr, "Error in SparseGridsSimulation::Initialize()\n");
25  fprintf(stderr, " m_sim_fg is NULL on rank %d!\n", m_rank);
26  return 1;
27  }
28 
29  /* set full grid processor distribution based on grid size and
30  * number of MPI ranks */
31  GridDimensions dim_fg(m_ndims);
32  for (int d=0; d<m_ndims; d++) dim_fg[d] = m_sim_fg->solver.dim_global[d];
33  ProcDistribution iproc_fg;
34  ComputeProcessorDistribution(iproc_fg, dim_fg);
35  for (int d=0; d<m_ndims; d++) m_sim_fg->mpi.iproc[d] = iproc_fg[d];
37  m_ndims,
38  0,
39  &(m_sim_fg->mpi.world)); CHECKERR(ierr);
40 
41  ::WriteInputs( (void*) m_sim_fg, 1, m_rank);
42  if (!m_rank) {
43  printf("Processor distribution for full grid object: ");
44  for (int d=0; d<m_ndims; d++) printf(" %3d", iproc_fg[d]);
45  printf("\n");
46  }
47 
48  if (!m_rank) printf("Initializing sparse grids...\n");
49  if (!m_rank) printf(" Number of spatial dimensions: %d\n", m_ndims);
50 
51  /* some sanity checks */
52  ierr = SanityChecks();
53  if (ierr) return ierr;
54 
55  /* compute the sizes of grids that go into the combination technique */
56  if (!m_rank) {
57  printf(" Computing sparse grids dimensions...\n");
58  }
59  ierr = ComputeSGDimsAndCoeffs();
60  if (ierr) return ierr;
61  m_nsims_sg = m_combination.size();
62  if (!m_rank) {
63  printf( " Number of sparse grid domains in combination technique: %d\n",
64  m_nsims_sg );
65  }
66  if (m_nsims_sg == 0) {
67  fprintf(stderr, "Error in SparseGridsSimulation::Initialize()\n");
68  fprintf(stderr, " ComputeSGDimsAndCoeffs() returned empty vector!\n");
69  return 1;
70  }
71 
72  /* compute processor distributions for the sparse grids */
73  if (!m_rank) {
74  printf(" Computing processor decompositions...\n");
75  }
76  m_iprocs.resize(m_nsims_sg);
77  for (int i = 0; i < m_nsims_sg; i++) {
79  m_combination[i]._dim_ );
80 
81  if (ierr) return ierr;
82  }
83 
84  /* Print some stuff to screen */
85  if (!m_rank) {
86  printf("Sparse Grids: Combination technique grids sizes and coefficients are:-\n");
87  for (int i = 0; i < m_nsims_sg; i++) {
88  printf(" %3d: dim = (", i);
89  for (int d=0; d<m_ndims; d++) printf(" %4d ", m_combination[i]._dim_[d]);
90  printf("), coeff = %+1.2e, ", m_combination[i]._coeff_);
91  printf("iproc = (");
92  for (int d=0; d<m_ndims; d++) printf(" %4d ", m_iprocs[i][d]);
93  printf(")\n");
94  }
95  }
96 
97  /* allocate full grid data structures (only what is needed) */
99  if (ierr) return ierr;
100 
101  /* create sparse grids simulation objects */
102  m_sims_sg.resize(m_nsims_sg);
103  /* set the solver parameters for the sparse grids sim objects */
104  for (int i = 0; i < m_nsims_sg; i++) {
105 #ifndef serial
106  MPI_Comm_dup(MPI_COMM_WORLD, &(m_sims_sg[i].mpi.world));
107 #endif
108  ierr = SetSolverParameters( m_sims_sg[i],
109  m_combination[i]._dim_,
110  m_iprocs[i],
111  *m_sim_fg,
112  i,
113  m_nsims_sg );
114  if (ierr) return ierr;
115  }
116 
117  /* allocate their data structures (everything) */
118  ierr = ::Initialize( (void*) m_sims_sg.data(), m_nsims_sg);
119  if (ierr) return ierr;
120 
121  /* compute and report total NDOFs for sparse grids */
122  long ndof_sg = 0;
123  for (int i = 0; i < m_nsims_sg; i++) {
124  ndof_sg += m_sims_sg[i].solver.npoints_global;
125  }
126  long ndof_fg = m_sim_fg->solver.npoints_global;
127  if (!m_rank) {
128  printf("Total number of DOFs:-\n");
129  printf(" using sparse grids: %d\n", (int)ndof_sg);
130  printf(" using conventional grid: %d\n", (int)ndof_fg);
131  }
132 
133  /* done */
134  return 0;
135 }
std::vector< SimulationObject > m_sims_sg
int * dim_global
Definition: hypar.h:33
int InitializeBarebones(SimulationObject *)
int SetSolverParameters(SimulationObject &, const GridDimensions &, const ProcDistribution &, const SimulationObject &, const int, const int)
int npoints_global
Definition: hypar.h:40
int WriteInputs(void *, int, int)
Definition: WriteInputs.c:15
int ComputeProcessorDistribution(ProcDistribution &, const GridDimensions &)
MPI_Comm world
#define CHECKERR(ierr)
Definition: basic.h:18
std::vector< int > ProcDistribution
std::vector< ProcDistribution > m_iprocs
Some basic definitions and macros.
std::vector< SGCTElem > m_combination
int ndims
Definition: hypar.h:26
Contains macros and function definitions for common array operations.
#define _coeff_
std::vector< int > GridDimensions
#define _dim_
int MPIBroadcast_integer(int *, int, int, void *)
Definition: MPIBroadcast.c:23