Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Nektar::FieldUtils::ProcessMapping Class Reference

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

#include <ProcessMapping.h>

Inheritance diagram for Nektar::FieldUtils::ProcessMapping:
[legend]

Public Member Functions

 ProcessMapping (FieldSharedPtr f)
 
virtual ~ProcessMapping ()
 
- 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)
 
virtual ~Module ()=default
 
void Process (po::variables_map &vm)
 
std::string GetModuleName ()
 
std::string GetModuleDescription ()
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
ModulePriority GetModulePriority ()
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::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 void AddFile (std::string fileType, std::string fileName)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

static std::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 
static GlobalMapping::MappingSharedPtr GetMapping (FieldSharedPtr f)
 

Static Public Attributes

static ModuleKey className
 

Protected Member Functions

virtual void v_Process (po::variables_map &vm) override
 Write mesh to output file. More...
 
virtual std::string v_GetModuleName () override
 
virtual std::string v_GetModuleDescription () override
 
virtual ModulePriority v_GetModulePriority () override
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 
std::set< std::string > m_allowedFiles
 List of allowed file formats. More...
 

Detailed Description

This processing module scales the input fld file.

Definition at line 50 of file ProcessMapping.h.

Constructor & Destructor Documentation

◆ ProcessMapping()

Nektar::FieldUtils::ProcessMapping::ProcessMapping ( FieldSharedPtr  f)

Definition at line 54 of file ProcessMapping.cpp.

54  : ProcessModule(f)
55 {
56 }

◆ ~ProcessMapping()

Nektar::FieldUtils::ProcessMapping::~ProcessMapping ( )
virtual

Definition at line 58 of file ProcessMapping.cpp.

59 {
60 }

Member Function Documentation

◆ create()

static std::shared_ptr<Module> Nektar::FieldUtils::ProcessMapping::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 54 of file ProcessMapping.h.

55  {
57  }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

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

◆ GetMapping()

GlobalMapping::MappingSharedPtr Nektar::FieldUtils::ProcessMapping::GetMapping ( FieldSharedPtr  f)
static

Definition at line 153 of file ProcessMapping.cpp.

154 {
155  // Create mapping object
156  Array<OneD, MultiRegions::ExpListSharedPtr> field(1);
157  field[0] = f->m_exp[0];
159  GlobalMapping::Mapping::Load(f->m_session, field);
160 
161  // Get time from metadata
162  NekDouble time;
163  if (f->m_fieldMetaDataMap.count("Time"))
164  {
165  string s_time = f->m_fieldMetaDataMap["Time"];
166  time = atof(s_time.c_str());
167  }
168  else
169  {
170  time = 0.0;
171  }
172 
173  // Get field information
174  int npoints = f->m_exp[0]->GetNpoints();
175  int expdim = f->m_graph->GetMeshDimension();
176  int spacedim = expdim + f->m_numHomogeneousDir;
177 
178  // Declare coordinates storage
179  Array<OneD, Array<OneD, NekDouble>> coords_new(3);
180  Array<OneD, Array<OneD, NekDouble>> coords_vel(3);
181  for (int i = 0; i < 3; i++)
182  {
183  coords_new[i] = Array<OneD, NekDouble>(npoints);
184  coords_vel[i] = Array<OneD, NekDouble>(npoints, 0.0);
185  }
186 
187  string fieldNames[3] = {"x", "y", "z"};
188  string velFieldNames[3] = {"vx", "vy", "vz"};
189 
190  // Evaluate coordinates and coordinates velocity
191  if (f->m_fieldMetaDataMap.count("MappingType"))
192  {
193  if (f->m_fieldMetaDataMap["MappingType"] == "Expression")
194  {
195  // Get name of the functions
196  string funcName;
197  string velFuncName;
198  if (f->m_fieldMetaDataMap.count("MappingExpression"))
199  {
200  funcName = f->m_fieldMetaDataMap["MappingExpression"];
201  }
202  else
203  {
204  funcName = "";
205  }
206  if (f->m_fieldMetaDataMap.count("MappingVelExpression"))
207  {
208  velFuncName = f->m_fieldMetaDataMap["MappingVelExpression"];
209  }
210  else
211  {
212  velFuncName = "";
213  }
214 
215  // Get original coordinates (in case some of them are not changed)
216  Array<OneD, Array<OneD, NekDouble>> coords(3);
217  for (int i = 0; i < 3; i++)
218  {
219  coords[i] = Array<OneD, NekDouble>(npoints);
220  }
221  f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
222 
223  // Load coordinates
224  std::string s_FieldStr;
225  for (int i = 0; i < 3; i++)
226  {
227  s_FieldStr = fieldNames[i];
228  if (f->m_session->DefinesFunction(funcName, s_FieldStr))
229  {
231  f->m_session->GetFunction(funcName, s_FieldStr);
232  ffunc->Evaluate(coords[0], coords[1], coords[2], time,
233  coords_new[i]);
234  }
235  else
236  {
237  // This coordinate is not defined, so use (x^i)' = x^i
238  Vmath::Vcopy(npoints, coords[i], 1, coords_new[i], 1);
239  }
240  }
241  // Load velocities
242  if (f->m_session->DefinesFunction(velFuncName))
243  {
244  for (int i = 0; i < 3; i++)
245  {
246  s_FieldStr = velFieldNames[i];
247  if (f->m_session->DefinesFunction(velFuncName, s_FieldStr))
248  {
250  f->m_session->GetFunction(velFuncName, s_FieldStr);
251  ffunc->Evaluate(coords[0], coords[1], coords[2], time,
252  coords_vel[i]);
253  }
254  }
255  }
256 
257  // Update mapping with coordinates
258  mapping->SetFromFunction(false);
259  mapping->UpdateMapping(time, coords_new, coords_vel);
260  }
261  else if (f->m_fieldMetaDataMap["MappingType"] == "File")
262  {
263  ASSERTL0(f->m_fieldMetaDataMap.count("FileName"),
264  "FileName parameter for Mapping missing in field file.");
265  string fileName = f->m_fieldMetaDataMap["FileName"];
266  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
267  std::vector<std::vector<NekDouble>> FieldData;
268 
269  f->FieldIOForFile(fileName)->Import(fileName, FieldDef, FieldData);
270 
271  for (int j = 0; j < spacedim; ++j)
272  {
273  int ncoeffs = f->m_exp[0]->GetNcoeffs();
274  Array<OneD, NekDouble> fieldcoeffs(ncoeffs, 0.0);
275  for (int i = 0; i < FieldData.size(); ++i)
276  {
277  f->m_exp[j]->ExtractDataToCoeffs(
278  FieldDef[i], FieldData[i], fieldNames[j], fieldcoeffs);
279  }
280  bool wavespace = f->m_exp[0]->GetWaveSpace();
281  f->m_exp[0]->SetWaveSpace(false);
282 
283  f->m_exp[0]->BwdTrans(fieldcoeffs, coords_new[j]);
284 
285  // Load coordinate velocity
286  if (std::find(FieldDef[0]->m_fields.begin(),
287  FieldDef[0]->m_fields.end(),
288  velFieldNames[j]) != FieldDef[0]->m_fields.end())
289  {
290  for (int i = 0; i < FieldData.size(); ++i)
291  {
292  f->m_exp[j]->ExtractDataToCoeffs(
293  FieldDef[i], FieldData[i], velFieldNames[j],
294  fieldcoeffs);
295  }
296  f->m_exp[0]->BwdTrans(fieldcoeffs, coords_vel[j]);
297  }
298  f->m_exp[0]->SetWaveSpace(wavespace);
299  }
300  // Update mapping with coordinates
301  mapping->SetFromFunction(false);
302  mapping->UpdateMapping(time, coords_new, coords_vel);
303  }
304  }
305  else
306  {
307  // Use trivial mapping
308  Array<OneD, Array<OneD, NekDouble>> coords(3);
309  Array<OneD, Array<OneD, NekDouble>> coords_vel(3);
310  for (int i = 0; i < 3; i++)
311  {
312  coords[i] = Array<OneD, NekDouble>(npoints);
313  coords_vel[i] = Array<OneD, NekDouble>(npoints, 0.0);
314  }
315  f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
316  mapping->SetFromFunction(false);
317  mapping->UpdateMapping(time, coords, coords_vel);
318  }
319 
320  return mapping;
321 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
static GLOBAL_MAPPING_EXPORT MappingSharedPtr Load(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
Return a pointer to the mapping, creating it on first call.
Definition: Mapping.cpp:270
GLOBAL_MAPPING_EXPORT typedef std::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
Definition: Mapping.h:50
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:129
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:444
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255

References ASSERTL0, Nektar::StdRegions::find(), Nektar::GlobalMapping::Mapping::Load(), Nektar::GlobalMapping::MappingSharedPtr, and Vmath::Vcopy().

Referenced by Nektar::FieldUtils::ProcessBodyFittedVelocity::GetVelAndConvertToCartSys(), Nektar::FieldUtils::ProcessGrad::ProcessMappingFld(), v_Process(), Nektar::FieldUtils::ProcessVelocityDivergence::v_Process(), and Nektar::FieldUtils::ProcessVorticity::v_Process().

◆ v_GetModuleDescription()

virtual std::string Nektar::FieldUtils::ProcessMapping::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 74 of file ProcessMapping.h.

75  {
76  return "Applying mapping to field";
77  }

◆ v_GetModuleName()

virtual std::string Nektar::FieldUtils::ProcessMapping::v_GetModuleName ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 69 of file ProcessMapping.h.

70  {
71  return "ProcessMapping";
72  }

◆ v_GetModulePriority()

virtual ModulePriority Nektar::FieldUtils::ProcessMapping::v_GetModulePriority ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 79 of file ProcessMapping.h.

80  {
81  return eModifyExp;
82  }

References Nektar::FieldUtils::eModifyExp.

◆ v_Process()

void Nektar::FieldUtils::ProcessMapping::v_Process ( po::variables_map &  vm)
overrideprotectedvirtual

Write mesh to output file.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 62 of file ProcessMapping.cpp.

63 {
64  m_f->SetUpExp(vm);
65 
66  // Determine dimensions of mesh, solution, etc...
67  int npoints = m_f->m_exp[0]->GetNpoints();
68  int expdim = m_f->m_graph->GetMeshDimension();
69  int spacedim = expdim;
70  if ((m_f->m_numHomogeneousDir) == 1 || (m_f->m_numHomogeneousDir) == 2)
71  {
72  spacedim = 3;
73  }
74  int nfields = m_f->m_variables.size();
75  int addfields = expdim;
76 
77  string fieldNames[3] = {"xCoord", "yCoord", "zCoord"};
78  for (int i = 0; i < addfields; ++i)
79  {
80  m_f->m_variables.push_back(fieldNames[i]);
81  }
82 
83  // Skip in case of empty partition
84  if (m_f->m_exp[0]->GetNumElmts() == 0)
85  {
86  return;
87  }
88 
89  m_f->m_exp.resize(nfields + addfields);
90 
91  // Load mapping
93 
94  // Convert velocity to Cartesian system
95  if (m_f->m_fieldMetaDataMap.count("MappingCartesianVel"))
96  {
97  if (m_f->m_fieldMetaDataMap["MappingCartesianVel"] == "False")
98  {
99  m_f->m_fieldMetaDataMap["MappingCartesianVel"] = "True";
100 
101  Array<OneD, Array<OneD, NekDouble>> vel(spacedim);
102  // Initialize arrays and copy velocity
103  for (int i = 0; i < spacedim; ++i)
104  {
105  vel[i] = Array<OneD, NekDouble>(npoints);
106  if (m_f->m_exp[0]->GetWaveSpace())
107  {
108  m_f->m_exp[0]->HomogeneousBwdTrans(
109  npoints, m_f->m_exp[i]->GetPhys(), vel[i]);
110  }
111  else
112  {
113  Vmath::Vcopy(npoints, m_f->m_exp[i]->GetPhys(), 1, vel[i],
114  1);
115  }
116  }
117  // Convert velocity to cartesian system
118  mapping->ContravarToCartesian(vel, vel);
119  // Copy result back
120  for (int i = 0; i < spacedim; ++i)
121  {
122  if (m_f->m_exp[0]->GetWaveSpace())
123  {
124  m_f->m_exp[0]->HomogeneousFwdTrans(
125  npoints, vel[i], m_f->m_exp[i]->UpdatePhys());
126  }
127  else
128  {
129  Vmath::Vcopy(npoints, vel[i], 1,
130  m_f->m_exp[i]->UpdatePhys(), 1);
131  }
132  m_f->m_exp[i]->FwdTransLocalElmt(m_f->m_exp[i]->GetPhys(),
133  m_f->m_exp[i]->UpdateCoeffs());
134  }
135  }
136  }
137 
138  // Get coordinates from mapping
139  Array<OneD, Array<OneD, NekDouble>> coords(3);
140  mapping->GetCartesianCoordinates(coords[0], coords[1], coords[2]);
141 
142  // Add new information to m_f
143  for (int i = 0; i < addfields; ++i)
144  {
145  m_f->m_exp[nfields + i] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
146  Vmath::Vcopy(npoints, coords[i], 1,
147  m_f->m_exp[nfields + i]->UpdatePhys(), 1);
148  m_f->m_exp[nfields + i]->FwdTransLocalElmt(
149  coords[i], m_f->m_exp[nfields + i]->UpdateCoeffs());
150  }
151 }
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
static GlobalMapping::MappingSharedPtr GetMapping(FieldSharedPtr f)

References GetMapping(), Nektar::FieldUtils::Module::m_f, Nektar::GlobalMapping::MappingSharedPtr, and Vmath::Vcopy().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessMapping::className
static
Initial value:
=
"Add mapping coordinates to output file.")
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49

Definition at line 58 of file ProcessMapping.h.