v0.8.20
Public Member Functions | Public Attributes | List of all members
MoFEM::Tools Struct Reference

Auxiliary tools. More...

#include <src/interfaces/Tools.hpp>

Inheritance diagram for MoFEM::Tools:
[legend]
Collaboration diagram for MoFEM::Tools:
[legend]

Public Member Functions

MoFEMErrorCode query_interface (const MOFEMuuid &uuid, UnknownInterface **iface) const
 
 Tools (const MoFEM::Core &core)
 
- Public Member Functions inherited from MoFEM::UnknownInterface
template<class IFACE >
MoFEMErrorCode registerInterface (const MOFEMuuid &uuid, bool error_if_registration_failed=true)
 Register interface. More...
 
template<class IFACE , bool VERIFY = false>
MoFEMErrorCode getInterface (const MOFEMuuid &uuid, IFACE *&iface) const
 Get interface by uuid and return reference to pointer of interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE *&iface) const
 Get interface refernce to pointer of interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE **const iface) const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get reference to interface. More...
 
template<class IFACE >
IFACE * getInterface () const
 Function returning pointer to interface. More...
 
virtual ~UnknownInterface ()
 
virtual MoFEMErrorCode getLibVersion (Version &version) const
 Get library version. More...
 
virtual const MoFEMErrorCode getFileVersion (moab::Interface &moab, Version &version) const
 Get database major version. More...
 
virtual MoFEMErrorCode getInterfaceVersion (Version &version) const
 Get database major version. More...
 
template<>
MoFEMErrorCode getInterface (const MOFEMuuid &uuid, UnknownInterface *&iface) const
 

Public Attributes

MoFEM::CorecOre
 

Computational

enum  SEGMENT_MIN_DISTANCE {
  SOLUTION_EXIST, SEGMENT_ONE_IS_POINT, SEGMENT_TWO_IS_POINT, SEGMENT_TWO_AND_TWO_ARE_POINT,
  NO_SOLUTION
}
 
MoFEMErrorCode minTetsQuality (const Range &tets, double &min_quality, Tag th=nullptr, boost::function< double(double, double)> f=[](double a, double b) -> double { return std::min(a, b);})
 calculate minimal quality of tetrahedra in range More...
 
MoFEMErrorCode getTetsWithQuality (Range &out_tets, const Range &tets, Tag th=nullptr, boost::function< bool(double)> f=[](double q) -> bool { if(q<=0) return true;else return false;})
 Get the Tets With Quality. More...
 
MoFEMErrorCode writeTetsWithQuality (const char *file_name, const char *file_type, const char *options, const Range &tets, Tag th=nullptr, boost::function< bool(double)> f=[](double q) -> bool { if(q<=0) return true;else return false;})
 Write file with tetrahedral of given quality. More...
 
MoFEMErrorCode getTriNormal (const EntityHandle tri, double *normal) const
 Get triangle normal. More...
 
double getTriArea (const EntityHandle tri) const
 Get triangle area. More...
 
double getEdgeLength (const EntityHandle edge)
 Get edge length. More...
 
MoFEMErrorCode findMinDistanceFromTheEdges (const double *v_ptr, Range edges, double *min_dist_ptr, double *o_ptr) const
 Find minimal distance to edges. More...
 
template<class T >
static double dEterminant (T &t)
 
static double volumeLengthQuality (const double *coords)
 Calculate tetrahedron volume length quality. More...
 
static double tetVolume (const double *coords)
 Calculate volume of tetrahedron. More...
 
static MoFEMErrorCode checkIfPointIsInTet (const double tet_coords[], const double global_coord[], const double tol, bool &result)
 Check of point is in tetrahedral. More...
 
static MoFEMErrorCode getTriNormal (const double *coords, double *normal)
 Get the Tri Normal objectGet triangle normal. More...
 
static double getEdgeLength (const double *edge_coords)
 Get edge length. More...
 
static SEGMENT_MIN_DISTANCE minDistancePointFromOnSegment (const double *w_ptr, const double *v_ptr, const double *p_ptr, double *const t_ptr=nullptr)
 Find closet point on the segment from the point. More...
 
static SEGMENT_MIN_DISTANCE minDistanceFromSegments (const double *w_ptr, const double *v_ptr, const double *k_ptr, const double *l_ptr, double *const tvw_ptr=nullptr, double *const tlk_ptr=nullptr)
 Find points on two segments in closest distance. More...
 

Debugging

MoFEMErrorCode checkVectorForNotANumber (const Problem *prb_ptr, const RowColData row_or_col, Vec v)
 Print all DOFs for which element of vector is not a number. More...
 

Additional Inherited Members

- Protected Member Functions inherited from MoFEM::UnknownInterface
boost::typeindex::type_index getClassIdx (const MOFEMuuid &uid) const
 Get type name for interface Id. More...
 
MOFEMuuid getUId (const boost::typeindex::type_index &class_idx) const
 Get interface Id for class name. More...
 

Detailed Description

Auxiliary tools.

Definition at line 30 of file Tools.hpp.

Member Enumeration Documentation

◆ SEGMENT_MIN_DISTANCE

Enumerator
SOLUTION_EXIST 
SEGMENT_ONE_IS_POINT 
SEGMENT_TWO_IS_POINT 
SEGMENT_TWO_AND_TWO_ARE_POINT 
NO_SOLUTION 

Definition at line 171 of file Tools.hpp.

Constructor & Destructor Documentation

◆ Tools()

MoFEM::Tools::Tools ( const MoFEM::Core core)

Definition at line 36 of file Tools.hpp.

36 : cOre(const_cast<MoFEM::Core &>(core)) {}
MoFEM::Core & cOre
Definition: Tools.hpp:35

Member Function Documentation

◆ checkIfPointIsInTet()

MoFEMErrorCode MoFEM::Tools::checkIfPointIsInTet ( const double  tet_coords[],
const double  global_coord[],
const double  tol,
bool result 
)
static

Check of point is in tetrahedral.

Parameters
tet_coords
global_coord
tol
result
Returns
MoFEMErrorCode

Definition at line 131 of file Tools.cpp.

133  {
134  double loc_coord[] = {0, 0, 0};
135  double N[4],diffN[12];
137  CHKERR ShapeDiffMBTET(diffN);
138  CHKERR ShapeMBTET(N, &loc_coord[0], &loc_coord[1], &loc_coord[2], 1);
139  CHKERR ShapeMBTET_inverse(N, diffN, tet_coords, global_coord, loc_coord);
140  CHKERR ShapeMBTET(N, &loc_coord[0], &loc_coord[1], &loc_coord[2], 1);
141  result = true;
142  for (int n = 0; n != 4; ++n) {
143  if (N[n] < -tol || (N[n] - 1) > tol) {
144  result = false;
145  break;
146  }
147  }
149 }
PetscErrorCode ShapeMBTET(double *N, const double *G_X, const double *G_Y, const double *G_Z, int DIM)
calculate shape functions
Definition: fem_tools.c:291
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:475
PetscErrorCode ShapeMBTET_inverse(double *N, double *diffN, const double *elem_coords, const double *glob_coords, double *loc_coords)
calculate local coordinates for given global coordinates
Definition: fem_tools.c:311
PetscErrorCode ShapeDiffMBTET(double *diffN)
calculate derivatives of shape functions
Definition: fem_tools.c:303
double tol
#define CHKERR
Inline error check.
Definition: definitions.h:594
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:405
const int N
Definition: speed_test.cpp:3

◆ checkVectorForNotANumber()

MoFEMErrorCode MoFEM::Tools::checkVectorForNotANumber ( const Problem prb_ptr,
const RowColData  row_or_col,
Vec  v 
)

Print all DOFs for which element of vector is not a number.

Definition at line 151 of file Tools.cpp.

153  {
155  int loc_size;
156  CHKERR VecGetLocalSize(v, &loc_size);
157  int prb_loc_size = 0;
158  boost::shared_ptr< NumeredDofEntity_multiIndex > prb_dofs;
159  switch(row_or_col) {
160  case ROW:
161  prb_loc_size = prb_ptr->getNbLocalDofsRow();
162  prb_dofs = prb_ptr->getNumeredDofsRows();
163  break;
164  case COL:
165  prb_loc_size = prb_ptr->getNbLocalDofsCol();
166  prb_dofs = prb_ptr->getNumeredDofsCols();
167  break;
168  break;
169  default:
170  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
171  "Wrong argument, row_or_col should be row or column");
172  }
173  if(loc_size != prb_loc_size) {
174  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
175  "Inconsistent size of vector and problem %d != %d", loc_size,
176  prb_loc_size);
177  }
178  const double *a;
179  CHKERR VecGetArrayRead(v, &a);
180  MPI_Comm comm = PetscObjectComm((PetscObject)v);
181  for (int ii = 0; ii != loc_size; ++ii) {
182  if (!boost::math::isfinite(a[ii])) {
183  NumeredDofEntityByLocalIdx::iterator dit =
184  prb_dofs->get<PetscLocalIdx_mi_tag>().find(ii);
185  std::ostringstream ss;
186  ss << "Not a number " << a[ii] << " on dof: " << endl
187  << **dit << endl
188  << endl;
189  PetscSynchronizedPrintf(comm, "%s", ss.str().c_str());
190  }
191  }
192  CHKERR VecRestoreArrayRead(v, &a);
193  PetscSynchronizedFlush(comm, PETSC_STDOUT);
195 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:475
#define CHKERR
Inline error check.
Definition: definitions.h:594
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:405

◆ dEterminant()

template<class T >
static double MoFEM::Tools::dEterminant ( T t)
static

Definition at line 43 of file Tools.hpp.

43  {
44  return
45  +t(0,0)*t(1,1)*t(2,2) + t(1,0)*t(2,1)*t(0,2)
46  +t(2,0)*t(0,1)*t(1,2) - t(0,0)*t(2,1)*t(1,2)
47  -t(2,0)*t(1,1)*t(0,2) - t(1,0)*t(0,1)*t(2,2);
48  }

◆ findMinDistanceFromTheEdges()

MoFEMErrorCode MoFEM::Tools::findMinDistanceFromTheEdges ( const double v_ptr,
Range  edges,
double min_dist_ptr,
double o_ptr 
) const

Find minimal distance to edges.

Note
Finding only edges with have smaller distance than distance set on the input by min_dist_ptr
Parameters
v_ptrpoint coordinates
edgesrange of edges
min_dist_ptron return minimal distance, on input starting distance
o_ptrcoordinates of the point on edge
Returns
MoFEMErrorCode

Definition at line 350 of file Tools.cpp.

353  {
354  MoFEM::Interface &m_field = cOre;
355  moab::Interface &moab(m_field.get_moab());
357 
359 
360  auto get_point = [i](auto &t_w, auto &t_delta, auto t) {
362  t = std::max(0., std::min(1., t));
363  t_p(i) = t_w(i) + t * t_delta(i);
364  return t_p;
365  };
366 
367  auto get_distance = [i](auto &t_p, auto &t_n) {
368  FTensor::Tensor1<double, 3> t_dist_vector;
369  t_dist_vector(i) = t_p(i) - t_n(i);
370  return sqrt(t_dist_vector(i) * t_dist_vector(i));
371  };
372 
373  FTensor::Tensor1<const double *, 3> t_n(v_ptr, &v_ptr[1], &v_ptr[2]);
374  double &min_dist = *min_dist_ptr;
375  FTensor::Tensor1<double *, 3> t_min_coords(o_ptr, &o_ptr[1], &o_ptr[2]);
376 
377  for (auto e : edges) {
378 
379  int num_nodes;
380  const EntityHandle *conn_fixed;
381  CHKERR moab.get_connectivity(e, conn_fixed, num_nodes, true);
382  VectorDouble6 coords_fixed(6);
383  CHKERR moab.get_coords(conn_fixed, num_nodes, &coords_fixed[0]);
385  &coords_fixed[0], &coords_fixed[1], &coords_fixed[2]);
387  &coords_fixed[3], &coords_fixed[4], &coords_fixed[5]);
388 
389  FTensor::Tensor1<double, 3> t_edge_delta;
390  t_edge_delta(i) = t_f1(i) - t_f0(i);
391 
392  double t;
393  if (Tools::minDistancePointFromOnSegment(&t_f0(0), &t_f1(0), &t_n(0), &t) ==
395  auto t_p = get_point(t_f0, t_edge_delta, t);
396  auto dist_n = get_distance(t_p, t_n);
397  if (dist_n < min_dist || min_dist < 0) {
398  t_min_coords(i) = t_p(i);
399  min_dist = dist_n;
400  }
401  }
402  }
403 
405 }
virtual moab::Interface & get_moab()=0
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:475
VectorBoundedArray< double, 6 > VectorDouble6
Definition: Types.hpp:86
#define CHKERR
Inline error check.
Definition: definitions.h:594
static SEGMENT_MIN_DISTANCE minDistancePointFromOnSegment(const double *w_ptr, const double *v_ptr, const double *p_ptr, double *const t_ptr=nullptr)
Find closet point on the segment from the point.
Definition: Tools.cpp:261
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:405
MoFEM::Core & cOre
Definition: Tools.hpp:35

◆ getEdgeLength() [1/2]

double MoFEM::Tools::getEdgeLength ( const double edge_coords)
static

Get edge length.

Parameters
edge_coords
Returns
double

Definition at line 230 of file Tools.cpp.

230  {
232  edge_coords[2]);
234  edge_coords[5]);
236  t_coords_n0(i) -= t_coords_n1(i);
237  return sqrt(t_coords_n0(i) * t_coords_n0(i));
238 }
static const double edge_coords[6][6]

◆ getEdgeLength() [2/2]

double MoFEM::Tools::getEdgeLength ( const EntityHandle  edge)

Get edge length.

Parameters
edge
Returns
double

Definition at line 240 of file Tools.cpp.

240  {
241  MoFEM::Interface &m_field = cOre;
242  moab::Interface &moab(m_field.get_moab());
243  auto get_edge_coords = [edge, &moab](double *const coords) {
245  if (moab.type_from_handle(edge) != MBEDGE) {
246  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "Works only for edge");
247  }
248  const EntityHandle *conn;
249  int num_nodes;
250  CHKERR moab.get_connectivity(edge, conn, num_nodes, true);
251  CHKERR moab.get_coords(conn, 2, coords);
253  };
254  double coords[6];
255  ierr = get_edge_coords(coords);
256  CHKERRABORT(PETSC_COMM_SELF, ierr);
257  return getEdgeLength(coords);
258 }
virtual moab::Interface & get_moab()=0
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:475
#define CHKERR
Inline error check.
Definition: definitions.h:594
static double getEdgeLength(const double *edge_coords)
Get edge length.
Definition: Tools.cpp:230
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:405
MoFEM::Core & cOre
Definition: Tools.hpp:35

◆ getTetsWithQuality()

MoFEMErrorCode MoFEM::Tools::getTetsWithQuality ( Range &  out_tets,
const Range &  tets,
Tag  th = nullptr,
boost::function< bool(double)>  f = [](double q) -> bool { if (q <= 0) return true; else return false; } 
)

Get the Tets With Quality.

Parameters
out_tets
tets
th
f
Returns
MoFEMErrorCode

Definition at line 90 of file Tools.cpp.

91  {
92  MoFEM::Interface &m_field = cOre;
93  moab::Interface &moab(m_field.get_moab());
95  Range to_write;
96  const EntityHandle *conn;
97  int num_nodes;
98  double coords[12];
99  for (auto tet : tets) {
100  CHKERR m_field.get_moab().get_connectivity(tet, conn, num_nodes, true);
101  if (th) {
102  CHKERR moab.tag_get_data(th, conn, num_nodes, coords);
103  } else {
104  CHKERR moab.get_coords(conn, num_nodes, coords);
105  }
106  double q = Tools::volumeLengthQuality(coords);
107  if (f(q)) {
108  out_tets.insert(tet);
109  }
110  }
112 }
static double volumeLengthQuality(const double *coords)
Calculate tetrahedron volume length quality.
Definition: Tools.cpp:32
virtual moab::Interface & get_moab()=0
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:475
#define CHKERR
Inline error check.
Definition: definitions.h:594
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:405
MoFEM::Core & cOre
Definition: Tools.hpp:35

◆ getTriArea()

double MoFEM::Tools::getTriArea ( const EntityHandle  tri) const

Get triangle area.

Parameters
tri
Returns
double

Definition at line 222 of file Tools.cpp.

222  {
224  ierr = getTriNormal(tri,&t_normal(0));
225  CHKERRABORT(PETSC_COMM_SELF, ierr);
227  return sqrt(t_normal(i)*t_normal(i))*0.5;
228 }
static MoFEMErrorCode getTriNormal(const double *coords, double *normal)
Get the Tri Normal objectGet triangle normal.
Definition: Tools.cpp:197

◆ getTriNormal() [1/2]

MoFEMErrorCode MoFEM::Tools::getTriNormal ( const double coords,
double normal 
)
static

Get the Tri Normal objectGet triangle normal.

Parameters
coords
normal
Returns
MoFEMErrorCode

Definition at line 197 of file Tools.cpp.

197  {
199  double diffN[6];
200  CHKERR ShapeDiffMBTRI(diffN);
201  CHKERR ShapeFaceNormalMBTRI(diffN, coords, normal);
203 }
PetscErrorCode ShapeFaceNormalMBTRI(double *diffN, const double *coords, double *normal)
Definition: fem_tools.c:219
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:475
PetscErrorCode ShapeDiffMBTRI(double *diffN)
calculate derivatives of shape functions
Definition: fem_tools.c:186
#define CHKERR
Inline error check.
Definition: definitions.h:594
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:405

◆ getTriNormal() [2/2]

MoFEMErrorCode MoFEM::Tools::getTriNormal ( const EntityHandle  tri,
double normal 
) const

Get triangle normal.

Parameters
tri
normal
Returns
MoFEMErrorCode

Definition at line 205 of file Tools.cpp.

206  {
207  MoFEM::Interface &m_field = cOre;
208  moab::Interface &moab(m_field.get_moab());
210  if (moab.type_from_handle(tri) != MBTRI) {
211  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "Works only for triangle");
212  }
213  const EntityHandle *conn;
214  int num_nodes;
215  double coords[9];
216  CHKERR moab.get_connectivity(tri, conn, num_nodes, true);
217  CHKERR moab.get_coords(conn, num_nodes, coords);
218  CHKERR getTriNormal(coords,normal);
220 }
virtual moab::Interface & get_moab()=0
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:475
static MoFEMErrorCode getTriNormal(const double *coords, double *normal)
Get the Tri Normal objectGet triangle normal.
Definition: Tools.cpp:197
#define CHKERR
Inline error check.
Definition: definitions.h:594
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:405
MoFEM::Core & cOre
Definition: Tools.hpp:35

◆ minDistanceFromSegments()

Tools::SEGMENT_MIN_DISTANCE MoFEM::Tools::minDistanceFromSegments ( const double w_ptr,
const double v_ptr,
const double k_ptr,
const double l_ptr,
double *const  tvw_ptr = nullptr,
double *const  tlk_ptr = nullptr 
)
static

Find points on two segments in closest distance.

Parameters
w_ptr
v_ptr
k_ptr
l_ptr
tvw_ptr
tlk_ptr
Returns
SEGMENT_MIN_DISTANCE
Note
If tvwk or tlk are outside bound [0,-1], it means that points are on the lines beyond segments, respectively for segment vw and lk.

Definition at line 284 of file Tools.cpp.

286  {
287 
289  FTensor::Tensor1<const double *, 3> t_w(&w_ptr[0], &w_ptr[1], &w_ptr[2]);
290  FTensor::Tensor1<const double *, 3> t_v(&v_ptr[0], &v_ptr[1], &v_ptr[2]);
291  FTensor::Tensor1<const double *, 3> t_k(&k_ptr[0], &k_ptr[1], &k_ptr[2]);
292  FTensor::Tensor1<const double *, 3> t_l(&l_ptr[0], &l_ptr[1], &l_ptr[2]);
293 
294  // First segnent is a point
296  t_vw(i) = t_v(i) - t_w(i);
297  double dot_vw = t_vw(i) * t_vw(i);
298  if (dot_vw == 0) {
299  if (tvw_ptr)
300  *tvw_ptr = 0;
301  if (minDistancePointFromOnSegment(k_ptr, l_ptr, w_ptr, tlk_ptr) ==
304  else
305  return SEGMENT_ONE_IS_POINT;
306  }
307 
308  // Second segment is a point
310  t_lk(i) = t_l(i) - t_k(i);
311  double dot_lk = t_lk(i) * t_lk(i);
312  if (dot_lk == 0) {
313  if (tlk_ptr)
314  *tlk_ptr = 0;
315  if (minDistancePointFromOnSegment(w_ptr, v_ptr, k_ptr, tvw_ptr) ==
318  else
319  return SEGMENT_TWO_IS_POINT;
320  }
321 
322  const double a = t_vw(i) * t_vw(i);
323  const double b = -t_vw(i) * t_lk(i);
324  const double c = t_lk(i) * t_lk(i);
325 
326  const double det = a * c - b * b;
327  if(det == 0) {
328 
329  return NO_SOLUTION;
330 
331  } else {
332 
334  t_wk(i) = t_w(i) - t_k(i);
335 
336  const double ft0 = t_vw(i) * t_wk(i);
337  const double ft1 = -t_lk(i) * t_wk(i);
338  const double t0 = (ft1 * b - ft0 * c) / det;
339  const double t1 = (ft0 * b - ft1 * a) / det;
340 
341  if (tvw_ptr)
342  *tvw_ptr = t0;
343  if (tlk_ptr)
344  *tlk_ptr = t1;
345 
346  return SOLUTION_EXIST;
347  }
348 }
static SEGMENT_MIN_DISTANCE minDistancePointFromOnSegment(const double *w_ptr, const double *v_ptr, const double *p_ptr, double *const t_ptr=nullptr)
Find closet point on the segment from the point.
Definition: Tools.cpp:261

◆ minDistancePointFromOnSegment()

Tools::SEGMENT_MIN_DISTANCE MoFEM::Tools::minDistancePointFromOnSegment ( const double w_ptr,
const double v_ptr,
const double p_ptr,
double *const  t_ptr = nullptr 
)
static

Find closet point on the segment from the point.

Parameters
w_ptrsegment first vertex coordinate
v_ptrsegment second vertex coordinate
p_ptrcoordinate of point
t_ptrdistance on the segment
Note
If t is outside bounds [ 0,-1 ] point is on the line point beyond segment.
double w[] = {-1, 0, 0};
double v[] = {1, 0, 0};
double p[] = {0, 1, 0};
double t;
CHKERR Toolas::minDistancePointFromOnSegment(w, v, p, &t);
double point_on_segment[3];
for (int i = 0; i != 3; ++i)
point_on_segment[i] = w[i] + t * (v[i] - w[i]);
Returns
SEGMENT_MIN_DISTANCE

Definition at line 261 of file Tools.cpp.

262  {
264  FTensor::Tensor1<const double *, 3> t_w(&w_ptr[0], &w_ptr[1], &w_ptr[2]);
265  FTensor::Tensor1<const double *, 3> t_v(&v_ptr[0], &v_ptr[1], &v_ptr[2]);
266  FTensor::Tensor1<const double *, 3> t_p(&p_ptr[0], &p_ptr[1], &p_ptr[2]);
268  t_vw(i) = t_v(i) - t_w(i);
269  const double dot_vw = t_vw(i) * t_vw(i);
270  if (dot_vw == 0) {
271  if (t_ptr)
272  *t_ptr = 0;
273  return SEGMENT_ONE_IS_POINT;
274  }
276  t_pw(i) = t_p(i) - t_w(i);
277  const double t = t_pw(i) * t_vw(i) / dot_vw;
278  if (t_ptr)
279  *t_ptr = t;
280  return SOLUTION_EXIST;
281 }

◆ minTetsQuality()

MoFEMErrorCode MoFEM::Tools::minTetsQuality ( const Range &  tets,
double min_quality,
Tag  th = nullptr,
boost::function< double(double, double)>  f = [](double a, double b) -> double { return std::min(a, b); } 
)

calculate minimal quality of tetrahedra in range

Parameters
tetsrange
min_qualitymimimal quality
Returns
error code

Definition at line 66 of file Tools.cpp.

67  {
68  MoFEM::Interface &m_field = cOre;
69  moab::Interface &moab(m_field.get_moab());
71  const EntityHandle *conn;
72  int num_nodes;
73  double coords[12];
74  for (auto tet : tets) {
75  CHKERR m_field.get_moab().get_connectivity(tet, conn, num_nodes, true);
76  if(th) {
77  CHKERR moab.tag_get_data(th, conn, num_nodes, coords);
78  } else {
79  CHKERR moab.get_coords(conn, num_nodes, coords);
80  }
81  double q = Tools::volumeLengthQuality(coords);
82  if(!std::isnormal(q))
83  q = -2;
84  min_quality = f(q, min_quality);
85  }
87 }
static double volumeLengthQuality(const double *coords)
Calculate tetrahedron volume length quality.
Definition: Tools.cpp:32
virtual moab::Interface & get_moab()=0
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:475
#define CHKERR
Inline error check.
Definition: definitions.h:594
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:405
MoFEM::Core & cOre
Definition: Tools.hpp:35

◆ query_interface()

MoFEMErrorCode MoFEM::Tools::query_interface ( const MOFEMuuid uuid,
UnknownInterface **  iface 
) const
virtual

Implements MoFEM::UnknownInterface.

Definition at line 20 of file Tools.cpp.

21  {
23  *iface = NULL;
24  if (uuid == IDD_MOFEMNodeMerger) {
25  *iface = const_cast<Tools *>(this);
27  }
28  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "unknown interface");
30 }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:499
static const MOFEMuuid IDD_MOFEMNodeMerger
Definition: NodeMerger.hpp:23
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:506
Tools(const MoFEM::Core &core)
Definition: Tools.hpp:36

◆ tetVolume()

double MoFEM::Tools::tetVolume ( const double coords)
static

Calculate volume of tetrahedron.

Parameters
coords
Returns
double volume

Definition at line 47 of file Tools.cpp.

47  {
48  double diff_n[12];
49  ShapeDiffMBTET(diff_n);
50  FTensor::Tensor1<double *, 3> t_diff_n(&diff_n[0], &diff_n[1], &diff_n[2], 3);
51  FTensor::Tensor1<const double *, 3> t_coords(&coords[0], &coords[1],
52  &coords[2], 3);
56  jac(i, j) = 0;
57  for (int nn = 0; nn != 4; nn++) {
58  jac(i, j) += t_coords(i) * t_diff_n(j);
59  ++t_coords;
60  ++t_diff_n;
61  }
62  return dEterminant(jac) / 6.;
63 }
static double dEterminant(T &t)
Definition: Tools.hpp:43
PetscErrorCode ShapeDiffMBTET(double *diffN)
calculate derivatives of shape functions
Definition: fem_tools.c:303

◆ volumeLengthQuality()

double MoFEM::Tools::volumeLengthQuality ( const double coords)
static

Calculate tetrahedron volume length quality.

Parameters
coordstet coordinates
Returns
Volume-length quality
Examples:
mesh_smoothing.cpp.

Definition at line 32 of file Tools.cpp.

32  {
33  double lrms = 0;
34  for (int dd = 0; dd != 3; dd++) {
35  lrms += pow(coords[0 * 3 + dd] - coords[1 * 3 + dd], 2) +
36  pow(coords[0 * 3 + dd] - coords[2 * 3 + dd], 2) +
37  pow(coords[0 * 3 + dd] - coords[3 * 3 + dd], 2) +
38  pow(coords[1 * 3 + dd] - coords[2 * 3 + dd], 2) +
39  pow(coords[1 * 3 + dd] - coords[3 * 3 + dd], 2) +
40  pow(coords[2 * 3 + dd] - coords[3 * 3 + dd], 2);
41  }
42  lrms = sqrt((1. / 6.) * lrms);
43  double volume = tetVolume(coords);
44  return 6. * sqrt(2.) * volume / pow(lrms, 3);
45 }
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T *> &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: ddTensor0.hpp:33
static double tetVolume(const double *coords)
Calculate volume of tetrahedron.
Definition: Tools.cpp:47

◆ writeTetsWithQuality()

MoFEMErrorCode MoFEM::Tools::writeTetsWithQuality ( const char *  file_name,
const char *  file_type,
const char *  options,
const Range &  tets,
Tag  th = nullptr,
boost::function< bool(double)>  f = [](double q) -> bool { if (q <= 0) return true; else return false; } 
)

Write file with tetrahedral of given quality.

Parameters
file_name
file_type
options
tets
th
f
Returns
MoFEMErrorCode

Definition at line 115 of file Tools.cpp.

117  {
118  MoFEM::Interface &m_field = cOre;
119  moab::Interface &moab(m_field.get_moab());
121  Range out_tets;
122  CHKERR getTetsWithQuality(out_tets, tets, th, f);
123  EntityHandle meshset;
124  CHKERR moab.create_meshset(MESHSET_SET, meshset);
125  CHKERR moab.add_entities(meshset, out_tets);
126  CHKERR moab.write_file(file_name, file_type, options, &meshset, 1);
127  CHKERR moab.delete_entities(&meshset, 1);
129 }
virtual moab::Interface & get_moab()=0
MoFEMErrorCode getTetsWithQuality(Range &out_tets, const Range &tets, Tag th=nullptr, boost::function< bool(double)> f=[](double q) -> bool { if(q<=0) return true;else return false;})
Get the Tets With Quality.
Definition: Tools.cpp:90
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:475
#define CHKERR
Inline error check.
Definition: definitions.h:594
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:405
MoFEM::Core & cOre
Definition: Tools.hpp:35

Member Data Documentation

◆ cOre

MoFEM::Core& MoFEM::Tools::cOre

Definition at line 35 of file Tools.hpp.


The documentation for this struct was generated from the following files: