ThermalParticle.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef ThermalParticle_H
27 #define ThermalParticle_H
28 #include "DPMBase.h"
29 
34 template<class Particle>
35 class Thermal : public Particle
36 {
37 public:
43  {
44  temperature_ = 0;
45  //temperatureDependentDensity_
46  }
47 
57  Thermal(const Thermal& p) : Particle(p)
58  {
61  }
62 
68  ~Thermal() override
69  = default;
70 
77  Thermal* copy() const override
78  {
79  return new Thermal(*this);
80  }
81 
88  void write(std::ostream& os) const override
89  {
90  Particle::write(os);
91  os << " temperature " << temperature_;
92  }
93 
94  std::string getName() const override
95  {
96  return "Thermal" + Particle::getName();
97  }
98 
99  void read(std::istream& is) override;
100 
102  {
103  return temperature_;
104  }
105 
106  void setTemperature(Mdouble temperature)
107  {
108  logger.assert_debug(temperature>0, "Temperature has to be positive");
109  temperature_ = temperature;
110  }
111 
112  void addTemperature(Mdouble temperature)
113  {
114  temperature_ += temperature;
115  logger.assert_debug(temperature_>0, "Temperature has to be positive");
116  }
117 
118  void setTemperatureDependentDensity(const std::function<double(double)>& temperatureDependentDensity);
119 
120  const std::function<double(double)>& getTemperatureDependentDensity() const;
121 
122  const std::function<double(double)>& getTimeDependentTemperature() const
123  {
125  }
126 
127  void setTimeDependentTemperature(const std::function<double(double)>& timeDependentTemperature);
128 
129  void actionsAfterTimeStep() override;
130 
131  bool isSphericalParticle() const override {return true;}
132 
133 private:
134 
138  std::function<double(double temperature)> timeDependentTemperature_;
139 
140 protected:
142 };
143 
152 template<class Particle>
153 void Thermal<Particle>::read(std::istream& is)
154 {
155  Particle::read(is);
156  std::string dummy;
157  is >> dummy >> temperature_;
158 }
159 
160 template<class Particle>
162 {
163  if (timeDependentTemperature_)
164  {
165  temperature_ = timeDependentTemperature_(this->getHandler()->getDPMBase()->getTime());
166  }
167  if (this->getSpecies()->getTemperatureDependentDensity())
168  {
169  const Mdouble density = this->getSpecies()->getTemperatureDependentDensity()(temperature_);
170  this->radius_ = this->getRadius() * cbrt(this->getMass() / (this->getVolume() * density));
171  }
172 }
173 
174 template<class Particle>
175 void Thermal<Particle>::setTimeDependentTemperature(const std::function<double(double)>& timeDependentTemperature)
176 {
177  timeDependentTemperature_ = timeDependentTemperature;
178  temperature_ = timeDependentTemperature(0);
179  logger(INFO, "Setting initial temperature to %", temperature_);
180 }
181 
183 #endif
std::string getName(int argc, char *argv[])
Definition: CombineParallelDataFiles.cpp:12
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
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:182
Definition: ThermalParticle.h:36
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:57
Thermal * copy() const override
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
Definition: ThermalParticle.h:77
~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:94
const std::function< double(double)> & getTemperatureDependentDensity() const
void actionsAfterTimeStep() override
Definition: ThermalParticle.h:161
Thermal()
Basic Particle constructor, creates a particle at (0,0,0) with radius, mass and inertia equal to 1.
Definition: ThermalParticle.h:42
void addTemperature(Mdouble temperature)
Definition: ThermalParticle.h:112
bool isSphericalParticle() const override
Definition: ThermalParticle.h:131
Mdouble temperature_
Definition: ThermalParticle.h:141
void write(std::ostream &os) const override
Definition: ThermalParticle.h:88
Mdouble getTemperature() const
Definition: ThermalParticle.h:101
const std::function< double(double)> & getTimeDependentTemperature() const
Definition: ThermalParticle.h:122
std::function< double(double temperature)> timeDependentTemperature_
Definition: ThermalParticle.h:138
void setTemperature(Mdouble temperature)
Definition: ThermalParticle.h:106
void setTimeDependentTemperature(const std::function< double(double)> &timeDependentTemperature)
Definition: ThermalParticle.h:175
void read(std::istream &is) override
Definition: ThermalParticle.h:153