Skip to content

Commit

Permalink
Added the deformDynMesh utility. (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
zilonglicfd authored Feb 3, 2025
1 parent 1931104 commit 7c38ac1
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/utilities/preProcessing/deformDynMesh/Make/files
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
deformDynMesh.C

EXE = $(DAFOAM_ROOT_PATH)/OpenFOAM/sharedBins/deformDynMesh
18 changes: 18 additions & 0 deletions src/utilities/preProcessing/deformDynMesh/Make/options
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
EXE_INC = \
-std=c++11 \
-Wno-old-style-cast \
-Wno-conversion-null \
-Wno-deprecated-copy \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude

EXE_LIBS = \
-lfiniteVolume \
-lmeshTools \
-lturbulenceModels \
-lincompressibleTurbulenceModels \
-lcompressibleTurbulenceModels

145 changes: 145 additions & 0 deletions src/utilities/preProcessing/deformDynMesh/deformDynMesh.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*---------------------------------------------------------------------------*\
DAFoam : Discrete Adjoint with OpenFOAM
Version : v4
Description
Deform the mesh for field inversion
\*---------------------------------------------------------------------------*/

#include "fvCFD.H"
#include "argList.H"
#include "Time.H"
#include "fvMesh.H"
#include "OFstream.H"

using namespace Foam;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char* argv[])
{

Info << "Deform the mesh for field inversion...." << endl;

argList::addOption(
"origin",
"(0 0 0)",
"prescribe the origin to deform the mesh");

argList::addOption(
"axis",
"(0 0 0)",
"prescribe the axis to deform the mesh");

argList::addOption(
"omega",
"0",
"prescribe the angular velocity to deform the mesh");

argList::addOption(
"time",
"-1",
"prescribe a specific time to deform the mesh");

#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"


vector origin={0.0, 0.0, 0.0};
if (args.readIfPresent("origin", origin))
{
Info<< "The origin to rotate the mesh: " << origin << endl;
}
else
{
Info << "origin not set!" << endl;
}

vector axis={0, 0, 0};
if (args.readIfPresent("axis", axis))
{
Info<< "The axis to rotate the mesh: " << axis << endl;
}
else
{
Info << "axis center not set!" << endl;
}

scalar omega = 0.0;
if (args.readIfPresent("omega", omega))
{
Info<< "The angular velocity to rotate the mesh: " << omega << endl;
}
else
{
Info << "omega not set! Don't rotate mesh." << endl;
}

scalar time = -1.0;
if (args.optionFound("time"))
{
time = readScalar(args.optionLookup("time")());
if (time == 9999)
{
Info << "Deform latestTime" << endl;
}
else
{
Info << "Deform time = " << time << endl;
}
}
else
{
Info << "Time not set! Deform all time instances." << endl;
}

Info << "Deforming the mesh..." << endl;

while (runTime.run())
{
++runTime;

Info<< "Time = " << runTime.timeName() << nl << endl;

pointField ourNewPoints(mesh.points());
scalar theta = omega * runTime.deltaT().value();
scalar cosTheta = std::cos(theta);
scalar sinTheta = std::sin(theta);

forAll(ourNewPoints, pointI)
{
scalar xTemp = ourNewPoints[pointI][0] - origin[0];
scalar yTemp = ourNewPoints[pointI][1] - origin[1];

ourNewPoints[pointI][0] = cosTheta * xTemp - sinTheta * yTemp + origin[0];
ourNewPoints[pointI][1] = sinTheta * xTemp + cosTheta * yTemp + origin[1];
}

mesh.movePoints(ourNewPoints);

pointIOField writePoints
(
IOobject
(
"points",
runTime.timeName(),
"polyMesh",
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh.points()
);

runTime.write();
}

Info << "Finished!" << endl;

return 0;
}

// ************************************************************************* //

0 comments on commit 7c38ac1

Please sign in to comment.