MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DropletBoundary.cc
Go to the documentation of this file.
2 #include <MercuryBase.h>
3 #include "DropletBoundary.h"
4 #include "ParticleHandler.h"
6 
8 {
9  MercuryBase* dpm = dynamic_cast<MercuryBase*>(getHandler()->getDPMBase());
10  logger.assert_always(dpm,"You can only run DropletBoundary with Mercury2D or Mercury3D, not DPMBase");
11  // generate new droplets
12  generateDroplets_(*this);
13 // logger(INFO,"Droplets: %",droplets_.size());
14  // integrate Newtons equation of motion
15  Vec3D g = dpm->getGravity();
16  double dt = dpm->getTimeStep();
17  for (auto& d : droplets_) {
18  d.velocity += dt*g;
19  d.position += dt*d.velocity;
20  }
21  // check for interaction with particles; this is costly, so we only do iit every 50 time steps
22  if (dpm->getNumberOfTimeSteps()%checkCount==0) {
25  for (auto &d : droplets_) {
26  p.setPosition(d.position);
27  p.setRadius(d.radius);
28  auto q = dpm->hGridFindParticleContacts(&p);
29  if (q.size() > 0) {
30  double liquidVolume = std::pow(d.radius, 3) * constants::pi / 6.0 / q.size();
31  for (auto particle : q) {
32  auto lfp = static_cast<LiquidFilmParticle *>(particle);
33  lfp->addLiquidVolume(liquidVolume);
34  }
35  d.radius = 0;
36  }
37  // check for interactions with walls
38  for (BaseWall* w : dpm->wallHandler) {
39  Mdouble distance;
40  Vec3D normal_return;
41  double overlap;
42  //Checks if the particle is interacting with the current wall
43  bool inContact = w->getDistanceNormalOverlap(p, distance, normal_return, overlap);
44  // if there is a wall interacting with the droplet
45  if (inContact) {
46  //set droplet radius to zero
47  d.radius = 0;
48  }
49  }
50  }
51  // erase all droplets of radius 0
52  droplets_.erase(std::remove_if(droplets_.begin(), droplets_.end(),
53  [](const Droplet &d) { return d.radius == 0; }), droplets_.end());
54  }
55 }
56 
61 void DropletBoundary::read(std::istream& is)
62 {
64  std::string dummy;
65  size_t n;
66  Vec3D position, velocity;
67  double radius;
68  is >> dummy >> checkCount;
69  is >> dummy >> n;
70  droplets_.reserve(n);
71  droplets_.resize(0);
72  for (int i = 0; i < n; ++i) {
73  is >> position >> velocity >> radius;
74  droplets_.emplace_back(Droplet{position,velocity,radius});
75  }
76 }
77 
82 void DropletBoundary::write(std::ostream& os) const
83 {
85  os << " checkCount " << checkCount;
86  os << " n " << droplets_.size();
87  for (auto& d : droplets_) {
88  os << " " << d.position;
89  os << " " << d.velocity;
90  os << " " << d.radius;
91  }
92 }
93 
94 void DropletBoundary::writeVTK(std::fstream& file) {
95  file << "<Piece NumberOfPoints=\"" << droplets_.size() << "\" NumberOfCells=\"" << 0 << "\">\n";
96  file << "<Points>\n";
97  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
98  for (const auto& d : droplets_) file << '\t' << d.position << '\n';
99  file << " </DataArray>\n";
100  file << "</Points>\n";
101  file << "<PointData Vectors=\"vector\">\n";
102  file << " <DataArray type=\"Float32\" Name=\"Velocity\" NumberOfComponents=\"3\" format=\"ascii\">\n";
103  for (const auto& d : droplets_) file << '\t' << d.velocity << '\n';
104  file << " </DataArray>\n";
105  file << " <DataArray type=\"Float32\" Name=\"Radius\" format=\"ascii\">\n";
106  for (const auto& d : droplets_) file << '\t' << d.radius << '\n';
107  file << " </DataArray>\n";
108  file << "</PointData>\n";
109 }
void writeVTK(std::fstream &file) override
void addLiquidVolume(Mdouble liquidVolume)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
virtual void setRadius(Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
std::vector< Droplet > droplets_
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
void setSpecies(const ParticleSpecies *species)
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
std::function< void(DropletBoundary &)> generateDroplets_
virtual std::vector< BaseParticle * > hGridFindParticleContacts(const BaseParticle *obj)=0
Purely virtual function that returns all particles that have a contact with a given particle...
This is the base class for both Mercury2D and Mercury3D. Note the actually abstract grid is defined i...
Definition: MercuryBase.h:125
const Mdouble pi
Definition: ExtendedMath.h:45
unsigned int getNumberOfTimeSteps() const
Returns the current counter of time-steps, i.e. the number of time-steps that the simulation has unde...
Definition: DPMBase.cc:821
Vec3D getGravity() const
Returns the gravitational acceleration.
Definition: DPMBase.cc:1382
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
BoundaryHandler * getHandler() const
Returns the boundary's BoundaryHandler.
Basic class for walls.
Definition: BaseWall.h:47
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1385
Container to store all BaseParticle.
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:1405
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:634
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:1241
void write(std::ostream &os) const override
Writes the boundary properties to an std::ostream.
virtual bool getDistanceNormalOverlap(const BaseParticle &P, Mdouble &distance, Vec3D &normal_return, Mdouble &overlap) const
Definition: BaseWall.cc:523
void read(std::istream &is) override
Reads some boundary properties from an std::istream.
void checkBoundaryAfterParticlesMove(ParticleHandler &pH) override
Runs at the end of each time step.