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.
Cubature.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_CUBATURE_H_
30 #define NEMOSYS_CUBATURE_H_
31 
32 #include <memory>
33 
34 // Nemosys headers
35 #include "nemosys_export.h"
36 
37 // VTK
38 #include <vtkDataArray.h>
39 #include <vtkDoubleArray.h>
40 #include <vtkGenericCell.h>
41 #include <vtkPointData.h>
42 #include <vtkPolyData.h>
43 #include <vtkQuadratureSchemeDefinition.h>
44 
45 // 3 point symmetric gaussian quadrature for triangle element
46 extern double TRI3[];
47 extern double TRI3W[];
48 // 4 point symmetric gaussian quadrature for tetrahedral element
49 extern double TET4[];
50 extern double TET4W[];
51 
52 // pair type for coordinate and data there
53 using pntDataPair = std::pair<std::vector<double>, std::vector<double>>;
54 // holds gauss points and data at these points as pairs
55 using pntDataPairVec = std::vector<pntDataPair>;
56 
57 class NEMOSYS_EXPORT GaussCubature {
58  public:
59  explicit GaussCubature(vtkDataSet *_dataSet);
60  GaussCubature(vtkDataSet *_dataSet, const std::vector<int> &arrayIDs);
61 
62  ~GaussCubature() { delete[] dict; }
63 
64  GaussCubature(const GaussCubature &that) = delete;
65  GaussCubature &operator=(const GaussCubature &that) = delete;
66 
67  void constructGaussMesh();
68 
69  public:
70  /**
71  * @brief Returns coordinates of gauss points and associated data at cell
72  * @param cellId cell id
73  * @return pntDataPairVec (see alias in Cubature.H)
74  */
75  pntDataPairVec getGaussPointsAndDataAtCell(int cellID);
76  /**
77  * @brief Interpolate values to gauss points for arrays specified in arrayIDs
78  * at construction time.
79  */
80  void interpolateToGaussPoints();
81  /**
82  * @brief Interpolate values to gauss points for arrays specified in arrayIDs
83  * at construction time and specify new names (in order).
84  * @param newArrayNames name of transferred data from arrayIDs[i] will be
85  * named newArrayNames[i]
86  */
87  void interpolateToGaussPoints(const std::vector<std::string> &newArrayNames);
88  /**
89  * @brief Integrate arrays specified by arrayIDs over all cells.
90  * @return Integral data (first index - array, second index - component)
91  */
92  std::vector<std::vector<double>> integrateOverAllCells();
93  /**
94  * @brief Same as integrateOverAllCells() but with integral value array
95  * names specified by newArrayNames and an optional flag to compute
96  * the root mean square error (RMSE) integral over an array with error values,
97  * an error metric normalized by cell volume.
98  * @param newArrayNames integral value array names
99  * @param computeRMSE compute RMSE (see above)
100  * @return Integral data (first index - array, second index - component)
101  */
102  std::vector<std::vector<double>> integrateOverAllCells(
103  const std::vector<std::string> &newArrayNames, bool computeRMSE);
104 
105  void setArrayIDs(const std::vector<int> &_arrayIDs) { arrayIDs = _arrayIDs; }
106  double computeJacobian(vtkSmartPointer<vtkGenericCell> genCell,
107  int cellType) const;
108  double computeCellVolume(vtkSmartPointer<vtkGenericCell> genCell,
109  int cellType) const;
110 
111  // access
112  public:
113  vtkDataSet *getDataSet() const { return dataSet; }
114 
115  vtkSmartPointer<vtkPolyData> getGaussMesh() const { return gaussMesh; }
116  vtkQuadratureSchemeDefinition **getDict() const { return dict; }
117  std::vector<int> getNumComponents() const { return numComponents; }
118  std::vector<int> getArrayIDs() const { return arrayIDs; }
119  int getTotalComponents() const { return totalComponents; }
120 
121  void writeGaussMesh(const char *name) const;
122 
123  // factory constructors
124  public:
125  static GaussCubature *Create(vtkDataSet *_dataSet);
126  static GaussCubature *Create(vtkDataSet *_dataSet,
127  const std::vector<int> &arrayIDs);
128  static std::unique_ptr<GaussCubature> CreateUnique(vtkDataSet *_dataSet);
129  static std::unique_ptr<GaussCubature> CreateUnique(
130  vtkDataSet *_dataSet, const std::vector<int> &arrayIDs);
131  static std::shared_ptr<GaussCubature> CreateShared(vtkDataSet *_dataSet);
132  static std::shared_ptr<GaussCubature> CreateShared(
133  vtkDataSet *_dataSet, const std::vector<int> &arrayIDs);
134 
135  private:
136  // we want gauss points of this mesh
137  vtkSmartPointer<vtkDataSet> dataSet;
138  // number of volume elements in node mesh
140  // we put the gauss points and interpolated data into this mesh
141  vtkSmartPointer<vtkPolyData> gaussMesh;
142  // dictionary relating cell type quadrature scheme info for that type
143  vtkQuadratureSchemeDefinition **dict;
144  // array ids of data to be interpolated
145  std::vector<int> arrayIDs;
146  std::vector<int> numComponents;
148 
149  // get offset from nodeMesh for lookup of gauss points in gaussMesh
150  int getOffset(int cellID) const;
151  // interpolates provided data (das) to gauss points in cell
152  int interpolateToGaussPointsAtCell(
153  int cellID, vtkSmartPointer<vtkGenericCell> genCell,
154  const std::vector<vtkSmartPointer<vtkDataArray>> &das,
155  std::vector<vtkSmartPointer<vtkDoubleArray>> &daGausses) const;
156  // integrates provided data over cell
157  void integrateOverCell(
158  int cellID, vtkSmartPointer<vtkGenericCell> genCell,
159  vtkSmartPointer<vtkPointData> pd,
160  std::vector<vtkSmartPointer<vtkDoubleArray>> &integralData,
161  std::vector<std::vector<double>> &totalIntegralData) const;
162  // integrates data specified by newArrayNames over cell,
163  // normalizes the integral by the cell volume and takes the sqrt
164  void integrateOverCell(
165  int cellID, vtkSmartPointer<vtkGenericCell> genCell,
166  vtkSmartPointer<vtkPointData> pd,
167  std::vector<vtkSmartPointer<vtkDoubleArray>> &integralData,
168  std::vector<std::vector<double>> &totalIntegralData,
169  const std::vector<std::string> &newArrayNames, bool normalizeByVol) const;
170 };
171 
172 #endif // NEMOSYS_CUBATURE_H_
double TET4[]
Definition: Cubature.C:68
std::vector< int > getArrayIDs() const
Definition: Cubature.H:118
double TRI3[]
Definition: Cubature.C:58
std::vector< int > numComponents
Definition: Cubature.H:146
vtkDataSet * getDataSet() const
Definition: Cubature.H:113
std::pair< std::vector< double >, std::vector< double > > pntDataPair
Definition: Cubature.H:53
void setArrayIDs(const std::vector< int > &_arrayIDs)
Definition: Cubature.H:105
vtkSmartPointer< vtkPolyData > getGaussMesh() const
Definition: Cubature.H:115
std::vector< pntDataPair > pntDataPairVec
Definition: Cubature.H:55
~GaussCubature()
Definition: Cubature.H:62
double TRI3W[]
Definition: Cubature.C:65
int totalComponents
Definition: Cubature.H:147
VTKCellType cellType
Definition: inpGeoMesh.C:129
double TET4W[]
Definition: Cubature.C:77
vtkQuadratureSchemeDefinition ** getDict() const
Definition: Cubature.H:116
vtkSmartPointer< vtkDataSet > dataSet
Definition: Cubature.H:137
int getTotalComponents() const
Definition: Cubature.H:119
std::vector< int > getNumComponents() const
Definition: Cubature.H:117
vtkSmartPointer< vtkPolyData > gaussMesh
Definition: Cubature.H:141
std::vector< int > arrayIDs
Definition: Cubature.H:145
int numVolCells
Definition: Cubature.H:139
vtkQuadratureSchemeDefinition ** dict
Definition: Cubature.H:143