HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
SparseGridsWriteErrors.cpp
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <string>
8 #include <basic.h>
9 #include <common_cpp.h>
11 
12 
14 void SparseGridsSimulation::WriteErrors(double solver_runtime,
15  double main_runtime
16  )
17 {
18  if (!m_rank) {
19 
20  /* Write sparse grids stuff, if asked for */
21  if (m_print_sg_errors == 1) {
22  for (int n = 0; n < m_nsims_sg; n++) {
23 
24  char err_fname[_MAX_STRING_SIZE_],
25  cons_fname[_MAX_STRING_SIZE_],
26  fc_fname[_MAX_STRING_SIZE_];
27 
28  strcpy(err_fname, "errors");
29  strcpy(cons_fname,"conservation");
30  strcpy(fc_fname, "function_counts");
31 
32  if (m_nsims_sg > 1) {
33 
34  strcat(err_fname,"_");
35  strcat(cons_fname,"_");
36  strcat(fc_fname,"_");
37 
38  char index[_MAX_STRING_SIZE_];
39  GetStringFromInteger(n, index, (int)log10(m_nsims_sg)+1);
40 
41  strcat(err_fname,index);
42  strcat(cons_fname,index);
43  strcat(fc_fname,index);
44  }
45 
46  strcat(err_fname,".dat");
47  strcat(cons_fname,".dat");
48  strcat(fc_fname,".dat");
49 
50  FILE *out;
51  /* write out solution errors and wall times to file */
52  int d;
53  out = fopen(err_fname,"w");
54  for (d=0; d<m_sims_sg[n].solver.ndims; d++) fprintf(out,"%4d ",m_sims_sg[n].solver.dim_global[d]);
55  for (d=0; d<m_sims_sg[n].solver.ndims; d++) fprintf(out,"%4d ",m_sims_sg[n].mpi.iproc[d]);
56  fprintf(out,"%1.16E ",m_sims_sg[n].solver.dt);
57  fprintf(out,"%1.16E %1.16E %1.16E ",m_sims_sg[n].solver.error[0],m_sims_sg[n].solver.error[1],m_sims_sg[n].solver.error[2]);
58  fprintf(out,"%1.16E %1.16E\n",solver_runtime,main_runtime);
59  fclose(out);
60  /* write out conservation errors to file */
61  out = fopen(cons_fname,"w");
62  for (d=0; d<m_sims_sg[n].solver.ndims; d++) fprintf(out,"%4d ",m_sims_sg[n].solver.dim_global[d]);
63  for (d=0; d<m_sims_sg[n].solver.ndims; d++) fprintf(out,"%4d ",m_sims_sg[n].mpi.iproc[d]);
64  fprintf(out,"%1.16E ",m_sims_sg[n].solver.dt);
65  for (d=0; d<m_sims_sg[n].solver.nvars; d++) fprintf(out,"%1.16E ",m_sims_sg[n].solver.ConservationError[d]);
66  fprintf(out,"\n");
67  fclose(out);
68  /* write out function call counts to file */
69  out = fopen(fc_fname,"w");
70  fprintf(out,"%d\n",m_sims_sg[n].solver.n_iter);
71  fprintf(out,"%d\n",m_sims_sg[n].solver.count_hyp);
72  fprintf(out,"%d\n",m_sims_sg[n].solver.count_par);
73  fprintf(out,"%d\n",m_sims_sg[n].solver.count_sou);
74  #ifdef with_petsc
75  fprintf(out,"%d\n",m_sims_sg[n].solver.count_RHSFunction);
76  fprintf(out,"%d\n",m_sims_sg[n].solver.count_IFunction);
77  fprintf(out,"%d\n",m_sims_sg[n].solver.count_IJacobian);
78  fprintf(out,"%d\n",m_sims_sg[n].solver.count_IJacFunction);
79  #endif
80  fclose(out);
81 
82  /* print solution errors, conservation errors, and wall times to screen */
83  if (m_sims_sg[n].solver.error[0] >= 0) {
84  printf("Computed errors for sparse grids domain %d:\n", n);
85  printf(" L1 Error: %1.16E\n",m_sims_sg[n].solver.error[0]);
86  printf(" L2 Error: %1.16E\n",m_sims_sg[n].solver.error[1]);
87  printf(" Linf Error: %1.16E\n",m_sims_sg[n].solver.error[2]);
88  }
89  if (!strcmp(m_sims_sg[n].solver.ConservationCheck,"yes")) {
90  printf("Conservation Errors:\n");
91  for (d=0; d<m_sims_sg[n].solver.nvars; d++) printf("\t%1.16E\n",m_sims_sg[n].solver.ConservationError[d]);
92  printf("\n");
93  }
94 
95  }
96  }
97 
98  /* First write stuff for the full grid solution */
99  {
100  char err_fname[_MAX_STRING_SIZE_];
101  strcpy(err_fname,"errors_fg");
102  strcat(err_fname,".dat");
103 
104  FILE *out;
105  /* write out solution errors and wall times to file */
106  int d;
107  out = fopen(err_fname,"w");
108  for (d=0; d<m_sim_fg->solver.ndims; d++) fprintf(out,"%4d ",m_sim_fg->solver.dim_global[d]);
109  for (d=0; d<m_sim_fg->solver.ndims; d++) fprintf(out,"%4d ",m_sim_fg->mpi.iproc[d]);
110  fprintf(out,"%1.16E ",m_sim_fg->solver.dt);
111  fprintf(out,"%1.16E %1.16E %1.16E ",m_sim_fg->solver.error[0],m_sim_fg->solver.error[1],m_sim_fg->solver.error[2]);
112  fprintf(out,"%1.16E %1.16E\n",solver_runtime,main_runtime);
113  fclose(out);
114 
115  /* print solution errors, conservation errors, and wall times to screen */
116  if (m_sim_fg->solver.error[0] >= 0) {
117  printf("Computed errors for full grid solution:\n");
118  printf(" L1 Error: %1.16E\n",m_sim_fg->solver.error[0]);
119  printf(" L2 Error: %1.16E\n",m_sim_fg->solver.error[1]);
120  printf(" Linf Error: %1.16E\n",m_sim_fg->solver.error[2]);
121  }
122  }
123 
124  /* report wall times */
125  printf("Solver runtime (in seconds): %1.16E\n",solver_runtime);
126  printf("Total runtime (in seconds): %1.16E\n",main_runtime);
127 
128  }
129 
130  return;
131 }
double error[3]
Definition: hypar.h:371
Some basic definitions and macros.
int ndims
Definition: hypar.h:26
void WriteErrors(double, double)
#define _MAX_STRING_SIZE_
Definition: basic.h:14
std::vector< SimulationObject > m_sims_sg
void GetStringFromInteger(int, char *, int)
double dt
Definition: hypar.h:67
Some common functions used here and there (C++ declarations)
int * dim_global
Definition: hypar.h:33