OpenLB 1.7
Loading...
Searching...
No Matches
optiSolverParameters.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Julius Jessberger
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
24
25#ifndef OPTI_SOLVER_PARAMETERS_H
26#define OPTI_SOLVER_PARAMETERS_H
27
28
29#include <limits>
30
31#include "adjointLbSolver.h"
33
34namespace olb {
35
36namespace opti {
37
38enum class SolverMode;
39
40}
41
42namespace parameters {
43
44
46
47struct OptiResultsBase : public ParameterBase { };
48
49
50// ---------------------- Output parameters -----------------------------------
51
52
53template <typename T, opti::SolverMode MODE=opti::SolverMode::Reference>
54struct OptiOutput : public ParameterBase {
55};
56
57template <typename T>
58struct OptiOutput<T,opti::SolverMode::Primal> : public ParameterBase{
59 std::size_t counterOptiStep {0};
60};
61
62template <typename T>
63struct OptiOutput<T,opti::SolverMode::Dual> : public ParameterBase {
64 std::size_t counterOptiStep {0};
65};
66
67template<typename T, opti::SolverMode MODE, typename TAG>
68struct Reader<OptiOutput<T,MODE>, TAG> : public ReaderBase<OptiOutput<T,MODE>> {
70
71 void read(XMLreader const& xml)
72 { }
73};
74
75
76// ---------------------- For ad and dq optimization --------------------------
77
78template<typename T>
80
81 // user has to define how the control values are applied in the simulation
82 virtual void applyControl(const std::vector<T>& control) = 0;
83};
84
85template<typename T>
87
88 using BT = BaseType<T>;
89 T objective {std::numeric_limits<BT>::infinity()};
90};
91
92
93// ------------------- Parameters for adjoint optimization --------------------
94
95// Parameters for distributed optimization problems, for use in combination
96// with OptiCaseDual.
97// Warning: only one lattice is supported so far.
98template<typename T, typename LATTICES>
100
101 using descriptor = typename LATTICES::values_t::template get<0>;
102
103 int fieldDim {descriptor::d};
105 std::shared_ptr<SuperLatticeF<T,descriptor>> controlledField; // this is set by OptiCaseDual
106};
107
108
109template<typename T, typename LATTICES, opti::SolverMode MODE=opti::SolverMode::Reference>
111 : public DistributedOptiSimulationBase<T,LATTICES> { };
112
113template<typename T, typename LATTICES>
114struct DistributedOptiSimulation<T,LATTICES,opti::SolverMode::Primal>
115 : public DistributedOptiSimulationBase<T,LATTICES> {
116
117 //using descriptor = typename LATTICES::values_t::template get<0>;
118
119 std::shared_ptr<SuperF3D<T,T>> referenceSolution;
120 std::shared_ptr<SuperF3D<T,T>> referencePorosity;
121};
122
123template<typename T, typename LATTICES>
124struct DistributedOptiSimulation<T,LATTICES,opti::SolverMode::Dual>
125 : public DistributedOptiSimulationBase<T,LATTICES> {
126
127 using descriptor = typename LATTICES::values_t::template get<0>;
128 static constexpr unsigned dim = descriptor::d;
129
130 std::shared_ptr<SuperLatticeF<T,descriptor>> fpop;
131 std::shared_ptr<SuperF3D<T,T>> dObjectiveDf;
132 std::shared_ptr<SuperF3D<T,T>> dObjectiveDcontrol;
133};
134
135
137template<typename T, typename LATTICES, opti::SolverMode MODE, typename TAG>
138struct Reader<DistributedOptiSimulation<T,LATTICES,MODE>, TAG>
139 : public ReaderBase<DistributedOptiSimulation<T,LATTICES,MODE>> {
141
142 void read(XMLreader const& xml)
143 {
144 xml.readOrWarn<int>("Optimization", "ControlMaterial", "",
145 this->params->controlMaterial, true, true, true);
146 xml.readOrWarn<int>("Optimization", "FieldDimension", "",
147 this->params->fieldDim, true, false, true);
148 }
149};
150
151
152// ------------------- Results of adjoint optimization ------------------------
153
154template<typename T, typename LATTICES, opti::SolverMode MODE>
156
157template<typename T, typename LATTICES>
158struct DistributedOptiSimulationResults<T,LATTICES,opti::SolverMode::Reference>
159 : public OptiResultsBase {
160
161 using descriptor = typename LATTICES::values_t::template get<0>;
162 std::shared_ptr<SuperGeometry<T,descriptor::d>> geometry;
163 std::shared_ptr<SuperLattice<T,descriptor>> lattice;
164
165 std::shared_ptr<SuperLatticeF<T,descriptor>> referenceSolution;
166};
167
168template<typename T, typename LATTICES>
169struct DistributedOptiSimulationResults<T,LATTICES,opti::SolverMode::Primal>
170 : public OptiResultsBase {
171
172 using descriptor = typename LATTICES::values_t::template get<0>;
173 std::shared_ptr<SuperGeometry<T,descriptor::d>> geometry;
174 std::shared_ptr<SuperLattice<T,descriptor>> lattice;
175
176 std::shared_ptr<SuperLatticeF<T,descriptor>> fpop;
177 std::shared_ptr<SuperF3D<T,T>> djdf;
178 std::shared_ptr<SuperLatticeF<T,descriptor>> djdalpha;
179
181 T objective {std::numeric_limits<BT>::infinity()};
182 bool objectiveComputed {false};
183};
184
185template<typename T, typename LATTICES>
186struct DistributedOptiSimulationResults<T,LATTICES,opti::SolverMode::Dual>
187 : public OptiResultsBase {
188
189 using descriptor = typename LATTICES::values_t::template get<0>;
190 std::shared_ptr<SuperLattice<T,descriptor>> lattice;
191
192 // std::shared_ptr<SuperLatticeF3D<T,descriptor>> phi;
193};
194
195} // namespace parameters
196
197} // namespace olb
198
199
200#endif
bool readOrWarn(std::string name_parameter_1, std::string name_parameter_2, std::string name_parameter_3, ParameterType &var, bool defaultAvailable=true, bool exitIfMissing=false, bool showWarning=true) const
This wrapper function reads the given parameter from the "type_parameter" and "name_parameter_1" or "...
Definition xmlReader.h:178
SolverMode
Tags different simulation modes: compute either reference simulation or perform primal or dual (adjoi...
Top level namespace for all of OpenLB.
typename util::BaseTypeHelper< T >::type BaseType
Definition baseType.h:59
Optimization Code.
virtual void applyControl(const std::vector< T > &control)=0
typename LATTICES::values_t::template get< 0 > descriptor
std::shared_ptr< SuperLatticeF< T, descriptor > > controlledField
ReaderBase(std::shared_ptr< PARAMETERS > params_)
std::shared_ptr< PARAMETERS > params
Base struct for reading parameters from files.