v0.9.0
NodeMerger.hpp
Go to the documentation of this file.
1 /** \file NodeMerger.hpp
2  * \brief NodeMerger interface
3  *
4  * Node merger interface
5  *
6  * \ingroup mofem_node_merger
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 #ifndef __NODE_MERGER_HPP__
19 #define __NODE_MERGER_HPP__
20 
21 namespace MoFEM {
22 
25 
26 /** \brief Merge node by collapsing edge between them
27  *
28  * \ingroup mofem_node_merger
29  */
31 
32 
34  UnknownInterface **iface) const;
35 
36  NodeMergerInterface(const MoFEM::Core &core);
37 
39 
40  /**
41  * \brief Return true if successful merge.
42  * @return Error code
43  */
44  inline bool getSuccessMerge() { return successMerge; }
45 
46  /**
47  * \brief Set error if no common edge
48  * @param b If true send error if false no error
49  */
50  inline void setErrorIfNoCommonEdge(const bool b = true) {
52  }
53 
54  /** \brief merge nodes which sharing edge
55 
56  Father is sties, mother is merged.
57 
58  \param father node to which mother is merged to.
59  \param mother merged node
60  \param out_tets tetrahedra after merge
61  \param tets_ptr test only tets_ptr from range are changed
62  \param only_if_improve_quality Do merge if that improve quality
63  \param move father by fraction of edge length move=[0,1]
64 
65  Move node on the edge, 0 not move, 1 move to mother side, 0.5 will be in the
66  middle.
67 
68  */
70  Range &out_tets, Range *tets_ptr = NULL,
71  const bool only_if_improve_quality = false,
72  const double move = 0, const int line_search = 0,
73  Tag th = NULL, const int verb = 0);
74 
75  /** \brief merge nodes which sharing edge
76 
77  Father is sties, mother is merged.
78 
79  \param father node to which mother is merged to.
80  \param mother merged node
81  \param bit level of mesh merged nodes mesh
82  \param test only tets_ptr from range are changed
83  \param only_if_improve_quality Do merge if that improve quality
84  \param move father by fraction of edge length move=[0,1]
85 
86  Move node on the edge, 0 not move, 1 move to mother side, 0.5 will be in the
87  middle.
88 
89  */
91  BitRefLevel bit, Range *tets_ptr = NULL,
92  const bool only_if_improve_quality = false,
93  const double move = 0, Tag th = NULL);
94 
95  /** \brief merge nodes which sharing edge
96 
97  Father is sties, mother is merged.
98 
99  \param father node to which mother is merged to.
100  \param mother merged node
101  \param tets_from_bit_ref_level only tetrahedrons from bit level are changed
102  \param only_if_improve_quality Do merge if that improve quality
103  \param move father by fraction of edge length move=[0,1]
104 
105  Move node on the edge, 0 not move, 1 move to mother side, 0.5 will be in the
106  middle.
107 
108  */
110  BitRefLevel bit,
111  BitRefLevel tets_from_bit_ref_level,
112  const bool only_if_improve_quality = false,
113  const double move = 0, Tag th = NULL);
114 
115  struct ParentChild {
118  ParentChild(const EntityHandle parent, const EntityHandle child)
119  : pArent(parent), cHild(child) {}
120  };
121 
122  typedef multi_index_container<
123  ParentChild,
124  indexed_by<ordered_unique<
125  member<ParentChild, EntityHandle, &ParentChild::pArent>>,
126  ordered_non_unique<
127  member<ParentChild, EntityHandle, &ParentChild::cHild>>>>
129 
130  /**
131  * \brief Get map of parent cand child
132  * @return
133  */
135 
136 private:
138  boost::function<double(const double a, const double b)> minQualityFunction;
139 
140  bool successMerge; ///< True if marge is success
141  bool errorIfNoCommonEdge; ///< Send error if no common edge
142 
143  /**
144  * \brief Calualte quality if nodes merged
145  * @param check_tests tets to check
146  * @param father first node of the edge
147  * @param mother second node of the edge
148  * @param coords_move moved father node
149  * @param min_quality calculated quality
150  * @return error code
151  */
153  minQuality(Range &check_tests, EntityHandle father, EntityHandle mother,
154  double *coords_move, double &min_quality, Tag th = NULL,
155  boost::function<double(double, double)> f =
156  [](double a, double b) -> double { return std::min(a, b); });
157 
158  /**
159  * \brief Use bisection method to find point of edge collapse
160  * @param check_tests range of tets to check quality
161  * @param father first node of the edge
162  * @param mother second node of the edge
163  * @param line_search number of iterations
164  * @param coords_move node to move
165  * @return error code
166  */
167  MoFEMErrorCode lineSearch(Range &check_tests, EntityHandle father,
168  EntityHandle mother, int line_search,
169  FTensor::Tensor1<double, 3> &t_move, Tag th = NULL);
170 
172 
173  struct FaceMap {
176  : e(e), n0(n0), n1(n1) {}
177  };
178 
179  typedef multi_index_container<
180  FaceMap, indexed_by<hashed_unique<composite_key<
181  FaceMap, member<FaceMap, EntityHandle, &FaceMap::n0>,
182  member<FaceMap, EntityHandle, &FaceMap::n1>>>>>
184 
185 };
186 
187 } // namespace MoFEM
188 
189 #endif //__NODE_MERGER_HPP__
190 
191 /**
192  * \defgroup mofem_node_merger NodeMerger
193  * \brief Node merger interface
194  *
195  * \ingroup mofem
196  */
197 
198 
ParentChild(const EntityHandle parent, const EntityHandle child)
Definition: NodeMerger.hpp:118
boost::function< double(const double a, const double b)> minQualityFunction
Definition: NodeMerger.hpp:138
MoFEM interface unique ID.
FaceMap(const EntityHandle e, const EntityHandle n0, const EntityHandle n1)
Definition: NodeMerger.hpp:175
base class for all interface classes
void setErrorIfNoCommonEdge(const bool b=true)
Set error if no common edge.
Definition: NodeMerger.hpp:50
bool getSuccessMerge()
Return true if successful merge.
Definition: NodeMerger.hpp:44
static const MOFEMuuid IDD_MOFEMNodeMerger
Definition: NodeMerger.hpp:23
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
bool successMerge
True if marge is success.
Definition: NodeMerger.hpp:140
multi_index_container< ParentChild, indexed_by< ordered_unique< member< ParentChild, EntityHandle, &ParentChild::pArent > >, ordered_non_unique< member< ParentChild, EntityHandle, &ParentChild::cHild > > > > ParentChildMap
Definition: NodeMerger.hpp:128
Merge node by collapsing edge between them.
Definition: NodeMerger.hpp:30
ParentChildMap parentChildMap
Definition: NodeMerger.hpp:171
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:66
bool errorIfNoCommonEdge
Send error if no common edge.
Definition: NodeMerger.hpp:141
ParentChildMap & getParentChildMap()
Get map of parent cand child.
Definition: NodeMerger.hpp:134
MoFEMErrorCode mergeNodes(EntityHandle father, EntityHandle mother, Range &out_tets, Range *tets_ptr=NULL, const bool only_if_improve_quality=false, const double move=0, const int line_search=0, Tag th=NULL, const int verb=0)
merge nodes which sharing edge
Definition: NodeMerger.cpp:89
MoFEMErrorCode lineSearch(Range &check_tests, EntityHandle father, EntityHandle mother, int line_search, FTensor::Tensor1< double, 3 > &t_move, Tag th=NULL)
Use bisection method to find point of edge collapse.
Definition: NodeMerger.cpp:455
NodeMergerInterface(const MoFEM::Core &core)
Definition: NodeMerger.cpp:72
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
multi_index_container< FaceMap, indexed_by< hashed_unique< composite_key< FaceMap, member< FaceMap, EntityHandle, &FaceMap::n0 >, member< FaceMap, EntityHandle, &FaceMap::n1 > > > > > FaceMapIdx
Definition: NodeMerger.hpp:183
MoFEMErrorCode minQuality(Range &check_tests, EntityHandle father, EntityHandle mother, double *coords_move, double &min_quality, Tag th=NULL, boost::function< double(double, double)> f=[](double a, double b) -> double { return std::min(a, b);})
Calualte quality if nodes merged.
Definition: NodeMerger.cpp:391
MoFEMErrorCode query_interface(const MOFEMuuid &uuid, UnknownInterface **iface) const
Definition: NodeMerger.cpp:56
MoFEMErrorCode getSubInterfaceOptions()
Definition: NodeMerger.cpp:76