Go to the documentation of this file.
44 incompressibleAdjointSolver,
71 if (adjointVars_.useSolverNameForFields())
74 <<
"useSolverNameForFields is set to true for adjointSolver "
75 << solverName() <<
nl <<
tab
76 <<
"Appending variable names with the solver name" <<
nl <<
tab
77 <<
"Please adjust the necessary entries in fvSchemes and fvSolution"
89 mag(
contErr)().weightedAverage(mesh_.V()).value();
97 <<
", cumulative = " << cumulativeContErr_
104 Foam::adjointSimple::adjointSimple
107 const word& managerType,
109 const word& primalSolverName
114 adjointVars_(allocateVars()),
115 cumulativeContErr_(
Zero),
116 adjointSensitivity_(nullptr)
164 if (adjointSensitivity_)
166 const IOdictionary& optDict =
167 mesh_.lookupObject<IOdictionary>(
"optimisationDict");
169 adjointSensitivity_().readDict
171 optDict.subDict(
"optimisation").subDict(
"sensitivities")
192 Info<<
"Time = " << mesh_.time().timeName() <<
"\n" <<
endl;
205 adjointVars_.adjointTurbulence();
206 const label& paRefCell = solverControl_().pRefCell();
207 const scalar& paRefValue = solverControl_().pRefValue();
216 + adjointTurbulence->divDevReff(Ua)
217 + adjointTurbulence->adjointMeanFlowSource()
227 objectiveManagerPtr_().addUaEqnSource(UaEqn);
230 ATCModel_->addATC(UaEqn);
233 addMomentumSource(UaEqn);
256 tmp<volScalarField> rAtUa(rAUa);
258 if (solverControl_().consistent())
260 rAtUa = 1.0/(1.0/rAUa - UaEqn.
H1());
272 while (solverControl_().correctNonOrthogonal())
281 addPressureSource(
paEqn);
288 if (solverControl_().finalNonOrthogonalIter())
306 adjointTurbulence->correct();
308 if (solverControl_().printMaxMags())
312 Info<<
"Max mag of adjoint velocity = " << maxUa.value() <<
endl;
313 Info<<
"Max mag of adjoint pressure = " << maxpa.
value() <<
endl;
320 solverControl_().write();
323 adjointVars_.computeMeanFields();
326 mesh_.time().printExecutionTime(
Info);
335 while (solverControl_().loop())
345 return solverControl_().loop();
352 adjointVars_.resetMeanFields();
358 if (computeSensitivities_)
360 adjointSensitivity_->accumulateIntegrand(scalar(1));
361 const scalarField& sens = adjointSensitivity_->calculateSensitivities();
366 *sensitivities_ = sens;
379 computeObjectiveSensitivities();
382 return sensitivities_();
388 if (computeSensitivities_)
390 adjointSensitivity_->clearSensitivities();
398 if (!adjointSensitivity_.valid())
401 <<
"Sensitivity object not allocated" <<
nl
402 <<
"Turn computeSensitivities on in "
408 return adjointSensitivity_();
429 objectiveManagerPtr_->updateAndWrite();
435 os.
writeEntry(
"averageIter", solverControl_().averageIter());
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
tmp< GeometricField< Type, fvPatchField, volMesh > > H() const
tmp< volVectorField > constrainHbyA(const tmp< volVectorField > &tHbyA, const volVectorField &U, const volScalarField &p)
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void boundaryManipulate(typename GeometricField< Type, fvPatchField, volMesh >::Boundary &values)
volScalarField::Internal contErr((fvc::ddt(rho)+fvc::div(rhoPhi) -(fvOptions(alpha1, mixture.thermo1().rho())&rho1) -(fvOptions(alpha2, mixture.thermo2().rho())&rho2))())
bool adjustPhi(surfaceScalarField &phi, const volVectorField &U, volScalarField &p)
autoPtr< ATCModel > ATCModel_
const bool momentumPredictor
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
bool computeSensitivities_
virtual void clearSensitivities()
Base class for incompressibleAdjoint solvers.
A class for handling words, derived from Foam::string.
void correct(GeometricField< Type, fvPatchField, volMesh > &field)
void clear() const noexcept
A class for managing temporary objects.
static constexpr const zero Zero
void constrain(fvMatrix< Type > &eqn)
static options & New(const fvMesh &mesh)
Find the reference cell nearest (in index) to the given cell but which is not on a cyclic,...
virtual void computeObjectiveSensitivities()
virtual void addMomentumSource(fvVectorMatrix &matrix)
incompressibleAdjointVars & adjointVars_
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Ostream & endl(Ostream &os)
const Type & value() const
void setReference(const label celli, const Type &value, const bool forceReference=false)
For cases which do no have a pressure boundary adjust the balance of fluxes to obey continuity....
Class including all adjoint fields for incompressible flows.
autoPtr< objectiveManager > objectiveManagerPtr_
autoPtr< incompressible::adjointSensitivity > adjointSensitivity_
SolverPerformance< Type > solve(const dictionary &)
const volScalarField & paInst() const
fvMatrix< scalar > fvScalarMatrix
Generic templated field type.
virtual void addPressureSource(fvScalarMatrix &matrix)
virtual sensitivity & getSensitivityBase()
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
static autoPtr< adjointSensitivity > New(const fvMesh &mesh, const dictionary &dict, incompressibleVars &primalVars, incompressibleAdjointVars &adjointVars, objectiveManager &objectiveManager)
tmp< volScalarField > H1() const
void relax(const scalar alpha)
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
bool setRefCell(const volScalarField &field, const volScalarField &fieldRef, const dictionary &dict, label &refCelli, scalar &refValue, const bool forceReference=false)
SolverPerformance< Type > solve(faMatrix< Type > &, Istream &)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
const Type & lookupObject(const word &name, const bool recursive=false) const
fvScalarMatrix paEqn(fvm::d2dt2(pa) - sqr(c0) *fvc::laplacian(pa))
virtual void updatePrimalBasedQuantities()
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
virtual void clearSensitivities()
OBJstream os(runTime.globalPath()/outputName)
Macros for easy insertion into run-time selection tables.
Generic dimensioned Type class.
tmp< volScalarField > A() const
Mesh data needed to do the Finite Volume discretisation.
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
static autoPtr< SIMPLEControl > New(fvMesh &mesh, const word &managerType, const solver &solver)
errorManipArg< error, int > exit(error &err, const int errNo=1)
void correctBoundaryConditions()
GeometricField< vector, fvPatchField, volMesh > volVectorField
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
#define FatalErrorInFunction
const fvMesh & mesh() const
virtual bool readDict(const dictionary &dict)
autoPtr< variablesSet > vars_
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &weightField) const
virtual void updatePrimalBasedQuantities()
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
incompressibleVars & primalVars_
void relax(const scalar alpha)
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Ostream & writeEntry(const keyType &key, const T &value)
virtual bool writeData(Ostream &os) const
virtual const incompressibleAdjointVars & getAdjointVars() const
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
tmp< surfaceScalarField > flux(const volVectorField &vvf)
Generic GeometricField class.
virtual const scalarField & getObjectiveSensitivities()
Abstract base class for adjoint sensitivities.
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
virtual bool readDict(const dictionary &dict)
defineTypeNameAndDebug(combustionModel, 0)
#define WarningInFunction
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > flux() const
virtual const dictionary & dict() const
Type gMax(const FieldField< Field, Type > &f)
autoPtr< SIMPLEControl > solverControl_
static autoPtr< ATCModel > New(const fvMesh &mesh, const incompressibleVars &primalVars, const incompressibleAdjointVars &adjointVars, const dictionary &dict)
SIMPLE control class to supply convergence information/checks for the SIMPLE loop.
incompressibleAdjointVars & allocateVars()