9#include <vtkDataArray.h>
10#include <vtkDataSet.h>
11#include <vtkIdTypeArray.h>
12#include <vtkInformation.h>
13#include <vtkIntArray.h>
14#include <vtkPointData.h>
19 this->SetNumberOfInputPorts(1);
20 this->SetNumberOfOutputPorts(1);
24 this->ArraySelection->AddObserver(
25 vtkCommand::ModifiedEvent,
this, &ttkArrayPreconditioning::Modified);
29 vtkInformation *info) {
31 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkDataSet");
38 vtkInformation *info) {
47 vtkInformationVector **inputVector,
48 vtkInformationVector *outputVector) {
50 auto input = vtkDataSet::GetData(inputVector[0]);
51 auto output = vtkDataSet::GetData(outputVector);
54 int keepGoing = checkEmptyMPIInput<vtkDataSet>(input);
61 output->ShallowCopy(input);
63 auto pointData = input->GetPointData();
64 size_t nVertices = input->GetNumberOfPoints();
66 std::vector<vtkDataArray *> scalarArrays{};
68 if(SelectFieldsWithRegexp) {
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);
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);
91 if(ttk::isRunningWithMPI()) {
94 for(
auto scalarArray : scalarArrays) {
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{};
103 orderArray->SetNumberOfComponents(1);
104 orderArray->SetNumberOfTuples(nVertices);
106 this->
printMsg(std::to_string(scalarArray->GetDataType()));
108 scalarArray->GetDataType(),
110 ttkUtils::GetPointer<ttk::SimplexId>(orderArray),
111 ttkUtils::GetPointer<T0>(scalarArray),
113 return triangulation->getVertexGlobalId(a);
116 return triangulation->getVertexRank(a);
119 return triangulation->getVertexLocalId(a);
121 nVertices, BurstSize, triangulation->getNeighborRanks())));
126 output->GetPointData()->AddArray(orderArray);
129 this->
printMsg(
"Preconditioned selected scalar arrays", 1.0,
130 tm.getElapsedTime(), this->threadNumber_);
133 this->
printMsg(
"Necessary arrays are present, TTK is built with MPI "
134 "support, but not run with mpirun. Running sequentially.");
139 for(
auto scalarArray : scalarArrays) {
140 vtkNew<ttkSimplexIdTypeArray> orderArray{};
143 orderArray->SetNumberOfComponents(1);
144 orderArray->SetNumberOfTuples(nVertices);
146 switch(scalarArray->GetDataType()) {
149 static_cast<int *
>(
nullptr),
154 output->GetPointData()->AddArray(orderArray);
155 this->
printMsg(
"Generated order array for scalar array `"
156 + std::string{scalarArray->GetName()} +
"'");
159 this->
printMsg(
"Preconditioned selected scalar arrays", 1.0,
160 tm.getElapsedTime(), this->threadNumber_);
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
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
ttkArrayPreconditioning()
int FillOutputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
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 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
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.
vtkStandardNewMacro(ttkArrayPreconditioning)
#define ttkTypeMacroA(group, call)