Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
37 #include "ProcessJac.h"
38 
39 using namespace std;
40 using namespace Nektar::NekMeshUtils;
41 
42 namespace Nektar
43 {
44 namespace Utilities
45 {
46 
47 ModuleKey ProcessJac::className = GetModuleFactory().RegisterCreatorFunction(
48  ModuleKey(eProcessModule, "jac"),
49  ProcessJac::create,
50  "Process elements based on values of Jacobian.");
51 
52 ProcessJac::ProcessJac(MeshSharedPtr m) : ProcessModule(m)
53 {
54  m_config["extract"] =
55  ConfigOption(true, "0", "Extract non-valid elements from mesh.");
56  m_config["list"] = ConfigOption(
57  true, "0", "Print list of elements having negative Jacobian.");
58 }
59 
61 {
62 }
63 
65 {
66  if (m_mesh->m_verbose)
67  {
68  cout << "ProcessJac: Calculating Jacobians... " << endl;
69  }
70 
71  bool extract = m_config["extract"].as<bool>();
72  bool printList = m_config["list"].as<bool>();
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  // Get the Jacobian and, if it is negative, print a warning
101  // message.
102  if (!gfac->IsValid())
103  {
104  nNeg++;
105 
106  if (printList)
107  {
108  cout << " - " << el[i]->GetId() << " ("
109  << LibUtilities::ShapeTypeMap[el[i]->GetConf().m_e] << ")"
110  << endl;
111  }
112 
113  if (extract)
114  {
115  m_mesh->m_element[m_mesh->m_expDim].push_back(el[i]);
116  }
117  }
118  }
119 
120  if (extract)
121  {
122  m_mesh->m_element[m_mesh->m_expDim - 1].clear();
123  ProcessVertices();
124  ProcessEdges();
125  ProcessFaces();
126  ProcessElements();
128  }
129 
130  if (printList || m_mesh->m_verbose)
131  {
132  cout << "Total negative Jacobians: " << nNeg << endl;
133  }
134  else if (nNeg > 0)
135  {
136  cout << "WARNING: Detected " << nNeg << " element"
137  << (nNeg == 1 ? "" : "s") << " with negative Jacobian." << endl;
138  }
139 }
140 }
141 }
virtual void Process()
Write mesh to output file.
Definition: ProcessJac.cpp:64
pair< ModuleType, string > ModuleKey
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
MeshSharedPtr m_mesh
Mesh object.
const char *const ShapeTypeMap[]
Definition: ShapeType.hpp:66
virtual void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
virtual void ProcessVertices()
Extract element vertices.
virtual void ProcessElements()
Generate element IDs.
virtual void ProcessComposites()
Generate composites.
Represents a command-line configuration option.
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:137
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