HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
CombineSolutions.c
Go to the documentation of this file.
1 
6 #include <arrayfunctions.h>
7 #include <mathfunctions.h>
8 #include <mpivars.h>
9 #include <simulation_object.h>
10 
20  double* const* const a_u_src,
21  const int a_nsims,
22  SimulationObject* a_sim_dst,
23  double* const a_u_dst,
24  const double* const a_coeffs
25  )
26 {
27  HyPar* solver_dst = &(a_sim_dst->solver);
28  MPIVariables* mpi_dst = &(a_sim_dst->mpi);
29 
30  int ndims = solver_dst->ndims;
31  int nvars = solver_dst->nvars;
32  int ghosts = solver_dst->ghosts;
33 
34  /* array size */
35  int* dim_global_dst = solver_dst->dim_global;
36  int dim_dst_wgpt[ndims];
37  _ArrayCopy1D_(dim_global_dst, dim_dst_wgpt, ndims);
38  long size_dst_wgpt = nvars;
39  for (int n=0; n<ndims; n++) {
40  dim_dst_wgpt[n] += 2*ghosts;
41  size_dst_wgpt *= dim_dst_wgpt[n];
42  }
43 
44  /* allocate global data array for combined solution */
45  double *ug_dst_wgpt = NULL;
46  if (!mpi_dst->rank) {
47  ug_dst_wgpt = (double*) calloc (size_dst_wgpt, sizeof(double));
48  _ArraySetValue_(ug_dst_wgpt, size_dst_wgpt, 0.0);
49  }
50 
51  /* for each sparse grids, interpolate onto the dst grid dimension
52  * and add to the solution */
53  for (int n = 0; n < a_nsims; n++) {
54 
55  int* dim_global_src = a_sims_src[n].solver.dim_global;
56  int dim_global_src_wgpt[ndims];
57  _ArrayCopy1D_(dim_global_src, dim_global_src_wgpt, ndims);
58  long size_src_wgpt = nvars;
59  for (int n=0; n<ndims; n++) {
60  dim_global_src_wgpt[n] += 2*ghosts;
61  size_src_wgpt *= dim_global_src_wgpt[n];
62  }
63 
64  double* ug_src_wgpt = NULL;
65  if (!a_sims_src[n].mpi.rank) {
66  ug_src_wgpt = (double*) calloc (size_src_wgpt, sizeof(double));
67  _ArraySetValue_(ug_src_wgpt, size_src_wgpt, 0.0);
68  }
70  (void*) &(a_sims_src[n].mpi),
71  ug_src_wgpt,
72  a_u_src[n],
73  dim_global_src,
74  a_sims_src[n].solver.dim_local,
75  ghosts,
76  nvars );
77 
78  if (!mpi_dst->rank) {
79  double *u_src_interpolated = NULL;
80  InterpolateGlobalnDVar( dim_global_dst,
81  &u_src_interpolated,
82  a_sims_src[n].solver.dim_global,
83  ug_src_wgpt,
84  nvars,
85  ghosts,
86  ndims,
87  a_sims_src[n].solver.isPeriodic );
88  _ArrayAXPY_(u_src_interpolated, a_coeffs[n], ug_dst_wgpt, size_dst_wgpt);
89  free(u_src_interpolated);
90  }
91 
92  }
93 
94  /* now partition the global combined solution to its processor */
96  mpi_dst,
97  (mpi_dst->rank ? NULL : ug_dst_wgpt),
98  a_u_dst,
99  solver_dst->dim_global,
100  solver_dst->dim_local,
101  ghosts,
102  nvars );
103 
104  /* free memory */
105  if (!mpi_dst->rank) free(ug_dst_wgpt);
106 
107  /* done */
108  return;
109 }
110 
int MPIPartitionArraynDwGhosts(int, void *, double *, double *, int *, int *, int, int)
int nvars
Definition: hypar.h:29
MPI related function definitions.
void CombineSolutions(SimulationObject *a_sims_src, double *const *const a_u_src, const int a_nsims, SimulationObject *a_sim_dst, double *const a_u_dst, const double *const a_coeffs)
Contains function definitions for common mathematical functions.
Structure defining a simulation.
Simulation object.
int ndims
Definition: hypar.h:26
int MPIGatherArraynDwGhosts(int, void *, double *, double *, int *, int *, int, int)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int InterpolateGlobalnDVar(const int *const, double **const, const int *const, double *const, const int, const int, const int, const int *const)
#define _ArrayAXPY_(x, a, y, size)
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
int * dim_global
Definition: hypar.h:33
int * isPeriodic
Definition: hypar.h:162