25 #include "libmesh/libmesh_common.h" 26 #include "libmesh/reference_counted_object.h" 27 #include "libmesh/parallel_object.h" 28 #include "libmesh/mesh.h" 29 #include "libmesh/elem.h" 30 #include "libmesh/exodusII_io.h" 31 #ifdef LIBMESH_HAVE_NANOFLANN 32 # include "libmesh/nanoflann.hpp" 56 template <
unsigned int KDDim>
75 template <
unsigned int KDDim>
76 class ParticleMesh :
public ReferenceCountedObject<ParticleMesh<KDDim> >,
81 #ifdef LIBMESH_HAVE_NANOFLANN 90 template <
unsigned int PLDim>
91 class PointListAdaptor
98 const std::vector<RigidParticle*> &_pts;
103 PointListAdaptor (
const std::vector<RigidParticle*> &
particles)
110 typedef Real coord_t;
111 typedef std::size_t size_t;
116 inline size_t kdtree_get_point_count()
const {
return _pts.size(); }
122 inline coord_t kdtree_distance(
const coord_t *p1,
const size_t idx_p2,
size_t size)
const 124 libmesh_assert_equal_to (size, PLDim);
125 libmesh_assert_less (idx_p2, _pts.size());
128 const Point &p2( _pts[idx_p2]->get_centroid() );
134 const coord_t d0=p1[0] - p2(0);
135 const coord_t d1=p1[1] - p2(1);
136 const coord_t d2=p1[2] - p2(2);
137 return d0*d0 + d1*d1 + d2*d2;
142 const coord_t d0=p1[0] - p2(0);
143 const coord_t d1=p1[1] - p2(1);
144 return d0*d0 + d1*d1;
149 const coord_t d0=p1[0] - p2(0);
153 libmesh_error_msg(
"ERROR: unknown size " << size);
164 inline coord_t kdtree_get_pt(
const size_t idx,
int dim)
const 166 libmesh_assert_less (dim, (
int) PLDim);
167 libmesh_assert_less (idx, _pts.size());
168 libmesh_assert_less (dim, 3);
170 const Point &p(_pts[idx]->get_centroid() );
171 if (dim==0)
return p(0);
172 if (dim==1)
return p(1);
182 template <
class BBOX>
183 bool kdtree_get_bbox(BBOX & )
const {
return false; }
188 typedef nanoflann::KDTreeSingleIndexAdaptor<nanoflann::L2_Simple_Adaptor<Real,PointListAdaptor<KDDim> >,
189 PointListAdaptor<KDDim>,
195 mutable UniquePtr<kd_tree_t> _kd_tree;
197 #endif // LIBMESH_HAVE_NANOFLANN 218 const Real& search_radius_p,
219 const Real& search_radius_e);
225 const Real& search_radius_p,
226 const Real& search_radius_e);
237 const std::string& particle_mesh_type);
244 const std::string& particle_mesh_type);
249 const unsigned int& o_step);
266 const Real bbox_XA,
const Real bbox_XB,
267 const Real bbox_YA,
const Real bbox_YB,
268 const Real bbox_ZA,
const Real bbox_ZB);
272 const Point& bbox_min,
273 const Point& bbox_max);
280 std::vector<RigidParticle*>
particles()
const {
return _particles; }
320 { _search_radius_p = rp; _search_radius_e = re; };
333 { _periodic_boundary = &_periodic_bdry; }
340 {
return _periodic_boundary; }
346 MeshBase&
mesh(){
return _mesh; }
360 void update_mesh(
const std::vector<Point>& nodal_pos,
361 const std::vector<Point>& nodal_vel);
409 const unsigned int& o_step,
410 const Real& real_time,
411 const std::vector<std::string>& output_file,
412 unsigned int comm_in_rank)
const;
418 const unsigned int& o_step,
419 const Real& real_time,
420 unsigned int comm_in_rank)
const;
428 unsigned int comm_in_rank)
const;
434 unsigned int comm_in_rank)
const;
465 {
return _elem_neighbor_list; }
474 const std::size_t elem_id = elem->id();
475 return _elem_neighbor_list[elem_id];
486 const std::size_t elem_id = elem->id();
487 return _local_elem_neighbor_list[elem_id];
509 std::vector<std::pair<std::size_t,Real> >& IndicesDists);
539 const bool is_sorted,
540 std::vector<std::size_t>& n_list);
558 std::size_t _n_rigid_particles;
561 std::size_t _n_rigid_particle_types;
564 std::size_t _n_rigid_particle_mesh_types;
567 std::vector<Real> _mass;
570 std::vector<std::string> _rigid_particle_mesh_files;
573 std::vector<RigidParticle*> _particles;
582 Real _search_radius_p;
585 Real _search_radius_e;
589 PointListAdaptor<KDDim> _point_list_adaptor;
598 std::map<const std::size_t, std::vector<std::size_t> > _elem_neighbor_list;
599 std::map<const std::size_t, std::vector<std::size_t> > _local_elem_neighbor_list;
605 const int o_precision = 6;
void write_particle_trajectory(const unsigned int &o_step, unsigned int comm_in_rank) const
Definition: particle_mesh.C:752
Definition: particle_mesh.h:76
void write_surface_node(const unsigned int &o_step, unsigned int comm_in_rank) const
Definition: particle_mesh.C:794
virtual void build_particle_neighbor_list_naively()
Definition: particle_mesh.C:1071
virtual void clear_kd_tree()
Definition: particle_mesh.C:940
virtual void build_elem_neighbor_list()
Definition: particle_mesh.C:1198
ParticleMesh(MeshBase &mesh)
Definition: particle_mesh.C:48
void set_search_radius(const Real rp, const Real re)
Definition: particle_mesh.h:319
PMPeriodicBoundary * pm_periodic_boundary()
Definition: particle_mesh.h:339
void reinit()
Definition: particle_mesh.C:441
Real search_radius(const std::string &p_e) const
Definition: particle_mesh.C:504
void add_periodic_boundary(PMPeriodicBoundary &_periodic_bdry)
Definition: particle_mesh.h:332
Definition: brownian_system.h:58
void generate_random_particles(const std::size_t N, const Real bbox_XA, const Real bbox_XB, const Real bbox_YA, const Real bbox_YB, const Real bbox_ZA, const Real bbox_ZB)
Definition: particle_mesh.C:376
Definition: pm_periodic_boundary.h:46
MeshBase & mesh()
Definition: particle_mesh.h:346
SerialMesh & stitched_mesh()
Definition: particle_mesh.C:864
void write_particle(const unsigned int &step_id, const unsigned int &o_step, const Real &real_time, const std::vector< std::string > &output_file, unsigned int comm_in_rank) const
Definition: particle_mesh.C:696
const std::vector< std::size_t > elem_neighbor_list(const Elem *elem)
Definition: particle_mesh.h:472
void write_particle_mesh_restart() const
Definition: particle_mesh.C:849
virtual void construct_kd_tree()
Definition: particle_mesh.C:916
std::map< const std::size_t, std::vector< std::size_t > > elem_neighbor_list() const
Definition: particle_mesh.h:464
void write_time(const unsigned int &step_id, const unsigned int &o_step, const Real &real_time, unsigned int comm_in_rank) const
Definition: particle_mesh.C:729
std::vector< Real > mesh_size() const
Definition: particle_mesh.C:641
std::vector< RigidParticle * > particles() const
Definition: particle_mesh.h:280
void write_particle_mesh(const unsigned int &o_step) const
Definition: particle_mesh.C:830
void print_elem_neighbor_list(std::ostream &out=libMesh::out) const
Definition: particle_mesh.C:1398
void initial_particle_center_of_mass(std::vector< Point > ¢er0) const
Definition: particle_mesh.C:684
virtual void build_particle_neighbor_list()
Definition: particle_mesh.C:1042
void read_particles_data(const std::string &filename, const std::string &particle_mesh_type)
Definition: particle_mesh.C:112
std::size_t num_particles() const
Definition: particle_mesh.h:286
void print_particle_info() const
Definition: particle_mesh.C:537
void zero_node_force()
Definition: particle_mesh.C:629
const std::vector< std::size_t > local_elem_neighbor_list(const Elem *elem)
Definition: particle_mesh.h:484
void update_mesh(const std::vector< Point > &nodal_pos, const std::vector< Point > &nodal_vel)
Definition: particle_mesh.C:553
void read_particles_data_restart(const std::string &filename, const std::string &particle_mesh_type)
Definition: particle_mesh.C:270
void volume_conservation()
Definition: particle_mesh.C:668
~ParticleMesh()
Definition: particle_mesh.C:99
bool is_sorted() const
Definition: particle_mesh.h:292
std::size_t num_mesh_points() const
Definition: particle_mesh.C:519
Definition: particle_mesh.h:57