ThermalSpecies.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef THERMALSPECIES_H
6 #define THERMALSPECIES_H
7 
9 
10 class BaseInteraction;
11 
12 template<class NormalForceSpecies>
14 {
15 public:
16 
19 
22 
25 
27  virtual ~ThermalSpecies();
28 
30  void write(std::ostream& os) const;
31 
33  void read(std::istream& is);
34 
36  std::string getBaseName() const;
37 
39  void actionsAfterTimeStep(BaseParticle* particle) const override;
40 
42  Mdouble getHeatCapacity() const;
43 
45  void setHeatCapacity(Mdouble heatCapacity);
46 
49 
51  void setThermalConductivity(Mdouble thermalConductivity);
52 
54  {
55  return ambientTemperature_;
56  }
57 
58  void setAmbientTemperature(Mdouble ambientTemperature)
59  {
60  logger.assert_always(ambientTemperature >= 0,"ambientTemperature cannot be negative");
61  ambientTemperature_ = ambientTemperature;
62  }
63 
66  return ambientVelocity_;
67  }
68 
70  void setAmbientVelocity(Vec3D ambientVelocity) {
71  ambientVelocity_ = ambientVelocity;
72  }
73 
77  }
78 
80  void setAmbientThermalConductivity(Mdouble ambientThermalConductivity) {
81  logger.assert_always(ambientThermalConductivity>0,"ambientThermalConductivity has to be positive");
82  ambientThermalConductivity_ = ambientThermalConductivity;
83  }
84 
88  }
89 
91  void setAmbientDynamicViscosity(Mdouble ambientDynamicViscosity) {
92  logger.assert_always(ambientDynamicViscosity>0,"ambientDynamicViscosity has to be positive");
93  ambientDynamicViscosity_ = ambientDynamicViscosity;
94  }
95 
98  return ambientHeatCapacity_;
99  }
100 
102  void setAmbientHeatCapacity(Mdouble ambientHeatCapacity) {
103  logger.assert_always(ambientHeatCapacity>0,"ambientHeatCapacity has to be positive");
104  ambientHeatCapacity_ = ambientHeatCapacity;
105  }
106 
109  return ambientDensity_;
110  }
111 
113  void setAmbientDensity(Mdouble ambientDensity) {
114  logger.assert_always(ambientDensity>0,"ambientDensity has to be positive");
115  ambientDensity_ = ambientDensity;
116  }
117 
118 
119 private:
124 
129 
134 
135  // heat transfer properties
136 
141 
146 
151 
156 
161 };
162 
163 template<class NormalForceSpecies>
166 {
167  heatCapacity_ = 0.0;
168  thermalConductivity_ = 0.0;
170  ambientVelocity_ = {0,0,0};
173  ambientHeatCapacity_ = 0.0;
174  ambientDensity_ = 0.0;
175 }
176 
177 template<class NormalForceSpecies>
180 {
181  heatCapacity_ = s.heatCapacity_;
182  thermalConductivity_ = s.thermalConductivity_;
183  ambientTemperature_=s.ambientTemperature_;
184  ambientVelocity_ = s.ambientVelocity_;
185  ambientThermalConductivity_ = s.ambientThermalConductivity_;
186  ambientDynamicViscosity_ = s.ambientDynamicViscosity_;
187  ambientHeatCapacity_ = s.ambientHeatCapacity_;
188  ambientDensity_ = s.ambientDensity_;
189 }
190 
191 template<class NormalForceSpecies>
193 {}
194 
195 template<class NormalForceSpecies>
196 void ThermalSpecies<NormalForceSpecies>::write(std::ostream& os) const
197 {
199  os << " heatCapacity " << heatCapacity_;
200  os << " thermalConductivity " << thermalConductivity_;
201  os << " ambientTemperature " << ambientTemperature_;
202  os << " ambientVelocity " << ambientVelocity_;
203  os << " ambientThermalConductivity " << ambientThermalConductivity_;
204  os << " ambientDynamicViscosity " << ambientDynamicViscosity_;
205  os << " ambientHeatCapacity " << ambientHeatCapacity_;
206  os << " ambientDensity " << ambientDensity_;
207 }
208 
209 template<class NormalForceSpecies>
211 {
212  std::string dummy;
214  is >> dummy >> heatCapacity_;
215  is >> dummy >> thermalConductivity_;
216  helpers::readOptionalVariable<Mdouble>(is, "ambientTemperature", ambientTemperature_);
217  helpers::readOptionalVariable<Vec3D>(is, "ambientVelocity", ambientVelocity_);
218  helpers::readOptionalVariable<Mdouble>(is, "ambientThermalConductivity", ambientThermalConductivity_);
219  helpers::readOptionalVariable<Mdouble>(is, "ambientDynamicViscosity", ambientDynamicViscosity_);
220  helpers::readOptionalVariable<Mdouble>(is, "ambientHeatCapacity", ambientHeatCapacity_);
221  helpers::readOptionalVariable<Mdouble>(is, "ambientDensity", ambientDensity_);
222 }
223 
224 template<class NormalForceSpecies>
226 {
227  return "Thermal" + NormalForceSpecies::getBaseName();
228 }
229 
230 
231 template<class NormalForceSpecies>
233 {
234  return heatCapacity_;
235 }
236 
237 template<class NormalForceSpecies>
239 {
240  logger.assert_always(heatCapacity > 0,
241  "[ThermalSpecies<>::setHeatCapacity(%)] value has to be positive",
242  heatCapacity);
243  heatCapacity_ = heatCapacity;
244 }
245 
246 template<class NormalForceSpecies>
248 {
249  return thermalConductivity_;
250 }
251 
252 template<class NormalForceSpecies>
254 {
255  logger.assert_always(thermalConductivity >= 0,
256  "[ThermalSpecies<>::setThermalConductivity(%)] value has to be positive",
257  thermalConductivity);
258  thermalConductivity_ = thermalConductivity;
259 }
260 
262 template<class NormalForceSpecies>
264  /* Compute temperature change due to heat convection with the ambient fluid */
265  if (getAmbientThermalConductivity()>0)
266  {
267  auto p = dynamic_cast<ThermalParticle*>(baseParticle);
268  double diameter = 2.0 * p->getRadius();
269  double prandtl = getAmbientDynamicViscosity() * getAmbientHeatCapacity() /
270  getAmbientThermalConductivity();
271  double reynolds = getAmbientDensity() * (p->getVelocity() - getAmbientVelocity()).getLength() * diameter / getAmbientDynamicViscosity();
272  double nusselt = 2.0 + 0.4 * sqrt(reynolds) * cbrt(prandtl);
273  double heatTransferCoefficient = nusselt * getAmbientThermalConductivity() / diameter;
274  double heatTransferRate = heatTransferCoefficient * p->getSurfaceArea() *
275  (getAmbientTemperature()-p->getTemperature());
276  Mdouble temperatureChange = heatTransferRate * p->getInvMass() / getHeatCapacity()
277  * p->getHandler()->getDPMBase()->getTimeStep();
278  p->addTemperature(temperatureChange);
279  }
280 }
281 
282 #endif
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
float * p
Definition: Tutorial_Map_using.cpp:9
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:39
Definition: BaseParticle.h:33
Defines a contact force parallel to the contact normal.
Definition: ThermalInteraction.h:16
Definition: ThermalSpecies.h:14
Mdouble getAmbientHeatCapacity() const
Allows ambientHeatCapacity_ to be accessed.
Definition: ThermalSpecies.h:97
Mdouble getAmbientThermalConductivity() const
Allows ambientThermalConductivity_ to be accessed.
Definition: ThermalSpecies.h:75
void read(std::istream &is)
Reads the species properties from an input stream.
Definition: ThermalSpecies.h:210
void write(std::ostream &os) const
Writes the species properties to an output stream.
Definition: ThermalSpecies.h:196
void actionsAfterTimeStep(BaseParticle *particle) const override
Computes the heat transfer rate (.
double ambientDynamicViscosity_
The dynamic viscosity of the ambient fluid (kg/m/s=Pa.s).
Definition: ThermalSpecies.h:150
void setAmbientTemperature(Mdouble ambientTemperature)
Definition: ThermalSpecies.h:58
Mdouble getAmbientTemperature() const
Definition: ThermalSpecies.h:53
void setAmbientHeatCapacity(Mdouble ambientHeatCapacity)
Allows ambientHeatCapacity_ to be changed.
Definition: ThermalSpecies.h:102
Mdouble heatCapacity_
The specific heat capacity of the particle/wall.
Definition: ThermalSpecies.h:123
void setAmbientThermalConductivity(Mdouble ambientThermalConductivity)
Allows ambientThermalConductivity_ to be changed.
Definition: ThermalSpecies.h:80
double ambientThermalConductivity_
The thermal conductivity of the ambient fluid (W/m/K).
Definition: ThermalSpecies.h:145
Mdouble thermalConductivity_
The thermal conductivity of the particle/wall.
Definition: ThermalSpecies.h:128
ThermalInteraction< typename NormalForceSpecies::InteractionType > InteractionType
The correct Interaction type for this FrictionForceSpecies.
Definition: ThermalSpecies.h:18
std::string getBaseName() const
Used in Species::getName to obtain a unique name for each Species.
Definition: ThermalSpecies.h:225
void setThermalConductivity(Mdouble thermalConductivity)
Allows heatCapacity_ to be changed.
Definition: ThermalSpecies.h:253
double ambientHeatCapacity_
The specific heat capacity of the ambient fluid (J/kg/K).
Definition: ThermalSpecies.h:155
void setHeatCapacity(Mdouble heatCapacity)
Allows heatCapacity_ to be changed.
Definition: ThermalSpecies.h:238
virtual ~ThermalSpecies()
The default destructor.
Definition: ThermalSpecies.h:192
Mdouble getThermalConductivity() const
Allows heatCapacity_ to be accessed.
Definition: ThermalSpecies.h:247
void setAmbientVelocity(Vec3D ambientVelocity)
Allows ambientVelocity_ to be changed.
Definition: ThermalSpecies.h:70
ThermalSpecies()
The default constructor.
Definition: ThermalSpecies.h:164
void setAmbientDynamicViscosity(Mdouble ambientDynamicViscosity)
Allows ambientDynamicViscosity_ to be changed.
Definition: ThermalSpecies.h:91
Vec3D ambientVelocity_
The velocity of the ambient fluid (m/s).
Definition: ThermalSpecies.h:140
double ambientDensity_
The density of the ambient fluid (kg/m^3).
Definition: ThermalSpecies.h:160
Vec3D getAmbientVelocity() const
Allows ambientVelocity_ to be accessed.
Definition: ThermalSpecies.h:65
Mdouble getAmbientDensity() const
Allows ambientDensity_ to be accessed.
Definition: ThermalSpecies.h:108
Mdouble getHeatCapacity() const
Allows heatCapacity_ to be accessed.
Definition: ThermalSpecies.h:232
void setAmbientDensity(Mdouble ambientDensity)
Allows ambientDensity_ to be changed.
Definition: ThermalSpecies.h:113
Mdouble getAmbientDynamicViscosity() const
Allows ambientDynamicViscosity_ to be accessed.
Definition: ThermalSpecies.h:86
Mdouble ambientTemperature_
The ambient temperature (K).
Definition: ThermalSpecies.h:133
Definition: ThermalParticle.h:15
Definition: Kernel/Math/Vector.h:30
RealScalar s
Definition: level1_cplx_impl.h:130
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::enable_if_t< dt !=data_source::global_mem, void > write(PacketType &packet_data, DataScalar ptr)
write, a template function used for storing the data to local memory. This function is used to guaran...
Definition: TensorContractionSycl.h:221
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::enable_if_t< PacketLoad, PacketType > read(const TensorMapper &tensorMapper, const StorageIndex &NCIndex, const StorageIndex &CIndex, const StorageIndex &ld)
read, a template function used for loading the data from global memory. This function is used to guar...
Definition: TensorContractionSycl.h:162
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T cbrt(const T &x)
Definition: MathFunctions.h:1320
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286