OpenLB 1.8.1
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
40
41namespace olb {
42
43namespace opti {
44
45template<typename S, unsigned dim>
46class GeometrySerializer;
47
48template <
49 typename T,
50 template<typename,SolverMode> typename SOLVER
51>
52class DistributedObjective;
53
64template<
65 typename S,
66 template<typename,SolverMode> typename SOLVER,
67 concepts::Field CONTROLLED_FIELD,
68 template<typename...> typename PRIMAL_DYNAMICS,
69 typename C = std::vector<S>>
70class OptiCaseDual : public OptiCase<S,C> {
71
72private:
73 mutable OstreamManager clout {std::cout, "OptiCaseDual"};
74 using descriptor = typename SOLVER<S,SolverMode::Reference>::AdjointLbSolver::DESCRIPTOR;
75 static constexpr unsigned dim = descriptor::d;
76 static constexpr unsigned fieldDim = CONTROLLED_FIELD::template size<descriptor>();
77
78public:
79 bool _verbose {true};
81 std::size_t _dimCtrl;
82
84 std::string _projectionName;
85
87 std::shared_ptr<SuperIndicatorF<S,dim>> _controlIndicator;
88
92 std::shared_ptr<SOLVER<S,SolverMode::Primal>> _primalSolver;
93 std::shared_ptr<SOLVER<S,SolverMode::Dual>> _dualSolver;
94
95 std::shared_ptr<DistributedObjective<S,SOLVER>> _objective;
96
97 std::shared_ptr<SuperGeometry<S,dim>> _primalGeometry;
98 // this lattice is not used for simulations, but rather for functor syntax
99 std::shared_ptr<SuperLattice<S,descriptor>> _refLattice;
100
101 std::shared_ptr<GeometrySerializer<S,dim>> _serializer;
102 std::shared_ptr<projection::Base<S>> _projection;
104 std::shared_ptr<SuperLatticeF<S,descriptor>> _projectedControl;
106 std::shared_ptr<SuperLatticeF<S,descriptor>> _dProjectionDcontrol;
107
109 readFromXML(xml);
110 initialize(xml);
111 initializeFields();
112 }
113
115 free();
116 }
117
118 void free() {
119 delete _converter;
120 _converter = nullptr;
121 delete _controller;
122 _controller = nullptr;
123 }
124
126 S evaluateObjective(const C& control, unsigned optiStep=0) override;
127
130 const C& control, C& derivatives, unsigned optiStep=0) override;
131
132
133 void setObjective(std::shared_ptr<DistributedObjective<S,SOLVER>> objective) {
134 _objective = objective;
135 _objective->initialize(_controller, _serializer);
136 }
137
138private:
139 void readFromXML(XMLreader const& xml);
140
141 void initialize(XMLreader const& xml);
142
143 void initializeFields();
144
145 void derivativesFromDualSolution(C& derivatives);
146
147 void derivativesFromDualSolutionPointwise(C& derivatives, LatticeR<dim+1> latticeR);
148};
149
150
151}
152
153}
154
155#endif
Conversion between physical and lattice units, as well as discretization.
Plain old scalar vector.
Objective in optimization with adjoint LBM.
Definition objective.h:46
std::size_t _dimCtrl
upper limit for the number of control variables (#voxels * field-dimension)
std::shared_ptr< projection::Base< S > > _projection
void setObjective(std::shared_ptr< DistributedObjective< S, SOLVER > > objective)
std::shared_ptr< SuperLatticeF< S, descriptor > > _dProjectionDcontrol
derivative of _projectionControl
S evaluateObjective(const C &control, unsigned optiStep=0) override
Solve primal problem and evaluate objective.
std::shared_ptr< SuperGeometry< S, dim > > _primalGeometry
std::shared_ptr< SuperIndicatorF< S, dim > > _controlIndicator
Marks, where there are active control variables.
std::string _projectionName
std::shared_ptr< SOLVER< S, SolverMode::Primal > > _primalSolver
std::shared_ptr< GeometrySerializer< S, dim > > _serializer
StartValueType _startValueType
void computeDerivatives(const C &control, C &derivatives, unsigned optiStep=0) override
Compute derivatives via adjoint problem.
std::shared_ptr< SuperLattice< S, descriptor > > _refLattice
std::shared_ptr< SuperLatticeF< S, descriptor > > _projectedControl
maps the control to a lattice functor
std::shared_ptr< DistributedObjective< S, SOLVER > > _objective
Controller< S > * _controller
Manages the array of control variables.
OptiCaseDual(XMLreader const &xml)
std::shared_ptr< SOLVER< S, SolverMode::Dual > > _dualSolver
UnitConverter< S, descriptor > * _converter
The description of a Controller – header file.
Top level namespace for all of OpenLB.
Optimization Code.
Input/Output in XML format – header file.