v0.8.16
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

MoFEMErrorCode minTetsQuality (const Range &tets, double &min_quality, Tag th=NULL, 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=NULL, 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=NULL, 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...
 
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...
 

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.

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 129 of file Tools.cpp.

131  {
132  double loc_coord[] = {0, 0, 0};
133  double N[4],diffN[12];
135  CHKERR ShapeDiffMBTET(diffN);
136  CHKERR ShapeMBTET(N, &loc_coord[0], &loc_coord[1], &loc_coord[2], 1);
137  CHKERR ShapeMBTET_inverse(N, diffN, tet_coords, global_coord, loc_coord);
138  CHKERR ShapeMBTET(N, &loc_coord[0], &loc_coord[1], &loc_coord[2], 1);
139  result = true;
140  for (int n = 0; n != 4; ++n) {
141  if (N[n] < -tol || (N[n] - 1) > tol) {
142  result = false;
143  break;
144  }
145  }
147 }
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:459
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:578
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:403
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 149 of file Tools.cpp.

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

◆ 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  }

◆ getEdgeLength() [1/2]

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

Get edge length.

Parameters
edge_coords
Returns
double

Definition at line 228 of file Tools.cpp.

228  {
230  edge_coords[2]);
232  edge_coords[5]);
234  t_coords_n0(i) -= t_coords_n1(i);
235  return sqrt(t_coords_n0(i) * t_coords_n0(i));
236 }
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 238 of file Tools.cpp.

238  {
239  MoFEM::Interface &m_field = cOre;
240  moab::Interface &moab(m_field.get_moab());
241  auto get_edge_coords = [edge, &moab](double *const coords) {
243  if (moab.type_from_handle(edge) != MBEDGE) {
244  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "Works only for edge");
245  }
246  const EntityHandle *conn;
247  int num_nodes;
248  CHKERR moab.get_connectivity(edge, conn, num_nodes, true);
249  CHKERR moab.get_coords(conn, 2, coords);
251  };
252  double coords[6];
253  ierr = get_edge_coords(coords);
254  CHKERRABORT(PETSC_COMM_SELF, ierr);
255  return getEdgeLength(coords);
256 }
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:459
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Common.hpp:80
#define CHKERR
Inline error check.
Definition: definitions.h:578
static double getEdgeLength(const double *edge_coords)
Get edge length.
Definition: Tools.cpp:228
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:403
MoFEM::Core & cOre
Definition: Tools.hpp:35

◆ getTetsWithQuality()

MoFEMErrorCode MoFEM::Tools::getTetsWithQuality ( Range &  out_tets,
const Range &  tets,
Tag  th = NULL,
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 88 of file Tools.cpp.

89  {
90  MoFEM::Interface &m_field = cOre;
91  moab::Interface &moab(m_field.get_moab());
93  Range to_write;
94  const EntityHandle *conn;
95  int num_nodes;
96  double coords[12];
97  for (auto tet : tets) {
98  CHKERR m_field.get_moab().get_connectivity(tet, conn, num_nodes, true);
99  if (th) {
100  CHKERR moab.tag_get_data(th, conn, num_nodes, coords);
101  } else {
102  CHKERR moab.get_coords(conn, num_nodes, coords);
103  }
104  double q = Tools::volumeLengthQuality(coords);
105  if (f(q)) {
106  out_tets.insert(tet);
107  }
108  }
110 }
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:459
#define CHKERR
Inline error check.
Definition: definitions.h:578
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:403
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 220 of file Tools.cpp.

220  {
222  ierr = getTriNormal(tri,&t_normal(0));
223  CHKERRABORT(PETSC_COMM_SELF, ierr);
225  return sqrt(t_normal(i)*t_normal(i))*0.5;
226 }
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Common.hpp:80
static MoFEMErrorCode getTriNormal(const double *coords, double *normal)
Get the Tri Normal objectGet triangle normal.
Definition: Tools.cpp:195

◆ 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 195 of file Tools.cpp.

195  {
197  double diffN[6];
198  CHKERR ShapeDiffMBTRI(diffN);
199  CHKERR ShapeFaceNormalMBTRI(diffN, coords, normal);
201 }
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:459
PetscErrorCode ShapeDiffMBTRI(double *diffN)
calculate derivatives of shape functions
Definition: fem_tools.c:186
#define CHKERR
Inline error check.
Definition: definitions.h:578
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:403

◆ getTriNormal() [2/2]

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

Get triangle normal.

Parameters
tri
normal
Returns
MoFEMErrorCode

Definition at line 203 of file Tools.cpp.

204  {
205  MoFEM::Interface &m_field = cOre;
206  moab::Interface &moab(m_field.get_moab());
208  if (moab.type_from_handle(tri) != MBTRI) {
209  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "Works only for triangle");
210  }
211  const EntityHandle *conn;
212  int num_nodes;
213  double coords[9];
214  CHKERR moab.get_connectivity(tri, conn, num_nodes, true);
215  CHKERR moab.get_coords(conn, num_nodes, coords);
216  CHKERR getTriNormal(coords,normal);
218 }
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:459
static MoFEMErrorCode getTriNormal(const double *coords, double *normal)
Get the Tri Normal objectGet triangle normal.
Definition: Tools.cpp:195
#define CHKERR
Inline error check.
Definition: definitions.h:578
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:403
MoFEM::Core & cOre
Definition: Tools.hpp:35

◆ minTetsQuality()

MoFEMErrorCode MoFEM::Tools::minTetsQuality ( const Range &  tets,
double min_quality,
Tag  th = NULL,
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  min_quality = f(q, min_quality);
83  }
85 }
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:459
#define CHKERR
Inline error check.
Definition: definitions.h:578
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:403
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:483
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:490
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 = NULL,
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 113 of file Tools.cpp.

115  {
116  MoFEM::Interface &m_field = cOre;
117  moab::Interface &moab(m_field.get_moab());
119  Range out_tets;
120  CHKERR getTetsWithQuality(out_tets, tets, th, f);
121  EntityHandle meshset;
122  CHKERR moab.create_meshset(MESHSET_SET, meshset);
123  CHKERR moab.add_entities(meshset, out_tets);
124  CHKERR moab.write_file(file_name, file_type, options, &meshset, 1);
125  CHKERR moab.delete_entities(&meshset, 1);
127 }
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:459
MoFEMErrorCode getTetsWithQuality(Range &out_tets, const Range &tets, Tag th=NULL, boost::function< bool(double)> f=[](double q) -> bool { if(q<=0) return true;else return false;})
Get the Tets With Quality.
Definition: Tools.cpp:88
#define CHKERR
Inline error check.
Definition: definitions.h:578
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:403
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: