OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
olb::opti::OptiCaseDual< S, SOLVER, C > Class Template Reference

This class implements the evaluation of the goal functional and its derivatives by using adjoint LBM. More...

#include <optiCaseDual.h>

+ Inheritance diagram for olb::opti::OptiCaseDual< S, SOLVER, C >:
+ Collaboration diagram for olb::opti::OptiCaseDual< S, SOLVER, C >:

Public Member Functions

 OptiCaseDual (XMLreader const &xml)
 
 ~OptiCaseDual ()
 
void free ()
 
evaluateObjective (const C &control, unsigned optiStep=0) override
 Solve primal problem and evaluate objective.
 
void computeDerivatives (const C &control, C &derivatives, unsigned optiStep=0) override
 Compute derivatives via adjoint problem.
 
getReferenceControl () const
 
- Public Member Functions inherited from olb::opti::OptiCase< S, C >
 OptiCase ()=default
 
 OptiCase (std::function< void(void)> postEvaluation)
 
void postEvaluation ()
 

Public Attributes

bool _verbose {true}
 
std::size_t _dimCtrl
 upper limit for the number of control variables (#voxels * field-dimension)
 
ControlType _controlType
 Either force or porosity field.
 
StartValueType _startValueType {Control}
 
std::string _projectionName
 
int _fieldDim
 Spatial dimension of controlled field.
 
int _controlMaterial
 Material number of design domain.
 
_regAlpha {0}
 Regulatory term in objective functional (so far unused)
 
Controller< S > * _controller {nullptr}
 Manages the array of control variables.
 
UnitConverter< S, descriptor > * _converter {nullptr}
 
std::shared_ptr< SOLVER< S, SolverMode::Primal > > _primalSolver
 
std::shared_ptr< SOLVER< S, SolverMode::Dual > > _dualSolver
 
std::shared_ptr< SOLVER< S, SolverMode::Reference > > _referenceSolver
 
bool _computeReference {false}
 
std::shared_ptr< SuperGeometry< S, dim > > _referenceGeometry
 
std::shared_ptr< SuperLattice< S, descriptor > > _referenceLattice
 
std::shared_ptr< GeometrySerializer< S, dim > > _serializer
 
std::shared_ptr< projection::Base< S > > _projection
 
std::shared_ptr< SuperLatticeF< S, descriptor > > _projectedControl
 maps the control to a lattice functor
 
std::shared_ptr< SuperLatticeF< S, descriptor > > _dProjectionDcontrol
 derivative of _projectionControl
 

Additional Inherited Members

- Protected Attributes inherited from olb::opti::OptiCase< S, C >
std::function< void(void)> _postEvaluation { [](){} }
 

Detailed Description

template<typename S, template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
class olb::opti::OptiCaseDual< S, SOLVER, C >

This class implements the evaluation of the goal functional and its derivatives by using adjoint LBM.

The adjoint equations are problem-specific and have been computed for force and porosity optimization so far.

Requirements: S is the arithmetic data type SOLVER implements the (primal/ dual) simulation, inherits from AdjointLbSolverBase An xml file is expected to provide additional information on e.g. simulation and optimization parameters

Definition at line 60 of file optiCaseDual.h.

Constructor & Destructor Documentation

◆ OptiCaseDual()

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
olb::opti::OptiCaseDual< S, SOLVER, C >::OptiCaseDual ( XMLreader const & xml)
inline

Definition at line 102 of file optiCaseDual.h.

102 {
103 readFromXML(xml);
104 initialize(xml);
105 initializeFields();
106 }

◆ ~OptiCaseDual()

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
olb::opti::OptiCaseDual< S, SOLVER, C >::~OptiCaseDual ( )
inline

Definition at line 108 of file optiCaseDual.h.

108 {
109 free();
110 }

References olb::opti::OptiCaseDual< S, SOLVER, C >::free().

+ Here is the call graph for this function:

Member Function Documentation

◆ computeDerivatives()

template<typename S , template< typename, SolverMode > typename SOLVER, typename C >
void olb::opti::OptiCaseDual< S, SOLVER, C >::computeDerivatives ( const C & control,
C & derivatives,
unsigned optiStep = 0 )
overridevirtual

Compute derivatives via adjoint problem.

Implements olb::opti::OptiCase< S, C >.

Definition at line 177 of file optiCaseDual.hh.

179{
180 _controller->setControl(control, _dimCtrl);
181 _dualSolver->parameters(names::OutputOpti()).counterOptiStep = optiStep;
182
183 const auto& primalResults = _primalSolver->parameters(names::Results());
184 auto& dualParams = _dualSolver->parameters(names::Opti());
185
186 dualParams.fpop = primalResults.fpop;
187 dualParams.dObjectiveDf = primalResults.djdf;
188 dualParams.dObjectiveDcontrol = primalResults.djdalpha;
189
190 _dualSolver->solve();
191
192 derivativesFromDualSolution(derivatives);
193}
std::size_t _dimCtrl
upper limit for the number of control variables (#voxels * field-dimension)
std::shared_ptr< SOLVER< S, SolverMode::Primal > > _primalSolver
std::shared_ptr< SOLVER< S, SolverMode::Dual > > _dualSolver
Controller< S > * _controller
Manages the array of control variables.

References olb::opti::control.

◆ evaluateObjective()

template<typename S , template< typename, SolverMode > typename SOLVER, typename C >
S olb::opti::OptiCaseDual< S, SOLVER, C >::evaluateObjective ( const C & control,
unsigned optiStep = 0 )
overridevirtual

Solve primal problem and evaluate objective.

Implements olb::opti::OptiCase< S, C >.

Definition at line 120 of file optiCaseDual.hh.

122{
123 //project control to enforce volume constraint
124#ifdef mathiasProjection
125
126 const int nx = _dualSolver->getGeometry()->getCuboidGeometry().getMotherCuboid().getNx();
127 const int ny = _dualSolver->getGeometry()->getCuboidGeometry().getMotherCuboid().getNy();
128 const int nz = _dualSolver->getGeometry()->getCuboidGeometry().getMotherCuboid().getNz();
129
130 S pi = 4.0 * util::atan(1.0);
131
132 S totalD = T();
133 S wantedTotalD = T();
134
135 S upperBound, lowerBound, volumeRatio;
136 xml.readOrWarn<T>("Optimization", "UpperBound", "", upperBound);
137 xml.readOrWarn<T>("Optimization", "LowerBound", "", lowerBound);
138 xml.readOrWarn<T>("Optimization", "VolumeRatio", "", volumeRatio);
139
140 for (int iX=1; iX<nx-1; iX++) {
141 for (int iY=1; iY<ny-1; iY++) {
142 for (int iZ=1; iZ<nz-1; iZ++) {
143 // TODO: this seems to be fixed to material number = 6
144 if (_dualSolver->getGeometry()->getMaterial(iX,iY,iZ)==6) {
145 S ctrl = control[(iX-1)*(ny-1)*(nz-1)+(iY-1)*(nz-1)+(iZ-1)];
146 totalD += 1./(upperBound-lowerBound)*(ctrl-1.);
147 wantedTotalD += 1.0;
148 }
149 }
150 }
151 }
152
153 for (int iX=1; iX<nx-1; iX++) {
154 for (int iY=1; iY<ny-1; iY++) {
155 for (int iZ=1; iZ<nz-1; iZ++) {
156 // TODO: this seems to be fixed to material number = 6
157 if (_dualSolver->getGeometry()->getMaterial(iX,iY,iZ)==6) {
158 control[(iX-1)*(ny-1)*(nz-1)+(iY-1)*(nz-1)+(iZ-1)]
159 = lowerBound
160 + (control[(iX-1)*(ny-1)*(nz-1)+(iY-1)*(nz-1)+(iZ-1)] - lowerBound)
161 * wantedTotalD * (1.-volumeRatio) / totalD;
162 }
163 }
164 }
165 }
166#endif
167
168 _controller->setControl(control, _dimCtrl);
169 _primalSolver->parameters(names::OutputOpti()).counterOptiStep = optiStep;
170 _primalSolver->solve();
171
172 return _primalSolver->parameters(names::Results()).objective;
173}
ADf< T, DIM > atan(const ADf< T, DIM > &a)
Definition aDiff.h:614

References olb::util::atan(), and olb::opti::control.

+ Here is the call graph for this function:

◆ free()

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
void olb::opti::OptiCaseDual< S, SOLVER, C >::free ( )
inline

Definition at line 112 of file optiCaseDual.h.

112 {
113 delete _converter;
114 _converter = nullptr;
115 delete _controller;
116 _controller = nullptr;
117 }
UnitConverter< S, descriptor > * _converter

References olb::opti::OptiCaseDual< S, SOLVER, C >::_controller, and olb::opti::OptiCaseDual< S, SOLVER, C >::_converter.

+ Here is the caller graph for this function:

◆ getReferenceControl()

template<typename S , template< typename, SolverMode > typename SOLVER, typename C >
C olb::opti::OptiCaseDual< S, SOLVER, C >::getReferenceControl ( ) const

Definition at line 269 of file optiCaseDual.hh.

270{
271 assert((this->_computeReference) && "Reference solution has not yet been computed\n");
272 C result = util::ContainerCreator<C>::create(_dimCtrl);
273
274 if (_controlType == ForceControl) {
275 LatticeR<dim+1> latticeR;
276 for (int iC=0; iC<_referenceGeometry->getCuboidGeometry().getNc(); iC++) {
277 latticeR[0] = iC;
278 int nX = _referenceGeometry->getCuboidGeometry().get(iC).getNx();
279 int nY = _referenceGeometry->getCuboidGeometry().get(iC).getNy();
280 int nZ = _referenceGeometry->getCuboidGeometry().get(iC).getNz();
281 for (int iX=0; iX<nX; iX++) {
282 latticeR[1] = iX;
283 for (int iY=0; iY<nY; iY++) {
284 latticeR[2] = iY;
285 for (int iZ=0; iZ<nZ; iZ++) {
286 latticeR[3] = iZ;
287
289 C force_help(_fieldDim, 0);
290 if (_referenceGeometry->getLoadBalancer().rank(iC) == singleton::mpi().getRank()) {
291 for (int iDim=0; iDim<_fieldDim; iDim++) {
292 const auto cell = _referenceLattice->get(latticeR);
293 force_help[iDim]
294 = _projection->inverse(cell.template getFieldComponent<descriptors::FORCE>(iDim));
295 }
296 }
297#ifdef PARALLEL_MODE_MPI
298 singleton::mpi().bCast(&force_help[0], _fieldDim, _referenceGeometry->getLoadBalancer().rank(iC));
299#endif
300 for (int iDim=0; iDim<_fieldDim; iDim++) {
301 const int index = _serializer->getSerializedComponentIndex(latticeR, iDim, _fieldDim);
302 result[index] = force_help[iDim];
303 }
304 }
305 }
306 }
307 }
308 }
309 } else {
310 clout << "getReferenceControl() is only implemented for forced optimization" << std::endl;
311 exit(1);
312 }
313 return result;
314}
int _controlMaterial
Material number of design domain.
std::shared_ptr< GeometrySerializer< S, dim > > _serializer
ControlType _controlType
Either force or porosity field.
std::shared_ptr< SuperGeometry< S, dim > > _referenceGeometry
int _fieldDim
Spatial dimension of controlled field.
std::shared_ptr< projection::Base< S > > _projection
std::shared_ptr< SuperLattice< S, descriptor > > _referenceLattice
void bCast(T *sendBuf, int sendCount, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Broadcast data from one processor to multiple processors.
int getRank() const
Returns the process ID.
int getMaterialGlobally(SuperGeometry< S, dim > &sGeometry, LatticeR< dim+1 > latticeR)
Helper that gives global access to material numbers.
void exit(int exitcode)
Definition singleton.h:165
MpiManager & mpi()

References olb::singleton::MpiManager::bCast(), olb::opti::ForceControl, olb::opti::getMaterialGlobally(), olb::singleton::MpiManager::getRank(), and olb::singleton::mpi().

+ Here is the call graph for this function:

Member Data Documentation

◆ _computeReference

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
bool olb::opti::OptiCaseDual< S, SOLVER, C >::_computeReference {false}

Definition at line 91 of file optiCaseDual.h.

91{false};

◆ _controller

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
Controller<S>* olb::opti::OptiCaseDual< S, SOLVER, C >::_controller {nullptr}

Manages the array of control variables.

Definition at line 85 of file optiCaseDual.h.

85{nullptr};

◆ _controlMaterial

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
int olb::opti::OptiCaseDual< S, SOLVER, C >::_controlMaterial

Material number of design domain.

Definition at line 80 of file optiCaseDual.h.

◆ _controlType

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
ControlType olb::opti::OptiCaseDual< S, SOLVER, C >::_controlType

Either force or porosity field.

Definition at line 73 of file optiCaseDual.h.

◆ _converter

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
UnitConverter<S,descriptor>* olb::opti::OptiCaseDual< S, SOLVER, C >::_converter {nullptr}

Definition at line 86 of file optiCaseDual.h.

86{nullptr};

◆ _dimCtrl

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
std::size_t olb::opti::OptiCaseDual< S, SOLVER, C >::_dimCtrl

upper limit for the number of control variables (#voxels * field-dimension)

Definition at line 70 of file optiCaseDual.h.

◆ _dProjectionDcontrol

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
std::shared_ptr<SuperLatticeF<S,descriptor> > olb::opti::OptiCaseDual< S, SOLVER, C >::_dProjectionDcontrol

derivative of _projectionControl

Definition at line 100 of file optiCaseDual.h.

◆ _dualSolver

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
std::shared_ptr<SOLVER<S,SolverMode::Dual> > olb::opti::OptiCaseDual< S, SOLVER, C >::_dualSolver

Definition at line 88 of file optiCaseDual.h.

◆ _fieldDim

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
int olb::opti::OptiCaseDual< S, SOLVER, C >::_fieldDim

Spatial dimension of controlled field.

Definition at line 78 of file optiCaseDual.h.

◆ _primalSolver

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
std::shared_ptr<SOLVER<S,SolverMode::Primal> > olb::opti::OptiCaseDual< S, SOLVER, C >::_primalSolver

Definition at line 87 of file optiCaseDual.h.

◆ _projectedControl

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
std::shared_ptr<SuperLatticeF<S,descriptor> > olb::opti::OptiCaseDual< S, SOLVER, C >::_projectedControl

maps the control to a lattice functor

Definition at line 98 of file optiCaseDual.h.

◆ _projection

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
std::shared_ptr<projection::Base<S> > olb::opti::OptiCaseDual< S, SOLVER, C >::_projection

Definition at line 96 of file optiCaseDual.h.

◆ _projectionName

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
std::string olb::opti::OptiCaseDual< S, SOLVER, C >::_projectionName

Definition at line 75 of file optiCaseDual.h.

◆ _referenceGeometry

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
std::shared_ptr<SuperGeometry<S,dim> > olb::opti::OptiCaseDual< S, SOLVER, C >::_referenceGeometry

Definition at line 92 of file optiCaseDual.h.

◆ _referenceLattice

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
std::shared_ptr<SuperLattice<S,descriptor> > olb::opti::OptiCaseDual< S, SOLVER, C >::_referenceLattice

Definition at line 93 of file optiCaseDual.h.

◆ _referenceSolver

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
std::shared_ptr<SOLVER<S,SolverMode::Reference> > olb::opti::OptiCaseDual< S, SOLVER, C >::_referenceSolver

Definition at line 89 of file optiCaseDual.h.

◆ _regAlpha

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
S olb::opti::OptiCaseDual< S, SOLVER, C >::_regAlpha {0}

Regulatory term in objective functional (so far unused)

Definition at line 82 of file optiCaseDual.h.

82{0};

◆ _serializer

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
std::shared_ptr<GeometrySerializer<S,dim> > olb::opti::OptiCaseDual< S, SOLVER, C >::_serializer

Definition at line 95 of file optiCaseDual.h.

◆ _startValueType

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
StartValueType olb::opti::OptiCaseDual< S, SOLVER, C >::_startValueType {Control}

Definition at line 74 of file optiCaseDual.h.

74{Control};

◆ _verbose

template<typename S , template< typename, SolverMode > typename SOLVER, typename C = std::vector<S>>
bool olb::opti::OptiCaseDual< S, SOLVER, C >::_verbose {true}

Definition at line 68 of file optiCaseDual.h.

68{true};

The documentation for this class was generated from the following files: