Parallel Finite Element - General geometry Ewald-like Method
Part of Continuum-particle Simulation Suite under MICCOM
rigid_particle.h
Go to the documentation of this file.
1 // Parallel Finite Element-General Geometry Ewald-like Method.
2 // Copyright (C) 2015-2016 Xujun Zhao, Jiyuan Li, Xikai Jiang
3 
4 // This code is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 
10 // This code is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 
15 
16 // You should have received a copy of the GNU General Public
17 // License along with this code; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20 
21 
22 #pragma once
23 
24 #include <stdio.h>
25 
26 
27 // Local includes
28 #include "libmesh/libmesh_common.h"
29 #include "libmesh/reference_counted_object.h"
30 #include "libmesh/parallel_object.h"
31 #include "libmesh/point.h"
32 #include "libmesh/id_types.h"
33 #include "libmesh/mesh.h"
34 #include "libmesh/serial_mesh.h"
35 #include "mesh_spring_network.h"
36 
37 
38 
39 namespace libMesh
40 {
41 
42  /*
43  * Shape of rigid particles
44  */
46  SPHERE = 0,
47  CYLINDER = 1,
48  ELLIPSOID = 2,
49  CUBE = 3,
50  GENERAL = 100
51  };
52 
53 
54 
55  /*
56  * This class only defines the rigid particle with general geometries
57  */
58 
59 
60 class RigidParticle : public ReferenceCountedObject<RigidParticle>,
61  public ParallelObject
62 {
63 public:
64 
65  // Constructor for a spherical particle with radius, density, total charge, and relative permittivity
66  RigidParticle(const dof_id_type& particle_id,
67  const int& particle_type,
68  const Point& pt,
69  const Point& mag,
70  const Point& rot,
71  const Real& charge,
72  const Real& epsilon_in,
73  const Point& sedimentation_body_force_density,
74  const Parallel::Communicator &comm_in);
75 
76  // ~ Destructor
78 
79 
80  /*
81  * Initialize particle volume0, volume, area0, area, centroid0, centroid, etc.
82  */
83  void init();
84 
85  /*
86  * The counter that counts how many times a particle has crossed boundaries
87  */
88  std::vector<int> & counter() { return _counter; };
89 
90 
91  /*
92  * Return particle id, which is unique for a particle.
93  * This id is set during the initialization,and not allowed to reset afterwards.
94  */
95  dof_id_type id() const { return _particle_id; };
96 
97 
98  /*
99  * particle radius.
100  * This parameter is only for spherical particles,
101  * but meaningless for particles with general shapes!
102  */
103  Real radius() const { return _radius; }
104 
105 
106  /*
107  * free charge carried by the particle
108  */
109  const Real& charge() const { return _charge; }
110 
111 
112  /*
113  * relative permittivity of the particle
114  */
115  const Real& epsilon_in() const { return _epsilon_in; }
116 
117 
118  /*
119  * The processor that the particle belongs to, which is the same as the
120  * processor id of its hosting element;
121  *
122  * For a finite sized particle whose parts can be on different processors,
123  * this becomes meaningless. So it is here set as -1 at this time
124  */
125  int processor_id() const { return _processor_id; };
126 
127 
128  /*
129  * (re-)set the processor id for the particle
130  */
131  void set_processor_id(const int pid) { _processor_id = pid; };
132 
133 
134  /*
135  * The mesh type of the particle
136  */
137  const std::string& mesh_type() const { return _mesh_type; };
138 
139 
140 
141  /*
142  * Set the neighbor list of the particle
143  * This is set by the member function in the class "ParticleMesh"
144  */
145  void set_neighbor_list(const std::vector<std::pair<std::size_t,Real> >& nei_list)
146  { _neighbor_list = nei_list; };
147 
148 
149  /*
150  * Return the neighbor list of the particle.
151  * NOTE, this includes the particle ids and distance values to this particle.
152  */
153  std::vector<std::pair<std::size_t,Real> > neighbor_list() const
154  { return _neighbor_list; };
155 
156  /*
157  * Attach MeshSpringNetwork & return the pointer
158  */
160  { _mesh_spring_network = msn; }
161 
162 
163  MeshSpringNetwork* mesh_spring_network() const { return _mesh_spring_network; }
164 
165 
166 
167  /*
168  * This extract the surface mesh from a volume mesh,
169  * and write the surface mesh to the local file
170  */
171  void extract_surface_mesh(const std::string& vmesh,
172  const std::string& smesh) const;
173 
174 
175 
176  /*
177  * Read the mesh data for the current particle without any modification,
178  * Then compute the particle's volume according to the mesh.
179  * It can be either a surface mesh of a volume mesh!
180  */
181  void read_mesh(const std::string& filename,
182  const std::string& mesh_type);
183 
184 
185  /*
186  * Read the mesh data for a spherical particle.
187  * and modify the mesh size according to the radius value
188  * and center position.
189  */
190  void read_mesh_sphere(const std::string& filename);
191 
192 
193  /*
194  * Read the mesh data for a cylindrical particle.
195  * and modify the mesh size according to the radius value
196  * height value, and center position.
197  * (assume the original size of the particle is : r=0.5; h=1;
198  * center = (0,0,0) and aligned along z-direction )
199  *
200  * Note this can also be used to read other particles, e.g. spheres
201  */
202  void read_mesh_cylinder(const std::string& filename);
203 
204  /*
205  * Write the mesh data for the current particle.
206  */
207  void write_mesh(const std::string& filename);
208 
209 
210  /*
211  * Update the particle position, which is achieved
212  * by updating the coordinates of each node on the mesh.
213  */
214  void update_mesh(const std::vector<Point>& nodal_pos,
215  const std::vector<Point>& nodal_vel);
216 
217 
218  /*
219  * Update the particle position, which is achieved
220  * by updating the coordinates of each node on the mesh.
221  */
222  void update_mesh(const std::vector<Point>& nodal_pos);
223 
224 
225  /*
226  * Rebuild mesh when rigidparticle is forced to make a translation move
227  *
228  */
229  void translate_mesh(const Point& translationDist);
230 
231  /*
232  * Extract nodal coordinates of the particle mesh.
233  * Note, this only extract the nodal values, but not change them!
234  */
235  void extract_nodes(std::vector<Point>& node_xyz) ;
236 
237 
238  /*
239  * Return the mesh associated with this particle
240  */
241  SerialMesh& mesh();
242 
243 
244  /*
245  * Return the mesh size (hmin/hmax) associated with this particle
246  */
247  std::vector<Real> mesh_size() const;
248 
249 
250  /*
251  * Return the coordinate of the i-th node (tracking point)
252  */
253  const Point& mesh_point(const std::size_t i) const;
254 
255  /*
256  * Return node to center distance
257  */
258  const Real node_center_dist(const std::size_t i) const;
259 
260 
261  /*
262  * total number of nodes of the mesh
263  */
264  std::size_t num_mesh_nodes() const;
265 
266 
267  /*
268  * total number of elements of the mesh
269  */
270  std::size_t num_mesh_elem() const;
271 
272 
273  /*
274  * Check if this particle is sitting on the periodic boundary
275  */
277 
278  /*
279  * get the information that if a particle is on the periodic boundary, this function is used in FixRigid::check_pbc_post_fix()
280  */
281  const bool& if_on_the_periodic_boundary() const {return _on_pb;};
282 
283 
284  /*
285  * When a particle is sitting on the periodic boundary, we need to
286  * rebuild the periodic mesh by moving nodes from one side to the other.
287  *
288  * This is necessary to correctly compute the particle quantities:
289  * volume/area/center/normal ...
290  */
291  void rebuild_periodic_mesh();
292 
293 
294  /*
295  * Restore the periodic mesh: moving nodes back to the right positions.
296  * This is usually used together with rebuild_periodic_mesh()
297  */
298  void restore_periodic_mesh();
299 
300 
301  /*
302  * This function builds the nodal force vector from a constant force density \f
303  * f = (fx,fy,fz) => nf = (f1x,f1y,f1z; f2x,f2y,f2z; ... fnx,fny,fnz;)
304  *
305  * It is an area density for surface mesh, and volume density of volume mesh!
306  * NOTE: we don't use "()" const for constructing es
307  */
309 
310  /*
311  * This function adds forces to the center of mass of rigid particles
312  * These forces will be distributed over the nodal points
313  */
314  // void add_particle_force(const std::vector<Real>& pforce);
315 
316 
317 
318  /*
319  * compute the volume of the particle.
320  * The algorithm is different for surface mesh and volume mesh.
321  */
322  void compute_volume();
323 
324 
325  /*
326  * compute the area of the particle.
327  * The algorithm is different for surface mesh and volume mesh.
328  */
329  void compute_area();
330 
331 
332  /*
333  * compute the centroid of the particle.
334  * \int x*dV sum Ci*Vi
335  * xc = ---------- = -------------
336  * \int dV sum Vi
337  *
338  * This function doesn't care what mesh type is used.
339  */
340  void compute_centroid();
341 
342 
343  /*
344  * Get volume0
345  */
346  const Real& get_volume0() const {return _volume0;};
347 
348  /*
349  * Get volume
350  */
351  const Real& get_volume() const{return _volume;};
352  /*
353  * Get area0
354  */
355  const Real& get_area0() const {return _area0;};
356 
357  /*
358  * Get area
359  */
360  const Real& get_area() const {return _area;};
361 
362  /*
363  * Get center0
364  */
365  const Point& get_center0() const {return _center0;};
366 
367 /*
368  * Get centroid
369  */
370  const Point& get_centroid0() {return _centroid0;};
371 
372 /*
373  * Get centroid0
374  */
375  const Point& get_centroid() {return _centroid;};
376 
377  /*
378  * Get particle shape
379  */
380  const std::string& get_particle_shape() {return _particle_shape;};
381 
382 
383  // this function has not implemented
384  //Point compute_centroid(const std::string& mesh_type = "surface_mesh"){};
385 
386  /*
387  * Construct the unit surface normal at point pt0 for a surface element.
388  * NOTE: this is only for surface mesh.
389  */
390  Point elem_surface_normal(const Elem& s_elem,
391  const Point& pt0) const;
392 
393 
394  /*
395  * Construct the unit surface normal
396  * NOTE: this is only for surface mesh.
397  */
398  std::vector<Point> compute_surface_normal();
399 
400 
401  /*
402  * Correct the position of tracking points to conserve the volume!
403  * NOTE: this is only for surface mesh.
404  */
405  void volume_conservation();
406 
407 
408  /*
409  * Print information of this particle
410  */
411  void print_info() const;
412 
413  /*
414  * set node velocity
415  */
416  void set_node_velocity(std::vector<Point>& node_velocity) {
417  _node_velocity = node_velocity;
418  };
419 
420 
424  void zero_node_force();
425 
429  void add_node_force(std::vector<Point>& node_force);
430 
434  void get_node_force(std::vector<Point>& node_force) const {node_force = _node_force;};
435 
442 
446  const Point& centroid_velocity() {return _centroid_velocity;};
447 
451  void compute_centroid_force();
452 
456  const Point& centroid_force() {return _centroid_force;};
457 
458 private:
459 
460  // particle id
461  dof_id_type _particle_id;
462 
463  // particle type
464  int _particle_type;
465 
466  // number of surface nodes
467  std::size_t _num_mesh_node;
468 
469  // number of surface element
470  std::size_t _num_mesh_elem;
471 
472  // mesh size
473  std::vector<Real> _mesh_size;
474 
475  // dim
476  std::size_t _dim;
477 
478  // mesh dim
479  std::size_t _mesh_dim;
480 
481  // how many time the particle has crossed the boundary
482  std::vector<int> _counter;
483 
484  // radius of particle (for spherical particles only)
485  Real _radius;
486 
487  // free charge of particle
488  Real _charge;
489 
490  // relative permittivity of particle
491  Real _epsilon_in;
492 
493  // the processor that the particle belongs to
494  // *** Currently, this is not used for the finite size particles.
495  int _processor_id;
496 
497  // neighbor particles around the present particle: particle id and distance value.
498  std::vector<std::pair<std::size_t,Real> > _neighbor_list;
499 
500  // mesh of the particle, which can be eigther surface mesh or volume mesh
501  SerialMesh _mesh;
502 
503  // Type of the particle's mesh: surface_mesh or volume_mesh
504  std::string _mesh_type;
505 
506 
507  // Mesh - spring network
508  MeshSpringNetwork* _mesh_spring_network;
509 
510  // Initial values (if it is the perfect shape)
511  Real _volume0;
512  Real _area0;
513  Point _center0;
514  Point _centroid0;
515 
516 
517  // discretized values
518  Real _volume;
519  Real _area;
520  Point _centroid;
521 
522  // particle shape
523  std::string _particle_shape;
524 
525  // particle rotation
526  Point _rot;
527 
528  // particle magnitude
529  Point _mag;
530 
531  // check if particle is on the periodic boundary
532  bool _on_pb;
533 
534  // // body force density
535  // Point _body_force_density;
536 
537  // // surface force density
538  // Point _surface_force_density;
539  // sedimentation force
540  Point _sedimentation_force;
541 
542  // sedimentation body force density
543  Point _body_sedimentation_force_density;
544 
545  // sedimentation surface force density
546  Point _surface_sedimentation_force_density;
547 
548  // forces on each nodes
549  std::vector<Point> _node_force;
550 
551  // velocity of each nodes
552  std::vector<Point> _node_velocity;
553 
554  // velocity of the centroid (mean over all node velocity)
555  Point _centroid_velocity;
556 
557  // force if the centroid (mean over all node force)
558  Point _centroid_force;
559 }; // end of class defination
560 
561 
562 
563 } // end of namespace
564 
565 
566 
567 
const bool & if_on_the_periodic_boundary() const
Definition: rigid_particle.h:281
void set_node_velocity(std::vector< Point > &node_velocity)
Definition: rigid_particle.h:416
Point elem_surface_normal(const Elem &s_elem, const Point &pt0) const
Definition: rigid_particle.C:812
void add_node_force(std::vector< Point > &node_force)
add force to surface nodes
Definition: rigid_particle.C:995
RigidParticle(const dof_id_type &particle_id, const int &particle_type, const Point &pt, const Point &mag, const Point &rot, const Real &charge, const Real &epsilon_in, const Point &sedimentation_body_force_density, const Parallel::Communicator &comm_in)
Definition: rigid_particle.C:48
const Real & get_area() const
Definition: rigid_particle.h:360
std::vector< Point > compute_surface_normal()
Definition: rigid_particle.C:868
const Point & centroid_velocity()
get centroid velocity
Definition: rigid_particle.h:446
const std::string & mesh_type() const
Definition: rigid_particle.h:137
void attach_mesh_spring_network(MeshSpringNetwork *msn)
Definition: rigid_particle.h:159
void read_mesh_sphere(const std::string &filename)
Definition: rigid_particle.C:166
void translate_mesh(const Point &translationDist)
Definition: rigid_particle.C:309
const Point & get_centroid0()
Definition: rigid_particle.h:370
std::vector< Real > mesh_size() const
Definition: rigid_particle.C:365
Definition: rigid_particle.h:49
const Real & get_area0() const
Definition: rigid_particle.h:355
void compute_area()
Definition: rigid_particle.C:718
void get_node_force(std::vector< Point > &node_force) const
get force on surface nodes
Definition: rigid_particle.h:434
void read_mesh(const std::string &filename, const std::string &mesh_type)
Definition: rigid_particle.C:139
Definition: brownian_system.h:58
void read_mesh_cylinder(const std::string &filename)
Definition: rigid_particle.C:198
void extract_surface_mesh(const std::string &vmesh, const std::string &smesh) const
Definition: rigid_particle.C:100
Definition: mesh_spring_network.h:55
const Real & charge() const
Definition: rigid_particle.h:109
void compute_centroid_force()
compute body force
Definition: rigid_particle.C:1018
Definition: rigid_particle.h:46
const Point & get_centroid()
Definition: rigid_particle.h:375
Definition: rigid_particle.h:60
SerialMesh & mesh()
Definition: rigid_particle.C:357
const std::string & get_particle_shape()
Definition: rigid_particle.h:380
void zero_node_force()
force on surface nodes
Definition: rigid_particle.C:981
void compute_volume()
Definition: rigid_particle.C:656
const Point & centroid_force()
Definition: rigid_particle.h:456
void build_nodal_sedimentation_force()
Definition: rigid_particle.C:528
const Real & get_volume0() const
Definition: rigid_particle.h:346
void set_neighbor_list(const std::vector< std::pair< std::size_t, Real > > &nei_list)
Definition: rigid_particle.h:145
bool on_the_periodic_boundary()
Definition: rigid_particle.C:401
const Point & get_center0() const
Definition: rigid_particle.h:365
Real radius() const
Definition: rigid_particle.h:103
const Point & mesh_point(const std::size_t i) const
Definition: rigid_particle.C:372
Definition: rigid_particle.h:47
Definition: rigid_particle.h:48
void init()
Definition: rigid_particle.C:82
void compute_centroid()
Definition: rigid_particle.C:768
std::size_t num_mesh_elem() const
Definition: rigid_particle.C:394
ParticleShape
Definition: rigid_particle.h:45
void extract_nodes(std::vector< Point > &node_xyz)
Definition: rigid_particle.C:333
MeshSpringNetwork * mesh_spring_network() const
Definition: rigid_particle.h:163
std::vector< std::pair< std::size_t, Real > > neighbor_list() const
Definition: rigid_particle.h:153
void update_mesh(const std::vector< Point > &nodal_pos, const std::vector< Point > &nodal_vel)
Definition: rigid_particle.C:241
dof_id_type id() const
Definition: rigid_particle.h:95
void compute_centroid_velocity()
compute body velocity each node of this rigid particle does not have member velocity so we can only c...
Definition: rigid_particle.C:1009
const Real & epsilon_in() const
Definition: rigid_particle.h:115
const Real & get_volume() const
Definition: rigid_particle.h:351
std::vector< int > & counter()
Definition: rigid_particle.h:88
int processor_id() const
Definition: rigid_particle.h:125
void volume_conservation()
Definition: rigid_particle.C:933
void set_processor_id(const int pid)
Definition: rigid_particle.h:131
void restore_periodic_mesh()
Definition: rigid_particle.C:495
std::size_t num_mesh_nodes() const
Definition: rigid_particle.C:386
const Real node_center_dist(const std::size_t i) const
Definition: rigid_particle.C:378
void write_mesh(const std::string &filename)
Definition: rigid_particle.C:228
Definition: rigid_particle.h:50
void rebuild_periodic_mesh()
Definition: rigid_particle.C:457
~RigidParticle()
Definition: rigid_particle.C:75
void print_info() const
Definition: rigid_particle.C:1026