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)
 
 ~ProcessMapping () override
 
- 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 ()
 
std::vector< ModuleKeyGetModulePrerequisites ()
 
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

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

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

Constructor & Destructor Documentation

◆ ProcessMapping()

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

Definition at line 50 of file ProcessMapping.cpp.

◆ ~ProcessMapping()

Nektar::FieldUtils::ProcessMapping::~ProcessMapping ( )
override

Definition at line 54 of file ProcessMapping.cpp.

55{
56}

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

53 {
55 }
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 149 of file ProcessMapping.cpp.

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

References ASSERTL0, FilterPython_Function::field, 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()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 72 of file ProcessMapping.h.

73 {
74 return "Applying mapping to field";
75 }

◆ v_GetModuleName()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 67 of file ProcessMapping.h.

68 {
69 return "ProcessMapping";
70 }

◆ v_GetModulePriority()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 77 of file ProcessMapping.h.

78 {
79 return eModifyExp;
80 }

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 58 of file ProcessMapping.cpp.

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

Definition at line 56 of file ProcessMapping.h.