Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
Nektar::FieldUtils::ProcessQualityMetric Class Reference

This processing module scales the input fld file. More...

#include <ProcessQualityMetric.h>

Inheritance diagram for Nektar::FieldUtils::ProcessQualityMetric:
Inheritance graph
[legend]
Collaboration diagram for Nektar::FieldUtils::ProcessQualityMetric:
Collaboration graph
[legend]

Public Member Functions

 ProcessQualityMetric (FieldSharedPtr f)
 
virtual ~ProcessQualityMetric ()
 
virtual void Process (po::variables_map &vm)
 Write mesh to output file. More...
 
virtual std::string GetModuleName ()
 
- Public Member Functions inherited from Nektar::FieldUtils::ProcessModule
 ProcessModule ()
 
 ProcessModule (FieldSharedPtr p_f)
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
FIELD_UTILS_EXPORT void RegisterConfig (string key, string value)
 Register a configuration option with a module. More...
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
FIELD_UTILS_EXPORT bool GetRequireEquiSpaced (void)
 
FIELD_UTILS_EXPORT void SetRequireEquiSpaced (bool pVal)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

static boost::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 

Static Public Attributes

static ModuleKey className
 

Private Member Functions

Array< OneD, NekDoubleGetQ (LocalRegions::ExpansionSharedPtr e, bool s)
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 

Detailed Description

This processing module scales the input fld file.

Definition at line 47 of file ProcessQualityMetric.h.

Constructor & Destructor Documentation

Nektar::FieldUtils::ProcessQualityMetric::ProcessQualityMetric ( FieldSharedPtr  f)

Definition at line 62 of file ProcessQualityMetric.cpp.

References Nektar::FieldUtils::Module::m_config.

62  : ProcessModule(f)
63 {
64  m_config["scaled"] =
65  ConfigOption(true, "", "use scaled jacobian instead");
66 }
map< string, ConfigOption > m_config
List of configuration values.
Nektar::FieldUtils::ProcessQualityMetric::~ProcessQualityMetric ( )
virtual

Definition at line 68 of file ProcessQualityMetric.cpp.

69 {
70 }

Member Function Documentation

static boost::shared_ptr<Module> Nektar::FieldUtils::ProcessQualityMetric::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 51 of file ProcessQualityMetric.h.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

52  {
54  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
virtual std::string Nektar::FieldUtils::ProcessQualityMetric::GetModuleName ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 63 of file ProcessQualityMetric.h.

64  {
65  return "ProcessQualityMetric";
66  }
Array< OneD, NekDouble > Nektar::FieldUtils::ProcessQualityMetric::GetQ ( LocalRegions::ExpansionSharedPtr  e,
bool  s 
)
private

Definition at line 392 of file ProcessQualityMetric.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::eFULL, Nektar::LibUtilities::eHexahedron, Nektar::LibUtilities::ePrism, Nektar::LibUtilities::eQuadrilateral, Nektar::LibUtilities::eTetrahedron, Nektar::LibUtilities::eTriangle, ErrorUtil::ewarning, Vmath::Fill(), Nektar::LibUtilities::Interp2D(), Nektar::LibUtilities::Interp3D(), Nektar::FieldUtils::MappingIdealToRef(), NEKERROR, and CellMLToNektar.cellml_metadata::p.

Referenced by Process().

395 {
396  SpatialDomains::GeometrySharedPtr geom = e->GetGeom();
397  StdRegions::StdExpansionSharedPtr chi = e->GetGeom()->GetXmap();
398  LibUtilities::PointsKeyVector p = chi->GetPointsKeys();
399  LibUtilities::PointsKeyVector pElem = e->GetPointsKeys();
400  SpatialDomains::GeomFactorsSharedPtr gfac = geom->GetGeomFactors();
401  const int expDim = chi->GetNumBases();
402  int nElemPts = 1;
403 
404  vector<LibUtilities::BasisKey> basisKeys;
405  bool needsInterp = false;
406 
407  for (int i = 0; i < expDim; ++i)
408  {
409  nElemPts *= pElem[i].GetNumPoints();
410  needsInterp =
411  needsInterp || pElem[i].GetNumPoints() < p[i].GetNumPoints() - 1;
412  }
413 
414  if (needsInterp)
415  {
416  stringstream err;
417  err << "Interpolating from higher order geometry to lower order in "
418  << "element " << geom->GetGlobalID();
419  NEKERROR(ErrorUtil::ewarning, err.str());
420  }
421 
422  for (int i = 0; i < expDim; ++i)
423  {
424  basisKeys.push_back(
425  needsInterp
426  ? chi->GetBasis(i)->GetBasisKey()
427  : LibUtilities::BasisKey(chi->GetBasisType(i),
428  chi->GetBasisNumModes(i), pElem[i]));
429  }
430 
432  switch (chi->DetShapeType())
433  {
436  basisKeys[0], basisKeys[1]);
437  break;
440  basisKeys[0], basisKeys[1]);
441  break;
444  basisKeys[0], basisKeys[1], basisKeys[2]);
445  break;
448  basisKeys[0], basisKeys[1], basisKeys[2]);
449  break;
452  basisKeys[0], basisKeys[1], basisKeys[2]);
453  break;
454  default:
455  ASSERTL0(false, "nope");
456  }
457 
458  SpatialDomains::DerivStorage deriv = gfac->GetDeriv(pElem);
459 
460  const int pts = deriv[0][0].num_elements();
461  const int nq = chiMod->GetTotPoints();
462 
463  ASSERTL0(pts == nq, "what");
464 
465  vector<DNekMat> i2rm = MappingIdealToRef(geom, chiMod);
466  Array<OneD, NekDouble> eta(nq);
467 
468  for (int k = 0; k < pts; ++k)
469  {
470  DNekMat jac(expDim, expDim, 0.0, eFULL);
471  DNekMat jacIdeal(expDim, expDim, 0.0, eFULL);
472 
473  for (int i = 0; i < expDim; ++i)
474  {
475  for (int j = 0; j < expDim; ++j)
476  {
477  jac(j, i) = deriv[i][j][k];
478  }
479  }
480 
481  jacIdeal = jac * i2rm[k];
482  NekDouble jacDet;
483 
484  if (expDim == 2)
485  {
486  jacDet = jacIdeal(0, 0) * jacIdeal(1, 1) -
487  jacIdeal(0, 1) * jacIdeal(1, 0);
488  }
489  else if (expDim == 3)
490  {
491  jacDet = jacIdeal(0, 0) * (jacIdeal(1, 1) * jacIdeal(2, 2) -
492  jacIdeal(2, 1) * jacIdeal(1, 2)) -
493  jacIdeal(0, 1) * (jacIdeal(1, 0) * jacIdeal(2, 2) -
494  jacIdeal(2, 0) * jacIdeal(1, 2)) +
495  jacIdeal(0, 2) * (jacIdeal(1, 0) * jacIdeal(2, 1) -
496  jacIdeal(2, 0) * jacIdeal(1, 1));
497  }
498  else
499  {
500  ASSERTL0(false, "silly exp dim");
501  }
502 
503  if(s)
504  {
505  eta[k] = jacDet;
506  }
507  else
508  {
509  NekDouble frob = 0.0;
510 
511  for (int i = 0; i < expDim; ++i)
512  {
513  for (int j = 0; j < expDim; ++j)
514  {
515  frob += jacIdeal(i,j) * jacIdeal(i,j);
516  }
517  }
518 
519  NekDouble sigma = 0.5*(jacDet + sqrt(jacDet*jacDet));
520  eta[k] = expDim * pow(sigma, 2.0/expDim) / frob;
521  }
522  }
523 
524  if(s)
525  {
526  NekDouble mx = -1.0 * numeric_limits<double>::max();
527  NekDouble mn = numeric_limits<double>::max();
528  for(int k = 0; k < pts; k++)
529  {
530  mx = max(mx,eta[k]);
531  mn = min(mn,eta[k]);
532  }
533  for(int k = 0; k < pts; k++)
534  {
535  eta[k] = mn/mx;
536  }
537  }
538 
539  // Project onto output stuff
540  if (needsInterp && pts != 1)
541  {
542  Array<OneD, NekDouble> tmp(nElemPts);
543 
544  if (expDim == 2)
545  {
546  LibUtilities::Interp2D(p[0], p[1], eta, pElem[0], pElem[1], tmp);
547  }
548  else if (expDim == 3)
549  {
550  LibUtilities::Interp3D(p[0], p[1], p[2], eta, pElem[0], pElem[1],
551  pElem[2], tmp);
552  }
553  else
554  {
555  ASSERTL0(false, "mesh dim makes no sense");
556  }
557 
558  eta = tmp;
559  }
560 
561  if (pts == 1)
562  {
563  Vmath::Fill(nq - 1, eta[0], &eta[1], 1);
564  }
565 
566  return eta;
567 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
vector< DNekMat > MappingIdealToRef(SpatialDomains::GeometrySharedPtr geom, StdRegions::StdExpansionSharedPtr chi)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:191
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:242
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:46
void Interp2D(const BasisKey &fbasis0, const BasisKey &fbasis1, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, Array< OneD, NekDouble > &to)
this function interpolates a 2D function evaluated at the quadrature points of the 2D basis...
Definition: Interp.cpp:116
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > DerivStorage
Storage type for derivative of mapping.
Definition: GeomFactors.h:75
NekMatrix< NekDouble, StandardMatrixTag > DNekMat
Definition: NekTypeDefs.hpp:52
double NekDouble
void Interp3D(const BasisKey &fbasis0, const BasisKey &fbasis1, const BasisKey &fbasis2, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, const BasisKey &tbasis2, Array< OneD, NekDouble > &to)
this function interpolates a 3D function evaluated at the quadrature points of the 3D basis...
Definition: Interp.cpp:186
boost::shared_ptr< GeomFactors > GeomFactorsSharedPtr
Pointer to a GeomFactors object.
Definition: GeomFactors.h:62
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
boost::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
void Nektar::FieldUtils::ProcessQualityMetric::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

Implements Nektar::FieldUtils::Module.

Definition at line 72 of file ProcessQualityMetric.cpp.

References ASSERTL0, GetQ(), Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, and Vmath::Vcopy().

73 {
74  if (m_f->m_verbose)
75  {
76  if (m_f->m_comm->TreatAsRankZero())
77  {
78  cout << "ProcessQualityMetric: Adding quality metric to field"
79  << endl;
80  }
81  }
82 
83  Array<OneD, NekDouble> &phys = m_f->m_exp[0]->UpdatePhys();
84  Array<OneD, NekDouble> &coeffs = m_f->m_exp[0]->UpdateCoeffs();
85 
86  for (int i = 0; i < m_f->m_exp[0]->GetExpSize(); ++i)
87  {
88  // copy Jacobian into field
89  LocalRegions::ExpansionSharedPtr Elmt = m_f->m_exp[0]->GetExp(i);
90  int offset = m_f->m_exp[0]->GetPhys_Offset(i);
91  Array<OneD, NekDouble> q = GetQ(Elmt,m_config["scaled"].m_beenSet);
92  Array<OneD, NekDouble> out = phys + offset;
93 
94  ASSERTL0(q.num_elements() == Elmt->GetTotPoints(),
95  "number of points mismatch");
96  Vmath::Vcopy(q.num_elements(), q, 1, out, 1);
97  }
98 
99  m_f->m_exp[0]->FwdTrans_IterPerExp(phys, coeffs);
100 
101  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
102  m_f->m_exp[0]->GetFieldDefinitions();
103  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
104 
105  for (int i = 0; i < FieldDef.size(); ++i)
106  {
107  FieldDef[i]->m_fields.push_back("QualityMetric");
108  m_f->m_exp[0]->AppendFieldData(FieldDef[i], FieldData[i]);
109  }
110 
111  m_f->m_fielddef = FieldDef;
112  m_f->m_data = FieldData;
113 }
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
boost::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:68
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1061
Array< OneD, NekDouble > GetQ(LocalRegions::ExpansionSharedPtr e, bool s)
FieldSharedPtr m_f
Field object.

Member Data Documentation

ModuleKey Nektar::FieldUtils::ProcessQualityMetric::className
static
Initial value:
=
ModuleKey(eProcessModule, "qualitymetric"),
"add quality metric to field.")

Definition at line 55 of file ProcessQualityMetric.h.