MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
lbsrctermcontroller.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef LBSRCTERMCONTROLLER_H
8#define LBSRCTERMCONTROLLER_H
9
10//------------------------------------------------------------------------------
11//------------------------------------------------------------------------------
12// DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING !
13//
14// If you want to add a new source term you can do so by directly adding it into
15// the lbsrcterm.cpp (and nothing else anywhere). Alternatively, you might want
16// to create a new file lbsrcterm_xy.cpp. This needs to include
17// lbsrctermcontroller.h and lbsrcterm.h.
18// Examples can be found in lbsrcterm.cpp.
19//------------------------------------------------------------------------------
20//------------------------------------------------------------------------------
21
22#include <functional>
23#include "INCLUDE/maiatypes.h"
24#include "IO/context.h"
25#include "UTIL/debug.h"
26#include "lbsrcterm.h"
27
28template <MInt nDim, MInt nDist, class SysEqn>
29class LbSolverDxQy;
30
31namespace maia::lb {
32
46template <MInt nDim, MInt nDist, class SysEqn>
48 using srcTermConstructor = std::function<LbSrcTerm<nDim, nDist, SysEqn>*(LbSolverDxQy<nDim, nDist, SysEqn>*)>;
49
50 public:
56 static LbSrcTermFactory* instance();
57
64 void reg_function(const MString& p_name, srcTermConstructor fact_function) { m_function_reg[p_name] = fact_function; }
65
73
74 private:
76 std::map<std::string, srcTermConstructor> m_function_reg;
78};
79
85template <class T>
87 public:
93 LbRegSrcTerm(const MString& p_name) {
95 p_name,
97 -> LbSrcTerm<T::nDim, T::nDist, typename T::SysEqn>* { return new T(p_solver); });
98 }
99};
100
105template <MInt nDim, MInt nDist, class SysEqn>
107 public:
109
110 void init();
111 void initSrcTerms();
112 void addSrcTerm(const MString& p_name);
113 void apply_preCollision();
114 void apply_postCollision();
116
117 private:
120 std::vector<std::unique_ptr<LbSrcTerm<nDim, nDist, SysEqn>>> m_srcTerms;
121};
122
127template <MInt nDim, MInt nDist, class SysEqn>
129 TRACE();
130 std::stringstream ss;
131 ss << "- Init source terms:" << std::endl;
132 m_noSrcTerms = 0;
133 if(Context::propertyExists("lbSrcTerms", m_solver->m_solverId)) {
134 m_noSrcTerms = Context::propertyLength("lbSrcTerms");
135 }
136 m_srcTerms.clear();
137 ss << " no source terms =" << m_noSrcTerms << std::endl;
138 ss << " ";
139 if(m_noSrcTerms > 0) {
140 for(MInt i = 0; i < m_noSrcTerms; i++) {
141 const MString srcTermName = Context::getBasicProperty<MString>("lbSrcTerms", AT_, &srcTermName, i);
142 m_srcTerms.emplace_back(LbSrcTermFactory<nDim, nDist, SysEqn>::instance()->create_srcTerm(srcTermName, m_solver));
143 ss << srcTermName << " ";
144 }
145 ss << std::endl;
146 m_log << ss.str();
147 if(m_solver->domainId() == 0) std::cout << ss.str();
148 }
149}
150
155template <MInt nDim, MInt nDist, class SysEqn>
157 // Call init routine for each source term instance created
158 for(auto& srcTerm : m_srcTerms) {
159 srcTerm->init();
160 }
161}
162
168template <MInt nDim, MInt nDist, class SysEqn>
170 TRACE();
171 m_srcTerms.emplace_back(LbSrcTermFactory<nDim, nDist, SysEqn>::instance()->create_srcTerm(p_name, m_solver));
172}
173
178template <MInt nDim, MInt nDist, class SysEqn>
180 TRACE();
181 for(auto& srcTerm : m_srcTerms) {
182 srcTerm->apply_preCollision();
183 }
184}
185
190template <MInt nDim, MInt nDist, class SysEqn>
192 TRACE();
193 for(auto& srcTerm : m_srcTerms) {
194 srcTerm->apply_postCollision();
195 }
196}
197
202template <MInt nDim, MInt nDist, class SysEqn>
204 TRACE();
205 for(auto& srcTerm : m_srcTerms) {
206 srcTerm->apply_postPropagation();
207 }
208}
209
210} // namespace maia::lb
211
212#endif
static MInt propertyLength(const MString &name, MInt solverId=m_noSolvers)
Returns the number of elements of a property.
Definition: context.cpp:538
static MBool propertyExists(const MString &name, MInt solver=m_noSolvers)
This function checks if a property exists in general.
Definition: context.cpp:494
This class represents all LB models.
Definition: lbsolverdxqy.h:29
Class for registering a source term to the factory registry.
LbRegSrcTerm(const MString &p_name)
Constructor, does the registering.
Front-end to control all source terms in a wrapping manner.
void apply_preCollision()
Call the pre collision routines of all source terms.
void initSrcTerms()
Initialize the source term controller.
std::vector< std::unique_ptr< LbSrcTerm< nDim, nDist, SysEqn > > > m_srcTerms
LbSolverDxQy< nDim, nDist, SysEqn > * m_solver
void apply_postCollision()
Call the post collision routines of all source terms.
void apply_postPropagation()
Call the post collision routines of all source terms.
LbSrcTermController(LbSolverDxQy< nDim, nDist, SysEqn > *p_solver)
void init()
Initialize the source term controller.
void addSrcTerm(const MString &p_name)
Add a source term to the controller by its property tag.
Front-end to create source term objects.
LbSrcTerm< nDim, nDist, SysEqn > * create_srcTerm(const MString &p_name, LbSolverDxQy< nDim, nDist, SysEqn > *p_solver)
Create an lb source term object and return a pointer to it.
static LbSrcTermFactory * instance()
Creates a static instance of LbSrcTermFactory.
void reg_function(const MString &p_name, srcTermConstructor fact_function)
Adds a new LbSrcTerm object to the function registry.
std::map< std::string, srcTermConstructor > m_function_reg
std::function< LbSrcTerm< nDim, nDist, SysEqn > *(LbSolverDxQy< nDim, nDist, SysEqn > *)> srcTermConstructor
Abstract class for lb source terms.
Definition: lbsrcterm.h:22
InfoOutFile m_log
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55