52 ProcessMapping::create,
"Add mapping coordinates to output file.");
66 if(
m_f->m_comm->GetRank() == 0)
68 cout <<
"ProcessMapping: Applying mapping to field..." << endl;
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)
81 int nfields =
m_f->m_fielddef[0]->m_fields.size();
82 int addfields = expdim;
83 m_f->m_exp.resize(nfields+addfields);
89 if (
m_f->m_fieldMetaDataMap.count(
"MappingCartesianVel"))
91 if (
m_f->m_fieldMetaDataMap[
"MappingCartesianVel"] ==
"False")
93 m_f->m_fieldMetaDataMap[
"MappingCartesianVel"] =
"True";
97 for (
int i =0; i<spacedim; ++i )
100 if (
m_f->m_exp[0]->GetWaveSpace())
102 m_f->m_exp[0]->HomogeneousBwdTrans(
m_f->m_exp[i]->GetPhys(),
113 mapping->ContravarToCartesian(vel, vel);
115 for (
int i =0; i<spacedim; ++i )
117 if (
m_f->m_exp[0]->GetWaveSpace())
119 m_f->m_exp[0]->HomogeneousFwdTrans(vel[i],
120 m_f->m_exp[i]->UpdatePhys());
125 m_f->m_exp[i]->UpdatePhys(), 1);
127 m_f->m_exp[i]->FwdTrans_IterPerExp(
m_f->m_exp[i]->GetPhys(),
128 m_f->m_exp[i]->UpdateCoeffs());
135 mapping->GetCartesianCoordinates(coords[0], coords[1], coords[2]);
138 string fieldNames[3] = {
"xCoord",
"yCoord",
"zCoord"};
139 vector<string > outname;
140 for (
int i = 0; i < addfields; ++i)
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]);
149 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
150 =
m_f->m_exp[0]->GetFieldDefinitions();
151 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
153 for (
int j = 0; j < nfields + addfields; ++j)
155 for (
int i = 0; i < FieldDef.size(); ++i)
159 FieldDef[i]->m_fields.push_back(outname[j-nfields]);
163 FieldDef[i]->m_fields.push_back(
m_f->m_fielddef[0]->m_fields[j]);
165 m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
169 m_f->m_fielddef = FieldDef;
170 m_f->m_data = FieldData;
177 field[0] = f->m_exp[0];
184 if (f->m_fieldMetaDataMap.count(
"Time"))
186 string s_time = f->m_fieldMetaDataMap[
"Time"];
187 time = atof(s_time.c_str());
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)
207 for (
int i = 0; i < 3; i++)
213 string fieldNames[3] = {
"x",
"y",
"z"};
214 string velFieldNames[3] = {
"vx",
"vy",
"vz"};
217 if (f->m_fieldMetaDataMap.count(
"MappingType"))
219 if (f->m_fieldMetaDataMap[
"MappingType"] ==
"Expression")
224 if (f->m_fieldMetaDataMap.count(
"MappingExpression"))
226 funcName = f->m_fieldMetaDataMap[
"MappingExpression"];
232 if (f->m_fieldMetaDataMap.count(
"MappingVelExpression"))
234 velFuncName = f->m_fieldMetaDataMap[
"MappingVelExpression"];
243 for (
int i = 0; i < 3; i++)
247 f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
250 std::string s_FieldStr;
251 for(
int i = 0; i < 3; i++)
253 s_FieldStr = fieldNames[i];
254 if ( f->m_session->DefinesFunction(funcName, s_FieldStr))
257 f->m_session->GetFunction(funcName, s_FieldStr);
258 ffunc->Evaluate(coords[0], coords[1], coords[2],
259 time, coords_new[i]);
268 if (f->m_session->DefinesFunction(velFuncName))
270 for (
int i = 0; i < 3; i++)
272 s_FieldStr = velFieldNames[i];
273 if ( f->m_session->DefinesFunction(velFuncName, s_FieldStr))
276 f->m_session->GetFunction(velFuncName, s_FieldStr);
277 ffunc->Evaluate(coords[0], coords[1], coords[2],
278 time, coords_vel[i]);
284 mapping->SetFromFunction(
false);
285 mapping->UpdateMapping(time, coords_new,coords_vel);
287 else if(f->m_fieldMetaDataMap[
"MappingType"] ==
"File")
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;
295 f->m_fld->Import(fileName,
299 for (
int j = 0; j < spacedim; ++j)
301 int ncoeffs = f->m_exp[0]->GetNcoeffs();
303 for (
int i = 0; i < FieldData.size(); ++i)
305 f->m_exp[j]->ExtractDataToCoeffs(FieldDef[i],
310 bool wavespace = f->m_exp[0]->GetWaveSpace();
311 f->m_exp[0]->SetWaveSpace(
false);
313 f->m_exp[0]->BwdTrans(fieldcoeffs,
319 if (
std::find(FieldDef[0]->m_fields.begin(), FieldDef[0]->m_fields.end(),
320 velFieldNames[j])!=FieldDef[0]->m_fields.end())
322 for (
int i = 0; i < FieldData.size(); ++i)
324 f->m_exp[j]->ExtractDataToCoeffs(FieldDef[i],
329 f->m_exp[0]->BwdTrans(fieldcoeffs,
332 f->m_exp[0]->SetWaveSpace(wavespace);
335 mapping->SetFromFunction(
false);
336 mapping->UpdateMapping(time, coords_new,coords_vel);
344 for (
int i = 0; i < 3; i++)
349 f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
350 mapping->SetFromFunction(
false);
351 mapping->UpdateMapping(time, coords,coords_vel);
#define ASSERTL0(condition, msg)
pair< ModuleType, string > ModuleKey
FieldSharedPtr m_f
Field object.
static GlobalMapping::MappingSharedPtr GetMapping(FieldSharedPtr f)
boost::shared_ptr< Field > FieldSharedPtr
GLOBAL_MAPPING_EXPORT typedef boost::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
boost::shared_ptr< Equation > EquationSharedPtr
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
virtual ~ProcessMapping()
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
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.
ModuleFactory & GetModuleFactory()
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.