SPHinXsys  alpha version
particle_dynamics_diffusion_reaction.h
Go to the documentation of this file.
1 /* -----------------------------------------------------------------------------*
2  * SPHinXsys *
3  * -----------------------------------------------------------------------------*
4  * SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle *
5  * Hydrodynamics for industrial compleX systems. It provides C++ APIs for *
6  * physical accurate simulation and aims to model coupled industrial dynamic *
7  * systems including fluid, solid, multi-body dynamics and beyond with SPH *
8  * (smoothed particle hydrodynamics), a meshless computational method using *
9  * particle discretization. *
10  * *
11  * SPHinXsys is partially funded by German Research Foundation *
12  * (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1, *
13  * HU1527/12-1 and HU1527/12-4. *
14  * *
15  * Portions copyright (c) 2017-2022 Technical University of Munich and *
16  * the authors' affiliations. *
17  * *
18  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
19  * not use this file except in compliance with the License. You may obtain a *
20  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
21  * *
22  * -----------------------------------------------------------------------------*/
30 #ifndef PARTICLE_DYNAMICS_DIFFUSION_REACTION_H
31 #define PARTICLE_DYNAMICS_DIFFUSION_REACTION_H
32 
33 #include "all_particle_dynamics.h"
35 #include "diffusion_reaction.h"
36 
37 namespace SPH
38 {
39  template <class BodyType, class BaseParticlesType, class BaseMaterialType>
40  using DiffusionReactionSimpleData =
41  DataDelegateSimple<BodyType,
42  DiffusionReactionParticles<BaseParticlesType>,
43  DiffusionReaction<BaseMaterialType>>;
44 
45  template <class BodyType, class BaseParticlesType, class BaseMaterialType>
46  using DiffusionReactionInnerData =
47  DataDelegateInner<BodyType,
48  DiffusionReactionParticles<BaseParticlesType>,
49  DiffusionReaction<BaseMaterialType>>;
50 
51  template <class BodyType, class BaseParticlesType, class BaseMaterialType,
52  class ContactBodyType, class ContactBaseParticlesType, class ContactBaseMaterialType>
53  using DiffusionReactionContactData =
54  DataDelegateContact<BodyType,
55  DiffusionReactionParticles<BaseParticlesType>,
56  DiffusionReaction<BaseMaterialType>,
57  ContactBodyType, DiffusionReactionParticles<ContactBaseParticlesType>,
58  DiffusionReaction<ContactBaseMaterialType>, DataDelegateEmptyBase>;
59 
64  template <class BodyType, class BaseParticlesType, class BaseMaterialType>
66  : public ParticleDynamicsSimple,
67  public DiffusionReactionSimpleData<BodyType, BaseParticlesType, BaseMaterialType>
68  {
69  public:
70  explicit DiffusionReactionInitialCondition(BodyType &body);
72 
73  protected:
74  StdLargeVec<Vecd> &pos_;
75  StdVec<StdLargeVec<Real>> &species_n_;
76  };
77 
82  template <class BodyType, class BaseParticlesType, class BaseMaterialType>
84  : public ParticleDynamics<Real>,
85  public DiffusionReactionSimpleData<BodyType, BaseParticlesType, BaseMaterialType>
86  {
87  public:
88  explicit GetDiffusionTimeStepSize(BodyType &body);
89  virtual ~GetDiffusionTimeStepSize(){};
90 
91  virtual Real exec(Real dt = 0.0) override { return diff_time_step_; };
92  virtual Real parallel_exec(Real dt = 0.0) override { return exec(dt); };
93 
94  protected:
95  Real diff_time_step_;
96  };
97 
102  template <class BodyType, class BaseParticlesType, class BaseMaterialType>
105  public DiffusionReactionInnerData<BodyType, BaseParticlesType, BaseMaterialType>
106  {
108  StdVec<BaseDiffusion *> species_diffusion_;
109  StdVec<StdLargeVec<Real>> &species_n_;
110  StdVec<StdLargeVec<Real>> &diffusion_dt_;
111  StdLargeVec<Real> &Vol_;
112 
113  protected:
114  void initializeDiffusionChangeRate(size_t particle_i);
115  void getDiffusionChangeRate(size_t particle_i, size_t particle_j, Vecd &e_ij, Real surface_area_ij);
116  virtual void updateSpeciesDiffusion(size_t particle_i, Real dt);
117  virtual void Interaction(size_t index_i, Real dt = 0.0) override;
118  virtual void Update(size_t index_i, Real dt = 0.0) override;
119 
120  public:
121  typedef BodyType InnerBodyType;
127  };
128 
133  template <class BodyType, class BaseParticlesType, class BaseMaterialType,
134  class ContactBodyType, class ContactBaseParticlesType, class ContactBaseMaterialType>
136  : public RelaxationOfAllDiffusionSpeciesInner<BodyType, BaseParticlesType, BaseMaterialType>,
137  public DiffusionReactionContactData<BodyType, BaseParticlesType, BaseMaterialType,
138  ContactBodyType, ContactBaseParticlesType, ContactBaseMaterialType>
139  {
140  StdVec<BaseDiffusion *> species_diffusion_;
141  StdVec<StdLargeVec<Real>> &species_n_;
142  StdVec<StdLargeVec<Real>> &diffusion_dt_;
143  StdVec<StdLargeVec<Real> *> contact_Vol_;
144  StdVec<StdVec<StdLargeVec<Real>> *> contact_species_n_;
145 
146  protected:
147  void getDiffusionChangeRateContact(size_t particle_i, size_t particle_j, Vecd &e_ij,
148  Real surface_area_ij, const StdVec<StdLargeVec<Real>> &species_n_k);
149  virtual void Interaction(size_t index_i, Real dt = 0.0) override;
150 
151  public:
155  };
156 
161  template <class BodyType, class BaseParticlesType, class BaseMaterialType>
163  : public ParticleDynamicsSimple,
164  public DiffusionReactionSimpleData<BodyType, BaseParticlesType, BaseMaterialType>
165  {
166  StdVec<BaseDiffusion *> species_diffusion_;
167  StdVec<StdLargeVec<Real>> &species_n_, &species_s_;
168 
169  void initializeIntermediateValue(size_t particle_i);
170  virtual void Update(size_t index_i, Real dt = 0.0) override;
171 
172  public:
173  InitializationRK(SPHBody &sph_body, StdVec<StdLargeVec<Real>> &species_s);
174  virtual ~InitializationRK(){};
175  };
176 
181  template <class FirstStageType>
182  class SecondStageRK2 : public FirstStageType
183  {
184  StdVec<BaseDiffusion *> species_diffusion_;
185  StdVec<StdLargeVec<Real>> &species_n_;
186  StdVec<StdLargeVec<Real>> &diffusion_dt_;
187 
188  protected:
189  StdVec<StdLargeVec<Real>> &species_s_;
190  virtual void updateSpeciesDiffusion(size_t particle_i, Real dt) override;
191 
192  public:
193  SecondStageRK2(typename FirstStageType::BodyRelationType &body_relation,
194  StdVec<StdLargeVec<Real>> &species_s);
195  virtual ~SecondStageRK2(){};
196  };
197 
203  template <class FirstStageType>
205  {
206  protected:
207  StdVec<BaseDiffusion *> species_diffusion_;
209  StdVec<StdLargeVec<Real>> species_s_;
210 
211  InitializationRK<typename FirstStageType::InnerBodyType,
212  typename FirstStageType::InnerBaseParticlesType,
213  typename FirstStageType::InnerBaseMaterialType>
214  rk2_initialization_;
215  FirstStageType rk2_1st_stage_;
216  SecondStageRK2<FirstStageType> rk2_2nd_stage_;
217 
218  public:
219  explicit RelaxationOfAllDiffusionSpeciesRK2(typename FirstStageType::BodyRelationType &body_relation);
221 
222  virtual void exec(Real dt = 0.0) override;
223  virtual void parallel_exec(Real dt = 0.0) override;
224  };
225 
227  {
228  Real operator()(Real input, Real production_rate, Real loss_rate, Real dt) const
229  {
230  return input * exp(-loss_rate * dt) + production_rate * (1.0 - exp(-loss_rate * dt)) / (loss_rate + TinyReal);
231  };
232  };
233 
238  template <class BodyType, class BaseParticlesType, class BaseMaterialType>
240  : public ParticleDynamicsSimple,
241  public DiffusionReactionSimpleData<BodyType, BaseParticlesType, BaseMaterialType>
242  {
243  BaseReactionModel *species_reaction_;
244  StdVec<StdLargeVec<Real>> &species_n_;
245  UpdateAReactionSpecies updateAReactionSpecies;
246 
247  protected:
248  virtual void Update(size_t index_i, Real dt = 0.0) override;
249 
250  public:
251  explicit RelaxationOfAllReactionsForward(BodyType &body);
252  virtual ~RelaxationOfAllReactionsForward(){};
253  };
254 
259  template <class BodyType, class BaseParticlesType, class BaseMaterialType>
261  : public ParticleDynamicsSimple,
262  public DiffusionReactionSimpleData<BodyType, BaseParticlesType, BaseMaterialType>
263  {
264  BaseReactionModel *species_reaction_;
265  StdVec<StdLargeVec<Real>> &species_n_;
266  UpdateAReactionSpecies updateAReactionSpecies;
267 
268  protected:
269  virtual void Update(size_t index_i, Real dt = 0.0) override;
270 
271  public:
272  explicit RelaxationOfAllReactionsBackward(BodyType &body);
274  };
275 
280  template <class BodyType, class BaseParticlesType, class BodyPartByParticleType, class BaseMaterialType>
283  public DiffusionReactionSimpleData<BodyType, BaseParticlesType, BaseMaterialType>
284  {
285  public:
286  ConstrainDiffusionBodyRegion(BodyType &body, BodyPartByParticleType &body_part)
287  : PartSimpleDynamicsByParticle(body, body_part),
289  pos_(this->particles_->pos_), species_n_(this->particles_->species_n_){};
290  virtual ~ConstrainDiffusionBodyRegion(){};
291 
292  protected:
293  StdLargeVec<Vecd> &pos_;
294  StdVec<StdLargeVec<Real>> &species_n_;
295  };
296 
302  template <class BodyType, class BaseParticlesType, class BaseMaterialType>
304  : public ParticleDynamicsSimple,
305  public DiffusionReactionSimpleData<BodyType, BaseParticlesType, BaseMaterialType>
306  {
307  public:
308  explicit DiffusionBasedMapping(BodyType &body)
309  : ParticleDynamicsSimple(body),
311  pos_(this->particles_->pos_), species_n_(this->particles_->species_n_){};
312  virtual ~DiffusionBasedMapping(){};
313 
314  protected:
315  StdLargeVec<Vecd> &pos_;
316  StdVec<StdLargeVec<Real>> &species_n_;
317  };
318 
323  template <class BodyType, class BaseParticlesType, class BaseMaterialType>
325  : public ParticleDynamicsReduce<Real, ReduceSum<Real>>,
326  public DiffusionReactionSimpleData<BodyType, BaseParticlesType, BaseMaterialType>
327  {
328  public:
329  explicit TotalAveragedParameterOnDiffusionBody(BodyType &body, const std::string &species_name)
332  species_n_(this->particles_->species_n_), species_name_(species_name)
333  {
334  quantity_name_ = "TotalAveragedParameterOnDiffusionBody";
335  initial_reference_ = Real(0);
336  phi_ = this->material_->SpeciesIndexMap()[species_name_];
337  }
339 
340  protected:
341  StdVec<StdLargeVec<Real>> &species_n_;
342  std::string species_name_;
343  size_t phi_;
344  Real ReduceFunction(size_t index_i, Real dt = 0.0) override
345  {
346  return species_n_[phi_][index_i] / this->base_particles_->total_real_particles_;
347  }
348  };
349 
354  template <class BodyType, class BaseParticlesType, class BaseMaterialType>
356  : public PartDynamicsByParticleReduce<Real, ReduceSum<Real>>,
357  public DiffusionReactionSimpleData<BodyType, BaseParticlesType, BaseMaterialType>
358  {
359  public:
360  explicit TotalAveragedParameterOnPartlyDiffusionBody(BodyType &body,
361  BodyPartByParticle &body_part, const std::string &species_name)
364  species_n_(this->particles_->species_n_), species_name_(species_name)
365  {
366  quantity_name_ = "TotalAveragedParameterOnPartlyDiffusionBody";
367  initial_reference_ = Real(0);
368  phi_ = this->material_->SpeciesIndexMap()[species_name_];
369  };
371 
372  protected:
373  StdVec<StdLargeVec<Real>> &species_n_;
374  std::string species_name_;
375  size_t phi_;
376  Real ReduceFunction(size_t index_i, Real dt = 0.0) override
377  {
378  return species_n_[phi_][index_i] / body_part_particles_.size();
379  }
380  };
381 }
382 #endif // PARTICLE_DYNAMICS_DIFFUSION_REACTION_H
prepare data for inner particle dynamics
Definition: base_particle_dynamics.h:216
StdVec< StdLargeVec< Real > > species_s_
Definition: particle_dynamics_diffusion_reaction.h:209
Simple particle dynamics without considering particle interaction.
Definition: particle_dynamics_algorithms.h:48
A body part with a collection of particles.
Definition: base_body_part.h:64
This is the derived class of diffusion reaction particles.
Compute the diffusion relaxation process of all species with second order Runge-Kutta time stepping...
Definition: particle_dynamics_diffusion_reaction.h:204
Abstract class for body part simple particle dynamics.
Definition: particle_dynamics_bodypart.h:70
Computing the total averaged parameter on partly diffusion body.
Definition: particle_dynamics_diffusion_reaction.h:355
Compute the diffusion relaxation process of all species.
Definition: particle_dynamics_diffusion_reaction.h:103
Compute the reaction process of all species by forward splitting.
Definition: particle_dynamics_diffusion_reaction.h:239
Base abstract class for reduce.
Definition: particle_dynamics_algorithms.h:69
Mapping inside of body according to diffusion. This is a abstract class to be override for case speci...
Definition: particle_dynamics_diffusion_reaction.h:303
Computing the time step size based on diffusion coefficient and particle smoothing length...
Definition: particle_dynamics_diffusion_reaction.h:83
Definition: particle_dynamics_diffusion_reaction.h:135
virtual void exec(Real dt=0.0) override
Definition: particle_dynamics_diffusion_reaction.hpp:241
Real initial_reference_
Definition: particle_dynamics_algorithms.h:104
Base class for all reaction models.
Definition: diffusion_reaction.h:163
prepare data for contact particle dynamics
Definition: base_particle_dynamics.h:240
virtual Real exec(Real dt=0.0) override
Definition: particle_dynamics_diffusion_reaction.h:91
pure abstract class for initial conditions
Definition: particle_dynamics_diffusion_reaction.h:65
the second stage of the 2nd-order Runge-Kutta scheme
Definition: particle_dynamics_diffusion_reaction.h:182
Compute the reaction process of all species by backward splitting.
Definition: particle_dynamics_diffusion_reaction.h:260
The relation combined an inner and a contact body relation. The interaction is in a inner-boundary-co...
Definition: complex_body_relation.h:42
SPHBody is a base body with basic data and functions. Its derived class can be a real fluid body...
Definition: base_body.h:61
reduce operation in a Lagrangian contrained region.
Definition: particle_dynamics_bodypart.h:227
This class includes an interaction and a update steps.
Definition: particle_dynamics_algorithms.h:160
The abstract relation within a SPH body.
Definition: base_body_relation.h:117
prepare data for simple particle dynamics.
Definition: base_particle_dynamics.h:185
set boundary condition for diffusion problem
Definition: particle_dynamics_diffusion_reaction.h:281
initialization of a runge-kutta integration scheme
Definition: particle_dynamics_diffusion_reaction.h:162
Definition: particle_dynamics_diffusion_reaction.h:226
Computing the total averaged parameter on the whole diffusion body.
Definition: particle_dynamics_diffusion_reaction.h:324
Definition: solid_body_supplementary.cpp:9
The base class for all particle dynamics This class contains the only two interface functions availab...
Definition: base_particle_dynamics.h:145