OpenLB 1.8.1
Loading...
Searching...
No Matches
phaseFieldBoundaryDynamics.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2024 Tim Bingert, Luiz Eduardo Czelusniak
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 PHASE_FIELD_BOUNDARY_DYNAMICS_H
25#define PHASE_FIELD_BOUNDARY_DYNAMICS_H
26
27#include "dynamics/dynamics.h"
28
29namespace olb {
30
34template<typename T, typename DESCRIPTOR, typename DYNAMICS, typename MOMENTA, int direction, int orientation>
35class PhaseFieldInletDynamics : public dynamics::CustomCollision<T,DESCRIPTOR,MOMENTA> {
36private:
37 // Use same MOMENTA in combined and nested (boundary) dynamics
38 using CORRECTED_DYNAMICS = typename DYNAMICS::template exchange_momenta<MOMENTA>;
39
40public:
41 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
42 using EquilibriumF = typename CORRECTED_DYNAMICS::EquilibriumF;
43
44 using parameters = typename CORRECTED_DYNAMICS::parameters;
45
46 template<typename M>
48
49 std::type_index id() override {
50 return typeid(PhaseFieldInletDynamics);
51 }
52
54 return block.template getData<OperatorParameters<PhaseFieldInletDynamics>>();
55 }
56
57 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
59 // Along all the commented parts of this code there will be an example based
60 // on the situation where the wall's normal vector if (0,1) and the
61 // numerotation of the velocites are done according to the D2Q9
62 // lattice of the OpenLB library.
63
64 // Find all the missing populations
65 // (directions 3,4,5)
66 constexpr auto missingIndices = util::subIndexOutgoing<DESCRIPTOR,direction,orientation>();
67
68 V phi = MomentaF().computeRho(cell);
69 V missingPhi = phi - 1.;
70 V missingWeightSum = 0;
71 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
72
73 bool contains = false;
74 for(unsigned i=0; i < missingIndices.size(); i++){
75 if(missingIndices[i] == (unsigned)iPop){
76 contains = true;
77 }
78 }
79
80 if(contains){
81 missingWeightSum += descriptors::t<V,DESCRIPTOR>(iPop);
82 } else {
83 missingPhi -= cell[iPop];
84 }
85 }
86
87 for (unsigned iPop=0; iPop < missingIndices.size(); ++iPop) {
88 cell[missingIndices[iPop]] = missingPhi * descriptors::t<V,DESCRIPTOR>(missingIndices[iPop]) / missingWeightSum;
89 }
90
91 return typename CORRECTED_DYNAMICS::CollisionO().apply(cell, parameters);
92 }
93
94 void computeEquilibrium(ConstCell<T,DESCRIPTOR>& cell, T rho, const T u[DESCRIPTOR::d], T fEq[DESCRIPTOR::q]) const override {
95 EquilibriumF().compute(cell, rho, u, fEq);
96 };
97
98 std::string getName() const override {
99 return "PhaseFieldInletDynamics<" + CORRECTED_DYNAMICS().getName() + ">";
100 };
101
102};
103
107template<typename T, typename DESCRIPTOR, typename DYNAMICS, typename MOMENTA, int direction, int orientation>
109 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
110 using EquilibriumF = typename DYNAMICS::EquilibriumF;
111
112 //using parameters = typename DYNAMICS::parameters;
114
115 std::type_index id() override {
117 }
118
120 return block.template getData<OperatorParameters<PhaseFieldConvectiveOutletDynamics>>();
121 }
122
123 constexpr static bool is_vectorizable = false;
124
125 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
127 V phi = MomentaF().computeRho(cell);
128 V u[DESCRIPTOR::d];
129 MomentaF().computeU(cell, u);
131 return {phi, uSqr};
132 }
133
134 void computeEquilibrium(ConstCell<T,DESCRIPTOR>& cell, T rho, const T u[DESCRIPTOR::d], T fEq[DESCRIPTOR::q]) const override {
135 EquilibriumF().compute(cell, rho, u, fEq);
136 };
137
138 std::string getName() const override {
139 return "PhaseFieldConvectiveOutletDynamics<" + DYNAMICS().getName() + ">";
140 };
141
142};
143
144template <typename T, typename DESCRIPTOR>
146 T, DESCRIPTOR,
150>;
152template<typename T, typename DESCRIPTOR>
154{
156}
157
159template<typename T, typename DESCRIPTOR>
161{
162 OstreamManager clout(std::cout, "setConvectivePhaseFieldBoundary");
163
164 for (int iCloc = 0; iCloc < sLattice.getLoadBalancer().size(); iCloc++) {
165 setConvectivePhaseFieldBoundary<T,DESCRIPTOR>(sLattice.getBlock(iCloc), indicator->getBlockIndicatorF(iCloc));
166 }
168 int _overlap = 1;
169 {
170 auto& communicator = sLattice.getCommunicator(stage::PostCollide());
171 communicator.template requestField<descriptors::POPULATION>();
172
173 SuperIndicatorBoundaryNeighbor<T,DESCRIPTOR::d> neighborIndicator(std::forward<decltype(indicator)>(indicator), _overlap);
174 communicator.requestOverlap(_overlap, neighborIndicator);
175 communicator.exchangeRequests();
176 }
177}
178
179
181template<typename T, typename DESCRIPTOR>
183{
184 using namespace boundaryhelper;
185 const auto& blockGeometryStructure = indicator.getBlockGeometry();
186 const int margin = 1;
187 std::vector<int> discreteNormal(3,0);
188 blockGeometryStructure.forSpatialLocations([&](auto iX, auto iY) {
189 if (blockGeometryStructure.getNeighborhoodRadius({iX, iY}) >= margin && indicator(iX, iY)) {
190 discreteNormal = blockGeometryStructure.getStatistics().getType(iX, iY);
191 if ((abs(discreteNormal[1]) + abs(discreteNormal[2])) == 1) {
192 block.addPostProcessor(
193 typeid(stage::PostCollide), {iX,iY},
194 promisePostProcessorForNormal<T,DESCRIPTOR,FlatConvectivePhaseFieldPostProcessorA2D>(
195 Vector<int,2>(discreteNormal.data() + 1)));
196 block.addPostProcessor(
197 typeid(stage::PostStream), {iX,iY},
198 promisePostProcessorForNormal<T,DESCRIPTOR,FlatConvectivePhaseFieldPostProcessorB2D>(
199 Vector<int,2>(discreteNormal.data() + 1)));
200 block.template defineDynamics<NoCollideDynamicsExternalVelocity>({iX, iY});
201 } else {
202 throw std::runtime_error("No valid discrete normal found. This BC is not suited for curved walls.");
203 }
204 }
205 });
206}
207
208}
209
210#endif
Base block indicator functor (discrete)
Definition aliases.h:203
BlockGeometry< T, 2 > & getBlockGeometry()
Get underlying block geometry structure.
Highest-level interface to read-only Cell data.
Definition interface.h:36
Smart pointer for managing the various ways of passing functors around.
Definition functorPtr.h:60
class for marking output with some text
Implementation of Dirichlet boundary condition for the order parameter.
typename CORRECTED_DYNAMICS::EquilibriumF EquilibriumF
void computeEquilibrium(ConstCell< T, DESCRIPTOR > &cell, T rho, const T u[DESCRIPTOR::d], T fEq[DESCRIPTOR::q]) const override
Return iPop equilibrium for given first and second momenta.
typename MOMENTA::template type< DESCRIPTOR > MomentaF
std::type_index id() override
Expose unique type-identifier for RTTI.
AbstractParameters< T, DESCRIPTOR > & getParameters(BlockLattice< T, DESCRIPTOR > &block) override
Parameters access for legacy post processors.
CellStatistic< V > collide(CELL &cell, PARAMETERS &parameters) any_platform
std::string getName() const override
Return human-readable name.
typename CORRECTED_DYNAMICS::parameters parameters
Representation of a statistic for a parallel 2D geometry.
std::unique_ptr< SuperIndicatorF< T, D > > getMaterialIndicator(std::vector< int > &&materials)
Returns a material indicator using the given vector of materials.
Super class maintaining block lattices for a cuboid decomposition.
SuperCommunicator< T, SuperLattice > & getCommunicator(STAGE stage=STAGE())
Return communicator for given communication stage.
BlockLattice< T, DESCRIPTOR > & getBlock(int locC)
Return BlockLattice with local index locC.
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
Plain old scalar vector.
constexpr T t(unsigned iPop, tag::CUM) any_platform
Definition cum.h:108
Tuple< BulkDensity, FixedVelocityMomentum, BulkStress, DefineUSeparately > ExternalVelocityTuple
The Velocity is stored in descriptors::VELOCITY (and computed e.g.
Definition aliases.h:59
constexpr auto subIndexOutgoing() any_platform
Compute opposites of wall-incoming population indices.
Definition util.h:262
auto normSqr(const ARRAY_LIKE &u) any_platform
Compute norm square of a d-dimensional vector.
Definition util.h:145
Top level namespace for all of OpenLB.
std::conditional_t< D==2, SuperIndicatorBoundaryNeighbor2D< T >, SuperIndicatorBoundaryNeighbor3D< T > > SuperIndicatorBoundaryNeighbor
Definition aliases.h:297
std::enable_if_t< std::is_arithmetic< T >::type::value, T > abs(T x) any_platform
Definition util.h:464
void setConvectivePhaseFieldBoundary(SuperLattice< T, DESCRIPTOR > &sLattice, SuperGeometry< T, 2 > &superGeometry, int material)
Initialising the setConvectivePhaseFieldBoundary function on the superLattice domain.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:77
Dynamic access interface for FIELD-valued parameters.
Return value of any collision.
Definition interface.h:45
Implementation of convective boundary condition for the order parameter.
typename MOMENTA::template type< DESCRIPTOR > MomentaF
void computeEquilibrium(ConstCell< T, DESCRIPTOR > &cell, T rho, const T u[DESCRIPTOR::d], T fEq[DESCRIPTOR::q]) const override
Return iPop equilibrium for given first and second momenta.
CellStatistic< V > collide(CELL &cell, PARAMETERS &parameters) any_platform
std::string getName() const override
Return human-readable name.
std::type_index id() override
Expose unique type-identifier for RTTI.
AbstractParameters< T, DESCRIPTOR > & getParameters(BlockLattice< T, DESCRIPTOR > &block) override
Parameters access for legacy post processors.
Dynamics constructed as a tuple of momenta, equilibrium and collision.
Definition interface.h:308
Plain wrapper for list of types.
Definition meta.h:276
Communication after collision.
Definition stages.h:34
Communication after propagation.
Definition stages.h:36