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

This processing module removes all the high-order information from the mesh leaving just the linear elements. More...

#include <ProcessLinear.h>

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

Public Member Functions

 ProcessLinear (NekMeshUtils::MeshSharedPtr m)
 
virtual ~ProcessLinear ()
 
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
 

Private Member Functions

bool Invalid (NekMeshUtils::ElementSharedPtr el, NekDouble thr)
 

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 removes all the high-order information from the mesh leaving just the linear elements.

Definition at line 48 of file ProcessLinear.h.

Constructor & Destructor Documentation

◆ ProcessLinear()

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

Definition at line 52 of file ProcessLinear.cpp.

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

52  : ProcessModule(m)
53 {
54  m_config["all"] =
55  ConfigOption(true, "0", "remove curve nodes for all elements.");
56  m_config["invalid"] =
57  ConfigOption(false, "0", "remove curve nodes if element is invalid.");
58  m_config["prismonly"] =
59  ConfigOption(true, "0", "only acts on prims");
60  m_config["extract"] =
61  ConfigOption(false, "", "dump a mesh of the extracted elements");
62 }
Represents a command-line configuration option.
NEKMESHUTILS_EXPORT ProcessModule(MeshSharedPtr p_m)
std::map< std::string, ConfigOption > m_config
List of configuration values.

◆ ~ProcessLinear()

Nektar::Utilities::ProcessLinear::~ProcessLinear ( )
virtual

Definition at line 64 of file ProcessLinear.cpp.

65 {
66 }

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 52 of file ProcessLinear.h.

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

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

◆ Invalid()

bool Nektar::Utilities::ProcessLinear::Invalid ( NekMeshUtils::ElementSharedPtr  el,
NekDouble  thr 
)
private

Definition at line 239 of file ProcessLinear.cpp.

References Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), Nektar::eFULL, Nektar::NekMeshUtils::GetElementFactory(), Nektar::NekMeshUtils::ElmtConfig::m_e, Nektar::NekMeshUtils::ElmtConfig::m_faceNodes, Nektar::NekMeshUtils::Module::m_mesh, Nektar::NekMeshUtils::ElmtConfig::m_order, Nektar::NekMeshUtils::ElmtConfig::m_reorient, Nektar::NekMeshUtils::ElmtConfig::m_volumeNodes, CellMLToNektar.cellml_metadata::p, Vmath::Vdiv(), Vmath::Vmax(), and Vmath::Vmin().

Referenced by Process().

240 {
241  // Create elemental geometry.
243  el->GetGeom(m_mesh->m_spaceDim);
244 
245  // Generate geometric factors.
247  geom->GetGeomFactors();
248 
249  if(!gfac->IsValid())
250  {
251  return true;
252  }
253 
254  vector<NodeSharedPtr> ns = el->GetVertexList();
255  ElmtConfig c = el->GetConf();
256  c.m_order = 1;
257  c.m_faceNodes = false;
258  c.m_volumeNodes = false;
259  c.m_reorient = false;
260 
262  c.m_e, c, ns, el->GetTagList());
263  SpatialDomains::GeometrySharedPtr geomL = elL->GetGeom(m_mesh->m_spaceDim);
264  SpatialDomains::GeomFactorsSharedPtr gfacL = geomL->GetGeomFactors();
265 
266  LibUtilities::PointsKeyVector p = geom->GetXmap()->GetPointsKeys();
267  SpatialDomains::DerivStorage deriv = gfac->GetDeriv(p);
268  SpatialDomains::DerivStorage derivL = gfacL->GetDeriv(p);
269  const int pts = deriv[0][0].num_elements();
270  Array<OneD,NekDouble> jc(pts);
271  Array<OneD,NekDouble> jcL(pts);
272  for (int k = 0; k < pts; ++k)
273  {
274  DNekMat jac(m_mesh->m_expDim, m_mesh->m_expDim, 0.0, eFULL);
275  DNekMat jacL(m_mesh->m_expDim, m_mesh->m_expDim, 0.0, eFULL);
276 
277  for (int l = 0; l < m_mesh->m_expDim; ++l)
278  {
279  for (int j = 0; j < m_mesh->m_expDim; ++j)
280  {
281  jac(j,l) = deriv[l][j][k];
282  jacL(j,l) = derivL[l][j][k];
283  }
284  }
285 
286  if(m_mesh->m_expDim == 2)
287  {
288  jc[k] = jac(0,0) * jac(1,1) - jac(0,1)*jac(1,0);
289  jcL[k] = jacL(0,0) * jacL(1,1) - jacL(0,1)*jacL(1,0);
290  }
291  else if(m_mesh->m_expDim == 3)
292  {
293  jc[k] = jac(0,0) * (jac(1,1)*jac(2,2) - jac(2,1)*jac(1,2)) -
294  jac(0,1) * (jac(1,0)*jac(2,2) - jac(2,0)*jac(1,2)) +
295  jac(0,2) * (jac(1,0)*jac(2,1) - jac(2,0)*jac(1,1));
296  jcL[k] = jacL(0,0) * (jacL(1,1)*jacL(2,2) - jacL(2,1)*jacL(1,2)) -
297  jacL(0,1) * (jacL(1,0)*jacL(2,2) - jacL(2,0)*jacL(1,2)) +
298  jacL(0,2) * (jacL(1,0)*jacL(2,1) - jacL(2,0)*jacL(1,1));
299  }
300  }
301 
302  Array<OneD, NekDouble> j(pts);
303  Vmath::Vdiv(jc.num_elements(),jc,1,jcL,1,j,1);
304 
305  NekDouble scaledJac = Vmath::Vmin(j.num_elements(),j,1) /
306  Vmath::Vmax(j.num_elements(),j,1);
307 
308  //cout << scaledJac << endl;
309 
310  if(scaledJac < thr)
311  {
312  return true;
313  }
314 
315  return false;
316 }
bool m_faceNodes
Denotes whether the element contains face nodes. For 2D elements, if this is true then the element co...
Definition: ElementConfig.h:81
Basic information about an element.
Definition: ElementConfig.h:49
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
void Vdiv(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x/y.
Definition: Vmath.cpp:244
ElementFactory & GetElementFactory()
Definition: Element.cpp:44
unsigned int m_order
Order of the element.
Definition: ElementConfig.h:88
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
bool m_volumeNodes
Denotes whether the element contains volume (i.e. interior) nodes. These are not supported by either ...
Definition: ElementConfig.h:86
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > DerivStorage
Storage type for derivative of mapping.
Definition: GeomFactors.h:70
std::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:49
std::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
NekMatrix< NekDouble, StandardMatrixTag > DNekMat
Definition: NekTypeDefs.hpp:51
double NekDouble
bool m_reorient
Denotes whether the element needs to be re-orientated for a spectral element framework.
Definition: ElementConfig.h:91
LibUtilities::ShapeType m_e
Element type (e.g. triangle, quad, etc).
Definition: ElementConfig.h:78

◆ Process()

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

Write mesh to output file.

Implements Nektar::NekMeshUtils::Module.

Definition at line 68 of file ProcessLinear.cpp.

References ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), Nektar::FieldUtils::eOutputModule, Nektar::LibUtilities::ePrism, Nektar::FieldUtils::GetModuleFactory(), Invalid(), Nektar::NekMeshUtils::Module::m_config, Nektar::NekMeshUtils::Module::m_mesh, and CG_Iterations::Mesh.

69 {
70  if (m_mesh->m_verbose)
71  {
72  cout << "ProcessLinear: Linearising mesh... " << endl;
73  }
74 
75  bool all = m_config["all"].as<bool>();
76  bool invalid = m_config["invalid"].beenSet;
77  NekDouble thr = m_config["invalid"].as<NekDouble>();
78 
79  ASSERTL0(all || invalid,
80  "Must specify an option: all (to remove all curvature) or invalid "
81  "(to remove curvature that makes elements invalid)");
82 
83  if (all)
84  {
85  for (auto &edge : m_mesh->m_edgeSet)
86  {
87  edge->m_edgeNodes.clear();
88  }
89 
90  for (auto &face : m_mesh->m_faceSet)
91  {
92  face->m_faceNodes.clear();
93  }
94 
95  for (int i = 0; i < m_mesh->m_element[m_mesh->m_expDim].size(); i++)
96  {
97  vector<NodeSharedPtr> empty;
98  m_mesh->m_element[m_mesh->m_expDim][i]->SetVolumeNodes(empty);
99  }
100 
101  if (m_mesh->m_verbose)
102  {
103  cerr << "Removed all element curvature" << endl;
104  }
105  }
106  else if (invalid)
107  {
108  map<int,vector<FaceSharedPtr> > eidToFace;
109  map<int,vector<ElementSharedPtr> > eidToElm;
110 
111  vector<ElementSharedPtr> els = m_mesh->m_element[m_mesh->m_expDim];
112  vector<ElementSharedPtr> el = els;
113 
114  for(int i = 0; i < el.size(); i++)
115  {
116  vector<EdgeSharedPtr> e = el[i]->GetEdgeList();
117  for(int j = 0; j < e.size(); j++)
118  {
119  eidToElm[e[j]->m_id].push_back(el[i]);
120  }
121  }
122 
123  if(m_mesh->m_expDim > 2)
124  {
125  for(auto &face : m_mesh->m_faceSet)
126  {
127  vector<EdgeSharedPtr> es = face->m_edgeList;
128  for(int i = 0; i < es.size(); i++)
129  {
130  eidToFace[es[i]->m_id].push_back(face);
131  }
132  }
133  }
134 
135  set<int> neigh;
136  vector<NodeSharedPtr> zeroNodes;
137  std::unordered_set<int> clearedEdges, clearedFaces, clearedElmts;
138 
139  vector<ElementSharedPtr> dumpEls;
140 
141  // Iterate over list of elements of expansion dimension.
142  while(el.size() > 0)
143  {
144  for (int i = 0; i < el.size(); ++i)
145  {
146  if(m_config["prismonly"].beenSet)
147  {
148  if(el[i]->GetConf().m_e != LibUtilities::ePrism)
149  {
150  continue;
151  }
152  }
153 
154  if (Invalid(el[i],thr))//(!gfac->IsValid())
155  {
156  dumpEls.push_back(el[i]);
157  clearedElmts.insert(el[i]->GetId());;
158  el[i]->SetVolumeNodes(zeroNodes);
159 
160  vector<FaceSharedPtr> f = el[i]->GetFaceList();
161  for (int j = 0; j < f.size(); j++)
162  {
163  f[j]->m_faceNodes.clear();
164  clearedFaces.insert(f[j]->m_id);
165  }
166  vector<EdgeSharedPtr> e = el[i]->GetEdgeList();
167  for(int j = 0; j < e.size(); j++)
168  {
169  e[j]->m_edgeNodes.clear();
170  clearedEdges.insert(e[j]->m_id);
171  }
172 
173  if(m_mesh->m_expDim > 2)
174  {
175  for(int j = 0; j < e.size(); j++)
176  {
177  auto it = eidToFace.find(e[j]->m_id);
178  for(int k = 0; k < it->second.size(); k++)
179  {
180  clearedEdges.insert(it->second[k]->m_id);
181  it->second[k]->m_faceNodes.clear();
182  }
183  }
184  }
185 
186  for(int j = 0; j < e.size(); j++)
187  {
188  auto it = eidToElm.find(e[j]->m_id);
189  for(int k = 0; k < it->second.size(); k++)
190  {
191  neigh.insert(it->second[k]->GetId());
192  }
193  }
194  }
195  }
196 
197  el.clear();
198  for(int i = 0; i < els.size(); i++)
199  {
200  auto it1 = neigh.find(els[i]->GetId());
201  auto it2 = clearedElmts.find(els[i]->GetId());
202  if(it1 != neigh.end() && it2 == clearedElmts.end())
203  {
204  el.push_back(els[i]);
205  }
206  }
207  neigh.clear();
208  }
209 
210  if (m_mesh->m_verbose)
211  {
212  cerr << "Removed curvature from " << clearedElmts.size()
213  << " elements (" << clearedEdges.size() << " edges, "
214  << clearedFaces.size() << " faces)" << endl;
215  }
216 
217  if(m_config["extract"].beenSet)
218  {
219  MeshSharedPtr dmp = std::shared_ptr<Mesh>(new Mesh());
220  dmp->m_expDim = 3;
221  dmp->m_spaceDim = 3;
222  dmp->m_nummode = 2;
223 
224  dmp->m_element[3] = dumpEls;
225 
227  ModuleKey(eOutputModule, "xml"), dmp);
228  mod->RegisterConfig("outfile", m_config["extract"].as<string>().c_str());
229  mod->ProcessVertices();
230  mod->ProcessEdges();
231  mod->ProcessFaces();
232  mod->ProcessElements();
233  mod->ProcessComposites();
234  mod->Process();
235  }
236  }
237 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::shared_ptr< Module > ModuleSharedPtr
std::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:156
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
std::pair< ModuleType, std::string > ModuleKey
bool Invalid(NekMeshUtils::ElementSharedPtr el, NekDouble thr)
double NekDouble
std::map< std::string, ConfigOption > m_config
List of configuration values.
ModuleFactory & GetModuleFactory()

Member Data Documentation

◆ className

ModuleKey Nektar::Utilities::ProcessLinear::className
static
Initial value:

Definition at line 56 of file ProcessLinear.h.