NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
OrderOfAccuracy.H
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 #ifndef NEMOSYS_ORDEROFACCURACY_H_
30 #define NEMOSYS_ORDEROFACCURACY_H_
31 
32 #include "nemosys_export.h"
33 
34 #include "Mesh/meshBase.H"
35 
36 #include <vector>
37 
38 /**
39  * The OrderOfAccuracy class computes the grid convergence
40  * index (GCI) given three successively refined meshes. The
41  * GCI is particularly robust since it accounts for the order
42  * of convergence as well as the grid refinement ratio.
43  *
44  * If a vector field is being analyzed, a GCI will be generated
45  * for each component.
46  *
47  * For
48  * more information see:
49  * Roache, P.J.
50  * Verification and Validation in Compuational Science and
51  * Engineering, Hermosa Publishers, Albuquerque, New Mexico,
52  * 1998
53  */
54 class NEMOSYS_EXPORT OrderOfAccuracy {
55  public:
56  OrderOfAccuracy(meshBase *_f3, meshBase *_f2, meshBase *_f1,
57  std::vector<int> _arrayIDs,
58  std::string transferType = "Consistent Interpolation",
59  double targetGCI = 1.1);
60 
61  ~OrderOfAccuracy() = default;
62 
63  /**
64  * @brief Compute order of accuracy.
65  * @return Order of accuracy for each component of each field
66  * based on errors between the coarse and finer mesh and the
67  * finer and finest mesh.
68  */
69  std::vector<std::vector<double>> computeOrderOfAccuracy();
70 
71  /**
72  * @brief Compute the GCI with respect to the finer and finest
73  * grids.
74  * @return GCI for each component of each field transferred
75  * from the finer mesh (f2) to the finest mesh (f1).
76  */
77  std::vector<std::vector<double>> computeGCI_21();
78 
79  /**
80  * @brief Compute the GCI with respect to the coarsest and
81  * finer grids.
82  * @return GCI for each component of each field transferred
83  * from the coarse mesh (f3) to the finer mesh (f2).
84  */
85  std::vector<std::vector<double>> computeGCI_32();
86 
87  /**
88  * @brief Compute the grid resolution required to obtain the
89  * desired gci/level of accuracy for each component across
90  * all mesh fields. Given a vector field, select the maximum
91  * refinement ratio in the components to ensure the desired
92  * GCI is met across all components.
93  * @return Necessary grid refinement ratio for each component
94  * of each field.
95  */
96  std::vector<std::vector<double>> computeResolution(double gciStar);
97  void computeRichardsonExtrapolation();
98 
99  /**
100  * @brief Returns order of accuracy for each component of each field
101  * @return Order of accuracy of each component of each field
102  */
103  std::vector<std::vector<double>> getOrderOfAccuracy() const {
104  return orderOfAccuracy;
105  }
106 
107  /**
108  * @brief Check if grids are in asymptotic range of convergence based
109  * on the computed GCIs (GCI_32 and GCI_21). We are within asymptotic
110  * range if all values are close to 1
111  * @return Weighted ratio of GCIs for each component of each field in grids
112  */
113  std::vector<std::vector<double>> checkAsymptoticRange();
114 
115  /**
116  * @brief Refine the coarsest mesh based on the target GCI, write
117  * to file with name ofname.
118  * @param gciStar target GCI
119  * @param ofname refined mesh filename
120  */
121  void computeMeshWithResolution(double gciStar, const std::string &ofname);
122 
123  std::vector<std::vector<double>> computeDiff(
124  meshBase *mesh, const std::vector<std::string> &newArrNames);
125 
126  std::vector<std::vector<double>> getDiffF2F1() const { return diffF2F1; }
127 
128  double getTargetGCI() const { return targetGCI; }
129 
130  private:
131  meshBase *f3, *f2, *f1; ///< meshes from least to most refined (f3 -
132  ///< coarsest, f2 - finer, f1 - finest)
133  const std::vector<int>
134  arrayIDs; ///< array ids for arrays to be considered in analysis
135  std::vector<int>
136  diffIDs; ///< array ids for differences^2 in solutions between meshes
137  std::vector<int>
138  relEIDs; ///< array ids for integral of solutions on the most refined
139  ///< mesh, used in computing relative discretization error
140  std::vector<int> realDiffIDs; ///< array ids for actual difference data
141  std::vector<std::string> f3ArrNames,
142  f2ArrNames; ///< names of data arrays transferred from f3 to f2 and from
143  ///< f2 to f1
144  double r21, r32; ///< effective grid refinement ratios
145  std::vector<std::vector<double>>
146  diffF3F2; ///< L2 norm of the difference in solution between f3 and f2
147  std::vector<std::vector<double>>
148  diffF2F1; ///< L2 norm of the difference in solution between f2 and f1
149  std::vector<std::vector<double>>
150  GCI_32; ///< GCIs with respect to the coarse mesh (f3)
151  std::vector<std::vector<double>>
152  GCI_21; ///< GCIs with respect to the finer mesh (f2)
153  std::vector<std::vector<double>>
154  orderOfAccuracy; ///< Order of accuracy (p) with respect to refinements
155  ///< f3-f2-f1
156  double targetGCI;
157 };
158 
159 #endif // NEMOSYS_ORDEROFACCURACY_H_
std::vector< int > diffIDs
array ids for differences^2 in solutions between meshes
A brief description of meshBase.
Definition: meshBase.H:64
The OrderOfAccuracy class computes the grid convergence index (GCI) given three successively refined ...
std::vector< std::vector< double > > diffF2F1
L2 norm of the difference in solution between f2 and f1.
const std::vector< int > arrayIDs
array ids for arrays to be considered in analysis
std::vector< std::string > f3ArrNames
std::vector< std::vector< double > > GCI_21
GCIs with respect to the finer mesh (f2)
std::vector< std::vector< double > > orderOfAccuracy
Order of accuracy (p) with respect to refinements f3-f2-f1.
std::shared_ptr< meshBase > mesh
std::vector< int > relEIDs
array ids for integral of solutions on the most refined mesh, used in computing relative discretizati...
std::vector< std::vector< double > > diffF3F2
L2 norm of the difference in solution between f3 and f2.
double r32
effective grid refinement ratios
std::vector< std::vector< double > > GCI_32
GCIs with respect to the coarse mesh (f3)
std::vector< std::vector< double > > getOrderOfAccuracy() const
Returns order of accuracy for each component of each field.
double getTargetGCI() const
std::vector< int > realDiffIDs
array ids for actual difference data
std::vector< std::vector< double > > getDiffF2F1() const