v0.9.0
BitLevelCoupler.hpp
Go to the documentation of this file.
1 /** \file BitLevelCoupler.hpp
2  * \brief BitLevelCoupler interface
3 
4  * Is used to couple bit levels to enable easy and efficient projection between
5  * levels. It is not assumed that print children relation between entities,
6  * however if such relation exist is used coupling algorithm.
7  */
8 
9 /* MoFEM is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12  * License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>
16 
17 */
18 
19 #ifndef __BITLEVELCOUPLER_HPP__
20 #define __BITLEVELCOUPLER_HPP__
21 
22 namespace MoFEM {
23 
25 
26 /** \brief Interface set parent for vertices, edges, triangles and tetrahedrons.
27  * \ingroup mofem
28  *
29  * FIXME: Not tested, slow, bugs
30  *
31  */
33 
34  MoFEMErrorCode query_interface(const MOFEMuuid& uuid, UnknownInterface** iface) const;
35 
37  bool vErify; ///< by default is switched off, with it on to verify if existing parent is equal to parent set by interface
38 
40  cOre(const_cast<MoFEM::Core&>(core)),
41  vErify(false) {}
42 
43  /** \brief build adaptive kd-tree
44  */
45  MoFEMErrorCode buildTree(const BitRefLevel &parent_level,int verb = 0);
46 
47  /** \brief reset adaptive kd-tree
48  */
49  MoFEMErrorCode resetTree(const BitRefLevel &parent_level,int verb = 0);
50 
51  /** \brief get parent entity
52 
53  * Use kd-tree to find tetrahedral or other volume element.
54 
55  \param coordinate
56  \param parent returned parent entity
57  \param iter_tol tolerance for convergence of point search
58  \param inside_tol tolerance for inside element calculation
59  \param throw_error if parent can not be found
60  \param verbose level
61 
62  */
64  const double *coords,
65  EntityHandle &parent,
66  bool tet_only = false,
67  const double iter_tol = 1.0e-10,
68  const double inside_tol = 1.0e-6,
69  int verb = 0
70  );
71 
72  /** \brief finding parents for vertices
73  *
74  * Use kd-tree to find tetrahedral or other volume element.
75 
76  \param parent_level bit level of parents
77 
78  \param children list of vertices for which parents are being set
79 
80  \param vertex_elements if true algorithm assumes that vertices elements are
81  used. IF NOT SET AND SUCH ELEMENTS EXIST IT WILL RESULT IN UNPREDICTABLE
82  BEHAVIOUR.
83 
84  \param iter_tol tolerance for convergence of point search
85 
86  \param inside_tol tolerance for inside element calculation
87 
88  \param throw_error if parent can not be found
89 
90  \param verbose level
91 
92  */
94  const BitRefLevel &parent_level,
95  Range &children,
96  bool vertex_elements = false,
97  const double iter_tol = 1.0e-10,
98  const double inside_tol = 1.0e-6,
99  bool throw_error = true,
100  int verb = 0
101  );
102 
103  /** \brief finding parents for edegs, faces and tets
104 
105  It assumes that parents for vertices are known. Run
106  buildAdjacenciesVerticesOnTets if parents for vertices are not set.
107 
108  \param parent_level bit level of parents
109 
110  \param children list of entities for which parents are being set
111 
112  \param vertex_elements if true algorithm assumes that vertices elements are
113  used. IF NOT SET AND SUCH ELEMENTS EXIST IT WILL RESULT IN UNPREDICTABLE
114  BEHAVIOR.
115 
116  \param iter_tol tolerance for convergence of point search
117 
118  \param inside_tol tolerance for inside element calculation
119 
120  \param throw_error if parent can not be found
121 
122  \param verbose level
123 
124  */
126  const BitRefLevel &parent_level,
127  Range &children,
128  bool elements = true,
129  int verb = 0
130  );
131 
132  /** \brief reset parent entities
133 
134  This is needed for testing.
135 
136  */
137  MoFEMErrorCode resetParents(Range &children,bool elements = true,int verb = 0);
138 
139  /**
140  * \brief copy data from parents
141  *
142  * This not approximate date from, simply copy DOFs values from one mesh to another.
143  * This is useful for special case of refinement, e.g. insertion of interface, where
144  * entities on the interface are doubled to create displacement jump.
145  * In general case use this function could lead to wrong results.
146  *
147  * \note Move data only if type of child and parent is the same.
148  *
149  * @param parent pointer to array of parent entities
150  * @param children pointer to array of children entities
151  * @param verify if true verifi consistency with database
152  * @return error code
153  */
155  const std::vector<EntityHandle> &parents,
156  const std::vector<EntityHandle> &children,
157  const bool verify = true
158  );
159 
160  /**
161  * \brief copy data from parents
162  *
163  * This not approximate date from, simply copy DOFs values from one mesh to another.
164  * This is useful for special case of refinement, e.g. insertion of interface, where
165  * entities on the interface are doubled to create displacement jump.
166  *
167  * In general case use this function could lead to wrong results.
168  *
169  *
170  * \note Move data only if type of child and parent is the same.
171  *
172  * @param bit bit ref level
173  * @param verify if true verifi consistency with database
174  * @return error code
175  */
177  const BitRefLevel bit,
178  const BitRefLevel mask,
179  const bool verify = true
180  );
181 
182  private:
183 
184  MoFEMErrorCode chanegParent(RefEntity_multiIndex::iterator it,EntityHandle parent);
185  MoFEMErrorCode verifyParent(RefEntity_multiIndex::iterator it,EntityHandle parent);
186 
187  double cOords[12+3];
188  double diffN[12],N[4];
189  double locCoords[3];
191 
192  MoFEMErrorCode getLocCoordsOnTet(EntityHandle tet,const double *glob_coords,int verb = 0);
193 
194  boost::scoped_ptr<AdaptiveKDTree> treePtr;
195 
196 };
197 
198 }
199 
200 #endif //__BITLEVELCOUPLER_HPP__
MoFEMErrorCode verifyParent(RefEntity_multiIndex::iterator it, EntityHandle parent)
bool vErify
by default is switched off, with it on to verify if existing parent is equal to parent set by interfa...
MoFEM interface unique ID.
boost::scoped_ptr< AdaptiveKDTree > treePtr
base class for all interface classes
MoFEMErrorCode getLocCoordsOnTet(EntityHandle tet, const double *glob_coords, int verb=0)
MoFEMErrorCode buildAdjacenciesVerticesOnTets(const BitRefLevel &parent_level, Range &children, bool vertex_elements=false, const double iter_tol=1.0e-10, const double inside_tol=1.0e-6, bool throw_error=true, int verb=0)
finding parents for vertices
Core (interface) class.
Definition: Core.hpp:50
std::bitset< BITINTERFACEUID_SIZE > BitIntefaceId
Definition: Types.hpp:56
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
MoFEMErrorCode buildTree(const BitRefLevel &parent_level, int verb=0)
build adaptive kd-tree
MoFEMErrorCode buildAdjacenciesEdgesFacesVolumes(const BitRefLevel &parent_level, Range &children, bool elements=true, int verb=0)
finding parents for edegs, faces and tets
MoFEMErrorCode getParent(const double *coords, EntityHandle &parent, bool tet_only=false, const double iter_tol=1.0e-10, const double inside_tol=1.0e-6, int verb=0)
get parent entity
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:66
MoFEMErrorCode resetParents(Range &children, bool elements=true, int verb=0)
reset parent entities
MoFEMErrorCode copyFieldDataFromParentToChildren(const std::vector< EntityHandle > &parents, const std::vector< EntityHandle > &children, const bool verify=true)
copy data from parents
BitLevelCoupler(const MoFEM::Core &core)
const EntityHandle * cOnn
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
Interface set parent for vertices, edges, triangles and tetrahedrons.FIXME: Not tested,...
MoFEMErrorCode resetTree(const BitRefLevel &parent_level, int verb=0)
reset adaptive kd-tree
MoFEMErrorCode query_interface(const MOFEMuuid &uuid, UnknownInterface **iface) const
MoFEMErrorCode chanegParent(RefEntity_multiIndex::iterator it, EntityHandle parent)
static const MOFEMuuid IDD_MOFEMBitLevelCoupler