Nektar++
ProcessJac.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessJac.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Calculate Jacobians of elements.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include "../MeshElements.h"
37 #include "ProcessJac.h"
38 
40 #include <LibUtilities/Foundations/ManagerAccess.h> // for PointsManager, etc
41 
42 #include <vector>
43 using namespace std;
44 
45 namespace Nektar
46 {
47  namespace Utilities
48  {
49  ModuleKey ProcessJac::className =
51  ModuleKey(eProcessModule, "jac"), ProcessJac::create,
52  "Process elements based on values of Jacobian.");
53 
54  ProcessJac::ProcessJac(MeshSharedPtr m) : ProcessModule(m)
55  {
56  m_config["extract"] = ConfigOption(
57  true, "0", "Extract non-valid elements from mesh.");
58  m_config["removecurveifsingular"] = ConfigOption(
59  true, "0", "remove curve nodes if element is singular.");
60  m_config["list"] = ConfigOption(
61  true, "0", "Print list of elements having negative Jacobian.");
62  }
63 
65  {
66 
67  }
68 
70  {
71  if (m_mesh->m_verbose)
72  {
73  cout << "ProcessJac: Calculating Jacobians... " << endl;
74  }
75 
76  bool extract = m_config["extract"].as<bool>();
77  bool printList = m_config["list"].as<bool>();
78  bool RemoveCurveIfSingular = m_config["removecurveifsingular"].as<bool>();
79  vector<ElementSharedPtr> el = m_mesh->m_element[m_mesh->m_expDim];
80 
81  if (extract)
82  {
83  m_mesh->m_element[m_mesh->m_expDim].clear();
84  }
85 
86  if (printList)
87  {
88  cout << "Elements with negative Jacobian:" << endl;
89  }
90 
91  int nNeg = 0;
92 
93  // Iterate over list of elements of expansion dimension.
94  for (int i = 0; i < el.size(); ++i)
95  {
96  // Create elemental geometry.
98  el[i]->GetGeom(m_mesh->m_spaceDim);
99 
100  // Generate geometric factors.
102  geom->GetGeomFactors();
103 
104  // Get the Jacobian and, if it is negative, print a warning
105  // message.
106  if (!gfac->IsValid())
107  {
108  nNeg++;
109 
110  if (printList)
111  {
112  cout << " - " << el[i]->GetId() << " ("
113  << StdRegions::ElementTypeMap[el[i]->GetConf().m_e]
114  << ")" << endl;
115  }
116 
117  if(RemoveCurveIfSingular)
118  {
119  int nSurf = el[i]->GetFaceCount();
120  if(nSurf == 5) // prism mesh
121  {
122  // find edges ndoes and blend to far side.
123  for(int e = 0; e < el[i]->GetEdgeCount(); ++e)
124  {
125  EdgeSharedPtr ed = el[i]->GetEdge(e);
126  EdgeSet::iterator it;
127  // find edge in m_edgeSet;
128  if((it = m_mesh->m_edgeSet.find(ed)) != m_mesh->m_edgeSet.end())
129  {
130  if((*it)->m_edgeNodes.size())
131  {
132  vector<NodeSharedPtr> zeroNodes;
133  (*it)->m_edgeNodes = zeroNodes;
134  }
135  }
136  }
137  }
138  }
139 
140  if (extract)
141  {
142  m_mesh->m_element[m_mesh->m_expDim].push_back(el[i]);
143  }
144  }
145  }
146 
147  if (extract)
148  {
149  m_mesh->m_element[m_mesh->m_expDim-1].clear();
150  ProcessVertices();
151  ProcessEdges();
152  ProcessFaces();
153  ProcessElements();
155  }
156 
157  if (printList || m_mesh->m_verbose)
158  {
159  cout << "Total negative Jacobians: " << nNeg << endl;
160  }
161  else if (nNeg > 0)
162  {
163  cout << "WARNING: Detected " << nNeg << " element"
164  << (nNeg == 1 ? "" : "s") << " with negative Jacobian."
165  << endl;
166  }
167  }
168  }
169 }
virtual void Process()
Write mesh to output file.
Definition: ProcessJac.cpp:69
pair< ModuleType, string > ModuleKey
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: MeshElements.h:318
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
MeshSharedPtr m_mesh
Mesh object.
virtual void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
virtual void ProcessVertices()
Extract element vertices.
virtual void ProcessElements()
Generate element IDs.
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
virtual void ProcessComposites()
Generate composites.
const char *const ElementTypeMap[]
Definition: StdRegions.hpp:76
Represents a command-line configuration option.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
boost::shared_ptr< GeomFactors > GeomFactorsSharedPtr
Pointer to a GeomFactors object.
Definition: GeomFactors.h:62
virtual void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
boost::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
ModuleFactory & GetModuleFactory()
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215