43 bool is_close(
double val1,
double val2,
double floor,
double rel_tol) {
44 if (std::fabs(val1) <= floor && std::fabs(val2) <= floor) {
47 return std::fabs((val1 - val2) / val1) < rel_tol;
52 double numCellsTol,
double numPointsTol) {
57 if (numPointsTol > 0) {
58 if (!
is_close(points1, points2, 0, numPointsTol)) {
59 std::cerr <<
"Meshes don't have similar number of points: " << points1
60 <<
" vs " << points2 << std::endl;
64 if (points1 != points2) {
65 std::cerr <<
"Meshes don't have same number of points: " << points1
66 <<
" vs " << points2 << std::endl;
74 if (numCellsTol > 0) {
75 if (!
is_close(cells1, cells2, 0, numCellsTol)) {
76 std::cerr <<
"Meshes don't have similar number of cells: " << cells1
77 <<
" vs " << cells2 << std::endl;
81 if (cells1 != cells2) {
82 std::cerr <<
"Meshes don't have same number of cells: " << cells1
83 <<
" vs " << cells2 << std::endl;
89 if (numPointsTol <= 0) {
92 std::array<double, 3> coord1{};
93 std::array<double, 3> coord2{};
96 for (
int j = 0; j < 3; ++j) {
97 if (!
is_close(coord1[j], coord2[j], floor, relTol)) {
98 std::cerr <<
"Meshes differ in point coordinates" << std::endl;
99 std::cerr <<
"Index " << i <<
" Component " << j << std::endl;
100 std::cerr <<
"Coord 1 " << std::setprecision(15) << coord1[j]
101 <<
" Coord 2 " << std::setprecision(15) << coord2[j]
103 std::cerr <<
"Meshes differ in point coordinates" << std::endl;
110 if (numCellsTol <= 0) {
112 vtkSmartPointer<vtkPoints> points1 = gmb1->
getCell(i)->GetPoints();
113 vtkSmartPointer<vtkPoints> points2 = gmb2->
getCell(i)->GetPoints();
115 if (points1->GetNumberOfPoints() != points2->GetNumberOfPoints()) {
116 std::cerr <<
"Meshes differ in cells" << std::endl;
120 for (
int j = 0; j < points1->GetNumberOfPoints(); ++j) {
121 std::vector<double> coord1(3);
122 std::vector<double> coord2(3);
123 points1->GetPoint(j, coord1.data());
124 points2->GetPoint(j, coord2.data());
125 for (
int k = 0; k < 3; ++k) {
126 if (!
is_close(coord1[k], coord2[k], floor, relTol)) {
127 std::cerr <<
"Meshes differ in cells" << std::endl;
138 if (numPointArr1 != numPointArr2) {
139 std::cerr <<
"Meshes have different numbers of point data" << std::endl;
140 std::cerr <<
"Mesh 1 has " << numPointArr1 << std::endl;
141 std::cerr <<
"Mesh 2 has " << numPointArr2 << std::endl;
145 for (
int i = 0; i < numPointArr1; ++i) {
149 std::cerr <<
"Mesh 2 does not have a point data array of name " 150 << arr1->GetName() << std::endl;
162 if (arr1->GetNumberOfComponents() != arr2->GetNumberOfComponents()) {
163 std::cerr <<
"For point data array " << arr1->GetName()
164 <<
",\narrays do not have same number of components:\n" 165 << arr1->GetNumberOfComponents() <<
" vs " 166 << arr2->GetNumberOfComponents() << std::endl;
169 if (numPointsTol <= 0) {
170 auto da1 = vtkDataArray::FastDownCast(arr1);
171 auto da2 = vtkDataArray::FastDownCast(arr2);
173 int numComponents = da1->GetNumberOfComponents();
175 std::vector<double> comps1(numComponents);
176 std::vector<double> comps2(numComponents);
177 da1->GetTuple(j, comps1.data());
178 da2->GetTuple(j, comps2.data());
179 for (
int k = 0; k < numComponents; ++k) {
180 if (!
is_close(comps1[k], comps2[k], floor, relTol)) {
181 std::cerr <<
"For point data array " << da1->GetName()
183 std::cerr <<
"Meshes differ in point data values at point " << j
184 <<
" component " << k << std::endl;
185 std::cerr << comps1[k] <<
" " << comps2[k] << std::endl;
197 if (numCellArr1 != numCellArr2) {
198 std::cerr <<
"Meshes have different numbers of cell data" << std::endl;
199 std::cerr <<
"Mesh 1 has " << numCellArr1 << std::endl;
200 std::cerr <<
"Mesh 2 has " << numCellArr2 << std::endl;
204 for (
int i = 0; i < numCellArr1; ++i) {
211 std::cerr <<
"Mesh 2 does not have a cell data array of name " 212 << arr1->GetName() << std::endl;
224 if (arr1->GetNumberOfComponents() != arr2->GetNumberOfComponents()) {
225 std::cerr <<
"For cell data array " << arr1->GetName()
226 <<
",\narrays do not have same number of components:\n" 227 << arr1->GetNumberOfComponents() <<
" vs " 228 << arr2->GetNumberOfComponents() << std::endl;
231 if (numCellsTol <= 0) {
232 auto da1 = vtkDataArray::FastDownCast(arr1);
233 auto da2 = vtkDataArray::FastDownCast(arr2);
235 int numComponents = da1->GetNumberOfComponents();
237 std::vector<double> comps1(numComponents);
238 std::vector<double> comps2(numComponents);
239 da1->GetTuple(j, comps1.data());
240 da2->GetTuple(j, comps2.data());
241 for (
int k = 0; k < numComponents; ++k) {
242 if (!
is_close(comps1[k], comps2[k], floor, relTol)) {
243 std::cerr <<
"For cell data array " << da1->GetName()
245 std::cerr <<
"Meshes differ in cell data values at cell " << j
246 <<
" component " << k << std::endl;
247 std::cerr << comps1[k] <<
" " << comps2[k] << std::endl;
255 std::cout <<
"Meshes are the same" << std::endl;
int getNumberOfCellDataArrays() const
Get number of arrays in the cell data.
void getPoint(nemId_t id, std::array< double, 3 > *x) const
Get the coordinate of a point.
void getPointDataArrayCopy(const std::string &arrayName, vtkAbstractArray *array, int *arrayIdx=nullptr) const
Get copy of point data array by name.
nemId_t getNumberOfCells() const
Get the number of cells in mesh.
int diffMesh(geoMeshBase *gmb1, geoMeshBase *gmb2, double floor, double relTol, double numCellsTol, double numPointsTol)
Compare two geoMeshBase objects.
nemId_t getNumberOfPoints() const
Get the number of points in mesh.
const std::string & getGeoEntArrayName() const
Get the name of the geometric entities array.
bool is_close(double val1, double val2, double floor, double rel_tol)
void getCellDataArrayCopy(const std::string &arrayName, vtkAbstractArray *array, int *arrayIdx=nullptr) const
Get copy of cell data array by name.
abstract class to specify geometry and mesh data
void getCell(nemId_t cellId, vtkGenericCell *cell) const
Get cell.
int getNumberOfPointDataArrays() const
Get number of arrays in the point data.