5#ifndef ResolveHangingNodesTestUtilities_h
6#define ResolveHangingNodesTestUtilities_h
48constexpr double EPSILON = 1e-6;
55 double BoundaryMeasure;
60constexpr Domain THREE_LEVEL_DOMAIN = { 32.0, 24.0, 8 };
67inline std::array<double, 3> Rotate(
double x,
double y)
71 return { c * x - s * y, s * x + c * y, 0.0 };
86 values->SetName(
"Values");
88 globalIds->SetName(
"GlobalIds");
89 auto add = [&](
double x,
double y)
91 values->InsertNextValue(x + 10.0 * y);
92 globalIds->InsertNextValue(
points->GetNumberOfPoints());
93 return points->InsertNextPoint(Rotate(x, y).
data());
95 const vtkIdType p00 = add(0, 0), p40 = add(4, 0), p44 = add(4, 4), p04 = add(0, 4);
96 const vtkIdType p80 = add(8, 0), p84 = add(8, 4), p42 = add(4, 2), p60 = add(6, 0),
97 p62 = add(6, 2), p64 = add(6, 4), p82 = add(8, 2);
98 const vtkIdType p72 = add(7, 2), p83 = add(8, 3), p74 = add(7, 4), p63 = add(6, 3),
105 polys->InsertNextCell(4, q);
107 quad(p00, p40, p44, p04);
108 quad(p40, p60, p62, p42);
109 quad(p60, p80, p82, p62);
110 quad(p42, p62, p64, p44);
111 quad(p62, p72, p73, p63);
112 quad(p72, p82, p83, p73);
113 quad(p63, p73, p74, p64);
114 quad(p73, p83, p84, p74);
117 pd->SetPoints(points);
121 pd->GetPointData()->SetGlobalIds(globalIds);
123 pd->GetPointData()->AddArray(values);
125 cellIds->SetName(
"CellIds");
128 cellIds->InsertNextValue(i);
130 pd->GetCellData()->AddArray(cellIds);
135constexpr Domain TWO_LEVEL_DOMAIN = { 32.0, 64.0, 11 };
150 this->Values->SetName(
"Values");
153 void AddHex(
int x,
int y,
int z,
int size)
156 this->
Point(x, y, z),
157 this->
Point(x + size, y, z),
158 this->
Point(x + size, y + size, z),
159 this->
Point(x, y + size, z),
160 this->
Point(x, y, z + size),
161 this->
Point(x + size, y, z + size),
162 this->
Point(x + size, y + size, z + size),
163 this->
Point(x, y + size, z + size),
165 this->Hexes.emplace_back(ids, ids + 8);
170 auto it = this->PointIds.find({ x, y, z });
171 if (it != this->PointIds.end())
175 this->Values->InsertNextValue(x + 10.0 * y + 100.0 * z);
176 const vtkIdType id = this->Points->InsertNextPoint(x, y, z);
177 this->PointIds[{ x, y, z }] = id;
181 vtkSmartPointer<vtkUnstructuredGrid> Build(
bool withGlobalIds =
false)
184 ug->AllocateExact(
static_cast<vtkIdType>(this->Hexes.size()), 8);
185 vtkNew<vtkIdTypeArray> cellIds;
186 cellIds->SetName(
"CellIds");
187 for (
const auto& hex : this->Hexes)
189 cellIds->InsertNextValue(ug->InsertNextCell(
VTK_HEXAHEDRON, 8, hex.data()));
191 ug->SetPoints(this->Points);
194 vtkNew<vtkIdTypeArray> globalIds;
195 globalIds->SetName(
"GlobalIds");
196 globalIds->SetNumberOfValues(this->Points->GetNumberOfPoints());
199 ug->GetPointData()->SetGlobalIds(globalIds);
201 ug->GetPointData()->AddArray(this->Values);
202 ug->GetCellData()->AddArray(cellIds);
207 vtkNew<vtkPoints> Points;
208 vtkNew<vtkDoubleArray> Values;
209 std::map<std::array<int, 3>,
vtkIdType> PointIds;
210 std::vector<std::vector<vtkIdType>> Hexes;
223 HexMeshBuilder builder;
224 builder.AddHex(0, 0, 0, 2);
225 builder.AddHex(0, 2, 0, 2);
226 builder.AddHex(2, 2, 0, 2);
227 for (
int k = 0; k < 2; ++k)
229 for (
int j = 0; j < 2; ++j)
231 for (
int i = 0; i < 2; ++i)
233 builder.AddHex(2 + i, j, k, 1);
237 return builder.Build();
244 const std::array<int, 3>& numCells,
double spacing,
vtkIdType firstCellId)
247 block->SetOrigin(origin.data());
248 block->SetSpacing(spacing, spacing, spacing);
249 block->SetDimensions(numCells[0] + 1, numCells[1] + 1, numCells[2] + 1);
251 values->SetName(
"Values");
253 levels->SetName(
"Levels");
254 for (
vtkIdType i = 0; i < block->GetNumberOfPoints(); ++i)
256 const double* p = block->GetPoint(i);
257 values->InsertNextValue(p[0] + 10.0 * p[1] + 100.0 * p[2]);
258 levels->InsertNextValue(level);
260 block->GetPointData()->AddArray(values);
261 block->GetPointData()->AddArray(levels);
263 cellIds->SetName(
"CellIds");
264 for (
vtkIdType i = 0; i < block->GetNumberOfCells(); ++i)
266 cellIds->InsertNextValue(firstCellId + i);
268 block->GetCellData()->AddArray(cellIds);
275 converter->SetInputData(pd);
277 return converter->GetOutput();
287 geometry->SetInputData(ds);
290 if constexpr (Dim == 2)
293 edges->SetInputData(boundary);
294 edges->BoundaryEdgesOn();
295 edges->FeatureEdgesOff();
296 edges->NonManifoldEdgesOff();
297 edges->ManifoldEdgesOff();
299 boundary =
edges->GetOutput();
301 double measure = 0.0;
303 for (
vtkIdType c = 0; c < boundary->GetNumberOfCells(); ++c)
305 boundary->GetCellPoints(c, ids);
306 if constexpr (Dim == 2)
309 boundary->GetPoint(ids->GetId(0), p0);
310 boundary->GetPoint(ids->GetId(1), p1);
317 boundary->GetPoints(), ids->GetNumberOfIds(), ids->
GetPointer(0), normal);
327 vtkPointSet* mesh,
const std::vector<vtkIdType>& cellIds)
338 std::vector<int> types;
339 std::map<vtkIdType, vtkIdType>
pointIds;
341 for (
vtkIdType i = 0; i < static_cast<vtkIdType>(cellIds.size()); ++i)
345 for (
vtkIdType j = 0; j < ids->GetNumberOfIds(); ++j)
347 const auto [it, isNew] =
pointIds.emplace(ids->GetId(j),
points->GetNumberOfPoints());
353 ids->SetId(j, it->second);
355 cells->InsertNextCell(ids);
359 part->SetPoints(points);
362 polyData->SetPolys(cells);
374 std::vector<vtkIdType> cellIds(end - begin);
375 std::iota(cellIds.begin(), cellIds.end(), begin);
376 return ExtractCells(mesh, cellIds);
385 partitions->SetPartition(0, ExtractCells(mesh, 0, numCellsOfFirst));
386 partitions->SetPartition(1, ExtractCells(mesh, numCellsOfFirst, mesh->
GetNumberOfCells()));
388 collection->SetPartitionedDataSet(0, partitions);
396 append->MergePointsOn();
399 append->AddInputData(partition);
402 return append->GetOutput();
408inline bool CheckOutput(
const std::string& name,
vtkUnstructuredGrid* output,
bool decompose,
413 std::cerr <<
name <<
": expected " << expectedPoints <<
" points and " << expectedCells
420 const double boundaryMeasure = BoundaryMeasure<Dim>(output);
421 if (std::abs(boundaryMeasure - domain.BoundaryMeasure) > EPSILON)
423 std::cerr <<
name <<
": the boundary " << (Dim == 2 ?
"length" :
"area") <<
" is "
424 << boundaryMeasure <<
" instead of " << domain.BoundaryMeasure
425 <<
", the output is not conforming\n";
434 const bool isValidType = Dim == 2
440 std::cerr <<
name <<
": unexpected type " <<
type <<
" for cell " << c <<
"\n";
449 validator->SetInputData(output);
455 if (states->
GetTuple1(c) !=
static_cast<short>(vtkCellValidator::State::Valid))
457 std::cerr <<
name <<
": cell " << c <<
" of type " << output->
GetCellType(c)
458 <<
" is not valid (state " << states->
GetTuple1(c) <<
")\n";
466 if (!cellIds || cellIds->
GetTuple1(0) != 0 ||
467 cellIds->
GetTuple1(expectedCells - 1) != domain.NumberOfCells - 1)
469 std::cerr <<
name <<
": cell data was not copied\n";
472 for (
vtkIdType c = 1; c < expectedCells; ++c)
475 if (step != 0 && step != 1)
477 std::cerr <<
name <<
": cells are not in input order\n";
483 const char* inverseMeasureName = Dim == 2 ?
"InverseArea" :
"InverseVolume";
485 if (!inverseMeasure ||
488 std::cerr <<
name <<
": expected the " << inverseMeasureName <<
" cell data array only\n";
491 double measure = 0.0;
496 std::cerr <<
name <<
": wrong " << inverseMeasureName <<
" for cell " << c <<
"\n";
499 measure += 1.0 / inverseMeasure->
GetTuple1(c);
501 if (std::abs(measure - domain.Measure) > EPSILON)
503 std::cerr <<
name <<
": the cells cover " << (Dim == 2 ?
"an area" :
"a volume") <<
" of "
504 << measure <<
" instead of " << domain.Measure <<
"\n";
511 std::cerr <<
name <<
": point data was not passed\n";
535 vtkTypeMacro(vtkRemotePointsTestFilter, vtkResolveHangingNodes);
537 vtkSmartPointer<vtkPolyData> Remote;
540 bool UseRemotePoints()
override {
return true; }
541 std::vector<vtkSmartPointer<vtkPolyData>> GetRemotePoints(
542 const std::vector<vtkPolyData*>& boundaries,
543 const std::vector<int>& partitionedDataSetIds)
override
545 std::vector<vtkSmartPointer<vtkPolyData>> remotePoints =
547 for (std::size_t p = 0; p < boundaries.size(); ++p)
550 this->MergeReceivedPoints({ { 0, remotePoints[p] }, { 1, this->Remote } }, boundaries[p]);
563 vtkTypeMacro(vtkLevelsTestFilter, vtkResolveHangingNodes);
565 std::vector<int> PartitionedDataSetIds;
566 bool ReceivedOnlyOtherLevels =
true;
569 std::vector<vtkSmartPointer<vtkPolyData>> GetRemotePoints(
570 const std::vector<vtkPolyData*>& boundaries,
571 const std::vector<int>& partitionedDataSetIds)
override
573 this->PartitionedDataSetIds = partitionedDataSetIds;
574 std::vector<vtkSmartPointer<vtkPolyData>> remotePoints =
576 for (std::size_t p = 0; p < remotePoints.size(); ++p)
579 remotePoints[p] ? remotePoints[p]->GetPointData()->GetArray(
"Levels") :
nullptr;
582 if (levels->
GetTuple1(i) == partitionedDataSetIds[p])
584 this->ReceivedOnlyOtherLevels =
false;
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
represent and manipulate cell attribute data
static std::vector< DataSetT * > GetDataSets(vtkDataObject *dobj, bool preserveNull=false)
Extract datasets from the given data object.
double GetTuple1(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
general representation of visualization data
void CopyData(vtkDataSetAttributes *fromPd, vtkIdType fromId, vtkIdType toId)
Copy the attribute data from one id to another.
void CopyAllocate(vtkDataSetAttributes *pd, vtkIdType sze=0, vtkIdType ext=1000)
Allocates point data for point-by-point (or cell-by-cell) copy operation.
abstract class to specify dataset behavior
vtkPointData * GetPointData()
Return a pointer to this dataset's point data.
static vtkDataSet * SafeDownCast(vtkObjectBase *o)
virtual vtkIdType GetNumberOfPoints()=0
Determine the number of points composing the dataset.
virtual double * GetPoint(vtkIdType ptId)=0
Get point coordinates with ptId such that: 0 <= ptId < NumberOfPoints.
vtkCellData * GetCellData()
Return a pointer to this dataset's cell data.
vtkDataArray * GetArray(int i)
Not recommended for use.
static ReturnTypeT Distance2BetweenPoints(const TupleRangeT1 &p1, const TupleRangeT2 &p2)
Compute distance squared between two points p1 and p2.
static constexpr double Pi()
A mathematical constant.
Allocate and hold a VTK object.
T * GetPointer() const noexcept
Get a raw pointer to the contained object.
represent and manipulate point attribute data
concrete class for storing a set of points
void GetCellPoints(vtkIdType, vtkIdList *idList) override
This method resets parameter idList, as there is no cell in a vtkPointSet.
vtkPointSet * NewInstance() const
Standard methods for type information and printing.
vtkPoints * GetPoints() override
Specify point array to define point coordinates.
vtkIdType GetNumberOfCells() override
This method always returns 0, as there are no cells in a vtkPointSet.
vtkIdType GetNumberOfPoints() override
See vtkDataSet for additional information.
void GetPoint(vtkIdType ptId, double x[3]) override
See vtkDataSet for additional information.
int GetCellType(vtkIdType) override
This method always returns VTK_EMPTY_CELL, as there is no cell in a vtkPointSet.
virtual int GetDataType() const
Return the underlying data type.
concrete dataset represents vertices, lines, polygons, and triangle strips
static vtkPolyData * SafeDownCast(vtkObjectBase *o)
double ComputeArea()
Compute the area of a polygon.
make a 2D or 3D multi-resolution mesh conforming by inserting hanging points
virtual std::vector< vtkSmartPointer< vtkPolyData > > GetRemotePoints(const std::vector< vtkPolyData * > &boundaries, const std::vector< int > &partitionedDataSetIds)
Called with the true boundary of every local partition: the edges (2D) or faces (3D) without neighbor...
Hold a reference to a vtkObjectBase instance.
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
dataset represents arbitrary combinations of all possible cell types
static vtkUnstructuredGrid * SafeDownCast(vtkObjectBase *o)
Standard methods for type information and printing.
void SetCells(int type, vtkCellArray *cells)
Provide cell information to define the dataset with a single type.
vtkIdType GetNumberOfCells() override
Standard vtkDataSet methods; see vtkDataSet.h for documentation.
int GetCellType(vtkIdType cellId) override
Get the type of the cell with the given cellId.
const std::string pointIds
const std::string pointData
vtkSmartPointer< T > TakeSmartPointer(T *obj)
Construct a vtkSmartPointer<T> containing obj.
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
#define VTK_STANDARD_NEW_BODY(thisClass)