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 Attributes | 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:
Inheritance graph
[legend]
Collaboration diagram for Nektar::FieldUtils::ProcessMapping:
Collaboration graph
[legend]

Public Member Functions

 ProcessMapping (FieldSharedPtr f)
 
virtual ~ProcessMapping ()
 
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
GlobalMapping::MappingSharedPtr 
GetMapping (FieldSharedPtr f)
 

Static Public Attributes

static ModuleKey className
 

Private Attributes

FieldSharedPtr m_fromField
 

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 51 of file ProcessMapping.h.

Constructor & Destructor Documentation

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

Definition at line 55 of file ProcessMapping.cpp.

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

Definition at line 59 of file ProcessMapping.cpp.

60 {
61 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 55 of file ProcessMapping.h.

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

56  {
58  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
GlobalMapping::MappingSharedPtr Nektar::FieldUtils::ProcessMapping::GetMapping ( FieldSharedPtr  f)
static

Definition at line 175 of file ProcessMapping.cpp.

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

Referenced by Nektar::FieldUtils::ProcessVorticity::Process(), Nektar::FieldUtils::ProcessGrad::Process(), and Process().

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

Implements Nektar::FieldUtils::Module.

Definition at line 67 of file ProcessMapping.h.

68  {
69  return "ProcessMapping";
70  }
void Nektar::FieldUtils::ProcessMapping::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

Implements Nektar::FieldUtils::Module.

Definition at line 63 of file ProcessMapping.cpp.

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

64 {
65  if (m_f->m_verbose)
66  {
67  if (m_f->m_comm->TreatAsRankZero())
68  {
69  cout << "ProcessMapping: Applying mapping to field..." << endl;
70  }
71  }
72 
73  // Determine dimensions of mesh, solution, etc...
74  int npoints = m_f->m_exp[0]->GetNpoints();
75  int expdim = m_f->m_graph->GetMeshDimension();
76  int spacedim = expdim;
77  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
78  (m_f->m_fielddef[0]->m_numHomogeneousDir) == 2)
79  {
80  spacedim = 3;
81  }
82  int nfields = m_f->m_fielddef[0]->m_fields.size();
83  int addfields = expdim;
84  m_f->m_exp.resize(nfields + addfields);
85 
86  // Load mapping
88 
89  // Convert velocity to Cartesian system
90  if (m_f->m_fieldMetaDataMap.count("MappingCartesianVel"))
91  {
92  if (m_f->m_fieldMetaDataMap["MappingCartesianVel"] == "False")
93  {
94  m_f->m_fieldMetaDataMap["MappingCartesianVel"] = "True";
95 
96  Array<OneD, Array<OneD, NekDouble> > vel(spacedim);
97  // Initialize arrays and copy velocity
98  for (int i = 0; i < spacedim; ++i)
99  {
100  vel[i] = Array<OneD, NekDouble>(npoints);
101  if (m_f->m_exp[0]->GetWaveSpace())
102  {
103  m_f->m_exp[0]->HomogeneousBwdTrans(m_f->m_exp[i]->GetPhys(),
104  vel[i]);
105  }
106  else
107  {
108  Vmath::Vcopy(npoints, m_f->m_exp[i]->GetPhys(), 1, vel[i],
109  1);
110  }
111  }
112  // Convert velocity to cartesian system
113  mapping->ContravarToCartesian(vel, vel);
114  // Copy result back
115  for (int i = 0; i < spacedim; ++i)
116  {
117  if (m_f->m_exp[0]->GetWaveSpace())
118  {
119  m_f->m_exp[0]->HomogeneousFwdTrans(
120  vel[i], m_f->m_exp[i]->UpdatePhys());
121  }
122  else
123  {
124  Vmath::Vcopy(npoints, vel[i], 1,
125  m_f->m_exp[i]->UpdatePhys(), 1);
126  }
127  m_f->m_exp[i]->FwdTrans_IterPerExp(
128  m_f->m_exp[i]->GetPhys(), m_f->m_exp[i]->UpdateCoeffs());
129  }
130  }
131  }
132 
133  // Get coordinates from mapping
134  Array<OneD, Array<OneD, NekDouble> > coords(3);
135  mapping->GetCartesianCoordinates(coords[0], coords[1], coords[2]);
136 
137  // Add new information to m_f
138  string fieldNames[3] = {"xCoord", "yCoord", "zCoord"};
139  vector<string> outname;
140  for (int i = 0; i < addfields; ++i)
141  {
142  m_f->m_exp[nfields + i] =
143  m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
144  m_f->m_exp[nfields + i]->UpdatePhys() = coords[i];
145  m_f->m_exp[nfields + i]->FwdTrans_IterPerExp(
146  coords[i], m_f->m_exp[nfields + i]->UpdateCoeffs());
147  outname.push_back(fieldNames[i]);
148  }
149 
150  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
151  m_f->m_exp[0]->GetFieldDefinitions();
152  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
153 
154  for (int j = 0; j < nfields + addfields; ++j)
155  {
156  for (int i = 0; i < FieldDef.size(); ++i)
157  {
158  if (j >= nfields)
159  {
160  FieldDef[i]->m_fields.push_back(outname[j - nfields]);
161  }
162  else
163  {
164  FieldDef[i]->m_fields.push_back(
165  m_f->m_fielddef[0]->m_fields[j]);
166  }
167  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
168  }
169  }
170 
171  m_f->m_fielddef = FieldDef;
172  m_f->m_data = FieldData;
173 }
static GlobalMapping::MappingSharedPtr GetMapping(FieldSharedPtr f)
GLOBAL_MAPPING_EXPORT typedef boost::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
Definition: Mapping.h:51
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1061
FieldSharedPtr m_f
Field object.

Member Data Documentation

ModuleKey Nektar::FieldUtils::ProcessMapping::className
static
Initial value:
=
"Add mapping coordinates to output file.")

Definition at line 59 of file ProcessMapping.h.

FieldSharedPtr Nektar::FieldUtils::ProcessMapping::m_fromField
private

Definition at line 75 of file ProcessMapping.h.