OpenLB 1.7
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 AdjointLbSolverBase : public LbSolver<T,PARAMETERS,LATTICES>
53{
54private:
55 mutable OstreamManager clout {std::cout, "AdjointLbSolverBase"};
56
57public:
58 using DESCRIPTOR = typename LATTICES::values_t::template get<0>;
59
63
64protected:
67 {
68 const auto& params = this->parameters(names::Opti());
69 auto lattice = std::get<0>(this->_sLattices);
70
71 lattice->template defineField<descriptors::F>(
72 this->geometry(), 1, *params.fpop);
73 lattice->template defineField<descriptors::F>(
74 this->geometry(), params.controlMaterial, *params.fpop);
75
76 lattice->template defineField<descriptors::DJDF>(
77 this->geometry(), 1, *(params.dObjectiveDf));
78 lattice->template defineField<descriptors::DJDF>(
79 this->geometry(), params.controlMaterial, *(params.dObjectiveDf));
80 lattice->template defineField<descriptors::DJDALPHA>(
81 this->geometry(), params.controlMaterial, *(params.dObjectiveDcontrol));
82
83 // update fields if gpu used
84 lattice->template setProcessingContext<Array<descriptors::F>>(ProcessingContext::Simulation);
85 lattice->template setProcessingContext<Array<descriptors::DJDF>>(ProcessingContext::Simulation);
86 lattice->template setProcessingContext<Array<descriptors::DJDALPHA>>(ProcessingContext::Simulation);
87 }
88};
89
90}
91
92} // namespace olb
93
94#endif
auto & parameters(KEY=KEY())
Access to parameter structs as parameters(KEY())
Definition lbSolver.h:104
LbSolver is a generic solver for Lattice-Boltzmann problems.
Definition lbSolver.h:130
auto & geometry()
Definition lbSolver.h:300
auto & lattice()
Definition lbSolver.h:292
LATTICES::values_t::template decompose_into< SuperLattices > _sLattices
Definition lbSolver.h:145
class for marking output with some text
Base class for solvers that solve both primal and dual problems.
typename LATTICES::values_t::template get< 0 > DESCRIPTOR
void loadPrimalPopulations()
Helper for dual solver: init external fields from primal solution.
AdjointLbSolverBase(utilities::TypeIndexedSharedPtrTuple< PARAMETERS > params)
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.