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()%50==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 
38  }
39  droplets_.erase(std::remove_if(droplets_.begin(), droplets_.end(),
40  [](const Droplet &d) { return d.radius == 0; }), droplets_.end());
41  }
42 }
43 
48 void DropletBoundary::read(std::istream& is)
49 {
51  std::string dummy;
52  size_t n;
53  Vec3D position, velocity;
54  double radius;
55  is >> dummy >> n;
56  droplets_.reserve(n);
57  droplets_.resize(0);
58  for (int i = 0; i < n; ++i) {
59  is >> position >> velocity >> radius;
60  droplets_.emplace_back(Droplet{position,velocity,radius});
61  }
62 }
63 
68 void DropletBoundary::write(std::ostream& os) const
69 {
71  os << " n " << droplets_.size();
72  for (auto& d : droplets_) {
73  os << " " << d.position;
74  os << " " << d.velocity;
75  os << " " << d.radius;
76  }
77 }
78 
79 void DropletBoundary::writeVTK(std::fstream& file) {
80  file << "<Piece NumberOfPoints=\"" << droplets_.size() << "\" NumberOfCells=\"" << 0 << "\">\n";
81  file << "<Points>\n";
82  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
83  for (const auto& d : droplets_) file << '\t' << d.position << '\n';
84  file << " </DataArray>\n";
85  file << "</Points>\n";
86  file << "<PointData Vectors=\"vector\">\n";
87  file << " <DataArray type=\"Float32\" Name=\"Velocity\" NumberOfComponents=\"3\" format=\"ascii\">\n";
88  for (const auto& d : droplets_) file << '\t' << d.velocity << '\n';
89  file << " </DataArray>\n";
90  file << " <DataArray type=\"Float32\" Name=\"Radius\" format=\"ascii\">\n";
91  for (const auto& d : droplets_) file << '\t' << d.radius << '\n';
92  file << " </DataArray>\n";
93  file << "</PointData>\n";
94 }
void writeVTK(std::fstream &file) override
void addLiquidVolume(Mdouble liquidVolume)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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:50
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:813
Vec3D getGravity() const
Returns the gravitational acceleration.
Definition: DPMBase.cc:1351
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.
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1319
Container to store all BaseParticle.
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:1211
void write(std::ostream &os) const override
Writes the boundary properties to an std::ostream.
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.