Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProcessJacobianEnergy.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessJacobianEnergy.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: Compute energy of Jacobian.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include "ProcessJacobianEnergy.h"
41 
44 
45 namespace Nektar
46 {
47 namespace Utilities
48 {
49 
50 ModuleKey ProcessJacobianEnergy::className =
52  ModuleKey(eProcessModule, "jacobianenergy"),
53  ProcessJacobianEnergy::create,
54  "Show high frequency energy of Jacobian.");
55 
56 ProcessJacobianEnergy::ProcessJacobianEnergy(FieldSharedPtr f) :
57  ProcessModule(f)
58 {
59  m_config["topmodes"] = ConfigOption(false, "1",
60  "how many top modes to keep ");
61 }
62 
64 {
65 }
66 
67 void ProcessJacobianEnergy::Process(po::variables_map &vm)
68 {
69  if (m_f->m_verbose)
70  {
71  if(m_f->m_comm->TreatAsRankZero())
72  {
73  cout << "ProcessJacobianEnergy: Processing Jacobian..." << endl;
74  }
75  }
76 
77  Array<OneD, NekDouble> phys = m_f->m_exp[0]->UpdatePhys();
78  Array<OneD, NekDouble> coeffs = m_f->m_exp[0]->UpdateCoeffs();
79  Array<OneD, NekDouble> tmp,tmp1;
80 
81  for(int i =0; i < m_f->m_exp[0]->GetExpSize(); ++i)
82  {
83  // copy Jacobian into field
84  StdRegions::StdExpansionSharedPtr Elmt = m_f->m_exp[0]->GetExp(i);
85 
86  int ncoeffs = Elmt->GetNcoeffs();
87  int nquad = Elmt->GetTotPoints();
88  int coeffoffset = m_f->m_exp[0]->GetCoeff_Offset(i);
89  Array<OneD, NekDouble> coeffs1(ncoeffs);
91  Elmt->GetMetricInfo()->GetJac(Elmt->GetPointsKeys());
92  if(Elmt->GetMetricInfo()->GetGtype() == SpatialDomains::eRegular)
93  {
94  Vmath::Fill(nquad,Jac[0],phys,1);
95  }
96  else
97  {
98  Vmath::Vcopy(nquad,Jac,1,phys,1);
99  }
100 
101  if(Elmt->GetMetricInfo()->GetGtype() == SpatialDomains::eDeformed)
102  {
103  NekDouble jacmax = Vmath::Vmax(nquad,Jac,1);
104  NekDouble jacmin = Vmath::Vmin(nquad,Jac,1);
105 
106  NekDouble jacmeasure = jacmax/jacmin -1.0;
107  Vmath::Fill(nquad,jacmeasure,phys,1);
108  }
109  else
110  {
111  Vmath::Fill(nquad,0.0,phys,1);
112  }
113 
114  Elmt->FwdTrans(phys,tmp = coeffs + coeffoffset);
115  }
116 
117  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
118  = m_f->m_exp[0]->GetFieldDefinitions();
119  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
120 
121  for (int i = 0; i < FieldDef.size(); ++i)
122  {
123  FieldDef[i]->m_fields.push_back("JacobianEnergy");
124  m_f->m_exp[0]->AppendFieldData(FieldDef[i], FieldData[i]);
125  }
126 
127  m_f->m_fielddef = FieldDef;
128  m_f->m_data = FieldData;
129 }
130 
131 }
132 }
pair< ModuleType, string > ModuleKey
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:765
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:857
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:46
virtual void Process()=0
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
FieldSharedPtr m_f
Field object.
double NekDouble
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:698
Represents a command-line configuration option.
Geometry is straight-sided with constant geometric factors.
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1047
Geometry is curved or has non-constant factors.
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