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)
132 adjointVars_.paInst(),
133 solverControl_().dict(),
134 solverControl_().pRefCell(),
135 solverControl_().pRefValue()
138 if (computeSensitivities_)
143 adjointSensitivity_.reset
151 objectiveManagerPtr_()
164 if (adjointSensitivity_)
169 adjointSensitivity_().readDict
192 Info<<
"Time = " << mesh_.time().timeName() <<
"\n" <<
endl;
205 adjointVars_.adjointTurbulence();
206 const label& paRefCell = solverControl_().pRefCell();
207 const scalar& paRefValue = solverControl_().pRefValue();
227 objectiveManagerPtr_().addUaEqnSource(UaEqn);
230 ATCModel_->addATC(UaEqn);
233 addMomentumSource(UaEqn);
258 if (solverControl_().consistent())
260 rAtUa = 1.0/(1.0/rAUa - UaEqn.H1());
272 while (solverControl_().correctNonOrthogonal())
281 addPressureSource(
paEqn);
288 if (solverControl_().finalNonOrthogonalIter())
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)
void continuityErrors()
Compute continuity errors.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
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)
Manipulate based on a boundary field.
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)
Adjust the balance of fluxes to obey continuity.
tmp< surfaceScalarField > flux(const volVectorField &vvf)
Return the face-flux field obtained from the given volVectorField.
const bool momentumPredictor
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
virtual void clearSensitivities()
Base class for incompressibleAdjoint solvers.
A class for handling words, derived from Foam::string.
void correct(GeometricField< Type, fvPatchField, volMesh > &field)
Apply correction to field.
virtual void solveIter()
Execute one iteration of the solution algorithm.
A class for managing temporary objects.
static constexpr const zero Zero
Global zero (0)
void constrain(fvMatrix< Type > &eqn)
Apply constraints to equation.
static options & New(const fvMesh &mesh)
Construct fvOptions and register to database if not present.
Find the reference cell nearest (in index) to the given cell but which is not on a cyclic,...
virtual void computeObjectiveSensitivities()
Compute sensitivities of the underlaying objectives.
virtual const incompressibleAdjointVars & getAdjointVars() const
Access to the incompressible adjoint variables set.
virtual void addMomentumSource(fvVectorMatrix &matrix)
Source terms for the momentum equations.
fvMesh & mesh_
Reference to the mesh database.
virtual void correct()
Solve the adjoint turbulence equations.
virtual void preLoop()
Functions to be called before loop.
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Type & value() const
Return const reference to value.
void setReference(const label celli, const Type &value, const bool forceReference=false)
Set reference level for solution.
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_
Object to manage objective functions.
virtual void preIter()
Steps to be executed before each main SIMPLE iteration.
virtual void addPressureSource(fvScalarMatrix &matrix)
Source terms for the continuity equation.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual sensitivity & getSensitivityBase()
Return the base sensitivity object.
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)
Return a reference to the selected turbulence model.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
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.
SolverPerformance< Type > solve(faMatrix< Type > &, Istream &)
Solve returning the solution statistics given convergence tolerance.
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()
Clears the sensitivity field known by the adjoint solver.
OBJstream os(runTime.globalPath()/outputName)
Macros for easy insertion into run-time selection tables.
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)
Interpolate field onto faces using scheme given by Istream.
virtual void solve()
Main control loop.
static autoPtr< SIMPLEControl > New(fvMesh &mesh, const word &managerType, const solver &solver)
Return a reference to the selected turbulence model.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual void mainIter()
The main SIMPLE iter.
void correctBoundaryConditions()
Correct boundary field.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual bool readDict(const dictionary &dict)
Read dict if updated.
autoPtr< variablesSet > vars_
Base variableSet pointer.
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &weightField) const
Calculate and return weighted average.
virtual void updatePrimalBasedQuantities()
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
virtual tmp< volVectorField > adjointMeanFlowSource()=0
virtual void postIter()
Steps to be executed before each main SIMPLE iteration.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
incompressibleVars & primalVars_
Primal variable set.
void relax(const scalar alpha)
Relax field (for steady-state solution).
A special matrix type and solver, designed for finite volume solutions of scalar equations....
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
virtual bool writeData(Ostream &os) const
Write average iteration.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual const scalarField & getObjectiveSensitivities()
Grab a reference to the computed sensitivities.
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)
Read dict if updated.
defineTypeNameAndDebug(combustionModel, 0)
#define WarningInFunction
Report a warning using Foam::Warning.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > flux() const
Return the face-flux field from the matrix.
Type gMax(const FieldField< Field, Type > &f)
virtual bool loop()
Looper (advances iters, time step)
autoPtr< SIMPLEControl > solverControl_
Solver control.
static autoPtr< ATCModel > New(const fvMesh &mesh, const incompressibleVars &primalVars, const incompressibleAdjointVars &adjointVars, const dictionary &dict)
Return a reference to the selected turbulence model.
incompressibleAdjointVars & allocateVars()
virtual tmp< fvVectorMatrix > divDevReff(volVectorField &U) const =0
Return the diffusion term for the momentum equation.