From 7f3b4e0e2cff635b67c7ee49c64d7b3ee6f31111 Mon Sep 17 00:00:00 2001 From: hamidrezanorouzi Date: Mon, 5 Sep 2022 11:14:41 +0430 Subject: [PATCH] utilities added --- .gitignore | 1 + CMakeLists.txt | 2 +- utilities/CMakeLists.txt | 10 + utilities/geometryPhasicFlow/CMakeLists.txt | 12 + utilities/geometryPhasicFlow/Wall/Wall.C | 103 +++++ utilities/geometryPhasicFlow/Wall/Wall.H | 113 ++++++ .../cylinderWall/cylinderWall.C | 101 +++++ .../cylinderWall/cylinderWall.H | 63 +++ .../geometryPhasicFlow/cylinderWall/zAxis.C | 150 ++++++++ .../geometryPhasicFlow/cylinderWall/zAxis.H | 107 ++++++ .../geometryPhasicFlow/geometryPhasicFlow.C | 98 +++++ .../geometryPhasicFlow/planeWall/planeWall.C | 75 ++++ .../geometryPhasicFlow/planeWall/planeWall.H | 60 +++ .../geometryPhasicFlow/stlWall/stlWall.C | 71 ++++ .../geometryPhasicFlow/stlWall/stlWall.H | 60 +++ utilities/pFlowToVTK/CMakeLists.txt | 9 + utilities/pFlowToVTK/geometric.C | 87 +++++ utilities/pFlowToVTK/geometric.H | 78 ++++ utilities/pFlowToVTK/pFlowToVTK.C | 142 +++++++ utilities/pFlowToVTK/pointFieldToVTK.H | 361 ++++++++++++++++++ utilities/pFlowToVTK/triSurfaceFieldToVTK.H | 245 ++++++++++++ utilities/pFlowToVTK/vtkFile.C | 75 ++++ utilities/pFlowToVTK/vtkFile.H | 90 +++++ utilities/particlesPhasicFlow/CMakeLists.txt | 11 + utilities/particlesPhasicFlow/empty/empty.C | 36 ++ utilities/particlesPhasicFlow/empty/empty.H | 94 +++++ .../particlesPhasicFlow/particlesPhasicFlow.C | 195 ++++++++++ .../positionOrdered/positionOrdered.C | 161 ++++++++ .../positionOrdered/positionOrdered.H | 115 ++++++ .../positionParticles/positionParticles.C | 110 ++++++ .../positionParticles/positionParticles.H | 98 +++++ .../positionRandom/positionRandom.C | 260 +++++++++++++ .../positionRandom/positionRandom.H | 113 ++++++ utilities/particlesPhasicFlow/setFields.H | 56 +++ 34 files changed, 3361 insertions(+), 1 deletion(-) create mode 100644 utilities/CMakeLists.txt create mode 100644 utilities/geometryPhasicFlow/CMakeLists.txt create mode 100755 utilities/geometryPhasicFlow/Wall/Wall.C create mode 100755 utilities/geometryPhasicFlow/Wall/Wall.H create mode 100644 utilities/geometryPhasicFlow/cylinderWall/cylinderWall.C create mode 100644 utilities/geometryPhasicFlow/cylinderWall/cylinderWall.H create mode 100644 utilities/geometryPhasicFlow/cylinderWall/zAxis.C create mode 100644 utilities/geometryPhasicFlow/cylinderWall/zAxis.H create mode 100755 utilities/geometryPhasicFlow/geometryPhasicFlow.C create mode 100755 utilities/geometryPhasicFlow/planeWall/planeWall.C create mode 100755 utilities/geometryPhasicFlow/planeWall/planeWall.H create mode 100755 utilities/geometryPhasicFlow/stlWall/stlWall.C create mode 100755 utilities/geometryPhasicFlow/stlWall/stlWall.H create mode 100644 utilities/pFlowToVTK/CMakeLists.txt create mode 100755 utilities/pFlowToVTK/geometric.C create mode 100755 utilities/pFlowToVTK/geometric.H create mode 100755 utilities/pFlowToVTK/pFlowToVTK.C create mode 100755 utilities/pFlowToVTK/pointFieldToVTK.H create mode 100644 utilities/pFlowToVTK/triSurfaceFieldToVTK.H create mode 100755 utilities/pFlowToVTK/vtkFile.C create mode 100755 utilities/pFlowToVTK/vtkFile.H create mode 100644 utilities/particlesPhasicFlow/CMakeLists.txt create mode 100755 utilities/particlesPhasicFlow/empty/empty.C create mode 100755 utilities/particlesPhasicFlow/empty/empty.H create mode 100755 utilities/particlesPhasicFlow/particlesPhasicFlow.C create mode 100755 utilities/particlesPhasicFlow/positionOrdered/positionOrdered.C create mode 100755 utilities/particlesPhasicFlow/positionOrdered/positionOrdered.H create mode 100755 utilities/particlesPhasicFlow/positionParticles/positionParticles.C create mode 100755 utilities/particlesPhasicFlow/positionParticles/positionParticles.H create mode 100755 utilities/particlesPhasicFlow/positionRandom/positionRandom.C create mode 100755 utilities/particlesPhasicFlow/positionRandom/positionRandom.H create mode 100755 utilities/particlesPhasicFlow/setFields.H diff --git a/.gitignore b/.gitignore index ed61ef2a..d0570535 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ build/** include/** bin/** lib/** +**/**notnow diff --git a/CMakeLists.txt b/CMakeLists.txt index e34b2463..3b3651a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,7 @@ add_subdirectory(src) add_subdirectory(solvers) -#add_subdirectory(utilities) +add_subdirectory(utilities) #add_subdirectory(test) diff --git a/utilities/CMakeLists.txt b/utilities/CMakeLists.txt new file mode 100644 index 00000000..1be15174 --- /dev/null +++ b/utilities/CMakeLists.txt @@ -0,0 +1,10 @@ + + + +add_subdirectory(particlesPhasicFlow) + +add_subdirectory(geometryPhasicFlow) + +add_subdirectory(pFlowToVTK) + + diff --git a/utilities/geometryPhasicFlow/CMakeLists.txt b/utilities/geometryPhasicFlow/CMakeLists.txt new file mode 100644 index 00000000..31aed235 --- /dev/null +++ b/utilities/geometryPhasicFlow/CMakeLists.txt @@ -0,0 +1,12 @@ + +set(source_files +geometryPhasicFlow.C +Wall/Wall.C +planeWall/planeWall.C +stlWall/stlWall.C +cylinderWall/zAxis.C +cylinderWall/cylinderWall.C +) +set(link_lib phasicFlow Geometry Kokkos::kokkos) + +pFlow_make_executable_install(geometryPhasicFlow source_files link_lib) diff --git a/utilities/geometryPhasicFlow/Wall/Wall.C b/utilities/geometryPhasicFlow/Wall/Wall.C new file mode 100755 index 00000000..9c5f539e --- /dev/null +++ b/utilities/geometryPhasicFlow/Wall/Wall.C @@ -0,0 +1,103 @@ +/*------------------------------- 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 "Wall.H" + +bool pFlow::Wall::readCommon(const dictionary& dict) +{ + materialName_ = dict.getVal("material"); + + motionName_ = dict.getValOrSet("motion", word("none")); + + name_ = dict.name(); + + return true; +} + + +pFlow::Wall::Wall(const dictionary& dict) +{ + if(!readCommon(dict)) + { + fatalExit; + } +} + + +bool pFlow::Wall::checkTrianlge +( + const realx3 &p1, + const realx3 &p2, + const realx3 &p3 +) +{ + realx3 ln = cross(p2 - p1, p3 - p1); + + if (ln.length() < smallValue) return false; + + return true; +} + +pFlow::uniquePtr +pFlow::Wall::create +( + const dictionary& dict +) +{ + word type = dict.getVal("type"); + + if( dictionaryvCtorSelector_.search(type) ) + { + return dictionaryvCtorSelector_[type] (dict); + } + else + { + printKeys + ( + fatalError << "Ctor Selector "<< type << " dose not exist. \n" + <<"Avaiable ones are: \n\n" + , + dictionaryvCtorSelector_ + ); + fatalExit; + } + return nullptr; +} + +namespace pFlow +{ + +bool checkNormalVec( + const realx3 &p1, + const realx3 &p2, + const realx3 &p3, + realx3& norm ) +{ + realx3 ln = cross(p2 - p1, p3 - p1); + real len = length(ln); + if (len < smallValue) return false; + + norm = ln/len; + + return true; +} + +} \ No newline at end of file diff --git a/utilities/geometryPhasicFlow/Wall/Wall.H b/utilities/geometryPhasicFlow/Wall/Wall.H new file mode 100755 index 00000000..d08a1c6e --- /dev/null +++ b/utilities/geometryPhasicFlow/Wall/Wall.H @@ -0,0 +1,113 @@ +/*------------------------------- 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 __Wall_H__ +#define __Wall_H__ + + +#include "virtualConstructor.H" +#include "Vectors.H" +#include "dictionary.H" + +namespace pFlow +{ + + +bool checkNormalVec( + const realx3 &p1, + const realx3 &p2, + const realx3 &p3, + realx3& norm ); + + +class Wall +{ +protected: + + realx3x3Vector triangles_; + + word name_; + + word materialName_; + + word motionName_; + + bool readCommon(const dictionary& ditc); + +public: + + // - type info + TypeName("Wall"); + + //// - Constructors + + // - empty + Wall(){} + + // - from dictionary + Wall(const dictionary& dict); + + + virtual ~Wall()=default; + + create_vCtor + ( + Wall, + dictionary, + (const dictionary& dict), + (dict) + ); + + //// - Methods + + // - + const realx3x3Vector& triangles()const + { + return triangles_; + } + + word name()const + { + return name_; + } + + word materialName()const + { + return materialName_; + } + + word motionName()const + { + return motionName_; + } + + static + bool checkTrianlge(const realx3& p1, const realx3& p2, const realx3& p3); + + static + uniquePtr create(const dictionary& dict); + +}; + +} + + +#endif diff --git a/utilities/geometryPhasicFlow/cylinderWall/cylinderWall.C b/utilities/geometryPhasicFlow/cylinderWall/cylinderWall.C new file mode 100644 index 00000000..bf10a5d8 --- /dev/null +++ b/utilities/geometryPhasicFlow/cylinderWall/cylinderWall.C @@ -0,0 +1,101 @@ +#include "cylinderWall.H" + + +bool pFlow::cylinderWall::readCylinderWall(const dictionary& dict) +{ + auto p1 = dict.getVal("p1"); + auto p2 = dict.getVal("p2"); + auto radius1 = dict.getVal("radius1"); + auto radius2 = dict.getVal("radius2") ; + + int32 resolution = dict.getValOrSet("resolution", 24 ); + + + return createCylinder(p1, p2, radius1, radius2, resolution); +} + +bool pFlow::cylinderWall::createCylinder( + const realx3& p1, + const realx3& p2, + real rad1, + real rad2, + int32 numDiv) +{ + + zAxis zAx(p1, p2); + + real L = zAx.length(); + + // number of wall elements will be twice numDiv + triangles_.clear(); + triangles_.reserve(2 * numDiv); + + realx3Vector r1P(numDiv + 1), r2P(numDiv + 1); + real dTheta = 2 * Pi / numDiv; + real theta = 0; + + for (int32 i = 0; i < numDiv + 1; i++) + { + r1P[i] = realx3(rad1*cos(theta), rad1*sin(theta), 0); + r2P[i] = realx3(rad2*cos(theta), rad2*sin(theta), L); + theta += dTheta; + } + + // transferring back all points to the original axis of cylinder + for (int32 i = 0; i < numDiv + 1; i++) + { + r1P[i] = zAx.transferBackZ(r1P[i]); + r2P[i] = zAx.transferBackZ(r2P[i]); + } + + realx3 norm; + for (int32 i = 0; i < numDiv; i++) + { + realx3 p1 = r1P[i]; + realx3 p2 = r2P[i]; + realx3 p3 = r2P[i + 1]; + realx3 p4 = r1P[i + 1]; + + if(checkNormalVec(p1, p2, p3, norm)) + { + triangles_.push_back(realx3x3(p1, p2, p3)); + } + else + { + fatalErrorInFunction<< + "planner input triangle: "< +void MatMul(T(&A)[nRow][nInner], T(&B)[nInner][nCol], T(&C)[nRow][nCol]); + +template +void assignMat(T(&A)[nRow][nCol], T(&B)[nRow][nCol]); + +class zAxis +{ +public: + // constructors + zAxis(const realx3 &lp1, const realx3 &lp2); + + real length()const + { + return pFlow::length(p2_-p1_); + } + + realx3 transferToZ(const realx3 & p); + + realx3 transferBackZ(const realx3 & p); + +private: + void makeTransMatrix(); +protected: + + realx3 p1_; + realx3 p2_; + realx3 n_; + + real Trans_z_xz_P1_[4][4]; + + real ITrans_P1_xz_z_[4][4]; +}; + + + +template +void MatMul(T(&A)[nRow][nInner], T(&B)[nInner][nCol], T(&C)[nRow][nCol]) +{ + + for (int32 row = 0; row < nRow; row++) + { + for (int32 col = 0; col < nCol; col++) + { + T sum = 0; + for (int inner = 0; inner < nInner; inner++) + { + sum += A[row][inner] * B[inner][col]; + } + C[row][col] = sum; + } + } +} + +template +void assignMat(T(&A)[nRow][nCol], T(&B)[nRow][nCol]) +{ + + for (int32 row = 0; row < nRow; row++) + { + for (int32 col = 0; col < nCol; col++) + { + B[row][col] = A[row][col]; + } + } +} + + +} + +#endif + diff --git a/utilities/geometryPhasicFlow/geometryPhasicFlow.C b/utilities/geometryPhasicFlow/geometryPhasicFlow.C new file mode 100755 index 00000000..26f03bf0 --- /dev/null +++ b/utilities/geometryPhasicFlow/geometryPhasicFlow.C @@ -0,0 +1,98 @@ +/*------------------------------- 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 "systemControl.H" +#include "Wall.H" +#include "multiTriSurface.H" +#include "geometryMotion.H" + +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::multiTriSurface; + +int main( int argc, char* argv[] ) +{ + +// this should be palced in each main +#include "initialize_Control.H" + + #include "setProperty.H" + + Report(0)<<"\nReading "<<"createGeometryDict"<<" . . ."< + ( + objectFile + ( + "createGeometryDict", + Control.settings().path(), + objectFile::READ_ALWAYS, + objectFile::WRITE_NEVER + ), + "createGeometryDict", + true + ); + + auto& geometryDict = objDict().getObject(); + + auto& surfacesDict = geometryDict.subDict("surfaces"); + + auto wallsDictName = surfacesDict.dictionaryKeywords(); + + + + multiTriSurface surface; + wordVector materials; + wordVector motion; + + for(auto& name:wallsDictName) + { + Report(1)<<"Creating wall "<("p1"); + auto p2 = dict.getVal("p2"); + auto p3 = dict.getVal("p3"); + auto p4 = dict.getVal("p4"); + + + if( Wall::checkTrianlge(p1,p2,p3) ) + { + triangles_.push_back(realx3x3(p1,p2,p3)); + }else + { + fatalErrorInFunction << + "points p1, p2 and p3 do not form a plane wall in dictionary " << dict.globalName()<("file"); + + + fileSystem file("",fileName); + + stlFile stl(file); + if(!stl.read()) + { + fatalErrorInFunction << + " error in reading stl file "<< file < +bool pFlow::dataToVTK( vtkFile& vtk, const triSurface& surface ) +{ + + + auto nP = surface.numPoints(); + auto hPoints = surface.points().hostVector(); + + vtk() << "DATASET POLYDATA" << endl; + vtk() << "POINTS " << nP << " float" << endl; + + + for ( auto i=0; i +bool pFlow::dataToVTK( vtkFile& vtk, const multiTriSurface& surface ) +{ + + auto nP = surface.numPoints(); + auto hPoints = surface.points().hostVector(); + + vtk() << "DATASET POLYDATA" << endl; + vtk() << "POINTS " << nP << " float" << endl; + + + for ( auto i=0; i +bool geomObjectToVTK(IOfileHeader& header, real time, fileSystem destPath, word bName) +{ + + if( ObjType::TYPENAME() != header.objectType() )return false; + + auto ioObjPtr = IOobject::make(header); + + auto& data = ioObjPtr().template getObject(); + + vtkFile vtk(destPath, bName, time); + + if(!vtk) return false; + + Report(1)<<"Converting geometry to vtk."< +bool dataToVTK(vtkFile& vtk, const Type& dataEntity) +{ + fatalErrorInFunction<< + "not implemented function!"; + fatalExit; + return false; +} + +template<> +bool dataToVTK( vtkFile& vtk, const triSurface& surface ); + +template<> +bool dataToVTK( vtkFile& vtk, const multiTriSurface& surface ); + + +} + +#endif //__geometric_H__ diff --git a/utilities/pFlowToVTK/pFlowToVTK.C b/utilities/pFlowToVTK/pFlowToVTK.C new file mode 100755 index 00000000..7087589a --- /dev/null +++ b/utilities/pFlowToVTK/pFlowToVTK.C @@ -0,0 +1,142 @@ +/*------------------------------- 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 "systemControl.H" +#include "pointFieldToVTK.H" +#include "triSurfaceFieldToVTK.H" +#include "timeFolder.H" +#include "commandLine.H" +#include "ranges.H" + +using pFlow::word; +using pFlow::wordVector; +using pFlow::geometryFolder__; +using pFlow::timeFolder; +using pFlow::fileSystem; +using pFlow::wordList; +using pFlow::IOfileHeader; +using pFlow::objectFile; +using pFlow::output; +using pFlow::endl; +using pFlow::multiTriSurface; +using pFlow::commandLine; +using pFlow::realCombinedRange; + +int main(int argc, char** argv ) +{ + word outFolder = (pFlow::CWD()/word("VTK")).wordPath(); + + commandLine cmds( + "pFlowToVTK", + "Convrtes the saved pointField and geometry" + " date in time folders into vtk file format."); + + wordVector times; + + bool noGoem = false; + cmds.add_flag( + "--no-geometry", + noGoem, + "Do not convert geometry to VTK file"); + + bool noParticle = false; + cmds.add_flag("--no-particles", + noParticle, + "Do not convert particle fields to VTK file"); + + cmds.addOption("-o,--out-folder", + outFolder, + "path to output folder of VTK", + "path"); + + cmds.addOption( + "-t,--time", + times.vectorField(), + "a space separated lits of time folders, or a strided range begin:stride:end, or an interval begin:end", + " "); + + if(!cmds.parse(argc, argv)) return 0; + + +// this should be palced in each main +#include "initialize_Control.H" + + + timeFolder folders(Control); + fileSystem destFolder = fileSystem(outFolder)/geometryFolder__; + fileSystem destFolderField = fileSystem(outFolder); + wordList geomfiles{"triSurface"}; + + realCombinedRange validRange; + if( cmds.count("--time") ) + { + if(!validRange.addRanges(times)) + { + fatalExit; + } + } + else + { + validRange.addIntervalRange(folders.startTime(), folders.endTime()); + } + + do + { + + if( !validRange.isMember( folders.time() ) )continue; + + output<< "time: " << cyanText( folders.time() )<<" s" < + +#include "vtkFile.H" +#include "pointFields.H" +#include "IOobject.H" + +namespace pFlow::PFtoVTK +{ + +template +bool addInt64PointField( + iOstream& os, + word fieldName, + int32 numActivePoints, + int64* field, + IncludeMaskType includeMask ); + +template +bool addRealPointField( + iOstream& os, + word fieldName, + int32 numActivePoints, + real* field, + IncludeMaskType includeMask ); + +template +bool addRealx3PointField( + iOstream& os, + word fieldName, + int32 numActivePoints, + realx3* field, + IncludeMaskType includeMask ); + +bool regexCheck(word TYPENAME, word fieldType) +{ + std::regex match("pointField\\<([A-Za-z1-9_]*)\\,([A-Za-z1-9_]*)\\>"); + std::smatch search1, search2; + if(!std::regex_match(fieldType, search1, match))return false; + if(!std::regex_match(TYPENAME, search2, match))return false; + if(search1.size()!=3)return false; + if(search1.size()!=search2.size())return false; + return search1[1] == search2[1]; +} + +template +bool checkFieldType(word objectType) +{ + //if( pointField::TYPENAME() == objectType )return true; + //if( pointField::TYPENAME() == objectType ) return true; + //if( pointField::TYPENAME() == objectType )return true; + return regexCheck(pointField::TYPENAME(), objectType); + +} + +bool convertIntTypesPointField( + iOstream& os, + const IOfileHeader& header, + const pointStructure& pStruct ) +{ + word objectType = header.objectType(); + + if( !(checkFieldType(objectType) || + checkFieldType(objectType) || + checkFieldType(objectType) || + checkFieldType(objectType) || + checkFieldType(objectType) || + checkFieldType