SPHinXsys  alpha version
fluid_dynamics_multi_phase.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
9 
10 //=================================================================================================//
11 namespace SPH
12 {
13 //=================================================================================================//
14  namespace fluid_dynamics
15  {
16  //=================================================================================================//
17  template<class RelaxationInnerType>
18  RelaxationMultiPhase<RelaxationInnerType>::
19  RelaxationMultiPhase(BaseBodyRelationInner &inner_relation,
20  BaseBodyRelationContact &contact_relation) :
21  RelaxationInnerType(inner_relation), MultiPhaseContactData(contact_relation)
22  {
23  if (inner_relation.sph_body_ != contact_relation.sph_body_)
24  {
25  std::cout << "\n Error: the two body_realtions do not have the same source body!" << std::endl;
26  std::cout << __FILE__ << ':' << __LINE__ << std::endl;
27  exit(1);
28  }
29 
30  for (size_t k = 0; k != contact_particles_.size(); ++k)
31  {
32  contact_Vol_.push_back(&(contact_particles_[k]->Vol_));
33  contact_p_.push_back(&(contact_particles_[k]->p_));
34  contact_rho_n_.push_back(&(contact_particles_[k]->rho_));
35  contact_vel_n_.push_back(&(contact_particles_[k]->vel_));
36  }
37  }
38  //=================================================================================================//
39  template<class PressureRelaxationInnerType>
40  BasePressureRelaxationMultiPhase<PressureRelaxationInnerType>::
41  BasePressureRelaxationMultiPhase(BaseBodyRelationInner &inner_relation,
42  BaseBodyRelationContact &contact_relation) :
43  RelaxationMultiPhase<PressureRelaxationInnerType>(inner_relation,
44  contact_relation)
45  {
46  for (size_t k = 0; k != this->contact_particles_.size(); ++k)
47  {
48  riemann_solvers_.push_back(CurrentRiemannSolver(*this->material_, *this->contact_material_[k]));
49  }
50  }
51  //=================================================================================================//
52  template<class PressureRelaxationInnerType>
53  BasePressureRelaxationMultiPhase<PressureRelaxationInnerType>::
54  BasePressureRelaxationMultiPhase(ComplexBodyRelation &complex_relation) :
55  BasePressureRelaxationMultiPhase(complex_relation.inner_relation_, complex_relation.contact_relation_) {}
56  //=================================================================================================//
57  template<class PressureRelaxationInnerType>
58  void BasePressureRelaxationMultiPhase<PressureRelaxationInnerType>::Interaction(size_t index_i, Real dt)
59  {
60  PressureRelaxationInnerType::Interaction(index_i, dt);
61 
62  FluidState state_i(this->rho_[index_i], this->vel_[index_i], this->p_[index_i]);
63  Vecd acceleration(0.0);
64  for (size_t k = 0; k < this->contact_configuration_.size(); ++k)
65  {
66  StdLargeVec<Real>& Vol_k = *(this->contact_Vol_[k]);
67  StdLargeVec<Real>& rho_k = *(this->contact_rho_n_[k]);
68  StdLargeVec<Real>& p_k = *(this->contact_p_[k]);
69  StdLargeVec<Vecd>& vel_k = *(this->contact_vel_n_[k]);
70  CurrentRiemannSolver& riemann_solver_k = riemann_solvers_[k];
71  Neighborhood& contact_neighborhood = (*this->contact_configuration_[k])[index_i];
72  for (size_t n = 0; n != contact_neighborhood.current_size_; ++n)
73  {
74  size_t index_j = contact_neighborhood.j_[n];
75  Vecd& e_ij = contact_neighborhood.e_ij_[n];
76  Real dW_ij = contact_neighborhood.dW_ij_[n];
77 
78  FluidState state_j(rho_k[index_j], vel_k[index_j], p_k[index_j]);
79  Real p_star = riemann_solver_k.getPStar(state_i, state_j, e_ij);
80  acceleration -= 2.0 * p_star * e_ij * Vol_k[index_j] * dW_ij / state_i.rho_;
81  }
82  }
83  this->acc_[index_i] += acceleration;
84  }
85  //=================================================================================================//
86  template<class PressureRelaxationInnerType>
87  Vecd BasePressureRelaxationMultiPhase<PressureRelaxationInnerType>::
88  computeNonConservativeAcceleration(size_t index_i)
89  {
90  Vecd acceleration = PressureRelaxationInnerType::computeNonConservativeAcceleration(index_i);
91 
92  Real rho_i = this->rho_[index_i];
93  Real p_i = this->p_[index_i];
94  for (size_t k = 0; k < this->contact_configuration_.size(); ++k)
95  {
96  StdLargeVec<Real>& rho_k = *(this->contact_rho_n_[k]);
97  StdLargeVec<Real>& p_k = *(this->contact_p_[k]);
98  Neighborhood& contact_neighborhood = (*this->contact_configuration_[k])[index_i];
99  for (size_t n = 0; n != contact_neighborhood.current_size_; ++n)
100  {
101  size_t index_j = contact_neighborhood.j_[n];
102  Vecd& e_ij = contact_neighborhood.e_ij_[n];
103  Real dW_ij = contact_neighborhood.dW_ij_[n];
104 
105  Real rho_j = rho_k[index_j];
106  Real p_j = p_k[index_j];
107 
108  Real p_star = (rho_i * p_j + rho_j * p_i) / (rho_i + rho_j);
109  acceleration += (p_i - p_star) * this->Vol_[index_j] * dW_ij * e_ij / rho_i;
110  }
111  }
112  return acceleration;
113  }
114  //=================================================================================================//
115  template<class DensityRelaxationInnerType>
116  BaseDensityRelaxationMultiPhase<DensityRelaxationInnerType>::
117  BaseDensityRelaxationMultiPhase(BaseBodyRelationInner &inner_relation,
118  BaseBodyRelationContact &contact_relation) :
119  RelaxationMultiPhase<DensityRelaxationInnerType>(inner_relation,
120  contact_relation)
121  {
122  for (size_t k = 0; k != this->contact_particles_.size(); ++k)
123  {
124  riemann_solvers_.push_back(CurrentRiemannSolver(*this->material_, *this->contact_material_[k]));
125  }
126  }
127  //=================================================================================================//
128  template<class DensityRelaxationInnerType>
129  BaseDensityRelaxationMultiPhase<DensityRelaxationInnerType>::
130  BaseDensityRelaxationMultiPhase(ComplexBodyRelation &complex_relation) :
131  BaseDensityRelaxationMultiPhase(complex_relation.inner_relation_, complex_relation.contact_relation_) {}
132  //=================================================================================================//
133  template<class DensityRelaxationInnerType>
134  void BaseDensityRelaxationMultiPhase<DensityRelaxationInnerType>::Interaction(size_t index_i, Real dt)
135  {
136  DensityRelaxationInnerType::Interaction(index_i, dt);
137 
138  FluidState state_i(this->rho_[index_i], this->vel_[index_i], this->p_[index_i]);
139  Real density_change_rate = 0.0;
140  for (size_t k = 0; k < this->contact_configuration_.size(); ++k)
141  {
142  StdLargeVec<Real>& Vol_k = *(this->contact_Vol_[k]);
143  StdLargeVec<Real>& rho_k = *(this->contact_rho_n_[k]);
144  StdLargeVec<Real>& p_k = *(this->contact_p_[k]);
145  StdLargeVec<Vecd>& vel_k = *(this->contact_vel_n_[k]);
146  CurrentRiemannSolver& riemann_solver_k = riemann_solvers_[k];
147  Neighborhood& contact_neighborhood = (*this->contact_configuration_[k])[index_i];
148  for (size_t n = 0; n != contact_neighborhood.current_size_; ++n)
149  {
150  size_t index_j = contact_neighborhood.j_[n];
151  Vecd& e_ij = contact_neighborhood.e_ij_[n];
152  Real dW_ij = contact_neighborhood.dW_ij_[n];
153 
154  FluidState state_j(rho_k[index_j], vel_k[index_j], p_k[index_j]);
155  Vecd vel_star = riemann_solver_k.getVStar(state_i, state_j, e_ij);
156  density_change_rate += 2.0 * state_i.rho_ * Vol_k[index_j] * dot(state_i.vel_ - vel_star, e_ij) * dW_ij;
157  }
158  }
159  this->drho_dt_[index_i] += density_change_rate;
160  }
161  //=================================================================================================//
162  }
163 //=================================================================================================//
164 }
165 //=================================================================================================//
Here, we define the algorithm classes for the dynamics involving multiple fluids. ...
Definition: solid_body_supplementary.cpp:9