MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HeaterBoundary.cc
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, 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 #include "HeaterBoundary.h"
27 #include "ParticleHandler.h"
28 #include "Particles/BaseParticle.h"
29 
31 {
32  posMin_ = Vec3D(0, 0, 0);
33  posMax_ = Vec3D(0, 0, 0);
34  specificHeatStrength_ = Vec3D(0, 0, 0);
35 }
36 
38 {
39  posMin_ = other.posMin_;
40  posMax_ = other.posMax_;
42 }
43 
45 {
46  logger(VERBOSE, "A HeaterBoundary has been destroyed.");
47 }
48 
50 {
51  return new HeaterBoundary(*this);
52 }
53 
54 void HeaterBoundary::set(Vec3D posMin, Vec3D posMax, Vec3D specificHeatStrength)
55 {
56  posMin_ = posMin;
57  posMax_ = posMax;
58  setStrength(specificHeatStrength);
59 }
60 
61 
62 void HeaterBoundary::set2D(Vec3D posMin, Vec3D posMax, Mdouble specificHeatStrength)
63 {
64  posMin_ = posMin;
65  posMax_ = posMax;
66  setStrength2D(specificHeatStrength);
67 }
68 
69 void HeaterBoundary::set3D(Vec3D posMin, Vec3D posMax, Mdouble specificHeatStrength)
70 {
71  posMin_ = posMin;
72  posMax_ = posMax;
73  setStrength3D(specificHeatStrength);
74 }
75 
76 void HeaterBoundary::setStrength(Vec3D specificHeatStrength)
77 {
78  specificHeatStrength_ = specificHeatStrength;
79 }
80 
81 void HeaterBoundary::setStrength2D(Mdouble specificHeatStrength)
82 {
83  specificHeatStrength_.X = specificHeatStrength / sqrt(2.);
84  specificHeatStrength_.Y = specificHeatStrength / sqrt(2.);
86 }
87 
88 void HeaterBoundary::setStrength3D(Mdouble specificHeatStrength)
89 {
90  specificHeatStrength_.X = specificHeatStrength / sqrt(3.);
91  specificHeatStrength_.Y = specificHeatStrength / sqrt(3.);
92  specificHeatStrength_.Z = specificHeatStrength / sqrt(3.);
93 }
94 
96 {
97  return ((posMax_.X - posMin_.X) * (posMax_.Y - posMin_.Y) * (posMax_.Z - posMin_.Z));
98 }
99 
104 {
105  // std::cerr << "Checking a particle position " << position << " against " << posMin_ << " and " << posMax_ << std::endl;
106  if (posMin_.X <= position.X && position.X <= posMax_.X
107  && posMin_.Y <= position.Y && position.Y <= posMax_.Y
108  && posMin_.Z <= position.Z && position.Z <= posMax_.Z
109  )
110  {
111  // std::cerr << "Yes\n";
112  return -1;
113  }
114  else
115  {
116  // std::cerr << "No\n";
117  return 1;
118  }
119 }
120 
122 {
123  for (auto p = pH.begin(); p != pH.end(); ++p)
125 }
126 
127 
132 {
133  if (!(p->isFixed()) && (getDistance(p->getPosition()) < 0))
134  {
135  // fprintf(stderr, "heating a particle\n");
136  // Mdouble noise = heatStrength_ / p->getMass() * pow(pH.getDPMBase()->getTimeStep(),0.5) ;
137  // We need a factor of sqrt(3) in front because we are generating random
138  // numbers using a uniformly distributed random variable, not a normal one.
139  Mdouble noiseX = sqrt(2. * pH.getDPMBase()->getTimeStep() * specificHeatStrength_.X);
140  Mdouble noiseY = sqrt(2. * pH.getDPMBase()->getTimeStep() * specificHeatStrength_.Y);
141  Mdouble noiseZ = sqrt(2. * pH.getDPMBase()->getTimeStep() * specificHeatStrength_.Z);
142 
143  Vec3D brownianMotion = Vec3D(
144  noiseX * pH.getDPMBase()->random.getRandomNumber(-1, 1),
145  noiseY * pH.getDPMBase()->random.getRandomNumber(-1, 1),
146  noiseZ * pH.getDPMBase()->random.getRandomNumber(-1, 1));
147  p->setVelocity(p->getVelocity() + brownianMotion);
148  }
149  return true;
150 }
151 
156 void HeaterBoundary::read(std::istream& is)
157 {
158  BaseBoundary::read(is);
159  std::string dummy;
160  is >> dummy >> posMin_
161  >> dummy >> posMax_
162  >> dummy >> specificHeatStrength_;
163 }
164 
169 void HeaterBoundary::write(std::ostream& os) const
170 {
172  os << " posMin " << posMin_
173  << " posMax " << posMax_
174  << " specificHeatStrength " << specificHeatStrength_;
175 }
176 
181 std::string HeaterBoundary::getName() const
182 {
183  return "HeaterBoundary";
184 }
185 
void set3D(Vec3D posMin, Vec3D posMax, Mdouble specificHeatStrength)
Vec3D specificHeatStrength_
The specific heat strengths have units of energy (mass)^{-1} (time)^{-1) = m^2 s^{-3} For isotropic h...
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Mdouble X
the vector components
Definition: Vector.h:65
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:704
void set2D(Vec3D posMin, Vec3D posMax, Mdouble specificHeatStrength)
void checkBoundaryAfterParticlesMove(ParticleHandler &pH) override
Runs at the end of each time step.
Mdouble getRandomNumber()
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:143
void read(std::istream &is) override=0
Reads the object's id_ from given istream NB: purely virtual function, overriding the version of Base...
Definition: BaseBoundary.cc:61
HeaterBoundary * copy() const override
Used to create a copy of the object NB: purely virtual function.
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:690
void setStrength3D(Mdouble specificHeatStrength)
Mdouble getDistance(const Vec3D &position) const
Returns a negative value if and only if the position is inside the boundary (and therefore the partic...
void setStrength(Vec3D specificHeatStrength)
void set(Vec3D posMin, Vec3D posMax, Vec3D specificHeatStrength)
void setStrength2D(Mdouble specificHeatStrength)
bool checkBoundaryAfterParticleMoved(BaseParticle *p, ParticleHandler &pH)
Checks if a given particle is inside the HeaterBoundary. If so, heats it.
~HeaterBoundary() override
void write(std::ostream &os) const override=0
Adds object's id_ to given ostream NB: purely virtual function, overriding the version of BaseObject...
Definition: BaseBoundary.cc:70
bool isFixed() const override
Is fixed Particle function. It returns whether a Particle is fixed or not, by checking its inverse Ma...
Definition: BaseParticle.h:93
Container to store all BaseParticle.
Mdouble Y
Definition: Vector.h:65
RNG random
This is a random generator, often used for setting up the initial conditions etc...
Definition: DPMBase.h:1324
std::string getName() const override
Mdouble getVolume() const
Returns the volume of the HeaterBoundary cuboid.
void read(std::istream &is) override
Reads some boundary properties from an std::istream.
void write(std::ostream &os) const override
Writes the boundary properties to an std::ostream.
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Definition: Vector.h:49
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
Mdouble getTimeStep() const
Returns the simulation time step.
Definition: DPMBase.cc:1211
Mdouble Z
Definition: Vector.h:65
Supplies a 'constant heat flux' to a cuboidal region (specified by two corner points) by adding a ran...