OpenLB 1.7
Loading...
Searching...
No Matches
advectionDiffusionReactionCouplingPostProcessor2D.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Paul Neugebauer, Lukas Richter, Kevin Schuelein
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#ifndef ADVECTION_DIFFUSSION_REACTION_COUPLING_POST_PROCESSOR_2D_H
25#define ADVECTION_DIFFUSSION_REACTION_COUPLING_POST_PROCESSOR_2D_H
26
27#include "core/blockStructure.h"
28#include "core/postProcessing.h"
29#include "core/util.h"
30#include "latticeDescriptors.h"
31#include "utilities/omath.h"
32
33
34namespace olb {
35
36
41//======================================================================
42// ======== AD coupling with Concentration 2D ====================//
43//======================================================================
44template<typename T, typename DESCRIPTOR>
46 : public LocalPostProcessor2D<T,DESCRIPTOR> {
47
48public:
50 int x0_, int x1_, int y0_, int y1_,
51 const std::vector<T>& stochiometricCoeff_,
52 const std::vector<T> latticeReactionCoeff_,
53 const std::vector<T>& react_order_,
54 std::vector<BlockStructureD<2>* > partners_)
55 : x0(x0_), x1(x1_), y0(y0_), y1(y1_),
56 stochiometricCoeff(stochiometricCoeff_),
57 latticeReactionCoeff(latticeReactionCoeff_),
58 react_order(react_order_), partners(partners_) {
59 this->getName() = "ConcentrationAdvectionDiffusionCouplingPostProcessor2D";
60 reaction_number = static_cast<int>(latticeReactionCoeff.size());
61 component_number = static_cast<int>(partners.size())+1;
62 for (int i = 0; i<component_number; i++) {
63 tpartners.emplace_back(
64 static_cast<BlockLattice<T,DESCRIPTOR> *>(partners[i]));
65 }
66 }
67
68 int extent() const override {
69 return 0;
70 }
71
72 int extent(int whichDirection) const override {
73 return 0;
74 }
75
76 void process(BlockLattice<T,DESCRIPTOR>& blockLattice) override {
77 processSubDomain(blockLattice, x0, x1, y0, y1);
78 }
79
81 int x0_, int x1_, int y0_, int y1_) override {
82
83 int newX0, newX1, newY0, newY1;
84 if ( util::intersect (
85 x0, x1, y0, y1,
86 x0_, x1_, y0_, y1_,
87 newX0, newX1, newY0, newY1 ) ) {
88
89 for (int iX=newX0; iX<=newX1; ++iX) {
90 for (int iY=newY0; iY<=newY1; ++iY) {
91
92 //std::cout << "iX: " << iX << " iY: " << iY << std::endl;
93
94 T conc[component_number];
95 conc[0] = blockLattice.get(iX,iY).computeRho();
96 for (int iter_component = 1; iter_component<component_number; ++iter_component) {
97 conc[iter_component] = tpartners[iter_component-1]->get(iX,iY).computeRho();
98 }
99
100 T sources[component_number];
101 computeSources(sources, conc);
102
103 blockLattice.get(iX,iY).template setField<descriptors::SOURCE>(sources[0]);
104 for (int iter_component = 1; iter_component<component_number; ++iter_component) {
105 tpartners[iter_component-1]->get(iX,iY).template setField<descriptors::SOURCE>(
106 sources[iter_component]);
107 }
108 }
109 }
110 }
111 }
112
113 void computeSources(T sources[], const T concentrations[]) {
114 T lambda[reaction_number];
115 T reaction_rate;
116 for (int iter_reaction = 0; iter_reaction<reaction_number; ++iter_reaction) {
117 lambda[iter_reaction] = 0;
118 reaction_rate = 1;
119 for(int iter_component = 0; iter_component<component_number; ++iter_component) {
120 reaction_rate *= util::pow(concentrations[iter_component],
121 react_order[iter_reaction*component_number+iter_component]);
122 }
123 lambda[iter_reaction] = reaction_rate*latticeReactionCoeff[iter_reaction];
124 }
125
126 for (int iter_component = 0; iter_component<component_number; ++iter_component) {
127 sources[iter_component] = 0;
128 for (int iter_reaction = 0; iter_reaction<reaction_number; ++iter_reaction) {
129 sources[iter_component]
130 += stochiometricCoeff[iter_reaction*component_number+iter_component]*lambda[iter_reaction];
131 }
132 }
133 }
134
135private:
136 int x0, x1, y0, y1;
137 int reaction_number;
138 int component_number;
139 const std::vector<T>& stochiometricCoeff;
140 const std::vector<T> latticeReactionCoeff;
141 const std::vector<T>& react_order;
142 std::vector<BlockLattice<T,DESCRIPTOR>*> tpartners;
143 std::vector<BlockStructureD<2>* > partners;
144};
145
146template<typename T, typename DESCRIPTOR>
148 : public LatticeCouplingGenerator2D<T,DESCRIPTOR> {
149
150public:
152 int x0_, int x1_, int y0_, int y1_,
153 const std::vector<T>& stochiometricCoeff_,
154 const std::vector<T> latticeReactionCoeff_,
155 const std::vector<T>& react_order_)
156 : LatticeCouplingGenerator2D<T,DESCRIPTOR>(x0_, x1_, y0_, y1_),
157 stochiometricCoeff(stochiometricCoeff_), latticeReactionCoeff(latticeReactionCoeff_), react_order(react_order_)
158 { }
159
161 std::vector<BlockStructureD<2>* > partners) const override {
163 this->x0,this->x1,this->y0,this->y1, stochiometricCoeff, latticeReactionCoeff, react_order, partners);
164 }
165
169
170private:
171 const std::vector<T>& stochiometricCoeff;
172 const std::vector<T> latticeReactionCoeff;
173 const std::vector<T>& react_order;
174};
175
176
177
178
179}
180
181#endif
Platform-abstracted block lattice for external access and inter-block interaction.
Cell< T, DESCRIPTOR > get(CellID iCell)
Get Cell interface for index iCell.
Base of a regular block.
ConcentrationAdvectionDiffusionCouplingGenerator2D(int x0_, int x1_, int y0_, int y1_, const std::vector< T > &stochiometricCoeff_, const std::vector< T > latticeReactionCoeff_, const std::vector< T > &react_order_)
LatticeCouplingGenerator2D< T, DESCRIPTOR > * clone() const override
PostProcessor2D< T, DESCRIPTOR > * generate(std::vector< BlockStructureD< 2 > * > partners) const override
void processSubDomain(BlockLattice< T, DESCRIPTOR > &blockLattice, int x0_, int x1_, int y0_, int y1_) override
Execute post-processing step on a sublattice.
ConcentrationAdvectionDiffusionCouplingPostProcessor2D(int x0_, int x1_, int y0_, int y1_, const std::vector< T > &stochiometricCoeff_, const std::vector< T > latticeReactionCoeff_, const std::vector< T > &react_order_, std::vector< BlockStructureD< 2 > * > partners_)
void process(BlockLattice< T, DESCRIPTOR > &blockLattice) override
Execute post-processing step.
int extent(int whichDirection) const override
Extent of application area along a direction (0 or 1)
int extent() const override
Extent of application area (0 for purely local operations)
Interface of 2D post-processing steps.
std::string & getName()
read and write access to name
Descriptor for all types of 2D and 3D lattices.
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
Definition pack.h:112
bool intersect(int x0, int x1, int y0, int y1, int x0_, int x1_, int y0_, int y1_, int &newX0, int &newX1, int &newY0, int &newY1)
Definition util.h:89
Top level namespace for all of OpenLB.
Interface for post-processing steps – header file.
Set of functions commonly used in LB computations – header file.