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)
175 if (adjointSensitivity_)
177 const IOdictionary& optDict =
178 mesh_.lookupObject<IOdictionary>(
"optimisationDict");
180 adjointSensitivity_().readDict
182 optDict.subDict(
"optimisation").subDict(
"sensitivities")
203 Info<<
"Time = " << mesh_.time().timeName() <<
"\n" <<
endl;
217 adjointVars_.adjointTurbulence();
218 const label& paRefCell = solverControl_().pRefCell();
219 const scalar& paRefValue = solverControl_().pRefValue();
239 objectiveManagerPtr_().addUaEqnSource(UaEqn);
242 ATCModel_->addATC(UaEqn);
245 addMomentumSource(UaEqn);
268 tmp<volScalarField> rAtUa(rAUa);
270 if (solverControl_().consistent())
272 rAtUa = 1.0/(1.0/rAUa - UaEqn.H1());
284 while (solverControl_().correctNonOrthogonal())
293 addPressureSource(
paEqn);
300 if (solverControl_().finalNonOrthogonalIter())
320 if (solverControl_().printMaxMags())
324 Info<<
"Max mag of adjoint velocity = " << maxUa.value() <<
endl;
325 Info<<
"Max mag of adjoint pressure = " << maxpa.
value() <<
endl;
332 solverControl_().write();
335 adjointVars_.computeMeanFields();
338 mesh_.time().printExecutionTime(
Info);
348 while (solverControl_().loop())
359 return solverControl_().loop();
366 adjointVars_.resetMeanFields();
372 if (computeSensitivities_)
374 adjointSensitivity_->accumulateIntegrand(scalar(1));
375 const scalarField& sens = adjointSensitivity_->calculateSensitivities();
380 sensitivities_.ref() = sens;
393 computeObjectiveSensitivities();
396 return sensitivities_();
402 if (computeSensitivities_)
404 adjointSensitivity_->clearSensitivities();
412 if (!adjointSensitivity_.valid())
415 <<
"Sensitivity object not allocated" <<
nl 416 <<
"Turn computeSensitivities on in " 422 return adjointSensitivity_();
443 objectiveManagerPtr_->updateAndWrite();
449 os.
writeEntry(
"averageIter", solverControl_().averageIter());
const bool momentumPredictor
virtual void mainIter()
The main SIMPLE iter.
bool computeSensitivities_
Are sensitivities computed.
const Type & value() const noexcept
Return const reference to value.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
void size(const label n)
Older name for setAddressableSize.
fvMatrix< scalar > fvScalarMatrix
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
const volScalarField & paInst() const
Return const reference to pressure.
SolverPerformance< Type > solve(faMatrix< Type > &, const dictionary &)
Solve returning the solution statistics given convergence tolerance.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual void updatePrimalBasedQuantities()
Update primal based quantities related to the objective functions.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
virtual const incompressibleAdjointVars & getAdjointVars() const
Access to the incompressible adjoint variables set.
void addExtraSchemes()
In case variable names are different than the base ones, add extra schemes and relaxation factors to ...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual tmp< fvVectorMatrix > divDevReff(volVectorField &U) const =0
Return the diffusion term for the momentum equation.
tmp< surfaceScalarField > flux(const volVectorField &vvf)
Return the face-flux field obtained from the given volVectorField.
void correct(GeometricField< Type, fvPatchField, volMesh > &field)
Apply correction to field.
virtual void preLoop()
Functions to be called before loop.
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
const fvMesh & mesh() const
Return the solver mesh.
virtual bool readDict(const dictionary &dict)
Read dict if updated.
constexpr char nl
The newline '\n' character (0x0a)
void setReference(const label celli, const Type &value, const bool forceReference=false)
Set reference level for solution.
autoPtr< ATCModel > ATCModel_
Adjoint Transpose Convection options.
autoPtr< SIMPLEControl > solverControl_
Solver control.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual void updatePrimalBasedQuantities()
Update primal based quantities, e.g. the primal fields in adjoint turbulence models.
constexpr char tab
The tab '\t' character(0x09)
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
autoPtr< variablesSet > vars_
Base variableSet pointer.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Abstract base class for adjoint sensitivities.
GeometricField< vector, fvPatchField, volMesh > volVectorField
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
bool adjustPhi(surfaceScalarField &phi, const volVectorField &U, volScalarField &p)
Adjust the balance of fluxes to obey continuity.
Find the reference cell nearest (in index) to the given cell but which is not on a cyclic...
Macros for easy insertion into run-time selection tables.
incompressibleAdjointVars & allocateVars()
Allocate incompressibleAdjointVars and return reference to be used for convenience in the rest of the...
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
virtual void clearSensitivities()
Clears the sensitivity field known by the adjoint solver.
Class including all adjoint fields for incompressible flows.
Base class for incompressibleAdjoint solvers.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
GeometricField< scalar, fvPatchField, volMesh > volScalarField
volScalarField::Internal contErr((fvc::ddt(rho)+fvc::div(rhoPhi) -(fvOptions(alpha1, mixture.thermo1().rho())&rho1) -(fvOptions(alpha2, mixture.thermo2().rho())&rho2))())
virtual bool loop()
Looper (advances iters, time step)
virtual bool writeData(Ostream &os) const
Write the sensitivity derivatives.
virtual void correct()
Solve the adjoint turbulence equations.
incompressibleVars & primalVars_
Primal variable set.
incompressibleAdjointVars & adjointVars_
Reference to incompressibleAdjointVars.
virtual void preIter()
Steps to be executed before each main SIMPLE iteration.
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual bool readDict(const dictionary &dict)
Read dict if updated.
virtual sensitivity & getSensitivityBase()
Return the base sensitivity object.
static autoPtr< adjointSensitivity > New(const fvMesh &mesh, const dictionary &dict, incompressibleAdjointSolver &adjointSolver)
Return a reference to the selected turbulence model.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
tmp< volVectorField > constrainHbyA(const tmp< volVectorField > &tHbyA, const volVectorField &U, const volScalarField &p)
virtual const dictionary & dict() const
Return the solver dictionary.
void continuityErrors()
Compute continuity errors.
virtual void postIter()
Steps to be executed before each main SIMPLE iteration.
void constrain(fvMatrix< Type > &eqn)
Apply constraints to equation.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
autoPtr< incompressible::adjointSensitivity > adjointSensitivity_
Sensitivity Derivatives engine.
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
static autoPtr< ATCModel > New(const fvMesh &mesh, const incompressibleVars &primalVars, const incompressibleAdjointVars &adjointVars, const dictionary &dict)
Return a reference to the selected turbulence model.
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Type gMax(const FieldField< Field, Type > &f)
OBJstream os(runTime.globalPath()/outputName)
virtual void solve()
Main control loop.
virtual const scalarField & getObjectiveSensitivities()
Grab a reference to the computed sensitivities.
defineTypeNameAndDebug(combustionModel, 0)
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
virtual void addPressureSource(fvScalarMatrix &matrix)
Source terms for the continuity equation.
void relax(const scalar alpha)
Relax field (for steady-state solution).
#define WarningInFunction
Report a warning using Foam::Warning.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Mesh data needed to do the Finite Volume discretisation.
Solution of the adjoint PDEs for incompressible, steady-state flows.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
virtual bool writeData(Ostream &os) const
Write average iteration.
void correctBoundaryConditions()
Correct boundary field.
SIMPLE control class to supply convergence information/checks for the SIMPLE loop.
For cases which do no have a pressure boundary adjust the balance of fluxes to obey continuity...
messageStream Info
Information stream (stdout output on master, null elsewhere)
fvScalarMatrix paEqn(fvm::d2dt2(pa) - sqr(c0) *fvc::laplacian(pa))
fvMesh & mesh_
Reference to the mesh database.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > flux() const
Return the face-flux field from the matrix.
void boundaryManipulate(typename GeometricField< Type, fvPatchField, volMesh >::Boundary &values)
Manipulate based on a boundary field.
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &weightField) const
Calculate and return weighted average.
virtual void solveIter()
Execute one iteration of the solution algorithm.
A class for managing temporary objects.
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
static options & New(const fvMesh &mesh)
Construct fvOptions and register to database if not present.
virtual void clearSensitivities()
Clears the sensitivity field known by the adjoint solver and zeros sensitivities constituents.
virtual tmp< volVectorField > adjointMeanFlowSource()=0
Source terms to the adjoint momentum equation due to the differentiation of the turbulence model...
bool setRefCell(const volScalarField &field, const volScalarField &fieldRef, const dictionary &dict, label &refCelli, scalar &refValue, const bool forceReference=false)
If the field fieldRef needs referencing find the reference cell nearest.
virtual void addMomentumSource(fvVectorMatrix &matrix)
Source terms for the momentum equations.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
autoPtr< objectiveManager > objectiveManagerPtr_
Object to manage objective functions.
virtual void computeObjectiveSensitivities()
Compute sensitivities of the underlaying objectives.
tmp< scalarField > sensitivities_
Sensitivities field.
static constexpr const zero Zero
Global zero (0)