Parallel Finite Element - General geometry Ewald-like Method
Part of Continuum-particle Simulation Suite under MICCOM
pm_periodic_boundary.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 #include <vector>
26 
27 #include "libmesh/libmesh_common.h"
28 #include "libmesh/reference_counted_object.h"
29 #include "libmesh/mesh_tools.h"
30 #include "libmesh/elem.h"
31 
32 
33 using libMesh::MeshTools::BoundingBox;
34 using libMesh::Point;
35 
36 namespace libMesh
37 {
38 
39 
40  /*
41  * The class is designed for dealing with the periodic boundary
42  * of the ParticleMesh system
43  */
44 
45 
46 class PMPeriodicBoundary : public ReferenceCountedObject<PMPeriodicBoundary>
47 {
48 public:
49  // Constructor
51 
52  // Destructor
54 
55  // Constructor
56  PMPeriodicBoundary(const std::pair<Point, Point> &bbox_pts,
57  const std::vector<bool>& periodic_directions);
58 
59  // Constructor
60  PMPeriodicBoundary(const Point &bbox_pmin,
61  const Point &bbox_pmax,
62  const std::vector<bool>& periodic_directions);
63 
64  // Constructor
65  PMPeriodicBoundary(const Point &bbox_pmin,
66  const Point &bbox_pmax,
67  const std::vector<bool>& periodic_directions,
68  const std::vector<bool>& inlet_directions,
69  const std::vector<Real>& inlet_pressure);
70 
71  // Constructor
72  PMPeriodicBoundary(const BoundingBox& bbox,
73  const std::vector<bool>& periodic_directions);
74 
75  // Copy Constructor
77 
78 
79  // periodic direction
80  bool periodic_direction(const std::size_t i) const;
81  const std::vector<bool>& periodic_direction() const;
82 
83  // inlet direction
84  bool inlet_direction (const std::size_t i) const;
85  const std::vector <bool>& inlet_direction() const;
86  const Real inlet_pressure(const std::size_t i) const;
87  const std::vector<Real>& inlet_pressure() const;
88 
89  // size of the Bounding box
90  Real box_length (const std::size_t i) const;
91  Point box_length () const;
92 
93 
94  // Box min and max boundaries and the center
95  Point box_min() const { return _bbox.min(); };
96  Point box_max() const { return _bbox.max(); };
97  Point box_mid() const { return 0.5*( _bbox.max() + _bbox.min() ); };
98 
99 
100  // Return the bounding box of the domain
101  const BoundingBox & bounding_box() const { return _bbox; }
102 
103 
104 
105  /*
106  * Compute the closest image point in x(y,z) - directions
107  * If there is no image in the specified direction, return "false"
108  * This is a simple version that is not used in this code.
109  */
110  bool get_image_point(const Point& pt0,
111  const std::size_t i, // i=0,1,2 for x,y,z direction
112  Point& im_pt) const;
113 
114 
115  /*
116  * Compute the closest image point in xyz-directions
117  * If there is no image in the specified direction, return "false"
118  * Note that if distance of this point to the periodic boundary is
119  * smaller than the search_radius, it is not necessary to get the image!
120  *
121  // 2D: i = 0, 1, 2 -> x, y, xy
122  // 3D: i = 0, 1, 2 -> x, y, z;
123  // i = 3, 4, 5 -> xy, xz, yz
124  // i = 6 -> xyz
125  *
126  * this is used in particle_mesh.C to build particle/elem neighbor list.
127  */
128  bool get_image_point(const Point& pt0,
129  const Real& search_radius,
130  const std::size_t i,
131  Point& im_pt) const;
132 
133  /*
134  * Correct the particle position
135  * (1) when a particle passes through the periodic boundary,
136  * it must re-enter the box through the opposite face.
137  * (2) when a particle passes an inpenetrable wall by numerical accidents,
138  * we will have to pull it back in order to avoid losing particles.
139  */
140  void correct_position(Point& pt0) const;
141 
142 
143  /*
144  * Correct the particle-particle distance when computing the interaction
145  * force between a particle near the periodic boundary and its ghost images
146  */
147  Real point_distance(const Point& pt0,
148  const Point& pt1) const;
149 
150 
151  /*
152  * Correct the particle-particle distance vector when a particle is near
153  * the periodic boundary.
154  * Return vector x = pt1 - pt0
155  */
156  Point point_vector(const Point& pt0,
157  const Point& pt1) const;
158 
159 
160  /*
161  * space dimension of the periodic box
162  */
163  std::size_t dimension() const { return _periodic_directions.size(); }
164 
165 
166 
167  /*
168  * If an elem is "split" by the i-th periodic boundaries, it is an "image" element
169  */
170  std::vector<bool> image_elem(const Elem* elem) const;
171 
172 
173  /*
174  * If an elem is "split" by the periodic boundary, we need to construct an "image"
175  * elem by moving some of its nodes to the other side of boundary
176  */
177  void build_image_elem(Elem* elem) const;
178 
179 
180  /*
181  * After building the image elem, the nodes are modified, so we
182  * need to restore the original elem.
183  *
184  * To avoid elem change, this function has to be used together with the above.
185  */
186  void restore_image_elem(Elem* elem) const;
187 
188 
189 
190 private:
191 
192  // the bounding box.
193  BoundingBox _bbox;
194 
195  // the periodic direction: X, Y or Z - direction
196  std::vector<bool> _periodic_directions;
197 
198  // the inlet direction: X, Y or Z - direction
199  std::vector<bool> _inlet_directions;
200 
201  // inlet pressure
202  std::vector<Real> _inlet_pressure;
203 
204  std::size_t _dim;
205 
206  Point _box_length;
207 
208 }; // end of class
209 
210 
211 } // end of namespace
212 
std::vector< bool > image_elem(const Elem *elem) const
Definition: pm_periodic_boundary.C:393
Point box_max() const
Definition: pm_periodic_boundary.h:96
void build_image_elem(Elem *elem) const
Definition: pm_periodic_boundary.C:420
std::size_t dimension() const
Definition: pm_periodic_boundary.h:163
void restore_image_elem(Elem *elem) const
Definition: pm_periodic_boundary.C:458
Point box_length() const
Definition: pm_periodic_boundary.C:155
const std::vector< bool > & periodic_direction() const
Definition: pm_periodic_boundary.C:116
Real point_distance(const Point &pt0, const Point &pt1) const
Definition: pm_periodic_boundary.C:344
Definition: brownian_system.h:58
const std::vector< bool > & inlet_direction() const
Definition: pm_periodic_boundary.C:128
Definition: pm_periodic_boundary.h:46
const BoundingBox & bounding_box() const
Definition: pm_periodic_boundary.h:101
bool get_image_point(const Point &pt0, const std::size_t i, Point &im_pt) const
Definition: pm_periodic_boundary.C:162
Point box_min() const
Definition: pm_periodic_boundary.h:95
const std::vector< Real > & inlet_pressure() const
Definition: pm_periodic_boundary.C:141
Point box_mid() const
Definition: pm_periodic_boundary.h:97
void correct_position(Point &pt0) const
Definition: pm_periodic_boundary.C:318
~PMPeriodicBoundary()
Definition: pm_periodic_boundary.C:101
Point point_vector(const Point &pt0, const Point &pt1) const
Definition: pm_periodic_boundary.C:364