From f4b0ccd7219023613b1465a042c7daeeb85595f4 Mon Sep 17 00:00:00 2001 From: Ping He Date: Fri, 20 Dec 2024 09:59:30 -0600 Subject: [PATCH] Added DARhoSimpleFoam (#726) * Fixed a bug for the distributed flag for functions * Made printInterval and maxRes class-wide vars. * Added the DARhoSimpleFoam tests. * Fixed test files. * Added the missing file. --- .../DAResidual/DAResidualRhoSimpleFoam.C | 7 +- src/adjoint/DAResidual/Make/files | 1 + .../DARhoSimpleFoam/DARhoSimpleFoam.C | 89 +-------- .../DARhoSimpleFoam/DARhoSimpleFoam.H | 4 +- .../DASolver/DARhoSimpleFoam/EEqnRhoSimple.H | 4 +- .../DASolver/DARhoSimpleFoam/UEqnRhoSimple.H | 6 +- .../DASolver/DARhoSimpleFoam/pEqnRhoSimple.H | 10 +- .../DASolver/DASimpleFoam/DASimpleFoam.C | 19 +- .../DASolver/DASimpleFoam/UEqnSimple.H | 4 +- .../DASolver/DASimpleFoam/pEqnSimple.H | 8 +- src/adjoint/DASolver/DASolver.C | 12 +- src/adjoint/DASolver/DASolver.H | 13 +- src/adjoint/DASolver/Make/files | 2 +- src/adjoint/DAStateInfo/Make/files | 1 + src/include/createAdjoint.H | 44 +++++ tests/refs/DAFoam_Test_DARhoSimpleFoamRef.txt | 26 +-- tests/runRegTests_DARhoSimpleFoam.py | 174 ++++++++++++++++++ tests/runRegTests_DASimpleFoam.py | 2 +- 18 files changed, 281 insertions(+), 145 deletions(-) create mode 100755 src/include/createAdjoint.H create mode 100755 tests/runRegTests_DARhoSimpleFoam.py diff --git a/src/adjoint/DAResidual/DAResidualRhoSimpleFoam.C b/src/adjoint/DAResidual/DAResidualRhoSimpleFoam.C index a688018f..af6149e4 100755 --- a/src/adjoint/DAResidual/DAResidualRhoSimpleFoam.C +++ b/src/adjoint/DAResidual/DAResidualRhoSimpleFoam.C @@ -33,7 +33,8 @@ DAResidualRhoSimpleFoam::DAResidualRhoSimpleFoam( fvSourceEnergy_(const_cast( mesh_.thisDb().lookupObject("fvSourceEnergy"))), fvOptions_(fv::options::New(mesh)), - thermo_(const_cast(daModel.getThermo())), + thermo_(const_cast( + mesh_.thisDb().lookupObject("thermophysicalProperties"))), he_(thermo_.he()), rho_(const_cast( mesh_.thisDb().lookupObject("rho"))), @@ -70,7 +71,7 @@ DAResidualRhoSimpleFoam::DAResidualRhoSimpleFoam( Info << "Cp " << Cp_ << endl; } - // this is just a dummy call because we need to run the constrain once + // this is just a dummy call because we need to run the constrain once // to initialize fvOptions, before we can use it. Otherwise, we may get // a seg fault when we call fvOptions_.correct(U_) in updateIntermediateVars fvVectorMatrix UEqn( @@ -193,7 +194,7 @@ void DAResidualRhoSimpleFoam::calcResiduals(const dictionary& options) HbyAPtr() = rAU * UEqn.H(); } volVectorField& HbyA = HbyAPtr(); - + tUEqn.clear(); surfaceScalarField phiHbyA("phiHbyA", fvc::interpolate(rho_) * fvc::flux(HbyA)); diff --git a/src/adjoint/DAResidual/Make/files b/src/adjoint/DAResidual/Make/files index b1750277..47b28e89 100755 --- a/src/adjoint/DAResidual/Make/files +++ b/src/adjoint/DAResidual/Make/files @@ -1,4 +1,5 @@ DAResidual.C DAResidualSimpleFoam.C +DAResidualRhoSimpleFoam.C LIB = $(DAFOAM_ROOT_PATH)/OpenFOAM/sharedLibs/libDAResidual$(WM_CODI_AD_LIB_POSTFIX) diff --git a/src/adjoint/DASolver/DARhoSimpleFoam/DARhoSimpleFoam.C b/src/adjoint/DASolver/DARhoSimpleFoam/DARhoSimpleFoam.C index b4e7e68e..bcbebcea 100755 --- a/src/adjoint/DASolver/DARhoSimpleFoam/DARhoSimpleFoam.C +++ b/src/adjoint/DASolver/DARhoSimpleFoam/DARhoSimpleFoam.C @@ -73,13 +73,13 @@ void DARhoSimpleFoam::initSolver() argList& args = argsPtr_(); #include "createSimpleControlPython.H" #include "createFieldsRhoSimple.H" -#include "createAdjointCompressible.H" +#include "createAdjoint.H" // initialize checkMesh daCheckMeshPtr_.reset(new DACheckMesh(daOptionPtr_(), runTime, mesh)); daLinearEqnPtr_.reset(new DALinearEqn(mesh, daOptionPtr_())); - this->setDAObjFuncList(); + this->setDAFunctionList(); // initialize fvSource and compute the source term const dictionary& allOptions = daOptionPtr_->getAllOptions(); @@ -94,19 +94,11 @@ void DARhoSimpleFoam::initSolver() } } -label DARhoSimpleFoam::solvePrimal( - const Vec xvVec, - Vec wVec) +label DARhoSimpleFoam::solvePrimal() { /* Description: Call the primal solver to get converged state variables - - Input: - xvVec: a vector that contains all volume mesh coordinates - - Output: - wVec: state variable vector */ #include "createRefsRhoSimple.H" @@ -121,44 +113,10 @@ label DARhoSimpleFoam::solvePrimal( Info << "\nStarting time loop\n" << endl; - // deform the mesh based on the xvVec - this->pointVec2OFMesh(xvVec); - - // check mesh quality - label meshOK = this->checkMesh(); - - if (!meshOK) - { - this->writeFailedMesh(); - return 1; - } - - // if the forwardModeAD is active, we need to set the seed here -#include "setForwardADSeeds.H" - - word divUScheme = "div(phi,U)"; - if (daOptionPtr_->getSubDictOption