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 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 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 // add the order array for every scalar array, except the ghostcells, the
93 // rankarray and the global ids
94 for(auto scalarArray : scalarArrays) {
95 int status = 0;
96 std::string arrayName = std::string(scalarArray->GetName());
97 if(arrayName != "GlobalPointIds" && arrayName != "vtkGhostType"
98 && arrayName != "RankArray") {
99 this->printMsg("Arrayname: " + arrayName);
100 vtkNew<ttkSimplexIdTypeArray> orderArray{};
101 orderArray->SetName(
103 orderArray->SetNumberOfComponents(1);
104 orderArray->SetNumberOfTuples(nVertices);
105
106 this->printMsg(std::to_string(scalarArray->GetDataType()));
108 scalarArray->GetDataType(),
109 (status = processScalarArray(
110 ttkUtils::GetPointer<ttk::SimplexId>(orderArray),
111 ttkUtils::GetPointer<T0>(scalarArray),
112 [triangulation](const ttk::SimplexId a) {
113 return triangulation->getVertexGlobalId(a);
114 },
115 [triangulation](const ttk::SimplexId a) {
116 return triangulation->getVertexRank(a);
117 },
118 [triangulation](const ttk::SimplexId a) {
119 return triangulation->getVertexLocalId(a);
120 },
121 nVertices, BurstSize, triangulation->getNeighborRanks())));
122
123 // On error cancel filter execution
124 if(status != 1)
125 return 0;
126 output->GetPointData()->AddArray(orderArray);
127 }
128 }
129 this->printMsg("Preconditioned selected scalar arrays", 1.0,
130 tm.getElapsedTime(), this->threadNumber_);
131 return 1;
132 } else {
133 this->printMsg("Necessary arrays are present, TTK is built with MPI "
134 "support, but not run with mpirun. Running sequentially.");
135 }
136 }
137#endif
138
139 for(auto scalarArray : scalarArrays) {
140 vtkNew<ttkSimplexIdTypeArray> orderArray{};
141 orderArray->SetName(
143 orderArray->SetNumberOfComponents(1);
144 orderArray->SetNumberOfTuples(nVertices);
145
146 switch(scalarArray->GetDataType()) {
147 vtkTemplateMacro(ttk::sortVertices(
148 nVertices, static_cast<VTK_TT *>(ttkUtils::GetVoidPointer(scalarArray)),
149 static_cast<int *>(nullptr),
150 static_cast<ttk::SimplexId *>(ttkUtils::GetVoidPointer(orderArray)),
151 this->threadNumber_));
152 }
153
154 output->GetPointData()->AddArray(orderArray);
155 this->printMsg("Generated order array for scalar array `"
156 + std::string{scalarArray->GetName()} + "'");
157 }
158
159 this->printMsg("Preconditioned selected scalar arrays", 1.0,
160 tm.getElapsedTime(), this->threadNumber_);
161
162 return 1;
163}
#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:225
int processScalarArray(ttk::SimplexId *orderArray, const DT *scalarArray, const GVGID &getVertexGlobalId, const GVR &getVertexRank, const GVLID &getVertexLocalId, const size_t nVerts, const int burstSize, std::vector< int > neighbors={}) const
int threadNumber_
Definition: BaseClass.h:95
int printMsg(const std::string &msg, const debug::Priority &priority=debug::Priority::INFO, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cout) const
Definition: Debug.h:118
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 ttkTypeMacroA(group, call)
Definition: ttkMacros.h:179