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

Write errors for each simulation. More...

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <basic.h>
#include <common.h>
#include <mpivars.h>
#include <simulation_object.h>

Go to the source code of this file.

Functions

void SimWriteErrors (void *s, int nsims, int rank, double solver_runtime, double main_runtime)
 

Detailed Description

Write errors for each simulation.

Author
Debojyoti Ghosh

Definition in file SimulationWriteErrors.c.

Function Documentation

◆ SimWriteErrors()

void SimWriteErrors ( void *  s,
int  nsims,
int  rank,
double  solver_runtime,
double  main_runtime 
)

Writes out the errors and other data for each simulation.

Parameters
sArray of simulations of type SimulationObject
nsimsNumber of simulations
rankMPI rank of this process
solver_runtimeMeasured runtime of solver
main_runtimeMeasured total runtime

Definition at line 18 of file SimulationWriteErrors.c.

24 {
26  int n;
27 
28  if (!rank) {
29 
30  if (nsims > 1) printf("\n");
31 
32  for (n = 0; n < nsims; n++) {
33 
34  char err_fname[_MAX_STRING_SIZE_],
35  cons_fname[_MAX_STRING_SIZE_],
36  fc_fname[_MAX_STRING_SIZE_];
37  strcpy(err_fname,"errors");
38  strcpy(cons_fname,"conservation");
39  strcpy(fc_fname,"function_counts");
40 #ifdef with_librom
41  char rom_diff_fname[_MAX_STRING_SIZE_];
42  strcpy(rom_diff_fname,"pde_rom_diff");
43 #endif
44 
45 
46  if (nsims > 1) {
47 
48  strcat(err_fname,"_");
49  strcat(cons_fname,"_");
50  strcat(fc_fname,"_");
51 #ifdef with_librom
52  strcat(rom_diff_fname,"_");
53 #endif
54 
55  char index[_MAX_STRING_SIZE_];
56  GetStringFromInteger(n, index, (int)log10(nsims)+1);
57 
58  strcat(err_fname,index);
59  strcat(cons_fname,index);
60  strcat(fc_fname,index);
61 #ifdef with_librom
62  strcat(rom_diff_fname,index);
63 #endif
64  }
65 
66  strcat(err_fname,".dat");
67  strcat(cons_fname,".dat");
68  strcat(fc_fname,".dat");
69 #ifdef with_librom
70  strcat(rom_diff_fname,".dat");
71 #endif
72 
73  FILE *out;
74  /* write out solution errors and wall times to file */
75  out = fopen(err_fname,"w");
76  for (int d=0; d<sim[n].solver.ndims; d++) fprintf(out,"%4d ",sim[n].solver.dim_global[d]);
77  for (int d=0; d<sim[n].solver.ndims; d++) fprintf(out,"%4d ",sim[n].mpi.iproc[d]);
78  fprintf(out,"%1.16E ",sim[n].solver.dt);
79  fprintf(out,"%1.16E %1.16E %1.16E ",sim[n].solver.error[0],sim[n].solver.error[1],sim[n].solver.error[2]);
80  fprintf(out,"%1.16E %1.16E\n",solver_runtime,main_runtime);
81  fclose(out);
82  /* write out conservation errors to file */
83  out = fopen(cons_fname,"w");
84  for (int d=0; d<sim[n].solver.ndims; d++) fprintf(out,"%4d ",sim[n].solver.dim_global[d]);
85  for (int d=0; d<sim[n].solver.ndims; d++) fprintf(out,"%4d ",sim[n].mpi.iproc[d]);
86  fprintf(out,"%1.16E ",sim[n].solver.dt);
87  for (int d=0; d<sim[n].solver.nvars; d++) fprintf(out,"%1.16E ",sim[n].solver.ConservationError[d]);
88  fprintf(out,"\n");
89  fclose(out);
90  /* write out function call counts to file */
91  out = fopen(fc_fname,"w");
92  fprintf(out,"%d\n",sim[n].solver.n_iter);
93  fprintf(out,"%d\n",sim[n].solver.count_hyp);
94  fprintf(out,"%d\n",sim[n].solver.count_par);
95  fprintf(out,"%d\n",sim[n].solver.count_sou);
96 #ifdef with_petsc
97  fprintf(out,"%d\n",sim[n].solver.count_RHSFunction);
98  fprintf(out,"%d\n",sim[n].solver.count_IFunction);
99  fprintf(out,"%d\n",sim[n].solver.count_IJacobian);
100  fprintf(out,"%d\n",sim[n].solver.count_IJacFunction);
101 #endif
102  fclose(out);
103 #ifdef with_librom
104  /* write out solution errors and wall times to file */
105  if (sim[n].solver.rom_diff_norms[0] >= 0) {
106  out = fopen(rom_diff_fname,"w");
107  for (int d=0; d<sim[n].solver.ndims; d++) fprintf(out,"%4d ",sim[n].solver.dim_global[d]);
108  for (int d=0; d<sim[n].solver.ndims; d++) fprintf(out,"%4d ",sim[n].mpi.iproc[d]);
109  fprintf(out,"%1.16E ",sim[n].solver.dt);
110  fprintf(out,"%1.16E %1.16E %1.16E ",sim[n].solver.rom_diff_norms[0],sim[n].solver.rom_diff_norms[1],sim[n].solver.rom_diff_norms[2]);
111  fprintf(out,"%1.16E %1.16E\n",solver_runtime,main_runtime);
112  fclose(out);
113  }
114 #endif
115 
116  /* print solution errors, conservation errors, and wall times to screen */
117  if (sim[n].solver.error[0] >= 0) {
118  printf("Computed errors for domain %d:\n", n);
119  printf(" L1 Error : %1.16E\n",sim[n].solver.error[0]);
120  printf(" L2 Error : %1.16E\n",sim[n].solver.error[1]);
121  printf(" Linfinity Error : %1.16E\n",sim[n].solver.error[2]);
122  }
123  if (!strcmp(sim[n].solver.ConservationCheck,"yes")) {
124  printf("Conservation Errors:\n");
125  for (int d=0; d<sim[n].solver.nvars; d++) printf("\t%1.16E\n",sim[n].solver.ConservationError[d]);
126  }
127 #ifdef with_librom
128  if (sim[n].solver.rom_diff_norms[0] >= 0) {
129  printf("Norms of the diff between ROM and PDE solutions for domain %d:\n", n);
130  printf(" L1 Norm : %1.16E\n",sim[n].solver.rom_diff_norms[0]);
131  printf(" L2 Norm : %1.16E\n",sim[n].solver.rom_diff_norms[1]);
132  printf(" Linfinity Norm : %1.16E\n",sim[n].solver.rom_diff_norms[2]);
133  }
134 #endif
135 
136  }
137 
138  printf("Solver runtime (in seconds): %1.16E\n",solver_runtime);
139  printf("Total runtime (in seconds): %1.16E\n",main_runtime);
140  if (nsims > 1) printf("\n");
141 
142  }
143 
144  return;
145 }
int nvars
Definition: hypar.h:29
Structure defining a simulation.
int ndims
Definition: hypar.h:26
#define _MAX_STRING_SIZE_
Definition: basic.h:14
void GetStringFromInteger(int, char *, int)