HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
CombineSolutions.c File Reference

Functions to combine solutions on multiple grids on a target grid. More...

#include <arrayfunctions.h>
#include <mathfunctions.h>
#include <mpivars.h>
#include <simulation_object.h>

Go to the source code of this file.

Functions

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)
 

Detailed Description

Functions to combine solutions on multiple grids on a target grid.

Author
Debojyoti Ghosh

Definition in file CombineSolutions.c.

Function Documentation

◆ CombineSolutions()

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 
)

This function combines solutions on multiple grids on a target grid using given coefficients.

The source grids may have varying processor layouts, so they are all gathered on to rank 0, interpolated on to the target grid, and combined. The result is partitioned to the destination processor layout.

Parameters
a_sims_srcArray of simulation objects of type SimulationObject
a_u_srcArray of source solutions
a_nsimsNumber of simulation objects
a_sim_dstsimulation object corresponding to destination
a_u_dstDestination solution array
a_coeffsCombination coefficients for the source solutions

Definition at line 19 of file CombineSolutions.c.

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 }
int MPIPartitionArraynDwGhosts(int, void *, double *, double *, int *, int *, int, int)
int nvars
Definition: hypar.h:29
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)
int * dim_global
Definition: hypar.h:33