BISICLES AMR ice sheet model  0.9
Regression.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3 * _______ __
4 * / ___/ / ___ __ _ / / ___
5 * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6 * \___/_//_/\___/_/_/_/_.__/\___/
7 * Please refer to Copyright.txt, in Chombo's root directory.
8 */
9 #endif
10 #ifndef _REGRESSION_H_
11 #define _REGRESSION_H_
12 
13 #include "ParmParse.H"
14 #include "AMRIO.H"
15 #include "computeNorm.H"
16 //#include "Vector.H"
17 #include "NamespaceHeader.H"
18 
19 #ifdef CH_USE_HDF5
20 
22 
27 Real HDF5NormTest(std::string a_result, std::string a_ref)
28 {
29 
30  Vector<LevelData<FArrayBox>* > resultSoln;
31  Vector<string> resultVars; // result solution variable names
32  Vector<DisjointBoxLayout> resultGrids;
33  Box resultDomain;
34  Real resultDx, resultDt, resultTime;
35  Vector<int> resultRefRatio;
36  int resultNumLevels;
37  IntVect ghostVect = IntVect::Unit;
38 
39  ReadAMRHierarchyHDF5(a_result,
40  resultGrids,
41  resultSoln,
42  resultVars,
43  resultDomain,
44  resultDx,
45  resultDt,
46  resultTime,
47  resultRefRatio,
48  resultNumLevels);
49 
50 
51  Vector<LevelData<FArrayBox>* > refSoln;
52  Vector<string> refVars; // ref soln variable names
53  Vector<DisjointBoxLayout> refGrids;
54  Box refDomain;
55  Real refDx, refDt, refTime;
56  Vector<int> refRefRatio;
57  int refNumLevels;
58 
59  ReadAMRHierarchyHDF5(a_ref,
60  refGrids,
61  refSoln,
62  refVars,
63  refDomain,
64  refDx,
65  refDt,
66  refTime,
67  refRefRatio,
68  refNumLevels);
69 
70  CH_assert (refDomain == resultDomain);
71  CH_assert (refNumLevels == resultNumLevels);
72 
73  Real maxnorm = 0.0;
74  for (int j = 0; j < resultSoln[0]->nComp() ; j++)
75  {
76  int k = 0;
77  while (k < refVars.size() && resultVars[j] != refVars[k])
78  {
79  k++;
80  }
81 
82  if ( k >= refVars.size() )
83  {
84  std::string msg = " var " + resultVars[j] + " missing from " + a_ref;
85  MayDay::Warning(msg.c_str());
86  }
87  else
88  {
89  for (int lev = 0; lev < resultNumLevels; lev++)
90  {
91  LevelData<FArrayBox> ref(resultGrids[lev], 1, IntVect::Zero);
92  refSoln[lev]->copyTo(Interval(k,k), ref, Interval(0,0));
93  for (DataIterator dit(resultGrids[lev]); dit.ok(); ++dit)
94  {
95  (*resultSoln[lev])[dit].minus(ref[dit], 0, j, 1);
96  }
97  }
98 
99  Real maxnormj = computeNorm(resultSoln, resultRefRatio, resultDx, Interval(j,j), 0);
100  pout() << "HDF5NormTest: maxnorm difference(" << resultVars[j] << ") = " << maxnormj << endl;
101  maxnorm = std::max(maxnorm, maxnormj);
102  }
103  }
104 
105  return maxnorm;
106 
107 }
108 #endif
109 
110 
111 #include "NamespaceFooter.H"
112 #endif
Real HDF5NormTest(std::string a_result, std::string a_ref)
Compute the maximum difference between (a subset of) the AMR data stored in two HDF5 fiels...
Definition: Regression.H:27