Nektar++
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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Compute energy of Jacobian.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <string>
37 using namespace std;
38 
39 #include <boost/core/ignore_unused.hpp>
40 
42 
43 #include "ProcessJacobianEnergy.h"
44 
45 namespace Nektar
46 {
47 namespace FieldUtils
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"] =
60  ConfigOption(false, "1", "how many top modes to keep ");
61 }
62 
64 {
65 }
66 
67 void ProcessJacobianEnergy::Process(po::variables_map &vm)
68 {
69  m_f->SetUpExp(vm);
70 
71  int nfields = m_f->m_variables.size();
72  m_f->m_variables.push_back("jacenergy");
73  // Skip in case of empty partition
74  if (m_f->m_exp[0]->GetNumElmts() == 0)
75  {
76  return;
77  }
78 
79  int NumHomogeneousDir = m_f->m_numHomogeneousDir;
81 
82  if (nfields)
83  {
84  m_f->m_exp.resize(nfields + 1);
85  exp = m_f->AppendExpList(NumHomogeneousDir);
86 
87  m_f->m_exp[nfields] = exp;
88  }
89  else
90  {
91  exp = m_f->m_exp[0];
92  }
93 
94  Array<OneD, NekDouble> phys = exp->UpdatePhys();
95  Array<OneD, NekDouble> coeffs = exp->UpdateCoeffs();
97 
98  for (int i = 0; i < exp->GetExpSize(); ++i)
99  {
100  // copy Jacobian into field
101  StdRegions::StdExpansionSharedPtr Elmt = exp->GetExp(i);
102 
103  const StdRegions::StdExpansion *sep = &(*Elmt);
104  const LocalRegions::Expansion *lep =
105  dynamic_cast<const LocalRegions::Expansion *>(sep);
106 
107  int nquad = Elmt->GetTotPoints();
108  int coeffoffset = exp->GetCoeff_Offset(i);
110  lep->GetMetricInfo()->GetJac(Elmt->GetPointsKeys());
111  if (lep->GetMetricInfo()->GetGtype() == SpatialDomains::eRegular)
112  {
113  Vmath::Fill(nquad, Jac[0], phys, 1);
114  }
115  else
116  {
117  Vmath::Vcopy(nquad, Jac, 1, phys, 1);
118  }
119 
120  if (lep->GetMetricInfo()->GetGtype() == SpatialDomains::eDeformed)
121  {
122  NekDouble jacmax = Vmath::Vmax(nquad, Jac, 1);
123  NekDouble jacmin = Vmath::Vmin(nquad, Jac, 1);
124 
125  NekDouble jacmeasure = jacmax / jacmin - 1.0;
126  Vmath::Fill(nquad, jacmeasure, phys, 1);
127  }
128  else
129  {
130  Vmath::Fill(nquad, 0.0, phys, 1);
131  }
132 
133  Elmt->FwdTrans(phys, tmp = coeffs + coeffoffset);
134  }
135  exp->BwdTrans(coeffs, phys);
136 }
137 } // namespace FieldUtils
138 } // namespace Nektar
FieldSharedPtr m_f
Field object.
Definition: Module.h:225
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:228
virtual void Process(po::variables_map &vm)
Write mesh to output file.
Abstract base class for processing modules.
Definition: Module.h:260
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
const SpatialDomains::GeomFactorsSharedPtr & GetMetricInfo() const
Definition: Expansion.cpp:245
The base class for all shapes.
Definition: StdExpansion.h:71
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
Definition: StdExpansion.h:140
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:989
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:285
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
@ eRegular
Geometry is straight-sided with constant geometric factors.
@ eDeformed
Geometry is curved or has non-constant factors.
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble
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:1050
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45
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:945
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255
Represents a command-line configuration option.
Definition: Module.h:131