utilities added

This commit is contained in:
hamidrezanorouzi
2022-09-05 11:14:41 +04:30
parent fb3fcf5945
commit 7f3b4e0e2c
34 changed files with 3361 additions and 1 deletions

View File

@ -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)

View File

@ -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<word>("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>
pFlow::Wall::create
(
const dictionary& dict
)
{
word type = dict.getVal<word>("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;
}
}

View File

@ -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<Wall> create(const dictionary& dict);
};
}
#endif

View File

@ -0,0 +1,101 @@
#include "cylinderWall.H"
bool pFlow::cylinderWall::readCylinderWall(const dictionary& dict)
{
auto p1 = dict.getVal<realx3>("p1");
auto p2 = dict.getVal<realx3>("p2");
auto radius1 = dict.getVal<real>("radius1");
auto radius2 = dict.getVal<real>("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: "<<realx3x3(p1, p2, p3)<<endl;
return false;
}
if (checkNormalVec(p3, p4, p1, norm))
{
triangles_.push_back(realx3x3(p3, p4, p1));
}
else
{
fatalErrorInFunction<<
"planner input triangle: "<<realx3x3(p3, p4, p1)<<endl;
return false;
}
}
return true;
}
pFlow::cylinderWall::cylinderWall()
{}
pFlow::cylinderWall::cylinderWall(
const dictionary& dict
)
:
Wall(dict)
{
if( !readCylinderWall(dict) )
{
fatalExit;
}
}

View File

@ -0,0 +1,63 @@
/*------------------------------- 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 __cylinderWall_H__
#define __cylinderWall_H__
#include "Wall.H"
#include "zAxis.H"
namespace pFlow
{
class cylinderWall
:
public Wall
{
protected:
bool readCylinderWall(const dictionary& dict);
bool createCylinder(const realx3& p1, const realx3& p2, real rad1, real rad2, int32 numDiv);
public:
TypeName("cylinderWall");
cylinderWall();
cylinderWall(const dictionary& dict);
add_vCtor
(
Wall,
cylinderWall,
dictionary
);
};
} // pFlow
#endif //__cylinderWall_H__

View File

@ -0,0 +1,150 @@
/*------------------------------- 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 "zAxis.H"
pFlow::zAxis::zAxis(const realx3 &p1, const realx3 &p2) :
p1_(p1),
p2_(p2)
{
n_ = p2-p1;
auto len = pFlow::length(n_);
if(len < smallValue )
{
fatalExit;
}
n_ /= len;
makeTransMatrix();
}
pFlow::realx3 pFlow::zAxis::transferToZ(const realx3 & p)
{
real pp[4][1] = {p.x(), p.y(), p.z(), 1.0};
real pn[4][1];
MatMul(Trans_z_xz_P1_, pp, pn);
return realx3(
pn[0][0],
pn[1][0],
pn[2][0]
);
}
pFlow::realx3 pFlow::zAxis::transferBackZ(const realx3 & p)
{
real pp[4][1] = { p.x(), p.y(), p.z(), 1.0 };
real pn[4][1];
MatMul(ITrans_P1_xz_z_, pp, pn);
return realx3(
pn[0][0],
pn[1][0],
pn[2][0]
);
}
void pFlow::zAxis::makeTransMatrix()
{
// transfering point p1 to the origin
real TransP1[4][4] =
{
1.0, 0.0, 0.0, -p1_.x(),
0.0, 1.0, 0.0, -p1_.y(),
0.0, 0.0, 1.0, -p1_.z(),
0.0, 0.0, 0.0, 1.0
};
// for transformation back
real ITransP1[4][4] =
{
1.0, 0.0, 0.0, p1_.x(),
0.0, 1.0, 0.0, p1_.y(),
0.0, 0.0, 1.0, p1_.z(),
0.0, 0.0, 0.0, 1.0
};
real u = n_.x();
real v = n_.y();
real w = n_.z();
real u2v2 = sqrt(u*u + v*v);
//correcting the transformation matrix in the case of coincidence with z - axis
if ( equal(w,1.0) )
{
assignMat(TransP1 , Trans_z_xz_P1_);
assignMat(ITransP1, ITrans_P1_xz_z_);
return;
}
u2v2 = max(smallValue, u2v2);
real TransXZ[4][4] =
{
u / u2v2, v / u2v2, 0.0, 0.0,
-v / u2v2, u / u2v2, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
real TransZ[4][4] =
{
w, 0.0, -u2v2, 0.0,
0.0, 1.0, 0.0, 0.0,
u2v2, 0.0, w, 0.0,
0.0, 0.0, 0.0, 1.0
};
real temp[4][4];
// creat transformation matrix to transfer point from line axis to z-axis
MatMul(TransXZ, TransP1, temp);
MatMul(TransZ, temp, Trans_z_xz_P1_);
real ITransXZ[4][4] =
{
u / u2v2, -v / u2v2, 0.0, 0.0,
+v / u2v2, u / u2v2, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
real ITransZ[4][4] =
{
w, 0.0, +u2v2, 0.0,
0.0, 1.0, 0.0, 0.0,
-u2v2, 0.0, w, 0.0,
0.0, 0.0, 0.0, 1.0
};
// creat transformation matrix to transfer point to from z-axis to line axis
MatMul(ITransXZ, ITransZ, temp);
MatMul(ITransP1, temp, ITrans_P1_xz_z_);
}

View File

@ -0,0 +1,107 @@
/*------------------------------- 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.
-----------------------------------------------------------------------------*/
/*
class name: zAxis
a class for transfering points to a cylinderical coordinates defined by points
p1 and p2
*/
#ifndef __zAxis_H__
#define __zAxis_H__
#include "types.H"
namespace pFlow
{
template <typename T, int32 nRow, int32 nInner, int32 nCol >
void MatMul(T(&A)[nRow][nInner], T(&B)[nInner][nCol], T(&C)[nRow][nCol]);
template <typename T, int32 nRow, int32 nCol >
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 <typename T, int32 nRow, int32 nInner, int32 nCol >
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 <typename T, int32 nRow, int32 nCol >
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

View File

@ -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"<<" . . ."<<endReport;
auto objDict = IOobject::make<dictionary>
(
objectFile
(
"createGeometryDict",
Control.settings().path(),
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
"createGeometryDict",
true
);
auto& geometryDict = objDict().getObject<dictionary>();
auto& surfacesDict = geometryDict.subDict("surfaces");
auto wallsDictName = surfacesDict.dictionaryKeywords();
multiTriSurface surface;
wordVector materials;
wordVector motion;
for(auto& name:wallsDictName)
{
Report(1)<<"Creating wall "<<greenText(name)<<" from file dictionary . . . "<<endReport;
auto wallPtr = Wall::create( surfacesDict.subDict(name));
auto& wall = wallPtr();
Report(1)<<"wall type is "<<greenText(wall.typeName())<<'\n'<<endReport;
surface.addTriSurface(wall.name(), wall.triangles());
materials.push_back(wall.materialName());
motion.push_back(wall.motionName());
}
Report(1)<<"Selected wall materials are "<<cyanText(materials)<<'\n'<<endReport;
Report(0)<< "\nCreating geometry . . ."<<endReport;
auto geomPtr = geometry::create(Control, proprties, geometryDict, surface, motion, materials);
Report(1)<< "geometry type is "<< greenText(geomPtr().typeName())<<endReport;
Report(1)<< "Writing geometry to folder "<< geomPtr().path()<<endl;
geomPtr().write();
Report(0)<< greenText("\nFinished successfully.\n");
// this should be palced in each main
#include "finalize.H"
return 0;
}

View File

@ -0,0 +1,75 @@
/*------------------------------- 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 "planeWall.H"
bool pFlow::planeWall::readPlaneWall
(
const dictionary& dict
)
{
auto p1 = dict.getVal<realx3>("p1");
auto p2 = dict.getVal<realx3>("p2");
auto p3 = dict.getVal<realx3>("p3");
auto p4 = dict.getVal<realx3>("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()<<endl;
return false;
}
if( Wall::checkTrianlge(p3,p4,p1) )
{
triangles_.push_back(realx3x3(p3,p4,p1));
}else
{
fatalErrorInFunction <<
"points p3, p4 and p1 do not form a plane wall in dictionary " << dict.globalName()<<endl;
return false;
}
return true;
}
pFlow::planeWall::planeWall()
{}
pFlow::planeWall::planeWall
(
const dictionary& dict
)
:
Wall(dict)
{
if(!readPlaneWall(dict))
{
fatalExit;
}
}

View File

@ -0,0 +1,60 @@
/*------------------------------- 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 __planeWall_H__
#define __planeWall_H__
#include "Wall.H"
#include "types.H"
namespace pFlow
{
class planeWall
:
public Wall
{
protected:
bool readPlaneWall(const dictionary& dict);
public:
TypeName("planeWall");
planeWall();
planeWall(const dictionary& dict);
add_vCtor
(
Wall,
planeWall,
dictionary
);
};
} // pFlow
#endif

View File

@ -0,0 +1,71 @@
/*------------------------------- 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 "stlWall.H"
#include "stlFile.H"
#include "streams.H"
bool pFlow::stlWall::readSTLWall
(
const dictionary& dict
)
{
auto fileName = dict.getVal<word>("file");
fileSystem file("",fileName);
stlFile stl(file);
if(!stl.read())
{
fatalErrorInFunction <<
" error in reading stl file "<< file <<endl;
return false;
}
for(label i=0; i<stl.size(); i++)
{
auto it = triangles_.end();
triangles_.insert(it, stl.solid(i).begin(), stl.solid(i).end());
}
return true;
}
pFlow::stlWall::stlWall()
{}
pFlow::stlWall::stlWall
(
const dictionary& dict
)
:
Wall(dict)
{
if(!readSTLWall(dict))
{
fatalExit;
}
}

View File

@ -0,0 +1,60 @@
/*------------------------------- 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 __stlWall_H__
#define __stlWall_H__
#include "Wall.H"
#include "types.H"
namespace pFlow
{
class stlWall
:
public Wall
{
protected:
bool readSTLWall(const dictionary& dict);
public:
TypeName("stlWall");
stlWall();
stlWall(const dictionary& dict);
add_vCtor
(
Wall,
stlWall,
dictionary
);
};
} // pFlow
#endif