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

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

#include <ProcessMapping.h>

Inheritance diagram for Nektar::Utilities::ProcessMapping:
Inheritance graph
[legend]
Collaboration diagram for Nektar::Utilities::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::Utilities::ProcessModule
 ProcessModule ()
 
 ProcessModule (FieldSharedPtr p_f)
 
 ProcessModule (MeshSharedPtr p_m)
 
- Public Member Functions inherited from Nektar::Utilities::Module
 Module (FieldSharedPtr p_f)
 
void RegisterConfig (string key, string value)
 Register a configuration option with a module. More...
 
void PrintConfig ()
 Print out all configuration options for a module. More...
 
void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
bool GetRequireEquiSpaced (void)
 
void SetRequireEquiSpaced (bool pVal)
 
void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 
 Module (MeshSharedPtr p_m)
 
virtual void Process ()=0
 
void RegisterConfig (std::string key, std::string value)
 
void PrintConfig ()
 
void SetDefaults ()
 
MeshSharedPtr GetMesh ()
 
virtual void ProcessVertices ()
 Extract element vertices. More...
 
virtual void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual void ProcessElements ()
 Generate element IDs. More...
 
virtual void ProcessComposites ()
 Generate composites. More...
 
virtual void ClearElementLinks ()
 

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::Utilities::Module
 Module ()
 
void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
void PrismLines (int prism, PerMap &perFaces, std::set< int > &prismsDone, std::vector< ElementSharedPtr > &line)
 
- Protected Attributes inherited from Nektar::Utilities::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 
MeshSharedPtr m_mesh
 Mesh object. More...
 
std::map< std::string,
ConfigOption
m_config
 List of configuration values. More...
 

Detailed Description

This processing module scales the input fld file.

Definition at line 51 of file ProcessMapping.h.

Constructor & Destructor Documentation

Nektar::Utilities::ProcessMapping::ProcessMapping ( FieldSharedPtr  f)

Definition at line 54 of file ProcessMapping.cpp.

Nektar::Utilities::ProcessMapping::~ProcessMapping ( )
virtual

Definition at line 58 of file ProcessMapping.cpp.

59 {
60 }

Member Function Documentation

static boost::shared_ptr<Module> Nektar::Utilities::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::Utilities::ProcessMapping::GetMapping ( FieldSharedPtr  f)
static

Definition at line 173 of file ProcessMapping.cpp.

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

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

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

Implements Nektar::Utilities::Module.

Definition at line 67 of file ProcessMapping.h.

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

Write mesh to output file.

Implements Nektar::Utilities::Module.

Definition at line 62 of file ProcessMapping.cpp.

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

63 {
64  if(m_f->m_verbose)
65  {
66  if(m_f->m_comm->TreatAsRankZero())
67  {
68  cout << "ProcessMapping: Applying mapping to field..." << endl;
69  }
70  }
71 
72  // Determine dimensions of mesh, solution, etc...
73  int npoints = m_f->m_exp[0]->GetNpoints();
74  int expdim = m_f->m_graph->GetMeshDimension();
75  int spacedim = expdim;
76  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
77  (m_f->m_fielddef[0]->m_numHomogeneousDir) == 2)
78  {
79  spacedim = 3;
80  }
81  int nfields = m_f->m_fielddef[0]->m_fields.size();
82  int addfields = expdim;
83  m_f->m_exp.resize(nfields+addfields);
84 
85  // Load mapping
87 
88  // Convert velocity to Cartesian system
89  if (m_f->m_fieldMetaDataMap.count("MappingCartesianVel"))
90  {
91  if (m_f->m_fieldMetaDataMap["MappingCartesianVel"] == "False")
92  {
93  m_f->m_fieldMetaDataMap["MappingCartesianVel"] = "True";
94 
95  Array<OneD, Array<OneD, NekDouble> > vel (spacedim);
96  // Initialize arrays and copy velocity
97  for ( int i =0; i<spacedim; ++i )
98  {
99  vel[i] = Array<OneD, NekDouble> (npoints);
100  if (m_f->m_exp[0]->GetWaveSpace())
101  {
102  m_f->m_exp[0]->HomogeneousBwdTrans(m_f->m_exp[i]->GetPhys(),
103  vel[i]);
104  }
105  else
106  {
107  Vmath::Vcopy(npoints, m_f->m_exp[i]->GetPhys(), 1,
108  vel[i], 1);
109  }
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(vel[i],
120  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(m_f->m_exp[i]->GetPhys(),
128  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] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
143  m_f->m_exp[nfields + i]->UpdatePhys() = coords[i];
144  m_f->m_exp[nfields + i]->FwdTrans_IterPerExp(coords[i],
145  m_f->m_exp[nfields + i]->UpdateCoeffs());
146  outname.push_back(fieldNames[i]);
147  }
148 
149  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
150  = m_f->m_exp[0]->GetFieldDefinitions();
151  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
152 
153  for (int j = 0; j < nfields + addfields; ++j)
154  {
155  for (int i = 0; i < FieldDef.size(); ++i)
156  {
157  if (j >= nfields)
158  {
159  FieldDef[i]->m_fields.push_back(outname[j-nfields]);
160  }
161  else
162  {
163  FieldDef[i]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[j]);
164  }
165  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
166  }
167  }
168 
169  m_f->m_fielddef = FieldDef;
170  m_f->m_data = FieldData;
171 }
FieldSharedPtr m_f
Field object.
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:1047

Member Data Documentation

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

Definition at line 59 of file ProcessMapping.h.

FieldSharedPtr Nektar::Utilities::ProcessMapping::m_fromField
private

Definition at line 75 of file ProcessMapping.h.