Membrane.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 MEMBRANE_H
6 #define MEMBRANE_H
7 
8 #include <Mercury3D.h>
9 #include <vector>
10 #include <Math/Vector.h>
11 #include <array>
12 
13 #include <Particles/BaseParticle.h>
14 #include <Walls/MeshTriangle.h>
15 
16 
58 class Membrane : public BaseObject
59 {
60 public:
61 
65  struct Edge
66  {
67  // 3 and 4
71  std::array<unsigned int, 2> vertexId;
72 
76  std::array<BaseParticle*, 2> vertex = {{nullptr}};
77 
78  // 1 and 2
82  std::array<unsigned int, 2> faceVertexId;
83 
87  std::array<BaseParticle*, 2> faceVertex = {{nullptr}};
88 
92  std::array<MeshTriangle*, 2> face = {{nullptr}};
93 
97  std::array<Mdouble, 2> faceInitialArea;
98 
102  std::array<Mdouble, 8> uPre;
103 
108 
113 
118 
123 
128 
133 
137  void applyForce(Mdouble Kn, Mdouble critDampCoeff, Mdouble Ke, Mdouble Kd, bool bendingAreaConstant);
138 
142  void applyStretchForce(Mdouble Kn, Mdouble critDampCoeff);
143 
147  void applyBendForce(Mdouble Kn, Mdouble Kd, bool bendingAreaConstant);
148 
152  void calculateUPre(Vec3D& state, Mdouble& length, std::array<Mdouble, 2>& faceArea);
153 
158 
162  void handleParticleRemoval(unsigned int id);
163 
167  void handleParticleAddition(unsigned int id, BaseParticle* p);
168 
172  void checkActive();
173  };
174 
178  Membrane();
179 
180  /*
181  * \brief Constructor to create a membrane with two species
182  */
183  Membrane(ParticleSpecies* membraneSpecies, ParticleSpecies* membraneParticleSpecies);
184 
188  // Membrane(const Membrane& other);
189 
190 
194  ~Membrane() override;
195 
199  // Membrane& operator=(const Membrane& other);
200 
204  Membrane* copy() const;
205 
209  void read(std::istream& is) override;
210 
214  void write(std::ostream& os) const override;
215 
219  std::string getName() const override;
220 
224  void setKnAndCrittDampCoeff(Mdouble Kn, Mdouble critDampCoeff);
225 
232 
237 
242 
246  void setKeAndKd(Mdouble Ke, Mdouble Kd);
247 
252  void setBendingAreaConstant(bool areaConstant);
253 
257  void setThickness(Mdouble thickness);
258 
259 
260  Mdouble getKn() { return Kn_; }
262  Mdouble getKe() { return Ke_; }
263  Mdouble getKd() { return Kd_; }
266 
271 
276 
280  void setDPMBase(DPMBase* dpm) { DPMBase_ = dpm; }
281 
285  DPMBase* getDPMBase() { return DPMBase_; }
286 
290  std::vector<BaseParticle*> getVertexParticles(){ return vertexParticle_; };
291 
295  std::vector<MeshTriangle*> getFaces(){ return face_; };
296 
300  void saveVertexPositions(std::ostream& os);
301 
306  void loadVertexPositions(std::istream& is);
307 
311  void saveAsOFF(unsigned int d);
312 
317 
322 
327 
331  void buildMesh(BaseParticle& p0, std::vector<Vec3D> vertexPositions, std::vector<unsigned int> edgeVertices, std::vector<unsigned int> faceVertices);
332 
338 
342  void updateEdgeMass();
343 
348 
352  void applyPressure(Mdouble pressure);
353 
357  void handleParticleRemoval(unsigned int id);
358 
362  void handleParticleAddition(unsigned int id, BaseParticle* p);
363 
367  Mdouble getVolume();
368 
369 private:
370 
374  void createVertexParticles(BaseParticle& p0, std::vector<Vec3D> vertexPositions);
375 
380 
384  void updateFaceNeighbors();
385 
389  unsigned int addVertex(std::vector<Vec3D>& vertices, Vec3D pos, Mdouble eps);
390 
394  bool addEdge(std::vector<unsigned int>& edges, std::map<std::pair<unsigned int, unsigned int>, int>& map, unsigned int v0, unsigned int v1);
395 
399  std::vector<BaseParticle*> vertexParticle_;
400 
404  std::vector<unsigned int> vertexParticleId_;
405 
410  unsigned int vertexInitId_;
411 
415  std::vector<MeshTriangle*> face_;
416 
421  std::vector<unsigned int> faceVertices_;
422 
426  std::vector<Edge> edge_;
427 
432 
437 
442 
447 
452 
457 
462 
467 
472 
476  DPMBase* DPMBase_ = nullptr;
477 };
478 
479 
480 #endif
Vector3f p0
Definition: MatrixBase_all.cpp:2
float * p
Definition: Tutorial_Map_using.cpp:9
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9;Map< RowVectorXf > v1(M1.data(), M1.size())
It is an abstract base class due to the purely virtual functions declared below. Even if the function...
Definition: BaseObject.h:30
Definition: BaseParticle.h:33
The DPMBase header includes quite a few header files, defining all the handlers, which are essential....
Definition: DPMBase.h:56
A Membrane consists of masses connected by springs.
Definition: Membrane.h:59
void write(std::ostream &os) const override
Writes a Membrane to an output stream, for example a restart file.
Definition: Membrane.cc:183
Mdouble getKe()
Definition: Membrane.h:262
std::vector< MeshTriangle * > getFaces()
Returns a vecter with pointers to the mesh triangles.
Definition: Membrane.h:295
void read(std::istream &is) override
Reads a Membrane from an input stream, for example a restart file.
Definition: Membrane.cc:68
std::vector< unsigned int > vertexParticleId_
Definition: Membrane.h:404
void updateEdgeMass()
Set the correct edge mass by taking the mass from the conencted vertices.
Definition: Membrane.cc:919
void setKnAndCrittDampCoeff(Mdouble Kn, Mdouble critDampCoeff)
Set the parameters needed for the stretching forces.
Definition: Membrane.cc:265
void computeAdditionalForces()
Compute the forces due to the mass spring system.
Definition: Membrane.cc:945
DPMBase * DPMBase_
Definition: Membrane.h:476
unsigned int addVertex(std::vector< Vec3D > &vertices, Vec3D pos, Mdouble eps)
Helper function to check if a given vertex already exists.
Definition: Membrane.cc:542
void updateFaceNeighbors()
Update the faces to have the correct neighbors.
Definition: Membrane.cc:768
Mdouble thickness_
Definition: Membrane.h:456
Mdouble critDampCoeff_
Definition: Membrane.h:441
Mdouble getKn()
Definition: Membrane.h:260
void saveAsOFF(unsigned int d)
Save the Membrane as a .off file.
Definition: Membrane.cc:395
void loadVertexPositions(std::istream &is)
Load the positions of the vertex particles from a stream and apply them to existing particles.
Definition: Membrane.cc:362
void setSpringConstant(Mdouble k)
Set the spring constant of the membrane.
Definition: Membrane.cc:276
ParticleSpecies * membraneSpecies_
Definition: Membrane.h:466
Mdouble Ke_
Definition: Membrane.h:446
ParticleSpecies * membraneParticleSpecies_
Definition: Membrane.h:471
std::vector< BaseParticle * > vertexParticle_
Definition: Membrane.h:399
Mdouble getThickness()
Definition: Membrane.h:264
void setElasticModulusAndThickness(Mdouble E, Mdouble thickness)
Set the elastic modulus and thickness of the membrane.
Definition: Membrane.cc:270
void loadFromSTL(BaseParticle &p0, std::string fileName)
Load the Membrane geometry from a .stl file.
Definition: Membrane.cc:465
std::vector< MeshTriangle * > face_
Definition: Membrane.h:415
void createVertexParticles(BaseParticle &p0, std::vector< Vec3D > vertexPositions)
Handles the actual creation of vertex particles.
Definition: Membrane.cc:684
unsigned int vertexInitId_
Definition: Membrane.h:410
void setThickness(Mdouble thickness)
Set the thickness of the membrane.
Definition: Membrane.cc:296
void handleParticleRemoval(unsigned int id)
Handles the removal of vertex particles from the particle handler.
Definition: Membrane.cc:978
void adjustVertexParticleSize()
Calculates an updated radius for every vertex particle in order to account for the correct mass.
Definition: Membrane.cc:885
Mdouble getKd()
Definition: Membrane.h:263
void setParticleRadius(Mdouble radius)
Set the radius of the vertex particles.
Definition: Membrane.cc:307
std::string getName() const override
Returns the name of the object, here the string "Membrane".
Definition: Membrane.cc:260
std::vector< Edge > edge_
Definition: Membrane.h:426
void buildMesh(BaseParticle &p0, std::vector< Vec3D > vertexPositions, std::vector< unsigned int > edgeVertices, std::vector< unsigned int > faceVertices)
Build the geometry from specified positions and their connectivity.
Definition: Membrane.cc:592
bool bendingAreaConstant_
Definition: Membrane.h:461
Mdouble Kn_
Definition: Membrane.h:436
Membrane * copy() const
Copy method. It calls the copy constructor of this Object.
Definition: Membrane.cc:59
Mdouble particleRadius_
Definition: Membrane.h:431
bool addEdge(std::vector< unsigned int > &edges, std::map< std::pair< unsigned int, unsigned int >, int > &map, unsigned int v0, unsigned int v1)
Helper function to check if a given edge already exists.
Definition: Membrane.cc:567
void saveVertexPositions(std::ostream &os)
save the current positions of the vertex particles to a stream
Definition: Membrane.cc:313
void saveAsSTL(std::string fileName)
Save the Membrane as a .stl file.
Definition: Membrane.cc:432
void initializeEdgeBendingQuantities()
Compute the forces due to the mass spring system.
Definition: Membrane.cc:706
DPMBase * getDPMBase()
Get the stored pointer to DPMBase.
Definition: Membrane.h:285
std::vector< unsigned int > faceVertices_
Definition: Membrane.h:421
Mdouble getBendingAreaConstant()
Definition: Membrane.h:265
Mdouble Kd_
Definition: Membrane.h:451
std::vector< BaseParticle * > getVertexParticles()
Returns a vector with pointers to the vertex particles.
Definition: Membrane.h:290
~Membrane() override
Copy constructor.
Membrane()
Default constructor.
Definition: Membrane.cc:18
Mdouble getCriticalDampingCoefficient()
Definition: Membrane.h:261
Mdouble getParticleRadius()
Returns the radius of the vertex particles.
Definition: Membrane.h:275
Mdouble getVolume()
Calculate the volume of the membrane.
Definition: Membrane.cc:1045
void handleParticleAddition(unsigned int id, BaseParticle *p)
Handles the addition of vertex particles to the particle handler.
Definition: Membrane.cc:1012
void setCriticalDampingCoefficient(Mdouble coeff)
Set damping coefficient for the distance springs.
Definition: Membrane.cc:282
void setDPMBase(DPMBase *dpm)
Set a pointer to DPMBase.
Definition: Membrane.h:280
void setKeAndKd(Mdouble Ke, Mdouble Kd)
Set the parameters needed for the bending forces.
Definition: Membrane.cc:290
void setBendingAreaConstant(bool areaConstant)
Definition: Membrane.cc:302
void applyPressure(Mdouble pressure)
Apply a surface pressure to the membrane.
Definition: Membrane.cc:957
Definition: ParticleSpecies.h:16
Definition: Kernel/Math/Vector.h:30
char char char int int * k
Definition: level2_impl.h:374
double eps
Definition: crbond_bessel.cc:24
double E
Elastic modulus.
Definition: TwenteMeshGluing.cpp:68
radius
Definition: UniformPSDSelfTest.py:15
string fileName
Definition: UniformPSDSelfTest.py:10
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
Definition: Membrane.h:66
void calculateUPre(Vec3D &state, Mdouble &length, std::array< Mdouble, 2 > &faceArea)
Calculate some prefactors for the bending penalty.
Definition: Membrane.cc:1179
std::array< Mdouble, 8 > uPre
Definition: Membrane.h:102
bool isBendActive
Definition: Membrane.h:132
Mdouble effectiveMass
Definition: Membrane.h:122
std::array< BaseParticle *, 2 > vertex
Definition: Membrane.h:76
Mdouble initialLength
Definition: Membrane.h:112
void applyForce(Mdouble Kn, Mdouble critDampCoeff, Mdouble Ke, Mdouble Kd, bool bendingAreaConstant)
Calculates and applies all neccesary forces.
Definition: Membrane.cc:1067
void handleParticleAddition(unsigned int id, BaseParticle *p)
Handle the particle addition.
Definition: Membrane.cc:1259
void applyBendForce(Mdouble Kn, Mdouble Kd, bool bendingAreaConstant)
Apply a force due to bending.
Definition: Membrane.cc:1115
Mdouble initialSineHalfTheta
Definition: Membrane.h:117
std::array< BaseParticle *, 2 > faceVertex
Definition: Membrane.h:87
std::array< Mdouble, 2 > faceInitialArea
Definition: Membrane.h:97
void applyStretchForce(Mdouble Kn, Mdouble critDampCoeff)
Apply the force due to stretching only.
Definition: Membrane.cc:1078
std::array< unsigned int, 2 > faceVertexId
Definition: Membrane.h:82
Mdouble getSineHalfTheta()
Calculate the sine of half the bending angle.
Definition: Membrane.cc:1206
void checkActive()
check if the edge should calculate bending or stretch forces
Definition: Membrane.cc:1281
std::array< MeshTriangle *, 2 > face
Definition: Membrane.h:92
bool isStretchActive
Definition: Membrane.h:127
std::array< unsigned int, 2 > vertexId
Definition: Membrane.h:71
void handleParticleRemoval(unsigned int id)
handle the partical removal
Definition: Membrane.cc:1233
Vec3D initialState
Definition: Membrane.h:107