ThermalParticle.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 ThermalParticle_H
6 #define ThermalParticle_H
7 #include "DPMBase.h"
8 
13 template<class Particle>
14 class Thermal : public Particle
15 {
16 public:
22  {
23  temperature_ = 0;
24  //temperatureDependentDensity_
25  }
26 
36  Thermal(const Thermal& p) : Particle(p)
37  {
38  temperature_ = p.temperature_;
39  timeDependentTemperature_ = p.timeDependentTemperature_;
40  }
41 
47  ~Thermal() override
48  = default;
49 
56  Thermal* copy() const override
57  {
58  return new Thermal(*this);
59  }
60 
67  void write(std::ostream& os) const override
68  {
69  Particle::write(os);
70  os << " temperature " << temperature_;
71  }
72 
73  std::string getName() const override
74  {
75  return "Thermal" + Particle::getName();
76  }
77 
78  void read(std::istream& is) override;
79 
81  {
82  return temperature_;
83  }
84 
85  void setTemperature(Mdouble temperature)
86  {
87  logger.assert_debug(temperature>0, "Temperature has to be positive");
88  temperature_ = temperature;
89  }
90 
91  void addTemperature(Mdouble temperature)
92  {
93  temperature_ += temperature;
94  logger.assert_debug(temperature_>0, "Temperature has to be positive");
95  }
96 
97  void setTemperatureDependentDensity(const std::function<double(double)>& temperatureDependentDensity);
98 
99  const std::function<double(double)>& getTemperatureDependentDensity() const;
100 
101  const std::function<double(double)>& getTimeDependentTemperature() const
102  {
104  }
105 
106  void setTimeDependentTemperature(const std::function<double(double)>& timeDependentTemperature);
107 
108  void actionsAfterTimeStep() override;
109 
110  bool isSphericalParticle() const override {return true;}
111 
112 private:
113 
117  std::function<double(double temperature)> timeDependentTemperature_;
118 
119 protected:
121 };
122 
131 template<class Particle>
132 void Thermal<Particle>::read(std::istream& is)
133 {
134  Particle::read(is);
135  std::string dummy;
136  is >> dummy >> temperature_;
137 }
138 
139 template<class Particle>
141 {
142  // reset temperature_ if timeDependentTemperature_ function is provided
143  if (timeDependentTemperature_)
144  {
145  temperature_ = timeDependentTemperature_(this->getHandler()->getDPMBase()->getTime());
146  }
147  // reset density and radius if getTemperatureDependentDensity function is provided
148  if (this->getSpecies()->getTemperatureDependentDensity())
149  {
150  const Mdouble density = this->getSpecies()->getTemperatureDependentDensity()(temperature_);
151  this->radius_ = this->getRadius() * cbrt(this->getMass() / (this->getVolume() * density));
152  }
153  /* Compute temperature change due to heat convection with the ambient fluid */
154  this->getSpecies()->actionsAfterTimeStep(this);
155 }
156 
157 template<class Particle>
158 void Thermal<Particle>::setTimeDependentTemperature(const std::function<double(double)>& timeDependentTemperature)
159 {
160  timeDependentTemperature_ = timeDependentTemperature;
161  temperature_ = timeDependentTemperature(0);
162  logger(INFO, "Setting initial temperature to %", temperature_);
163 }
164 
166 #endif
std::string getName(int argc, char *argv[])
Definition: CombineParallelDataFiles.cpp:16
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
Thermal< SphericalParticle > ThermalParticle
Definition: ThermalParticle.h:165
float * p
Definition: Tutorial_Map_using.cpp:9
Definition: ThermalParticle.h:15
Thermal(const Thermal &p)
Particle copy constructor, which accepts as input a reference to a Particle. It creates a copy of thi...
Definition: ThermalParticle.h:36
Thermal * copy() const override
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
Definition: ThermalParticle.h:56
~Thermal() override=default
Particle destructor, needs to be implemented and checked if it removes tangential spring information.
void setTemperatureDependentDensity(const std::function< double(double)> &temperatureDependentDensity)
std::string getName() const override
Definition: ThermalParticle.h:73
const std::function< double(double)> & getTemperatureDependentDensity() const
void actionsAfterTimeStep() override
Definition: ThermalParticle.h:140
Thermal()
Basic Particle constructor, creates a particle at (0,0,0) with radius, mass and inertia equal to 1.
Definition: ThermalParticle.h:21
void addTemperature(Mdouble temperature)
Definition: ThermalParticle.h:91
bool isSphericalParticle() const override
Definition: ThermalParticle.h:110
Mdouble temperature_
Definition: ThermalParticle.h:120
void write(std::ostream &os) const override
Definition: ThermalParticle.h:67
Mdouble getTemperature() const
Definition: ThermalParticle.h:80
const std::function< double(double)> & getTimeDependentTemperature() const
Definition: ThermalParticle.h:101
std::function< double(double temperature)> timeDependentTemperature_
Definition: ThermalParticle.h:117
void setTemperature(Mdouble temperature)
Definition: ThermalParticle.h:85
void setTimeDependentTemperature(const std::function< double(double)> &timeDependentTemperature)
Definition: ThermalParticle.h:158
void read(std::istream &is) override
Definition: ThermalParticle.h:132
#define INFO(i)
Definition: mumps_solver.h:54
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
density
Definition: UniformPSDSelfTest.py:19
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286