OpenLB 1.7
Loading...
Searching...
No Matches
optiCaseDual.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2*
3* Copyright (C) 2012-2021 Mathias J. Krause, Benjamin Förster, Julius Jeßberger
4* E-mail contact: info@openlb.net
5* The most recent release of OpenLB can be downloaded at
6* <http://www.openlb.net/>
7*
8* This program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public License
10* as published by the Free Software Foundation; either version 2
11* of the License, or (at your option) any later version.
12*
13* This program is distributed in the hope that it will be useful,
14* but WITHOUT ANY WARRANTY; without even the implied warranty of
15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16* GNU General Public License for more details.
17*
18* You should have received a copy of the GNU General Public
19* License along with this program; if not, write to the Free
20* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21* Boston, MA 02110-1301, USA.
22*/
23
29#ifndef OPTI_CASE_DUAL_H
30#define OPTI_CASE_DUAL_H
31
32#include "io/xmlReader.h"
33
34#include "adjointLbSolver.h"
35#include "controller.h"
36#include "optiCase.h"
37#include "projection.h"
38#include "serialization.h"
39
40namespace olb {
41
42namespace opti {
43
45
56template<
57 typename S,
58 template<typename,SolverMode> typename SOLVER,
59 typename C = std::vector<S>>
60class OptiCaseDual : public OptiCase<S,C> {
61
62private:
63 mutable OstreamManager clout {std::cout, "OptiCaseDual"};
64 using descriptor = typename SOLVER<S,SolverMode::Reference>::AdjointLbSolverBase::DESCRIPTOR;
65 static constexpr int dim = descriptor::d;
66
67public:
68 bool _verbose {true};
70 std::size_t _dimCtrl;
71
75 std::string _projectionName;
76
82 S _regAlpha {0};
83
87 std::shared_ptr<SOLVER<S,SolverMode::Primal>> _primalSolver;
88 std::shared_ptr<SOLVER<S,SolverMode::Dual>> _dualSolver;
89 std::shared_ptr<SOLVER<S,SolverMode::Reference>> _referenceSolver;
90
91 bool _computeReference {false};
92 std::shared_ptr<SuperGeometry<S,dim>> _referenceGeometry;
93 std::shared_ptr<SuperLattice<S,descriptor>> _referenceLattice;
94
95 std::shared_ptr<GeometrySerializer<S,dim>> _serializer;
96 std::shared_ptr<projection::Base<S>> _projection;
98 std::shared_ptr<SuperLatticeF<S,descriptor>> _projectedControl;
100 std::shared_ptr<SuperLatticeF<S,descriptor>> _dProjectionDcontrol;
101
103 readFromXML(xml);
104 initialize(xml);
105 initializeFields();
106 }
107
109 free();
110 }
111
112 void free() {
113 delete _converter;
114 _converter = nullptr;
115 delete _controller;
116 _controller = nullptr;
117 }
118
120 S evaluateObjective(const C& control, unsigned optiStep=0) override;
121
124 const C& control, C& derivatives, unsigned optiStep=0) override;
125
126 // get the control values as they were computed in the reference solution
127 // only ForceControl & without projection is implemented so far
128 C getReferenceControl() const;
129
130private:
131 void readFromXML(XMLreader const& xml);
132
133 void initialize(XMLreader const& xml);
134
135 void initializeFields();
136
137 void derivativesFromDualSolution(C& derivatives);
138
139};
140
141
142}
143
144}
145
146#endif
class for marking output with some text
Conversion between physical and lattice units, as well as discretization.
This class implements the evaluation of the goal functional and its derivatives by using adjoint LBM.
std::size_t _dimCtrl
upper limit for the number of control variables (#voxels * field-dimension)
int _controlMaterial
Material number of design domain.
OptiCaseDual(XMLreader const &xml)
std::shared_ptr< SOLVER< S, SolverMode::Primal > > _primalSolver
S evaluateObjective(const C &control, unsigned optiStep=0) override
Solve primal problem and evaluate objective.
std::shared_ptr< SOLVER< S, SolverMode::Reference > > _referenceSolver
void computeDerivatives(const C &control, C &derivatives, unsigned optiStep=0) override
Compute derivatives via adjoint problem.
std::shared_ptr< GeometrySerializer< S, dim > > _serializer
UnitConverter< S, descriptor > * _converter
std::string _projectionName
ControlType _controlType
Either force or porosity field.
std::shared_ptr< SuperLatticeF< S, descriptor > > _projectedControl
maps the control to a lattice functor
std::shared_ptr< SuperGeometry< S, dim > > _referenceGeometry
int _fieldDim
Spatial dimension of controlled field.
S _regAlpha
Regulatory term in objective functional (so far unused)
std::shared_ptr< SOLVER< S, SolverMode::Dual > > _dualSolver
std::shared_ptr< projection::Base< S > > _projection
std::shared_ptr< SuperLattice< S, descriptor > > _referenceLattice
StartValueType _startValueType
std::shared_ptr< SuperLatticeF< S, descriptor > > _dProjectionDcontrol
derivative of _projectionControl
Controller< S > * _controller
Manages the array of control variables.
Abstract base class for optimization tasks.
Definition optiCase.h:40
The description of a Controller – header file.
Top level namespace for all of OpenLB.
Optimization Code.
Input/Output in XML format – header file.