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.
Z2ErrorSizeField.C
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 *******************************************************************************/
30 
31 #include <vtkCellData.h>
32 #include <vtkCellIterator.h>
33 
35 
36 namespace NEM {
37 namespace ADP {
38 
39 Z2ErrorSizeField::Z2ErrorSizeField(vtkDataSet *_ds, int arrayID, int _order)
40  : SizeFieldBase(_ds, arrayID, 0.0, false, "Z2ErrorSF"), order(_order) {
41  std::cout << "Z2ErrorSizeField constructed" << std::endl;
42 }
43 
44 double Z2ErrorSizeField::computeNodalError(int arrayID) const {
45  std::vector<int> arrayIDs(1);
46  arrayIDs[0] = arrayID;
47  std::unique_ptr<PatchRecovery> recoverObj =
48  std::unique_ptr<PatchRecovery>(new PatchRecovery(ds, order, arrayIDs));
49  return recoverObj->computeNodalError()[0][0];
50 }
51 
53  int arrayID;
54  ds->GetPointData()->GetArray(da->GetName(), arrayID);
55  double aveError = computeNodalError(arrayID) / ds->GetNumberOfCells();
56 
57  std::string errorName = da->GetName();
58  errorName += "ErrorIntegral";
59 
60  vtkSmartPointer<vtkDataArray> errorIntegrals =
61  ds->GetCellData()->GetArray(errorName.c_str());
62  vtkSmartPointer<vtkDataArray> nodeSizes =
63  ds->GetPointData()->GetArray("nodeSizes");
64 
65  std::vector<double> sizeField;
66  sizeField.reserve(ds->GetNumberOfCells());
67 
68  vtkCellIterator *it = ds->NewCellIterator();
69  vtkSmartPointer<vtkGenericCell> cell = vtkSmartPointer<vtkGenericCell>::New();
70  for (it->InitTraversal(); !it->IsDoneWithTraversal(); it->GoToNextCell()) {
71  double interpSize = 0.0;
72  it->GetCell(cell);
73 
74  double center[3];
75  auto *weights = new double[cell->GetNumberOfPoints()];
76  int subId; // dummy
77  double x[3]; // dummy
78  cell->GetParametricCenter(center);
79  cell->EvaluateLocation(subId, center, x, weights);
80 
81  for (int j = 0; j < cell->GetNumberOfPoints(); ++j) {
82  int pntID = cell->GetPointId(j);
83  double size[1];
84  nodeSizes->GetTuple(pntID, size);
85  interpSize += size[0] * weights[j];
86  }
87  delete[] weights;
88 
89  double error[1];
90  errorIntegrals->GetTuple(it->GetCellId(), error);
91  sizeField.emplace_back(
92  interpSize / (std::pow(error[0] / aveError, 1.0 / order)) * sizeFactor);
93  }
94  it->Delete();
95 
96  vtkSmartPointer<vtkDoubleArray> da2 = vtkSmartPointer<vtkDoubleArray>::New();
97  da2->SetName(sfname.c_str());
98  da2->SetNumberOfComponents(1);
99  for (vtkIdType i = 0; i < ds->GetNumberOfCells(); ++i)
100  da2->InsertNextTypedTuple(&sizeField[i]);
101  ds->GetCellData()->AddArray(da2);
102 }
103 
104 } // namespace ADP
105 } // namespace NEM
std::vector< std::vector< double > > computeNodalError()
vtkSmartPointer< vtkDataSet > ds
Definition: SizeFieldGen.H:76
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
double computeNodalError(int arrayID) const
vtkSmartPointer< vtkDataArray > da
Definition: SizeFieldGen.H:79
Z2ErrorSizeField(vtkDataSet *_ds, int arrayID, int _order)
void computeSizeField(vtkDataArray *da) override