OpenLB 1.8.1
Loading...
Searching...
No Matches
adjointLbSolver.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 ADJOINT_LBSOLVER_H
26#define ADJOINT_LBSOLVER_H
27
29#include "solver/lbSolver.h"
30
31
32namespace olb {
33
34namespace opti {
35
39enum class SolverMode : int {Reference, Primal, Dual};
40
46template<
47 typename T,
48 typename PARAMETERS,
49 typename LATTICES,
50 SolverMode MODE
51>
52class AdjointLbSolver : virtual public LbSolver<T,PARAMETERS,LATTICES>
53{
54private:
55 mutable OstreamManager clout {std::cout, "AdjointLbSolver"};
56
57public:
58 using DESCRIPTOR = typename LATTICES::values_t::template get<0>;
59
62
66
67protected:
69 // User needs to call this method for dual solver at the end of setInitialValues
71 {
72 const auto& params = this->parameters(names::Opti());
73
74 this->lattice().template defineField<opti::F>(params.bulkIndicator, *params.fpop);
75 this->lattice().template defineField<opti::DJDF>(params.objectiveDomain, *(params.dObjectiveDf));
76
77 // update fields if gpu used
78 this->lattice().template setProcessingContext<Array<opti::F>>(ProcessingContext::Simulation);
79 this->lattice().template setProcessingContext<Array<opti::DJDF>>(ProcessingContext::Simulation);
80 }
81
83 // This method is called by default after simulation
84 // If it gets overridden, the user needs to ensure that this method gets called
85 virtual void computeResults() override
86 {
87 this->parameters(names::Results()).lattice = std::get<0>(this->_sLattices);
88 }
89};
90
91}
92
93} // namespace olb
94
95#endif
auto & parameters(KEY=KEY())
Access to parameter structs as parameters(KEY())
Definition lbSolver.h:106
LbSolver is a generic solver for Lattice-Boltzmann problems.
Definition lbSolver.h:132
auto & lattice()
Definition lbSolver.h:297
LATTICES::values_t::template decompose_into< SuperLattices > _sLattices
Definition lbSolver.h:148
class for marking output with some text
Base class for solvers that solve both primal and dual problems.
AdjointLbSolver(utilities::TypeIndexedSharedPtrTuple< PARAMETERS > params)
virtual void computeResults() override
Store SuperLattice pointer for interaction with optimization routine.
void loadPrimalPopulations()
Helper for dual solver: init external fields from primal solution.
typename LATTICES::values_t::template get< 0 > DESCRIPTOR
SolverMode
Tags different simulation modes: compute either reference simulation or perform primal or dual (adjoi...
Top level namespace for all of OpenLB.
@ Simulation
Data available on host for e.g. functor evaluation.
Optimization Code.
Mapping between KEYs and instances of type VALUEs.