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

Computes the diff between PDE and ROM solutions. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <basic.h>
#include <common.h>
#include <arrayfunctions.h>
#include <timeintegration.h>
#include <mpivars.h>
#include <hypar.h>

Go to the source code of this file.

Functions

int CalculateROMDiff (void *s, void *m)
 

Detailed Description

Computes the diff between PDE and ROM solutions.

Author
Debojyoti Ghosh

Definition in file CalculateROMDiff.c.

Function Documentation

◆ CalculateROMDiff()

int CalculateROMDiff ( void *  s,
void *  m 
)

Calculates the L1, L2, & Linf norms of the diff between the PDE solution and the predicted solution by libROM. error in the solution if the exact solution is

Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables

Definition at line 24 of file CalculateROMDiff.c.

26 {
27  HyPar* solver = (HyPar*) s;
28  MPIVariables* mpi = (MPIVariables*) m;
29  double sum = 0, global_sum = 0;
30 
31  static const double tolerance = 1e-15;
32 
33  int size = solver->npoints_local_wghosts * solver->nvars;
34  double* u_diff = (double*) calloc (size, sizeof(double));
35 
36  /* calculate solution norms (for relative error) */
37  double solution_norm[3] = {0.0,0.0,0.0};
38  /* L1 */
39  sum = ArraySumAbsnD ( solver->nvars,
40  solver->ndims,
41  solver->dim_local,
42  solver->ghosts,
43  solver->index,
44  solver->u );
45  global_sum = 0; MPISum_double(&global_sum,&sum,1,&mpi->world);
46  solution_norm[0] = global_sum/((double)solver->npoints_global);
47  /* L2 */
48  sum = ArraySumSquarenD ( solver->nvars,
49  solver->ndims,
50  solver->dim_local,
51  solver->ghosts,
52  solver->index,
53  solver->u );
54  global_sum = 0; MPISum_double(&global_sum,&sum,1,&mpi->world);
55  solution_norm[1] = sqrt(global_sum/((double)solver->npoints_global));
56  /* Linf */
57  sum = ArrayMaxnD ( solver->nvars,
58  solver->ndims,
59  solver->dim_local,
60  solver->ghosts,
61  solver->index
62  ,solver->u );
63  global_sum = 0; MPIMax_double(&global_sum,&sum,1,&mpi->world);
64  solution_norm[2] = global_sum;
65 
66  /* set u_diff to PDE solution */
67  _ArrayCopy1D_(solver->u, u_diff, size);
68  /* subtract the ROM solutions */
69  _ArrayAXPY_(solver->u_rom_predicted, -1.0, u_diff, size);
70 
71  /* calculate L1 norm of error */
72  sum = ArraySumAbsnD ( solver->nvars,
73  solver->ndims,
74  solver->dim_local,
75  solver->ghosts,
76  solver->index,
77  u_diff );
78  global_sum = 0; MPISum_double(&global_sum,&sum,1,&mpi->world);
79  solver->rom_diff_norms[0] = global_sum/((double)solver->npoints_global);
80 
81  /* calculate L2 norm of error */
82  sum = ArraySumSquarenD ( solver->nvars,
83  solver->ndims,
84  solver->dim_local,
85  solver->ghosts,
86  solver->index,
87  u_diff );
88  global_sum = 0; MPISum_double(&global_sum,&sum,1,&mpi->world);
89  solver->rom_diff_norms[1] = sqrt(global_sum/((double)solver->npoints_global));
90 
91  /* calculate Linf norm of error */
92  sum = ArrayMaxnD ( solver->nvars,
93  solver->ndims,
94  solver->dim_local,
95  solver->ghosts,
96  solver->index,
97  u_diff );
98  global_sum = 0; MPIMax_double(&global_sum,&sum,1,&mpi->world);
99  solver->rom_diff_norms[2] = global_sum;
100 
101  /* decide whether to normalize and report relative diff norms,
102  or report absolute diff norms. */
103  if ( (solution_norm[0] > tolerance)
104  && (solution_norm[1] > tolerance)
105  && (solution_norm[2] > tolerance) ) {
106  solver->rom_diff_norms[0] /= solution_norm[0];
107  solver->rom_diff_norms[1] /= solution_norm[1];
108  solver->rom_diff_norms[2] /= solution_norm[2];
109  }
110 
111  free(u_diff);
112  return 0;
113 }
int nvars
Definition: hypar.h:29
int MPISum_double(double *, double *, int, void *)
Definition: MPISum.c:39
long sum(const std::vector< int > &a_iv)
Definition: std_vec_ops.h:18
double * u
Definition: hypar.h:116
int ndims
Definition: hypar.h:26
INLINE double ArraySumAbsnD(int, int, int *, int, int *, double *)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int MPIMax_double(double *, double *, int, void *)
Definition: MPIMax.c:38
#define _ArrayAXPY_(x, a, y, size)
int npoints_global
Definition: hypar.h:40
MPI_Comm world
int * index
Definition: hypar.h:102
int * dim_local
Definition: hypar.h:37
double rom_diff_norms[3]
Definition: hypar.h:405
INLINE double ArrayMaxnD(int, int, int *, int, int *, double *)
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
int npoints_local_wghosts
Definition: hypar.h:42
double * u_rom_predicted
Definition: hypar.h:403
INLINE double ArraySumSquarenD(int, int, int *, int, int *, double *)
#define _ArrayCopy1D_(x, y, size)