TTK
Loading...
Searching...
No Matches
ttkArrayPreconditioning.cpp
Go to the documentation of this file.
2#include <Triangulation.h>
4#include <ttkMacros.h>
5#include <ttkUtils.h>
6
7#include <regex>
8#include <vtkCommand.h>
9#include <vtkDataArray.h>
10#include <vtkDataSet.h>
11#include <vtkIdTypeArray.h>
12#include <vtkInformation.h>
13#include <vtkIntArray.h>
14#include <vtkPointData.h>
15
17
19 this->SetNumberOfInputPorts(1);
20 this->SetNumberOfOutputPorts(1);
21
22 // ensure that modifying the selection re-triggers the filter
23 // (c.f. vtkPassSelectedArrays.cxx)
24 this->ArraySelection->AddObserver(
25 vtkCommand::ModifiedEvent, this, &ttkArrayPreconditioning::Modified);
26}
27
29 vtkInformation *info) {
30 if(port == 0) {
31 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
32 return 1;
33 }
34 return 0;
35}
36
38 vtkInformation *info) {
39 if(port == 0) {
41 return 1;
42 }
43 return 0;
44}
45
47 vtkInformationVector **inputVector,
48 vtkInformationVector *outputVector) {
49
50 auto input = vtkDataSet::GetData(inputVector[0]);
51 auto output = vtkDataSet::GetData(outputVector);
52 ttk::Timer tm{};
53
54 int const keepGoing = checkEmptyMPIInput<vtkDataSet>(input);
55 if(keepGoing < 2) {
56 return keepGoing;
57 }
58#ifdef TTK_ENABLE_MPI
59 const auto triangulation{this->GetTriangulation(input)};
60#endif
61 output->ShallowCopy(input);
62
63 auto pointData = input->GetPointData();
64 size_t const nVertices = input->GetNumberOfPoints();
65
66 std::vector<vtkDataArray *> scalarArrays{};
67
68 if(SelectFieldsWithRegexp) {
69 // select all input point data arrays whose name is matching the regexp
70 const auto n = pointData->GetNumberOfArrays();
71 for(int i = 0; i < n; ++i) {
72 auto array = pointData->GetArray(i);
73 if(array != nullptr && array->GetName() != nullptr
74 && std::regex_match(array->GetName(), std::regex(RegexpString))) {
75 scalarArrays.emplace_back(array);
76 }
77 }
78 } else {
79 // get all selected input point data arrays
80 for(int i = 0; i < pointData->GetNumberOfArrays(); ++i) {
81 auto array = pointData->GetArray(i);
82 if(array != nullptr && array->GetName() != nullptr
83 && ArraySelection->ArrayIsEnabled(array->GetName())) {
84 scalarArrays.emplace_back(array);
85 }
86 }
87 }
88
89#ifdef TTK_ENABLE_MPI
90 if(GlobalOrder) {
91 if(ttk::isRunningWithMPI()) {
92
93 this->preconditionTriangulation(triangulation);
94 // add the order array for every scalar array, except the ghostcells, the
95 // rankarray and the global ids
96 for(auto scalarArray : scalarArrays) {
97 int status = 0;
98 std::string arrayName = std::string(scalarArray->GetName());
99 if(arrayName != "GlobalPointIds" && arrayName != "vtkGhostType"
100 && arrayName != "RankArray") {
101 this->printMsg("Arrayname: " + arrayName);
102 vtkNew<ttkSimplexIdTypeArray> orderArray{};
103 orderArray->SetName(
105 orderArray->SetNumberOfComponents(1);
106 orderArray->SetNumberOfTuples(nVertices);
107
108 this->printMsg(std::to_string(scalarArray->GetDataType()));
109 ttkTypeMacroAT(scalarArray->GetDataType(), triangulation->getType(),
110 (status = processScalarArray<T0, T1>(
111 static_cast<const T1 *>(triangulation->getData()),
112 ttkUtils::GetPointer<ttk::SimplexId>(orderArray),
113 ttkUtils::GetPointer<T0>(scalarArray), nVertices)));
114
115 // On error cancel filter execution
116 if(status != 1)
117 return 0;
118 output->GetPointData()->AddArray(orderArray);
119 triangulation->setIsOrderArrayGlobal(
120 ttkUtils::GetVoidPointer(scalarArray), true);
121 }
122 }
123 this->printMsg("Preconditioned selected scalar arrays", 1.0,
124 tm.getElapsedTime(), this->threadNumber_);
125 return 1;
126 } else {
127 this->printMsg("Necessary arrays are present, TTK is built with MPI "
128 "support, but not run with mpirun. Running sequentially.");
129 }
130 }
131#endif
132
133 for(auto scalarArray : scalarArrays) {
134 vtkNew<ttkSimplexIdTypeArray> orderArray{};
135 orderArray->SetName(
137 orderArray->SetNumberOfComponents(1);
138 orderArray->SetNumberOfTuples(nVertices);
139
140 switch(scalarArray->GetDataType()) {
141 vtkTemplateMacro(ttk::sortVertices(
142 nVertices, static_cast<VTK_TT *>(ttkUtils::GetVoidPointer(scalarArray)),
143 static_cast<int *>(nullptr),
144 static_cast<ttk::SimplexId *>(ttkUtils::GetVoidPointer(orderArray)),
145 this->threadNumber_));
146 }
147#ifdef TTK_ENABLE_MPI
148 triangulation->setIsOrderArrayGlobal(
149 ttkUtils::GetVoidPointer(scalarArray), false);
150#endif // TTK_ENABLE_MPI
151 output->GetPointData()->AddArray(orderArray);
152 this->printMsg("Generated order array for scalar array `"
153 + std::string{scalarArray->GetName()} + "'");
154 }
155
156 this->printMsg("Preconditioned selected scalar arrays", 1.0,
157 tm.getElapsedTime(), this->threadNumber_);
158
159 return 1;
160}
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition BaseClass.h:47
static vtkInformationIntegerKey * SAME_DATA_TYPE_AS_INPUT_PORT()
ttk::Triangulation * GetTriangulation(vtkDataSet *dataSet)
static std::string GetOrderArrayName(vtkDataArray *const array)
TTK VTK-filter to generate order fields.
int FillInputPortInformation(int port, vtkInformation *info) override
int FillOutputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
Definition ttkUtils.cpp:226
int preconditionTriangulation(AbstractTriangulation *triangulation)
void sortVertices(const size_t nVerts, const scalarType *const scalars, const idType *const offsets, SimplexId *const order, const int nThreads)
Sort vertices according to scalars disambiguated by offsets.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22
vtkStandardNewMacro(ttkArrayPreconditioning)
#define ttkTypeMacroAT(group0, group1, call)
Definition ttkMacros.h:272
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)