Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Nektar::Utilities::ProcessJac Class Reference

This processing module calculates the Jacobian of elements using SpatialDomains::GeomFactors and the Element::GetGeom method. For now it simply prints a list of elements which have negative Jacobian. More...

#include <ProcessJac.h>

Inheritance diagram for Nektar::Utilities::ProcessJac:
[legend]

Public Member Functions

 ProcessJac (NekMeshUtils::MeshSharedPtr m)
 
virtual ~ProcessJac ()
 
virtual void Process ()
 Write mesh to output file. More...
 
- Public Member Functions inherited from Nektar::NekMeshUtils::ProcessModule
NEKMESHUTILS_EXPORT ProcessModule (MeshSharedPtr p_m)
 
- Public Member Functions inherited from Nektar::NekMeshUtils::Module
NEKMESHUTILS_EXPORT Module (MeshSharedPtr p_m)
 
NEKMESHUTILS_EXPORT void RegisterConfig (std::string key, std::string value=std::string())
 Register a configuration option with a module. More...
 
NEKMESHUTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
NEKMESHUTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
NEKMESHUTILS_EXPORT MeshSharedPtr GetMesh ()
 
virtual NEKMESHUTILS_EXPORT void ProcessVertices ()
 Extract element vertices. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessElements ()
 Generate element IDs. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessComposites ()
 Generate composites. More...
 
virtual NEKMESHUTILS_EXPORT void ClearElementLinks ()
 

Static Public Member Functions

static std::shared_ptr< Modulecreate (NekMeshUtils::MeshSharedPtr m)
 Creates an instance of this class. More...
 

Static Public Attributes

static NekMeshUtils::ModuleKey className
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::NekMeshUtils::Module
NEKMESHUTILS_EXPORT void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
NEKMESHUTILS_EXPORT void PrismLines (int prism, PerMap &perFaces, std::set< int > &prismsDone, std::vector< ElementSharedPtr > &line)
 
- Protected Attributes inherited from Nektar::NekMeshUtils::Module
MeshSharedPtr m_mesh
 Mesh object. More...
 
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 

Detailed Description

This processing module calculates the Jacobian of elements using SpatialDomains::GeomFactors and the Element::GetGeom method. For now it simply prints a list of elements which have negative Jacobian.

Definition at line 51 of file ProcessJac.h.

Constructor & Destructor Documentation

◆ ProcessJac()

Nektar::Utilities::ProcessJac::ProcessJac ( NekMeshUtils::MeshSharedPtr  m)

Definition at line 51 of file ProcessJac.cpp.

References Nektar::NekMeshUtils::Module::m_config.

51  : ProcessModule(m)
52 {
53  m_config["extract"] =
54  ConfigOption(false, "0.0", "Extract non-valid elements from mesh.");
55  m_config["list"] = ConfigOption(
56  true, "0", "Print list of elements having negative Jacobian.");
57 }
Represents a command-line configuration option.
NEKMESHUTILS_EXPORT ProcessModule(MeshSharedPtr p_m)
std::map< std::string, ConfigOption > m_config
List of configuration values.

◆ ~ProcessJac()

Nektar::Utilities::ProcessJac::~ProcessJac ( )
virtual

Definition at line 59 of file ProcessJac.cpp.

60 {
61 }

Member Function Documentation

◆ create()

static std::shared_ptr<Module> Nektar::Utilities::ProcessJac::create ( NekMeshUtils::MeshSharedPtr  m)
inlinestatic

Creates an instance of this class.

Definition at line 55 of file ProcessJac.h.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

56  {
58  }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

◆ Process()

void Nektar::Utilities::ProcessJac::Process ( )
virtual

Write mesh to output file.

Implements Nektar::NekMeshUtils::Module.

Definition at line 63 of file ProcessJac.cpp.

References Nektar::eFULL, CellMLToNektar.pycml::extract(), Nektar::NekMeshUtils::Module::m_config, Nektar::NekMeshUtils::Module::m_mesh, CellMLToNektar.cellml_metadata::p, Nektar::NekMeshUtils::Module::ProcessComposites(), Nektar::NekMeshUtils::Module::ProcessEdges(), Nektar::NekMeshUtils::Module::ProcessElements(), Nektar::NekMeshUtils::Module::ProcessFaces(), Nektar::NekMeshUtils::Module::ProcessVertices(), Nektar::LibUtilities::ShapeTypeMap, Vmath::Vmax(), and Vmath::Vmin().

64 {
65  if (m_mesh->m_verbose)
66  {
67  cout << "ProcessJac: Calculating Jacobians... " << endl;
68  }
69 
70  bool extract = m_config["extract"].beenSet;
71  bool printList = m_config["list"].as<bool>();
72  NekDouble thres = m_config["extract"].as<NekDouble>();
73 
74  vector<ElementSharedPtr> el = m_mesh->m_element[m_mesh->m_expDim];
75 
76  if (extract)
77  {
78  m_mesh->m_element[m_mesh->m_expDim].clear();
79  }
80 
81  if (printList)
82  {
83  cout << "Elements with negative Jacobian:" << endl;
84  }
85 
86  int nNeg = 0;
87 
88  Array<OneD, int> bin(20, 0);
89 
90  // Iterate over list of elements of expansion dimension.
91  for (int i = 0; i < el.size(); ++i)
92  {
93  // Create elemental geometry.
95  el[i]->GetGeom(m_mesh->m_spaceDim);
96 
97  // Generate geometric factors.
98  SpatialDomains::GeomFactorsSharedPtr gfac = geom->GetGeomFactors();
99 
100  LibUtilities::PointsKeyVector p = geom->GetXmap()->GetPointsKeys();
101  SpatialDomains::DerivStorage deriv = gfac->GetDeriv(p);
102  const int pts = deriv[0][0].num_elements();
103  Array<OneD,NekDouble> jc(pts);
104  for (int k = 0; k < pts; ++k)
105  {
106  DNekMat jac(m_mesh->m_expDim, m_mesh->m_expDim, 0.0, eFULL);
107 
108  for (int l = 0; l < m_mesh->m_expDim; ++l)
109  {
110  for (int j = 0; j < m_mesh->m_expDim; ++j)
111  {
112  jac(j,l) = deriv[l][j][k];
113  }
114  }
115 
116  if(m_mesh->m_expDim == 2)
117  {
118  jc[k] = jac(0,0) * jac(1,1) - jac(0,1)*jac(1,0);
119  }
120  else if(m_mesh->m_expDim == 3)
121  {
122  jc[k] = jac(0,0) * (jac(1,1)*jac(2,2) - jac(2,1)*jac(1,2)) -
123  jac(0,1) * (jac(1,0)*jac(2,2) - jac(2,0)*jac(1,2)) +
124  jac(0,2) * (jac(1,0)*jac(2,1) - jac(2,0)*jac(1,1));
125  }
126  }
127 
128  NekDouble scaledJac = Vmath::Vmin(jc.num_elements(),jc,1) /
129  Vmath::Vmax(jc.num_elements(),jc,1);
130 
131  bool valid = gfac->IsValid();
132 
133  if (extract && (scaledJac < thres || !valid))
134  {
135  m_mesh->m_element[m_mesh->m_expDim].push_back(el[i]);
136  }
137 
138  // Get the Jacobian and, if it is negative, print a warning
139  // message.
140  if (!valid)
141  {
142  nNeg++;
143 
144  if (printList)
145  {
146  cout << " - " << el[i]->GetId() << " ("
147  << LibUtilities::ShapeTypeMap[el[i]->GetConf().m_e] << ")"
148  << " " << scaledJac
149  << endl;
150  }
151  }
152  }
153 
154  if (extract)
155  {
156  m_mesh->m_element[m_mesh->m_expDim - 1].clear();
157  ProcessVertices();
158  ProcessEdges();
159  ProcessFaces();
160  ProcessElements();
162  }
163 
164  if (printList || m_mesh->m_verbose)
165  {
166  cout << "Total negative Jacobians: " << nNeg << endl;
167  }
168  else if (nNeg > 0)
169  {
170  cout << "WARNING: Detected " << nNeg << " element"
171  << (nNeg == 1 ? "" : "s") << " with negative Jacobian." << endl;
172  }
173 }
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:246
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
Definition: Vmath.cpp:782
std::shared_ptr< GeomFactors > GeomFactorsSharedPtr
Pointer to a GeomFactors object.
Definition: GeomFactors.h:62
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
Definition: Vmath.cpp:874
const char *const ShapeTypeMap[]
Definition: ShapeType.hpp:67
virtual NEKMESHUTILS_EXPORT void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > DerivStorage
Storage type for derivative of mapping.
Definition: GeomFactors.h:70
virtual NEKMESHUTILS_EXPORT void ProcessElements()
Generate element IDs.
std::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
NekMatrix< NekDouble, StandardMatrixTag > DNekMat
Definition: NekTypeDefs.hpp:51
double NekDouble
std::map< std::string, ConfigOption > m_config
List of configuration values.
def extract(self, check_equality=False)
Definition: pycml.py:2657
virtual NEKMESHUTILS_EXPORT void ProcessVertices()
Extract element vertices.
virtual NEKMESHUTILS_EXPORT void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
virtual NEKMESHUTILS_EXPORT void ProcessComposites()
Generate composites.

Member Data Documentation

◆ className

ModuleKey Nektar::Utilities::ProcessJac::className
static
Initial value:
"Process elements based on values of Jacobian.")

Definition at line 59 of file ProcessJac.h.