diff --git a/src/PostprocessData/CMakeLists.txt b/src/PostprocessData/CMakeLists.txt index 0e19ac04..da5f7715 100644 --- a/src/PostprocessData/CMakeLists.txt +++ b/src/PostprocessData/CMakeLists.txt @@ -13,6 +13,7 @@ set(SourceFiles region/regionPoints/lineRegionPoints/lineRegionPoints.cpp region/regionPoints/centerPointsRegionPoints/centerPointsRegionPoints.cpp region/regionPoints/multipleSpheresRegionPoints/multipleSpheresRegionPoints.cpp + region/regionPoints/rectMeshRegionPoints/rectMeshRegionPoints.cpp # Postprocess components postprocessComponent/postprocessComponent/postprocessComponent.cpp diff --git a/src/PostprocessData/postprocessComponent/PostprocessComponent/PostprocessComponents.cpp b/src/PostprocessData/postprocessComponent/PostprocessComponent/PostprocessComponents.cpp index 5556e342..30401895 100644 --- a/src/PostprocessData/postprocessComponent/PostprocessComponent/PostprocessComponents.cpp +++ b/src/PostprocessData/postprocessComponent/PostprocessComponent/PostprocessComponents.cpp @@ -26,6 +26,7 @@ Licence: #include "sphereRegionPoints.hpp" #include "lineRegionPoints.hpp" #include "multipleSpheresRegionPoints.hpp" +#include "rectMeshRegionPoints.hpp" namespace pFlow::postprocessData { @@ -37,6 +38,10 @@ template class PostprocessComponentGaussian; template class PostprocessComponentUniform; template class PostprocessComponentArithmetic; +template class PostprocessComponentGaussian; +template class PostprocessComponentUniform; +template class PostprocessComponentArithmetic; + template class PostprocessComponentGaussian; template class PostprocessComponentUniform; template class PostprocessComponentArithmetic; diff --git a/src/PostprocessData/region/regionPoints/rectMeshRegionPoints/rectMeshRegionPoints.cpp b/src/PostprocessData/region/regionPoints/rectMeshRegionPoints/rectMeshRegionPoints.cpp new file mode 100644 index 00000000..ad78e18d --- /dev/null +++ b/src/PostprocessData/region/regionPoints/rectMeshRegionPoints/rectMeshRegionPoints.cpp @@ -0,0 +1,111 @@ +#include "rectMeshRegionPoints.hpp" +#include "fieldsDataBase.hpp" +#include "numericConstants.hpp" + + +pFlow::postprocessData::rectMeshRegionPoints::rectMeshRegionPoints +( + const dictionary &dict, + fieldsDataBase &fieldsDataBase +) +: + regionPoints(dict, fieldsDataBase) +{ + const auto& rectMeshInfo = dict.subDict("rectMeshInfo"); + boxRegion_ = box(rectMeshInfo.subDict("boxInfo")); + nx = rectMeshInfo.getValMax("nx", 1); + ny = rectMeshInfo.getValMax("ny", 1); + nz = rectMeshInfo.getValMax("nz", 1); + + // boxRegion_ = box(minP, maxP); + cells_ = uint32x3(nx, ny, nz); + uint32 nCells = nx * ny * nz; + + volumes_.resize(nCells, boxRegion_.volume() / nCells); + diameter_.resize(nCells, 2 * pow(3 * boxRegion_.volume() / nCells / 4.0 / Pi, 1.0 / 3.0)); + selectedPoints_.resize(nCells); + centerPoints_.resize(nCells); + + + for(uint32 i = 0; i < nx; ++i) + { + for(uint32 j = 0; j < ny; ++j) + { + for(uint32 k = 0; k < nz; ++k) + { + // calculate the center point of each cell + uint32 index = (i * ny + j) * nz + k; + realx3 center = boxRegion_.minPoint() + + realx3( + (i + 0.5) * (boxRegion_.maxPoint().x() - boxRegion_.minPoint().x()) / nx, + (j + 0.5) * (boxRegion_.maxPoint().y() - boxRegion_.minPoint().y()) / ny, + (k + 0.5) * (boxRegion_.maxPoint().z() - boxRegion_.minPoint().z()) / nz + ); + centerPoints_[index] = center; + } + } + } +} + +bool pFlow::postprocessData::rectMeshRegionPoints::update() +{ + const auto points = database().updatePoints(); + for (auto& elem : selectedPoints_) + { + elem.clear(); + } + + real dx = (boxRegion_.maxPoint().x() - boxRegion_.minPoint().x()) / cells_.x(); + real dy = (boxRegion_.maxPoint().y() - boxRegion_.minPoint().y()) / cells_.y(); + real dz = (boxRegion_.maxPoint().z() - boxRegion_.minPoint().z()) / cells_.z(); + + for (uint32 i = 0; i < points.size(); ++i) + { + if(boxRegion_.isInside(points[i])) + { + uint indexX = (points[i] - boxRegion_.minPoint()).x() / dx; + uint indexY = (points[i] - boxRegion_.minPoint()).y() / dy; + uint indexZ = (points[i] - boxRegion_.minPoint()).z() / dz; + uint cellIndex = (indexX * cells_.y() + indexY) * cells_.z() + indexZ; + selectedPoints_[cellIndex].push_back(i); + } + } + return true; +} + +bool pFlow::postprocessData::rectMeshRegionPoints::write(iOstream &os) const +{ + os << "# vtk DataFile Version 3.0" << endl; + os << "postProcessData" << endl; + os << "ASCII" << endl; + os << "DATASET RECTILINEAR_GRID" << endl; + os << "DIMENSIONS " << nx + 1 << " " << ny + 1 << " " << nz + 1 << endl; + + auto [x, y , z] = boxRegion_.minPoint(); + auto [dx, dy, dz] = (boxRegion_.maxPoint() - boxRegion_.minPoint()) / realx3(nx, ny, nz); + + os << "X_COORDINATES " << nx + 1 << " float\n"; + for(int32 i = 0; i < nx + 1; i++) + { + os << x << "\n"; + x += dx; + } + + os << "Y_COORDINATES " << ny + 1 << " float\n"; + for(int32 j = 0; j < ny + 1; j++) + { + os << y << "\n"; + y += dy; + } + + os << "Z_COORDINATES " << nz + 1 << " float\n"; + for(int32 j = 0; j < nz + 1; j++) + { + os << z << "\n"; + z += dz; + } + + os << "CELL_DATA " << nx * ny * nz << endl; + + return true; +} diff --git a/src/PostprocessData/region/regionPoints/rectMeshRegionPoints/rectMeshRegionPoints.hpp b/src/PostprocessData/region/regionPoints/rectMeshRegionPoints/rectMeshRegionPoints.hpp new file mode 100644 index 00000000..f8bbaa8b --- /dev/null +++ b/src/PostprocessData/region/regionPoints/rectMeshRegionPoints/rectMeshRegionPoints.hpp @@ -0,0 +1,195 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +-----------------------------------------------------------------------------*/ + +/** + * @file rectMeshRegionPoints.hpp + * @brief A class representing a rectMesh region for point selection + * + * This class provides functionality to select points within a rectMesh region + * and to compute related properties such as volume and equivalent diameter. + * It inherits from regionPoints and implements all required virtual methods. + * + * @see regionPoints + * @see rectMesh + * @see fieldsDataBase + */ + +#ifndef __rectMeshRegionPoints_hpp__ +#define __rectMeshRegionPoints_hpp__ + +#include "regionPoints.hpp" +#include "box.hpp" +#include "Vectors.hpp" +#include "cells.hpp" + +namespace pFlow::postprocessData +{ + +class rectMeshRegionPoints +: + public regionPoints +{ +private: + + /// box object defining the region for point selection + box boxRegion_; + + /// Number of cells in each direction + uint32 nx, ny, nz; + + /// store the cells that are inside the box region + uint32x3 cells_; + + /// Center points of each cell in the rectMesh region + realx3Vector centerPoints_; + + /// Volume of each cell in the rectMesh region + realVector volumes_; + + /// Diameter of each cell in the rectMesh region + realVector diameter_; + + /// Indices of points that are selected by this region + Vector selectedPoints_; + +public: + + TypeInfo("rectMesh"); + + /** + * @brief Construct a rectMesh region for point selection + * + * @param dict Dictionary containing sphereInfo dictionary + * @param fieldsDataBase Database containing fields data + */ + rectMeshRegionPoints( + const dictionary& dict, + fieldsDataBase& fieldsDataBase); + + /// Destructor + ~rectMeshRegionPoints() override = default; + + /** + * @brief Get the number of regions + */ + uint32 size()const override + { + return volumes_.size(); + } + + /** + * @brief Check if the region is empty + * @return Always returns false + */ + bool empty()const override + { + return volumes_.empty(); + } + + /** + * @brief Get the volume of the rectMesh region + * @return A span containing the volume of the region + */ + span volumes()const override + { + return span(volumes_.data(), volumes_.size()); + } + + /** + * @brief Get the equivalent diameter of the rectMesh region + * @return A span containing the diameter of the region + */ + span eqDiameters()const override + { + return span(diameter_.data(), diameter_.size()); + } + + /** + * @brief Get the center of the rectMesh region + * @return A span containing the center point of the region + */ + span centers()const override + { + return span(centerPoints_.data(), centerPoints_.size()); + } + + /** + * @brief Get the indices of points within the region (const version) + * @param elem Element index (ignored as there's only one sphere) + * @return A span containing indices of points within the region + */ + span indices(uint32 elem)const override + { + if (elem >= size()) + { + fatalErrorInFunction + << "The element index is out of range. elem: " << elem + << " size: " << size() << endl; + fatalExit; + } + + return span(selectedPoints_[elem].data(), selectedPoints_[elem].size()); + } + + /** + * @brief Get the indices of points within the region (non-const version) + * @param elem Element index (ignored as there's only one sphere) + * @return A span containing indices of points within the region + */ + span indices(uint32 elem) override + { + if (elem >= size()) + { + fatalErrorInFunction + << "The element index is out of range. elem: " << elem + << " size: " << size() << endl; + fatalExit; + } + + return span(selectedPoints_[elem].data(), selectedPoints_[elem].size()); + } + + /** + * @brief Update the points selected by this region + * @return True if update was successful + */ + bool update()override; + + /** + * @brief Determine if data should be written to the same time file + * @return Always returns true + */ + bool writeToSameTimeFile()const override + { + return true; + } + + /** + * @brief Write region data to output stream + * @param os Output stream to write to + * @return True if write was successful + */ + bool write(iOstream& os)const override; + +}; + +} + +#endif // __sphereRegionPoints_hpp__ \ No newline at end of file diff --git a/src/phasicFlow/structuredData/box/box.hpp b/src/phasicFlow/structuredData/box/box.hpp index 13a3fe7b..92554250 100644 --- a/src/phasicFlow/structuredData/box/box.hpp +++ b/src/phasicFlow/structuredData/box/box.hpp @@ -111,6 +111,14 @@ public: return max_; } + INLINE_FUNCTION_HD + real volume()const + { + return (max_.x() - min_.x()) * + (max_.y() - min_.y()) * + (max_.z() - min_.z()); + } + //// - IO operation FUNCTION_H bool read(iIstream & is);