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 
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["list"] = ConfigOption(
59  true, "0", "Print list of elements having negative Jacobian.");
60  }
61 
63  {
64 
65  }
66 
68  {
69  if (m_mesh->m_verbose)
70  {
71  cout << "ProcessJac: Calculating Jacobians... " << endl;
72  }
73 
74  bool extract = m_config["extract"].as<bool>();
75  bool printList = m_config["list"].as<bool>();
76 
77  vector<ElementSharedPtr> el = m_mesh->m_element[m_mesh->m_expDim];
78 
79  if (extract)
80  {
81  m_mesh->m_element[m_mesh->m_expDim].clear();
82  }
83 
84  if (printList)
85  {
86  cout << "Elements with negative Jacobian:" << endl;
87  }
88 
89  int nNeg = 0;
90 
91  // Iterate over list of elements of expansion dimension.
92  for (int i = 0; i < el.size(); ++i)
93  {
94  // Create elemental geometry.
96  el[i]->GetGeom(m_mesh->m_spaceDim);
97 
98  // Generate geometric factors.
100  geom->GetGeomFactors();
101 
102  // Get the Jacobian and, if it is negative, print a warning
103  // message.
104  if (!gfac->IsValid())
105  {
106  nNeg++;
107 
108  if (printList)
109  {
110  cout << " - " << el[i]->GetId() << " ("
111  << StdRegions::ElementTypeMap[el[i]->GetConf().m_e]
112  << ")" << endl;
113  }
114 
115  if (extract)
116  {
117  m_mesh->m_element[m_mesh->m_expDim].push_back(el[i]);
118  }
119  }
120  }
121 
122  if (extract)
123  {
124  m_mesh->m_element[m_mesh->m_expDim-1].clear();
125  ProcessVertices();
126  ProcessEdges();
127  ProcessFaces();
128  ProcessElements();
130  }
131 
132  if (printList || m_mesh->m_verbose)
133  {
134  cout << "Total negative Jacobians: " << nNeg << endl;
135  }
136  else if (nNeg > 0)
137  {
138  cout << "WARNING: Detected " << nNeg << " element"
139  << (nNeg == 1 ? "" : "s") << " with negative Jacobian."
140  << endl;
141  }
142  }
143  }
144 }