From fd039f234fc0e7ffd4cf34127b195e5c8387daa0 Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Sat, 3 Feb 2024 11:49:07 -0800 Subject: [PATCH] geometryPhasicFlow-pass1 and triSurface and multiTriSurface tested --- src/phasicFlow/CMakeLists.txt | 7 +- src/phasicFlow/containers/Field/Fields.hpp | 4 + src/phasicFlow/containers/Vector/Vectors.hpp | 2 + .../containers/VectorHD/VectorSingle.cpp | 27 +- .../containers/VectorHD/VectorSingle.hpp | 6 +- .../trisurfaceStructure/bitTransfer.hpp | 71 ----- .../trisurfaceStructure/triSurface.cpp | 234 -------------- .../trisurfaceStructure/triSurface.hpp | 288 ------------------ .../multiTriSurface.cpp | 101 +++--- .../multiTriSurface.hpp | 77 ++--- .../stlFile.cpp | 0 .../stlFile.hpp | 0 src/phasicFlow/triSurface/subSurface.cpp | 26 ++ src/phasicFlow/triSurface/subSurface.hpp | 105 +++++++ src/phasicFlow/triSurface/triSurface.cpp | 262 ++++++++++++++++ src/phasicFlow/triSurface/triSurface.hpp | 177 +++++++++++ .../triSurfaceKernels.hpp | 0 .../triangleFunctions.hpp | 29 +- src/phasicFlow/types/triple/triple.hpp | 18 +- utilities/CMakeLists.txt | 2 +- utilities/Utilities/CMakeLists.txt | 8 +- utilities/geometryPhasicFlow/CMakeLists.txt | 2 +- .../geometryPhasicFlow/geometryPhasicFlow.cpp | 75 ++--- 23 files changed, 788 insertions(+), 733 deletions(-) delete mode 100644 src/phasicFlow/structuredData/trisurfaceStructure/bitTransfer.hpp delete mode 100644 src/phasicFlow/structuredData/trisurfaceStructure/triSurface.cpp delete mode 100644 src/phasicFlow/structuredData/trisurfaceStructure/triSurface.hpp rename src/phasicFlow/{structuredData/trisurfaceStructure => triSurface}/multiTriSurface.cpp (79%) rename src/phasicFlow/{structuredData/trisurfaceStructure => triSurface}/multiTriSurface.hpp (67%) rename src/phasicFlow/{structuredData/trisurfaceStructure => triSurface}/stlFile.cpp (100%) rename src/phasicFlow/{structuredData/trisurfaceStructure => triSurface}/stlFile.hpp (100%) create mode 100644 src/phasicFlow/triSurface/subSurface.cpp create mode 100644 src/phasicFlow/triSurface/subSurface.hpp create mode 100644 src/phasicFlow/triSurface/triSurface.cpp create mode 100644 src/phasicFlow/triSurface/triSurface.hpp rename src/phasicFlow/{structuredData/trisurfaceStructure => triSurface}/triSurfaceKernels.hpp (100%) rename src/phasicFlow/{structuredData/trisurfaceStructure => triSurface}/triangleFunctions.hpp (70%) diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt index 29ec8261..e5a14d00 100644 --- a/src/phasicFlow/CMakeLists.txt +++ b/src/phasicFlow/CMakeLists.txt @@ -63,7 +63,7 @@ Timer/Timer.cpp Timer/Timers.cpp - +structuredData/zAxis/zAxis.cpp structuredData/box/box.cpp structuredData/line/line.cpp structuredData/infinitePlane/infinitePlane.cpp @@ -85,6 +85,11 @@ structuredData/pointStructure/selectors/selectBox/selectBox.cpp structuredData/pointStructure/selectors/selectRange/selectRange.cpp structuredData/pointStructure/selectors/selectRandom/selectRandom.cpp +triSurface/subSurface.cpp +triSurface/triSurface.cpp +triSurface/multiTriSurface.cpp + + commandLine/commandLine.cpp diff --git a/src/phasicFlow/containers/Field/Fields.hpp b/src/phasicFlow/containers/Field/Fields.hpp index abe589fe..a0b8d192 100644 --- a/src/phasicFlow/containers/Field/Fields.hpp +++ b/src/phasicFlow/containers/Field/Fields.hpp @@ -54,6 +54,10 @@ using uint64Field_D = Field; using uint64Field_H = Field ; +using uint32x3Field_D = Field; + +using uint32x3Field_H = Field; + using realField_D = Field; using realField_H = Field ; diff --git a/src/phasicFlow/containers/Vector/Vectors.hpp b/src/phasicFlow/containers/Vector/Vectors.hpp index 523444e4..ff1c1db7 100644 --- a/src/phasicFlow/containers/Vector/Vectors.hpp +++ b/src/phasicFlow/containers/Vector/Vectors.hpp @@ -41,6 +41,8 @@ using uint32Vector = Vector; using uint64Vector = Vector; +using uint32x3Vector = Vector; + using realVector = Vector ; using realx3Vector = Vector; diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.cpp b/src/phasicFlow/containers/VectorHD/VectorSingle.cpp index 451c091a..72f2790b 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.cpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.cpp @@ -1,3 +1,4 @@ +#include "VectorSingle.hpp" /*------------------------------- phasicFlow --------------------------------- O C enter of O O E ngineering and @@ -434,9 +435,29 @@ void pFlow::VectorSingle::assign(const VectorTypeHost& src) copy(deviceView(), src.hostView()); } -template -INLINE_FUNCTION_H -auto pFlow::VectorSingle::getSpan() +template +void pFlow::VectorSingle::append +( + const std::vector &appVec +) +{ + if(appVec.empty())return; + + auto srcSize = appVec.size(); + uint32 oldSize = size(); + uint32 newSize = srcSize + oldSize; + + changeSize(newSize); + + hostViewType1D temp(appVec.data(), srcSize ); + auto dest = Kokkos::subview(view_, Kokkos::make_pair(oldSize,newSize)); + + copy(dest, temp); + +} + +template +INLINE_FUNCTION_H auto pFlow::VectorSingle::getSpan() { return span(view_.data(), size()); } diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp index 7f32e1e3..137d3a46 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp @@ -282,6 +282,9 @@ public: /// The capacity of *this becomes the capacity of src. INLINE_FUNCTION_H void assign(const VectorTypeHost& src); + + INLINE_FUNCTION_H + void append(const std::vector& appVec); INLINE_FUNCTION_H auto getSpan(); @@ -493,7 +496,8 @@ inline iOstream& operator << (iOstream& os, const VectorSingle& #endif //__VectorSingle_hpp__ -/*INLINE_FUNCTION_H +/* +INLINE_FUNCTION_H bool append(const deviceViewType1D& dVec, size_t numElems) { diff --git a/src/phasicFlow/structuredData/trisurfaceStructure/bitTransfer.hpp b/src/phasicFlow/structuredData/trisurfaceStructure/bitTransfer.hpp deleted file mode 100644 index 720a2eb3..00000000 --- a/src/phasicFlow/structuredData/trisurfaceStructure/bitTransfer.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/*------------------------------- 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. - ------------------------------------------------------------------------------*/ - - -#ifndef __bitTransfer_hpp__ -#define __bitTransfer_hpp__ - - -#include "types.hpp" -#include "Vectors.hpp" - -namespace pFlow -{ - -// a simple functor that transfers 3 integers into a long variable and -// transfer the long to 3 integers - -class bitTransfer -{ -protected: - - static const int numBits_ = 21; - static const int numBits2_ = 2 * numBits_; - static const unsigned long mask1_ = 0x000000000001FFFFF; - static const unsigned long mask2_ = 0x0000003FFFFE00000; - static const unsigned long mask3_ = 0x07FFFFC0000000000; - -public: - - bitTransfer(){} - - inline unsigned long operator()(const unit3& int3 ) - { - return - static_cast(int3.x()) | - static_cast(int3.y()) << numBits_ | - static_cast(int3.z()) << numBits2_; - } - - inline unit3 operator() (const unsigned long& ul ) - { - return unit3 - ( - ul & mask1_, - (ul & mask2_)>> numBits_, - (ul & mask3_)>> numBits2_ - ); - } -}; - -} - - -#endif diff --git a/src/phasicFlow/structuredData/trisurfaceStructure/triSurface.cpp b/src/phasicFlow/structuredData/trisurfaceStructure/triSurface.cpp deleted file mode 100644 index 83507bad..00000000 --- a/src/phasicFlow/structuredData/trisurfaceStructure/triSurface.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/*------------------------------- 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. - ------------------------------------------------------------------------------*/ - - -#include "triSurface.hpp" -#include "error.hpp" -#include "iOstream.hpp" -#include "triSurfaceKernels.hpp" - - -pFlow::int32 pFlow::triSurface::addTriangle -( - const realx3x3 & tri, - realx3Vector& points, - int32x3Vector& vertices -) -{ - int32x3 newTri; - - // first point - if ( int32 i = find(points, tri.x()) ; i > -1) - { - newTri.x() = i; // existing point - } - else - { - points.push_back(tri.x()); // new point - newTri.x() = static_cast(points.size()) - 1; - } - - // second point - - if ( int32 j = find(points, tri.y()) ; j > -1) - { - newTri.y() = j; // existing point - } - else - { - points.push_back(tri.y()); // new point - newTri.y() = static_cast(points.size()) - 1; - } - - // third point - - if ( int32 k = find(points, tri.z()) ; k > -1) - { - newTri.z() = k; // existing point - } - else - { - points.push_back(tri.z()); // new point - newTri.z() = static_cast(points.size()) - 1; - } - - // adds the new tirple vertices to the list - vertices.push_back( newTri ); - - //output<< " points " <(vertices.size()) -1; -} - -pFlow::int32 pFlow::triSurface::calcMaxIndex()const -{ - - int32 maxIdx = -1; - - if(vertices_.size()>0) - { - auto verDeviceVec = vertices_.deviceViewAll(); - - Kokkos::parallel_reduce( - "triSurface::calcMaxIndex", - vertices_.size(), - LAMBDA_HD(int32 i, int32& valueToUpdate){ - valueToUpdate = max(valueToUpdate, max(verDeviceVec[i])); - }, - Kokkos::Max( maxIdx ) - ); - } - - return maxIdx; -} - -bool pFlow::triSurface::check() -{ - - auto maxIdx = calcMaxIndex(); - maxIndex_ = maxIdx; - if( maxIdx >= static_cast(points_.size())) return false; - return true; -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *// -pFlow::triSurface::triSurface() -: - points_("points"), - vertices_("vertices"), - area_("area"), - maxIndex_(-1) -{} - -pFlow::triSurface::triSurface -( - const realx3Vector& points, - const int32x3Vector& vertices -) -: - points_("points", "points", points), - vertices_("vertices", "vertices", vertices), - area_("area", "area"), - maxIndex_(-1) -{ - if( check() ) - { - fatalErrorInFunction<< - "the indices and number of points do not match. \n"; - fatalExit; - } - - area_.reallocate(vertices_.capacity(), vertices_.size()); - - pFlow::triSurfaceKernels::calculateArea(points_, vertices_, area_); - -} - - -pFlow::triSurface::triSurface -( - const realx3x3Vector& triangles -) -: - points_("points"), - vertices_("vertices"), - area_("area") -{ - - Vector points; - Vector vertices; - - points.clear(); - vertices.clear(); - - for( const auto& tr: triangles) - { - if(auto i= addTriangle(tr, points, vertices); i < 0 ) - { - fatalErrorInFunction << - "failed to insert a triangle into triSurface. \n"; - fatalExit; - } - } - - points_.assign(points); - - vertices_.assign(vertices); - - area_.reallocate(vertices_.capacity(), vertices_.size()); - - pFlow::triSurfaceKernels::calculateArea(points_, vertices_, area_); - - if( !check() ) - { - fatalErrorInFunction<< - "the indices and number of points do not match. \n"; - fatalExit; - } -} - - -bool pFlow::triSurface::readTriSurface -( - iIstream& is -) -{ - - std::cout<<"triSurface file is binary "<< is.isBinary()< dPoints_; - - deviceViewType1D dVectices_; - public: - - INLINE_FUNCTION_H - triangleAccessor( - int32 numPoints, - deviceViewType1D points, - int32 numTrianlges, - deviceViewType1D vertices ) - : - numPoints_(numPoints), - numTriangles_(numTrianlges), - dPoints_(points), - dVectices_(vertices) - {} - - INLINE_FUNCTION_HD - triangleAccessor(const triangleAccessor&)= default; - - INLINE_FUNCTION_HD - triangleAccessor& operator=(const triangleAccessor&)= default; - - INLINE_FUNCTION_HD - triangleAccessor(triangleAccessor&&)= default; - - INLINE_FUNCTION_HD - triangleAccessor& operator=(triangleAccessor&&)= default; - - INLINE_FUNCTION_HD - ~triangleAccessor()=default; - - INLINE_FUNCTION_HD - realx3x3 triangle(int32 i)const { - auto v = dVectices_[i]; - return realx3x3( - dPoints_[v.x_], - dPoints_[v.y_], - dPoints_[v.z_]); - } - - INLINE_FUNCTION_HD - realx3x3 operator()(int32 i)const { return triangle(i); } - - INLINE_FUNCTION_HD - realx3x3 operator[](int32 i)const { return triangle(i); } - - INLINE_FUNCTION_HD - int32 numPoints()const { return numPoints_; } - - INLINE_FUNCTION_HD - int32 numTrianlges()const { return numTriangles_;} - }; - -protected: - - /// points of triangles - realx3Field_D points_; - - /// vectices indices of triangles - int32x3Field_D vertices_; - - /// area of each triangle - realField_D area_; - - int32 maxIndex_ = -1; - - - // protected methods - - - int32 addTriangle(const realx3x3 & tri, realx3Vector& points, int32x3Vector& vertices); - - // - check if the range of indices in vectors match - bool check(); - -public: - - // - type info - TypeInfo("triSurface"); - - //// - Constructors - - // - empty - triSurface(); - - // - construct from components - triSurface(const realx3Vector& points, const int32x3Vector& vertices); - - // - construct from vertices of triangles - triSurface(const realx3x3Vector& triangles); - - virtual ~triSurface() = default; - - //// - Methods - size_t numPoints() const - { - return points_.size(); - } - - size_t numTriangles()const - { - return vertices_.size(); - } - - size_t size()const - { - return numTriangles(); - } - - size_t capacity()const - { - return vertices_.capacity(); - } - - int32 maxIndex()const - { - return maxIndex_; - } - - auto getTriangleAccessor()const - { - return triangleAccessor( - numPoints(), - points_.deviceViewAll(), - numTriangles(), - vertices_.deviceViewAll() - ); - } - - const realx3Vector_D& points() const - { - return points_; - } - - realx3Vector_D& points() - { - return points_; - } - - const realVector_D& area()const - { - return area_; - } - - realVector_D& area() - { - return area_; - } - - const realx3* pointsData_D()const - { - return points_.deviceViewAll().data(); - } - - realx3* pointsData_D() - { - return points_.deviceViewAll().data(); - } - - const int32x3Vector_D& vertices() const - { - return vertices_; - } - - int32x3Vector_D& vertices() - { - return vertices_; - } - - int32x3* verticesData_D() - { - return vertices_.deviceViewAll().data(); - } - - const int32x3* verticesData_D()const - { - return vertices_.deviceViewAll().data(); - } - - void clear() - { - points_.clear(); - vertices_.clear(); - area_.clear(); - } - - int32 calcMaxIndex()const; - - //// - IO operations - - bool readTriSurface(iIstream& is); - - bool writeTriSurface(iOstream& os)const; - - bool read(iIstream& is) - { - return readTriSurface(is); - } - - bool write(iOstream& os)const - { - return writeTriSurface(os); - } - -}; - -inline iIstream& operator >> (iIstream & is, triSurface & tri ) -{ - if(!tri.readTriSurface(is)) - { - ioErrorInFile(is.name(), is.lineNumber())<< - " error in reading triSurface from file.\n"; - fatalExit; - } - return is; -} - -inline iOstream& operator << (iOstream& os, const triSurface& tri) -{ - if( !tri.writeTriSurface(os) ) - { - ioErrorInFile(os.name(), os.lineNumber())<< - " error in writing triSurface to file.\n"; - fatalExit; - } - return os; -} - - -} // pFlow - - - -#endif diff --git a/src/phasicFlow/structuredData/trisurfaceStructure/multiTriSurface.cpp b/src/phasicFlow/triSurface/multiTriSurface.cpp similarity index 79% rename from src/phasicFlow/structuredData/trisurfaceStructure/multiTriSurface.cpp rename to src/phasicFlow/triSurface/multiTriSurface.cpp index 247748db..043919cd 100644 --- a/src/phasicFlow/structuredData/trisurfaceStructure/multiTriSurface.cpp +++ b/src/phasicFlow/triSurface/multiTriSurface.cpp @@ -21,7 +21,7 @@ Licence: #include "multiTriSurface.hpp" -void pFlow::multiTriSurface::calculateVars() +/*void pFlow::multiTriSurface::calculateVars() { numSurfaces_ = surfaceNames_.size(); @@ -80,9 +80,9 @@ void pFlow::multiTriSurface::calculateVars() verticesStartPos_.syncViews(); -} +}*/ -pFlow::multiTriSurface::multiTriSurface() +/*pFlow::multiTriSurface::multiTriSurface() : triSurface(), lastPointIndex_("lastPointIndex", "lastPointIndex"), @@ -90,9 +90,9 @@ pFlow::multiTriSurface::multiTriSurface() surfaceNames_("surfaceNames", "surfaceNames") { calculateVars(); -} +}*/ -bool pFlow::multiTriSurface::addTriSurface +/*bool pFlow::multiTriSurface::addTriSurface ( const word& name, const triSurface& tSurf @@ -152,17 +152,63 @@ bool pFlow::multiTriSurface::addTriSurface return true; +}*/ + +pFlow::multiTriSurface::multiTriSurface +( + const objectFile &obj, + repository *owner +) +: + triSurface(obj, owner) +{ + if( !IOobject::readObject() ) + { + fatalErrorInFunction<< + "Error in reading from file "<=numSurfaces())return points_.data()+numPoints(); return points_.data()+lastPointIndex_[i]+1; -}*/ - -bool pFlow::multiTriSurface::readMultiTriSurface -( - iIstream& is -) -{ - if( !readTriSurface(is) )return false; - - // from current position - if(!lastPointIndex_.read(is, true)) return false; - - if(!lastVertexIndex_.read(is, true) ) return false; - - if( !surfaceNames_.read(is, true)) return false; - - calculateVars(); - - return true; -} - -bool pFlow::multiTriSurface::writeMultiTriSurface -( - iOstream& os -)const -{ - if(!writeTriSurface(os)) return false; - - os << lastPointIndex_; - os << lastVertexIndex_; - os << surfaceNames_; - - return os.check(FUNCTION_NAME); -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/src/phasicFlow/structuredData/trisurfaceStructure/multiTriSurface.hpp b/src/phasicFlow/triSurface/multiTriSurface.hpp similarity index 67% rename from src/phasicFlow/structuredData/trisurfaceStructure/multiTriSurface.hpp rename to src/phasicFlow/triSurface/multiTriSurface.hpp index 8791be86..95dc9280 100644 --- a/src/phasicFlow/structuredData/trisurfaceStructure/multiTriSurface.hpp +++ b/src/phasicFlow/triSurface/multiTriSurface.hpp @@ -24,7 +24,8 @@ Licence: #include "triSurface.hpp" -#include "VectorDuals.hpp" +#include "subSurface.hpp" + namespace pFlow { @@ -34,70 +35,64 @@ class multiTriSurface : public triSurface { -protected: +private: + + subSurfaceList subSurfaces_; // - the index of last point of each triSurface - int32Field_HD lastPointIndex_; + - // - the index of the last vertex of each triSurface - int32Field_HD lastVertexIndex_; + - // - name of each surface - wordField surfaceNames_; + - int32Field_HD surfaceNumPoints_; - - int32Vector_HD pointsStartPos_; - - int32Field_HD surfaceNumVertices_; - - int32Vector_HD verticesStartPos_; - - int32 numSurfaces_ = 0; - - void calculateVars(); + //void calculateVars(); public: // - type info - TypeInfoNV("multiTriSurface"); + TypeInfo("multiTriSurface"); //// - Constructors // - emtpy - multiTriSurface(); + multiTriSurface(const objectFile& obj, repository* owner); - multiTriSurface(const multiTriSurface&) = default; + /*multiTriSurface(const multiTriSurface&) = default; multiTriSurface& operator = (const multiTriSurface&) = default; multiTriSurface(multiTriSurface&&) = delete; - multiTriSurface& operator = (multiTriSurface&&) = delete; + multiTriSurface& operator = (multiTriSurface&&) = delete; */ - ~multiTriSurface() = default; + ~multiTriSurface() override = default; //// - Methods - bool addTriSurface(const word& name, const triSurface& tSurf); + //bool addTriSurface(const word& name, const triSurface& tSurf); - bool addTriSurface(const word& name, const realx3x3Vector& vertices); + bool appendTriSurface(const word& name, const realx3x3Vector& vertices); - int32 numSurfaces()const + uint32 numSurfaces()const { - return numSurfaces_; + return subSurfaces_.size(); } - void clear() + const subSurfaceList& subSurfaces()const + { + return subSurfaces_; + } + /*void clear() { triSurface::clear(); lastPointIndex_.clear(); surfaceNames_.clear(); - } + }*/ - const auto& pointsStartPos()const + /*const auto& pointsStartPos()const { return pointsStartPos_; } @@ -135,27 +130,21 @@ public: word surfaceName(int32 i)const { return surfaceNames_[i]; - } + }*/ //// - IO operations - bool readMultiTriSurface(iIstream& is); + - bool writeMultiTriSurface(iOstream& os)const; + bool read(iIstream& is, const IOPattern& iop)override; - bool read(iIstream& is) - { - return readMultiTriSurface(is); - } - bool write(iOstream& os)const - { - return writeMultiTriSurface(os); - } + bool write(iOstream& os, const IOPattern& iop)const override; + }; -inline iIstream& operator >> (iIstream & is, multiTriSurface & tri ) +/*inline iIstream& operator >> (iIstream & is, multiTriSurface & tri ) { if(!tri.readMultiTriSurface(is)) { @@ -164,11 +153,11 @@ inline iIstream& operator >> (iIstream & is, multiTriSurface & tri ) fatalExit; } return is; -} +}*/ inline iOstream& operator << (iOstream& os, const multiTriSurface& tri) { - if( !tri.writeMultiTriSurface(os) ) + if( !tri.write(os, IOPattern::AllProcessorsDifferent) ) { ioErrorInFile(os.name(), os.lineNumber())<< " error in writing multiTriSurface to file.\n"; diff --git a/src/phasicFlow/structuredData/trisurfaceStructure/stlFile.cpp b/src/phasicFlow/triSurface/stlFile.cpp similarity index 100% rename from src/phasicFlow/structuredData/trisurfaceStructure/stlFile.cpp rename to src/phasicFlow/triSurface/stlFile.cpp diff --git a/src/phasicFlow/structuredData/trisurfaceStructure/stlFile.hpp b/src/phasicFlow/triSurface/stlFile.hpp similarity index 100% rename from src/phasicFlow/structuredData/trisurfaceStructure/stlFile.hpp rename to src/phasicFlow/triSurface/stlFile.hpp diff --git a/src/phasicFlow/triSurface/subSurface.cpp b/src/phasicFlow/triSurface/subSurface.cpp new file mode 100644 index 00000000..9fbd406b --- /dev/null +++ b/src/phasicFlow/triSurface/subSurface.cpp @@ -0,0 +1,26 @@ +#include "subSurface.hpp" + +pFlow::iOstream& pFlow::operator<<(iOstream &str, const subSurface &sub) +{ + + str.beginSquare()<>(iIstream &str, subSurface &sub) +{ + str.readBeginSquare("subSurface"); + str >> sub.name_; + str >> sub.start_; + str >> sub.end_; + str >> sub.pointStart_; + str >> sub.pointEnd_; + str.readEndSquare("subSurface"); + str.check(FUNCTION_NAME); + return str; +} diff --git a/src/phasicFlow/triSurface/subSurface.hpp b/src/phasicFlow/triSurface/subSurface.hpp new file mode 100644 index 00000000..f6cdc75f --- /dev/null +++ b/src/phasicFlow/triSurface/subSurface.hpp @@ -0,0 +1,105 @@ +/*------------------------------- 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. + +-----------------------------------------------------------------------------*/ + +#include "types.hpp" +#include "List.hpp" + +namespace pFlow +{ + +class subSurface +{ +private: + uint32 start_= 0; + + uint32 end_ = 0; + + uint32 pointStart_ = 0; + + uint32 pointEnd_=0; + + word name_; + +public: + subSurface()=default; + + subSurface(const word& name, uint32 start, uint32 end, uint32 pointStart, uint32 pointEnd) + : + start_(start), + end_(end), + pointStart_(pointStart), + pointEnd_(pointEnd), + name_(name) + {} + + subSurface(const subSurface&) = default; + + subSurface& operator = (const subSurface&) = default; + + ~subSurface()=default; + + uint32 operator()(uint32 i)const + { + return start_ + i; + } + uint32 start()const + { + return start_; + } + + uint32 end()const + { + return end_; + } + + uint32 pointStart()const + { + return pointStart_; + } + + uint32 pointEnd()const + { + return pointEnd_; + } + + const auto& name()const + { + return name_; + } + + uint32 size()const + { + return end_-start_; + } + + friend iOstream& operator<< (iOstream& str, const subSurface & sub); + + /// >> operator + friend iIstream& operator >> (iIstream & str, subSurface & sub); +}; + +iOstream& operator<< (iOstream& str, const subSurface & sub); + +iIstream& operator >> (iIstream & str, subSurface & sub); + +using subSurfaceList = List; + + +} \ No newline at end of file diff --git a/src/phasicFlow/triSurface/triSurface.cpp b/src/phasicFlow/triSurface/triSurface.cpp new file mode 100644 index 00000000..846046f5 --- /dev/null +++ b/src/phasicFlow/triSurface/triSurface.cpp @@ -0,0 +1,262 @@ +/*------------------------------- 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. + +-----------------------------------------------------------------------------*/ + + +#include "triSurface.hpp" +#include "Vectors.hpp" +#include "triangleFunctions.hpp" +#include "error.hpp" +#include "iOstream.hpp" + +//#include "triSurfaceKernels.hpp" + +namespace pFlow +{ +bool convertToTriSurfaceComponents +( + uint32 basePointIndex, + span tris, + realx3Vector& points, + uint32x3Vector& vertices, + realVector& area, + realx3Vector& normal +) +{ + auto nt = tris.size(); + + points.clear(); + points.reserve(nt); + + vertices.clear(); + vertices.resize(nt); + + area.clear(); + area.resize(nt); + + normal.clear(); + normal.resize(nt); + + for(auto i=0; i( basePointIndex + points.size() - 1); + } + else + { + newTri.comp1() = basePointIndex+static_cast(np); + } + + if(auto np = find(points, tri.comp2()); np<0 ) + { + points.push_back(tri.comp2()); // new point + newTri.comp2() = static_cast( basePointIndex + points.size() - 1); + } + else + { + newTri.comp2() = basePointIndex+static_cast(np); + } + + if(auto np = find(points, tri.comp3()); np<0 ) + { + points.push_back(tri.comp3()); // new point + newTri.comp3() = static_cast( basePointIndex + points.size() - 1); + } + else + { + newTri.comp3() = basePointIndex+static_cast(np); + } + + vertices[i] = newTri; + normal[i] = triangle::normal(tri.comp1(), tri.comp2(), tri.comp3()); + area[i] = triangle::surface(tri.comp1(), tri.comp2(), tri.comp3()); + } + + return true; +} + +} + + +pFlow::triSurface::triSurface +( + const objectFile &obj, + repository *owner +) +: + IOobject + ( + obj, + IOPattern::AllProcessorsSimilar, + owner + ), + points_("points", "points"), + vertices_("vertices", "vertices"), + area_("area", "area"), + normals_("normals","normals") +{ +} + +pFlow::triSurface::triSurface +( + const realx3x3Field_H &triangles, + repository* owner +) +: + IOobject + ( + objectFile + ( + triangles.name(), + "", + IOobject::READ_NEVER, + IOobject::WRITE_ALWAYS + ), + IOPattern::AllProcessorsSimilar, + owner + ), + points_("points", "points"), + vertices_("vertices", "vertices"), + area_("area", "area"), + normals_("normals","normals") +{ + if( !appendTriSurface(triangles) ) + { + fatalExit; + } + +} + +bool pFlow::triSurface::appendTriSurface +( + const realx3x3Field_H &triangles +) +{ + uint32 basePointIndex = numPoints(); + + auto triData = triangles.getSpan(); + + realx3Vector points("points"); + uint32x3Vector vertices("vertices"); + realVector area("area"); + realx3Vector normal("normal"); + + if( !convertToTriSurfaceComponents( + basePointIndex, + triData, + points, + vertices, + area, + normal)) + { + fatalErrorInFunction<< + "Error in constructing triSuface from raw data "<> (iIstream & is, triSurface & tri ) +{ + if(!tri.read(is, IOPattern::AllProcessorsDifferent)) + { + ioErrorInFile(is.name(), is.lineNumber())<< + " error in reading triSurface from file.\n"; + fatalExit; + } + return is; +} + +inline iOstream& operator << (iOstream& os, const triSurface& tri) +{ + if( !tri.write(os, IOPattern::AllProcessorsDifferent) ) + { + ioErrorInFile(os.name(), os.lineNumber())<< + " error in writing triSurface to file.\n"; + fatalExit; + } + return os; +} + + +} // pFlow + + + +#endif diff --git a/src/phasicFlow/structuredData/trisurfaceStructure/triSurfaceKernels.hpp b/src/phasicFlow/triSurface/triSurfaceKernels.hpp similarity index 100% rename from src/phasicFlow/structuredData/trisurfaceStructure/triSurfaceKernels.hpp rename to src/phasicFlow/triSurface/triSurfaceKernels.hpp diff --git a/src/phasicFlow/structuredData/trisurfaceStructure/triangleFunctions.hpp b/src/phasicFlow/triSurface/triangleFunctions.hpp similarity index 70% rename from src/phasicFlow/structuredData/trisurfaceStructure/triangleFunctions.hpp rename to src/phasicFlow/triSurface/triangleFunctions.hpp index a78e555c..62c1c076 100644 --- a/src/phasicFlow/structuredData/trisurfaceStructure/triangleFunctions.hpp +++ b/src/phasicFlow/triSurface/triangleFunctions.hpp @@ -23,17 +23,40 @@ Licence: #include "types.hpp" -namespace pFlow::triangleFunctions +namespace pFlow::triangle { INLINE_FUNCTION_HD -real triangleSurface( const realx3& p1, const realx3& p2, const realx3& p3) +real surface( const realx3& p1, const realx3& p2, const realx3& p3) { realx3 V1 = p2 - p1; realx3 V2 = p3 - p1; - return abs((cross(V1,V2)).length() / static_cast(2.0)); + return abs((cross(V1,V2)).length()/2.0); } +INLINE_FUNCTION_HD +realx3 normal(const realx3& p1, const realx3& p2, const realx3& p3) +{ + auto n = cross(p2-p1, p3-p1); + if( equal(n.length(), 0.0) ) + return zero3; + else + return normalize(n); +} + +INLINE_FUNCTION_HD +bool valid +( + const realx3& p1, + const realx3& p2, + const realx3& p3 +) +{ + return !equal(cross(p2-p1, p3-p1).length(), 0.0); +} + + + } #endif diff --git a/src/phasicFlow/types/triple/triple.hpp b/src/phasicFlow/types/triple/triple.hpp index 34b12176..c11154a0 100644 --- a/src/phasicFlow/types/triple/triple.hpp +++ b/src/phasicFlow/types/triple/triple.hpp @@ -146,7 +146,23 @@ struct triple /// access component INLINE_FUNCTION_HD const T & z()const { return z_; } - INLINE_FUNCTION_HD const T& comp(uint32 i) const {return *(this+i);} + /// access component + INLINE_FUNCTION_HD T & comp1(){ return x_; } + + /// access component + INLINE_FUNCTION_HD const T & comp1()const { return x_; } + + /// access component + INLINE_FUNCTION_HD T & comp2(){ return y_; } + + /// access component + INLINE_FUNCTION_HD const T & comp2()const { return y_; } + + /// access component + INLINE_FUNCTION_HD T & comp3(){ return z_; } + + /// access component + INLINE_FUNCTION_HD const T & comp3()const { return z_; } //// methods diff --git a/utilities/CMakeLists.txt b/utilities/CMakeLists.txt index 4216d45b..db9fee8b 100644 --- a/utilities/CMakeLists.txt +++ b/utilities/CMakeLists.txt @@ -3,7 +3,7 @@ add_subdirectory(particlesPhasicFlow) -#add_subdirectory(geometryPhasicFlow) +add_subdirectory(geometryPhasicFlow) #add_subdirectory(pFlowToVTK) diff --git a/utilities/Utilities/CMakeLists.txt b/utilities/Utilities/CMakeLists.txt index ddb55b6f..47124ab0 100644 --- a/utilities/Utilities/CMakeLists.txt +++ b/utilities/Utilities/CMakeLists.txt @@ -3,11 +3,11 @@ set(SourceFiles readFromTimeFolder.cpp readControlDict.cpp #vtkFile/vtkFile.cpp -#geometryPhasicFlow/Wall/Wall.cpp -#geometryPhasicFlow/planeWall/planeWall.cpp +geometryPhasicFlow/Wall/Wall.cpp +geometryPhasicFlow/planeWall/planeWall.cpp #geometryPhasicFlow/stlWall/stlWall.cpp -#geometryPhasicFlow/cylinderWall/cylinderWall.cpp -#geometryPhasicFlow/cuboidWall/cuboidWall.cpp +geometryPhasicFlow/cylinderWall/cylinderWall.cpp +geometryPhasicFlow/cuboidWall/cuboidWall.cpp ) #set(link_libs Kokkos::kokkos phasicFlow Particles Geometry) diff --git a/utilities/geometryPhasicFlow/CMakeLists.txt b/utilities/geometryPhasicFlow/CMakeLists.txt index 6fe0358e..11040b23 100644 --- a/utilities/geometryPhasicFlow/CMakeLists.txt +++ b/utilities/geometryPhasicFlow/CMakeLists.txt @@ -2,6 +2,6 @@ set(source_files geometryPhasicFlow.cpp ) -set(link_lib phasicFlow Geometry Kokkos::kokkos Utilities) +set(link_lib phasicFlow Kokkos::kokkos Utilities) pFlow_make_executable_install(geometryPhasicFlow source_files link_lib) diff --git a/utilities/geometryPhasicFlow/geometryPhasicFlow.cpp b/utilities/geometryPhasicFlow/geometryPhasicFlow.cpp index f6967f92..282de86a 100755 --- a/utilities/geometryPhasicFlow/geometryPhasicFlow.cpp +++ b/utilities/geometryPhasicFlow/geometryPhasicFlow.cpp @@ -18,26 +18,19 @@ Licence: -----------------------------------------------------------------------------*/ - +#include "vocabs.hpp" #include "systemControl.hpp" +#include "fileDictionary.hpp" #include "Wall.hpp" #include "Vectors.hpp" +#include "VectorSingles.hpp" #include "multiTriSurface.hpp" -#include "geometryMotion.hpp" +//#include "geometryMotion.hpp" #include "commandLine.hpp" -#include "readControlDict.hpp" +//#include "readControlDict.hpp" -using pFlow::output; -using pFlow::endl; -using pFlow::IOobject; -using pFlow::dictionary; -using pFlow::objectFile; -using pFlow::wordVector; -using pFlow::Wall; -using pFlow::geometry; -using pFlow::realx3x3Vector; -using pFlow::multiTriSurface; -using pFlow::commandLine; + +using namespace pFlow; int main( int argc, char* argv[] ) { @@ -59,11 +52,10 @@ int main( int argc, char* argv[] ) // this should be palced in each main #include "initialize_Control.hpp" - #include "setProperty.hpp" + //#include "setProperty.hpp" - REPORT(0)<<"\nReading "<<"createGeometryDict"<<" . . ."< - ( + REPORT(0)<<"\nReading "<<"geometryDict"<<" . . ."<(); - + auto& surfacesDict = geometryDict.subDict("surfaces"); auto wallsDictName = surfacesDict.dictionaryKeywords(); - multiTriSurface surface; - wordVector materials; - wordVector motion; + multiTriSurface surface + ( + objectFile + ( + triSurfaceFile__, + "", + objectFile::READ_NEVER, + objectFile::WRITE_ALWAYS + ), + &Control.geometry() + ); + + //wordVector materials; + //wordVector motion; for(auto& name:wallsDictName) { - REPORT(1)<<"Creating wall "<