From d44b670bccf70d56b4a03c8f870ea7497385888c Mon Sep 17 00:00:00 2001 From: Ping He Date: Fri, 19 Jan 2024 21:03:08 -0600 Subject: [PATCH] Updated the solid solver. (#568) --- .../DAObjFunc/DAObjFuncVonMisesStressKS.C | 9 +-- .../DAResidualSolidDisplacementFoam.C | 75 ++----------------- .../DAResidualSolidDisplacementFoam.H | 8 +- .../DASolidDisplacementFoam.C | 56 ++++---------- .../DASolidDisplacementFoam.H | 20 ----- .../calculateStressSolidDisplacement.H | 40 +++++----- .../createControlsSolidDisplacement.H | 7 -- .../createFieldsSolidDisplacement.H | 38 ---------- .../createRefsSolidDisplacement.H | 2 - ...eadMechanicalPropertiesSolidDisplacement.H | 16 ++-- .../tractionDisplacementFvPatchVectorField.C | 37 ++------- ...DAFoam_Test_DASolidDisplacementFoamRef.txt | 26 +++---- tests/runTests_DASolidDisplacementFoam.py | 9 ++- 13 files changed, 81 insertions(+), 262 deletions(-) delete mode 100644 src/adjoint/DASolver/DASolidDisplacementFoam/createControlsSolidDisplacement.H diff --git a/src/adjoint/DAObjFunc/DAObjFuncVonMisesStressKS.C b/src/adjoint/DAObjFunc/DAObjFuncVonMisesStressKS.C index de67494e..111c05bb 100755 --- a/src/adjoint/DAObjFunc/DAObjFuncVonMisesStressKS.C +++ b/src/adjoint/DAObjFunc/DAObjFuncVonMisesStressKS.C @@ -46,7 +46,6 @@ DAObjFuncVonMisesStressKS::DAObjFuncVonMisesStressKS( objFuncDict_.readEntry("scale", scale_); objFuncDict_.readEntry("coeffKS", coeffKS_); - } /// calculate the value of objective function @@ -87,16 +86,16 @@ void DAObjFuncVonMisesStressKS::calcObjFunc( objFuncValue = 0.0; const objectRegistry& db = mesh_.thisDb(); - //const volVectorField& D = db.lookupObject("D"); + const volTensorField& gradD = db.lookupObject("gradD"); const volScalarField& lambda = db.lookupObject("solid:lambda"); const volScalarField& mu = db.lookupObject("solid:mu"); const volScalarField& rho = db.lookupObject("solid:rho"); - const volTensorField& gradD = db.lookupObject("gradD"); - volSymmTensorField sigma = rho * (mu * twoSymm(gradD) + lambda * (I * tr(gradD))); + // volTensorField gradD(fvc::grad(D)); + volSymmTensorField sigma = rho * (mu * twoSymm(gradD) + (lambda * I) * tr(gradD)); // NOTE: vonMises stress is scaled by scale_ provided in the objFunc dict - volScalarField vonMises = scale_* sqrt((3.0 / 2.0) * magSqr(dev(sigma))); + volScalarField vonMises = scale_ * sqrt((3.0 / 2.0) * magSqr(dev(sigma))); scalar objValTmp = 0.0; forAll(objFuncCellSources, idxI) diff --git a/src/adjoint/DAResidual/DAResidualSolidDisplacementFoam.C b/src/adjoint/DAResidual/DAResidualSolidDisplacementFoam.C index 9488ee43..4e061d70 100755 --- a/src/adjoint/DAResidual/DAResidualSolidDisplacementFoam.C +++ b/src/adjoint/DAResidual/DAResidualSolidDisplacementFoam.C @@ -28,47 +28,11 @@ DAResidualSolidDisplacementFoam::DAResidualSolidDisplacementFoam( // these are intermediate variables or objects gradD_(const_cast( mesh.thisDb().lookupObject("gradD"))), - sigmaD_(const_cast( - mesh.thisDb().lookupObject("sigmaD"))), - divSigmaExp_(const_cast( - mesh.thisDb().lookupObject("divSigmaExp"))), lambda_(const_cast( mesh.thisDb().lookupObject("solid:lambda"))), mu_(const_cast( mesh.thisDb().lookupObject("solid:mu"))) { - - IOdictionary thermalProperties( - IOobject( - "thermalProperties", - mesh.time().constant(), - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE)); - - Switch thermalStress(thermalProperties.lookup("thermalStress")); - if (thermalStress) - { - FatalErrorIn("") << "thermalStress=true not supported" << abort(FatalError); - } - - const dictionary& stressControl = mesh.solutionDict().subDict("stressAnalysis"); - - Switch compactNormalStress(stressControl.lookup("compactNormalStress")); - - if (!compactNormalStress) - { - FatalErrorIn("") << "compactNormalStress=false not supported" << abort(FatalError); - } - - isTractionDisplacementBC_ = 0; - forAll(D_.boundaryField(), patchI) - { - if (D_.boundaryField()[patchI].type() == "tractionDisplacement") - { - isTractionDisplacementBC_ = 1; - } - } } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -99,42 +63,19 @@ void DAResidualSolidDisplacementFoam::calcResiduals(const dictionary& options) URes_, pRes_, TRes_, phiRes_: residual field variables */ + volSymmTensorField sigmaD = mu_ * twoSymm(gradD_) + (lambda_ * I) * tr(gradD_); + + volVectorField divSigmaExp = fvc::div(sigmaD - (2 * mu_ + lambda_) * gradD_, "div(sigmaD)"); + fvVectorMatrix DEqn( fvm::d2dt2(D_) == fvm::laplacian(2 * mu_ + lambda_, D_, "laplacian(DD,D)") - + divSigmaExp_); + + divSigmaExp); DRes_ = DEqn & D_; normalizeResiduals(DRes); } -void DAResidualSolidDisplacementFoam::updateDAndGradD() -{ - /* - Description: - Update D and gradD. - - NOTE: we need to update D boundary conditions iteratively if tractionDisplacement BC - is used this is because tractionDisplacement BC is dependent on gradD, while gradD - is dependent on the D bc values. - */ - - // this will be called after doing perturbStates - if (isTractionDisplacementBC_) - { - for (label i = 0; i < daOption_.getOption