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_
107 const word& managerType,
109 const word& primalSolverName
114 adjointVars_(allocateVars()),
115 cumulativeContErr_(
Zero),
116 adjointSensitivity_(nullptr)
173 if (incompressibleAdjointSolver::readDict(
dict))
175 if (adjointSensitivity_)
180 adjointSensitivity_().readDict
203 Info<<
"Time = " << mesh_.time().timeName() <<
"\n" <<
endl;
217 adjointVars_.adjointTurbulence();
218 const label& paRefCell = solverControl_().pRefCell();
219 const scalar& paRefValue = solverControl_().pRefValue();
228 + adjointTurbulence->divDevReff(Ua)
229 + adjointTurbulence->adjointMeanFlowSource()
239 objectiveManagerPtr_().addUaEqnSource(UaEqn);
242 ATCModel_->addATC(UaEqn);
245 addMomentumSource(UaEqn);
270 if (solverControl_().consistent())
272 rAtUa = 1.0/(1.0/rAUa - UaEqn.
H1());
284 while (solverControl_().correctNonOrthogonal())
293 addPressureSource(
paEqn);
300 if (solverControl_().finalNonOrthogonalIter())
318 adjointTurbulence->correct();
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());
450 return adjointSolver::writeData(
os);
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
For cases which do no have a pressure boundary adjust the balance of fluxes to obey continuity....
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &weightField) const
Calculate and return weighted average.
void relax(const scalar alpha)
Relax field (for steady-state solution).
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
void correctBoundaryConditions()
Correct boundary field.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
SIMPLE control class to supply convergence information/checks for the SIMPLE loop.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
void size(const label n)
Older name for setAddressableSize.
Solution of the adjoint PDEs for incompressible, steady-state flows.
virtual void postIter()
Steps to be executed before each main SIMPLE iteration.
virtual void clearSensitivities()
autoPtr< SIMPLEControl > solverControl_
Solver control.
virtual void preIter()
Steps to be executed before each main SIMPLE iteration.
virtual bool writeData(Ostream &os) const
Write average iteration.
autoPtr< incompressible::adjointSensitivity > adjointSensitivity_
Sensitivity Derivatives engine.
virtual void addMomentumSource(fvVectorMatrix &matrix)
Source terms for the momentum equations.
virtual sensitivity & getSensitivityBase()
Return the base sensitivity object.
virtual bool readDict(const dictionary &dict)
Read dict if updated.
virtual const scalarField & getObjectiveSensitivities()
Grab a reference to the computed sensitivities.
incompressibleAdjointVars & allocateVars()
virtual void mainIter()
The main SIMPLE iter.
virtual void updatePrimalBasedQuantities()
incompressibleAdjointVars & adjointVars_
Reference to incompressibleAdjointVars.
virtual void preLoop()
Functions to be called before loop.
void continuityErrors()
Compute continuity errors.
virtual void computeObjectiveSensitivities()
Compute sensitivities of the underlaying objectives.
virtual bool loop()
Looper (advances iters, time step)
virtual void solveIter()
Execute one iteration of the solution algorithm.
virtual void solve()
Main control loop.
virtual void addPressureSource(fvScalarMatrix &matrix)
Source terms for the continuity equation.
virtual void clearSensitivities()
Clears the sensitivity field known by the adjoint solver.
tmp< scalarField > sensitivities_
Sensitivities field.
autoPtr< objectiveManager > objectiveManagerPtr_
Object to manage objective functions.
bool computeSensitivities_
Are sensitivities computed.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
const Type & value() const
Return const reference to value.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
void relax(const scalar alpha)
Relax matrix (for steady-state solution).
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > flux() const
Return the face-flux field from the matrix.
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
tmp< volScalarField > A() const
Return the central coefficient.
tmp< volScalarField > H1() const
Return H(1)
void setReference(const label celli, const Type &value, const bool forceReference=false)
Set reference level for solution.
void boundaryManipulate(typename GeometricField< Type, fvPatchField, volMesh >::Boundary &values)
Manipulate based on a boundary field.
tmp< GeometricField< Type, fvPatchField, volMesh > > H() const
Return the H operation source.
Mesh data needed to do the Finite Volume discretisation.
void constrain(fvMatrix< Type > &eqn)
Apply constraints to equation.
void correct(GeometricField< Type, fvPatchField, volMesh > &field)
Apply correction to field.
const volScalarField & paInst() const
Return const reference to pressure.
Base class for incompressibleAdjoint solvers.
autoPtr< ATCModel > ATCModel_
Adjoint Transpose Convection options.
virtual const incompressibleAdjointVars & getAdjointVars() const
Access to the incompressible adjoint variables set.
virtual void updatePrimalBasedQuantities()
incompressibleVars & primalVars_
Primal variable set.
Class including all adjoint fields for incompressible flows.
const Type & lookupObject(const word &name, const bool recursive=false) const
Abstract base class for adjoint sensitivities.
autoPtr< variablesSet > vars_
Base variableSet pointer.
virtual const dictionary & dict() const
Return the solver dictionary.
const fvMesh & mesh() const
Return the solver mesh.
fvMesh & mesh_
Reference to the mesh database.
A class for managing temporary objects.
void clear() const noexcept
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
volScalarField::Internal contErr((fvc::ddt(rho)+fvc::div(rhoPhi) -(fvOptions(alpha1, mixture.thermo1().rho())&rho1) -(fvOptions(alpha2, mixture.thermo2().rho())&rho2))())
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
Find the reference cell nearest (in index) to the given cell but which is not on a cyclic,...
#define WarningInFunction
Report a warning using Foam::Warning.
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.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
tmp< surfaceScalarField > flux(const volVectorField &vvf)
Return the face-flux field obtained from the given volVectorField.
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
bool adjustPhi(surfaceScalarField &phi, const volVectorField &U, volScalarField &p)
Adjust the balance of fluxes to obey continuity.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Type gMax(const FieldField< Field, Type > &f)
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.
constexpr char nl
The newline '\n' character (0x0a)
constexpr char tab
The tab '\t' character(0x09)
SolverPerformance< Type > solve(faMatrix< Type > &, const dictionary &)
Solve returning the solution statistics given convergence tolerance.
fvScalarMatrix paEqn(fvm::d2dt2(pa) - sqr(c0) *fvc::laplacian(pa))
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
const bool momentumPredictor