11#include <vtkAbstractArray.h>
12#include <vtkCellData.h>
13#include <vtkCellLocator.h>
14#include <vtkDataArray.h>
15#include <vtkDoubleArray.h>
16#include <vtkIntArray.h>
17#include <vtkLongLongArray.h>
18#include <vtkXMLUnstructuredGridReader.h>
33 std::array<double, 3>
const& ranges, std::array<double, 3>
const& cellsize)
35 if (cellsize[0] <= 0 || cellsize[1] <= 0 || cellsize[2] <= 0)
37 OGS_FATAL(
"A cellsize ({},{},{}) is not allowed to be <= 0",
38 cellsize[0], cellsize[1], cellsize[2]);
40 std::array<double, 3> numberOfVoxel = {ranges[0] / cellsize[0],
41 ranges[1] / cellsize[1],
42 ranges[2] / cellsize[2]};
44 if (ranges[0] < 0 || ranges[1] < 0 || ranges[2] < 0)
47 "The difference of max-min ({},{},{}) is not allowed to be < 0",
48 ranges[0], ranges[1], ranges[2]);
50 std::replace(numberOfVoxel.begin(), numberOfVoxel.end(), 0, 1);
52 return {
static_cast<std::size_t
>(std::lround(numberOfVoxel[0])),
53 static_cast<std::size_t
>(std::lround(numberOfVoxel[1])),
54 static_cast<std::size_t
>(std::lround(numberOfVoxel[2]))};
57std::vector<int>
assignCellIds(vtkSmartPointer<vtkUnstructuredGrid>
const& mesh,
59 std::array<std::size_t, 3>
const& dims,
60 std::array<double, 3>
const& cellsize)
62 vtkSmartPointer<vtkCellLocator> locator =
63 vtkSmartPointer<vtkCellLocator>::New();
64 locator->SetDataSet(mesh);
67 std::vector<int> cell_ids;
68 cell_ids.reserve(dims[0] * dims[1] * dims[2]);
69 std::array<double, 3>
const grid_max = {min[0] + dims[0] * cellsize[0],
70 min[1] + dims[1] * cellsize[1],
71 min[2] + dims[2] * cellsize[2]};
73 double const start[3] = {min[0] + cellsize[0] / 2.,
74 min[1] + cellsize[1] / 2.,
75 min[2] + cellsize[2] / 2.};
77 for (pnt[2] = start[2]; pnt[2] < grid_max[2]; pnt[2] += cellsize[2])
79 for (pnt[1] = start[1]; pnt[1] < grid_max[1]; pnt[1] += cellsize[1])
81 for (pnt[0] = start[0]; pnt[0] < grid_max[0]; pnt[0] += cellsize[0])
83 cell_ids.push_back(
static_cast<int>(locator->FindCell(pnt)));
91 std::unique_ptr<MeshLib::Mesh>& grid)
95 cell_id_name, 0,
static_cast<int>(mesh->GetNumberOfCells()),
true);
97 if (n_elems_marked == grid->getNumberOfElements())
99 ERR(
"No valid elements found. Aborting...");
112template <
typename T,
typename VTK_TYPE>
117 if (cell_ids ==
nullptr)
124 std::size_t
const n_elems = cell_ids->size();
126 for (std::size_t j = 0; j < n_elems; ++j)
127 arr[j] = vtk_arr->GetValue((*cell_ids)[j]);
134 vtkSmartPointer<vtkCellData>
const cell_data,
135 char const*
const name)
137 using DataArrayType = vtkAOSDataArrayTemplate<T>;
138 vtkSmartPointer<DataArrayType>
const arr =
139 dynamic_cast<DataArrayType*
>(cell_data->GetArray(name));
149 std::unique_ptr<MeshLib::Mesh>
const& grid)
151 assert(mesh !=
nullptr);
152 assert(grid !=
nullptr);
153 vtkSmartPointer<vtkCellData>
const cell_data = mesh->GetCellData();
154 for (
int i = 0; i < cell_data->GetNumberOfArrays(); ++i)
156 auto const name = cell_data->GetArrayName(i);
163 WARN(
"Ignoring array '{:s}', array type {:s} not implemented...",
165 cell_data->GetArray(name)->GetDataTypeAsString());
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the Point3d class.
const std::vector< std::size_t > & getSearchedElementIDs() const
return marked elements
std::size_t searchByPropertyValueRange(std::string const &property_name, PROPERTY_TYPE const min_property_value, PROPERTY_TYPE const max_property_value, bool outside_of)
Properties & getProperties()
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)
PropertyVector< T > const * getPropertyVector(std::string_view name) const