Chombo + EB + MF  3.2
generalFuncs.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 
11 // generalFuncs.H
12 // petermc, 24 March 2003; modified 28 Jan 2009
13 
14 #ifndef _GENERALFUNCS_H_
15 #define _GENERALFUNCS_H_
16 #include <iostream>
17 #include <cstdio>
18 #include "LevelData.H"
19 #include "FArrayBox.H"
20 #include "Vector.H"
21 #include "RealVect.H"
22 #include "ParmParse.H"
23 #ifdef CH_USE_PYTHON
24 #include "PyParse.H"
25 #endif
26 
27 #include "UsingNamespace.H"
28 
29 namespace GenFuncs
30 {
31 
32 
33 /*==============================================================================
34  * Routines for comparing floating point numbers
35  *============================================================================*/
36 
37 // Comparison with limit tol^2 as x and y -> 0.
38 // Returns true if not equal
39 template <typename T>
40 inline bool compare(const T &x, const T &y, int prec)
41 {
42  const T tol = std::pow(10., -std::abs(prec));
43  return std::fabs(x - y) >
44  (std::min(std::fabs(x), std::fabs(y)) + tol)*tol;
45 }
46 
47 // Comparison with limit tol as x and y -> 0.
48 // Return true if not equal
49 template <typename T>
50 inline bool compare1(const T &x, const T &y, int prec)
51 {
52  const T tol = std::pow(10., -std::abs(prec));
53  return std::fabs(x - y) >
54  std::min(std::fabs(x), std::fabs(y))*tol + tol;
55 }
56 
57 
58 /*==============================================================================
59  * Routines for generating a box layout
60  *============================================================================*/
61 
62 Box boxFromVector(const Vector<int>& a_ints,
63  int a_start = 0);
64 
65 int readBoxes(Vector< Vector<Box> >& a_vectVectBoxes,
66  ParmParse& a_pp,
67  const ProblemDomain& a_domain,
68  const int& a_maxGridSize,
69  const int& a_blockFactor,
70  const int& a_numlevels,
71  const Vector<int>& a_vectRefRatio,
72  const bool& a_verbose);
73 
74 #ifdef CH_USE_PYTHON
75 // Python-savvy version of readBoxes.
76 int readBoxes(Vector< Vector<Box> >& a_vectVectBoxes,
77  PyParse& a_pp,
78  const ProblemDomain& a_domain,
79  const int& a_maxGridSize,
80  const int& a_blockFactor,
81  const int& a_numlevels,
82  const Vector<int>& a_vectRefRatio,
83  const bool& a_verbose);
84 #endif
85 
86 int getDiff(Vector<LevelData<FArrayBox>* >& a_vectDiff,
87  const Vector<LevelData<FArrayBox>* >& a_vectPhi1,
88  const Vector<LevelData<FArrayBox>* >& a_vectPhi2);
89 
90 int getMagnitude(Vector<LevelData<FArrayBox>* >& a_vectMag,
91  const Vector<LevelData<FArrayBox>* >& a_vectField);
92 
93 int project2(Vector<LevelData<FArrayBox>* >& a_vectProj,
94  const Vector<LevelData<FArrayBox>* >& a_vectPhi,
95  const Vector<DisjointBoxLayout>& a_vectGrids);
96 
97 
98 int printErrorNorms(const string& a_prefix,
99  Real a_dxFine,
100  int a_deginterp,
101  Real a_normMaxerrFine,
102  Real a_norm1errFine,
103  Real a_norm2errFine,
104  Real a_normMaxerrCoarse,
105  Real a_norm1errCoarse,
106  Real a_norm2errCoarse);
107 
108 int printDiffNorms(const string& a_prefix,
109  Real a_dxFine,
110  int a_deginterp,
111  Real a_normMaxdiff,
112  Real a_norm1diff,
113  Real a_norm2diff);
114 
115 
116 int getBoxesFromIndices(Vector<Box>& a_vectBoxes,
117  const Box& a_domainBox,
118  const int& a_maxGridSize,
119  const int& a_blockFactor,
120  const int& a_boxCount,
121  const Vector<int>& a_boxIndices,
122  const Vector<int>& a_domainIndices);
123 
124 } // End of namespace GenFuncs
125 
126 #endif
int project2(Vector< LevelData< FArrayBox > * > &a_vectProj, const Vector< LevelData< FArrayBox > * > &a_vectPhi, const Vector< DisjointBoxLayout > &a_vectGrids)
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
int getBoxesFromIndices(Vector< Box > &a_vectBoxes, const Box &a_domainBox, const int &a_maxGridSize, const int &a_blockFactor, const int &a_boxCount, const Vector< int > &a_boxIndices, const Vector< int > &a_domainIndices)
IndexTM< T, N > min(const IndexTM< T, N > &a_p1, const IndexTM< T, N > &a_p2)
Definition: IndexTMI.H:394
bool compare(const T &x, const T &y, int prec)
Definition: generalFuncs.H:40
int getDiff(Vector< LevelData< FArrayBox > * > &a_vectDiff, const Vector< LevelData< FArrayBox > * > &a_vectPhi1, const Vector< LevelData< FArrayBox > * > &a_vectPhi2)
Parse Parameters From Command Line and Input Files.
Definition: ParmParse.H:2849
int readBoxes(Vector< Vector< Box > > &a_vectVectBoxes, ParmParse &a_pp, const ProblemDomain &a_domain, const int &a_maxGridSize, const int &a_blockFactor, const int &a_numlevels, const Vector< int > &a_vectRefRatio, const bool &a_verbose)
Definition: generalFuncs.H:29
int printErrorNorms(const string &a_prefix, Real a_dxFine, int a_deginterp, Real a_normMaxerrFine, Real a_norm1errFine, Real a_norm2errFine, Real a_normMaxerrCoarse, Real a_norm1errCoarse, Real a_norm2errCoarse)
double Real
Definition: REAL.H:33
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
int getMagnitude(Vector< LevelData< FArrayBox > * > &a_vectMag, const Vector< LevelData< FArrayBox > * > &a_vectField)
Box boxFromVector(const Vector< int > &a_ints, int a_start=0)
bool compare1(const T &x, const T &y, int prec)
Definition: generalFuncs.H:50
int printDiffNorms(const string &a_prefix, Real a_dxFine, int a_deginterp, Real a_normMaxdiff, Real a_norm1diff, Real a_norm2diff)