52 ProcessMapping::create,
53 "Add mapping coordinates to output file.");
67 if (
m_f->m_comm->TreatAsRankZero())
69 cout <<
"ProcessMapping: Applying mapping to field..." << endl;
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)
82 int nfields =
m_f->m_fielddef[0]->m_fields.size();
83 int addfields = expdim;
84 m_f->m_exp.resize(nfields + addfields);
90 if (
m_f->m_fieldMetaDataMap.count(
"MappingCartesianVel"))
92 if (
m_f->m_fieldMetaDataMap[
"MappingCartesianVel"] ==
"False")
94 m_f->m_fieldMetaDataMap[
"MappingCartesianVel"] =
"True";
98 for (
int i = 0; i < spacedim; ++i)
101 if (
m_f->m_exp[0]->GetWaveSpace())
103 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(
120 vel[i],
m_f->m_exp[i]->UpdatePhys());
125 m_f->m_exp[i]->UpdatePhys(), 1);
127 m_f->m_exp[i]->FwdTrans_IterPerExp(
128 m_f->m_exp[i]->GetPhys(),
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] =
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]);
150 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
151 m_f->m_exp[0]->GetFieldDefinitions();
152 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
154 for (
int j = 0; j < nfields + addfields; ++j)
156 for (
int i = 0; i < FieldDef.size(); ++i)
160 FieldDef[i]->m_fields.push_back(outname[j - nfields]);
164 FieldDef[i]->m_fields.push_back(
165 m_f->m_fielddef[0]->m_fields[j]);
167 m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
171 m_f->m_fielddef = FieldDef;
172 m_f->m_data = FieldData;
179 field[0] = f->m_exp[0];
185 if (f->m_fieldMetaDataMap.count(
"Time"))
187 string s_time = f->m_fieldMetaDataMap[
"Time"];
188 time = atof(s_time.c_str());
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)
208 for (
int i = 0; i < 3; i++)
214 string fieldNames[3] = {
"x",
"y",
"z"};
215 string velFieldNames[3] = {
"vx",
"vy",
"vz"};
218 if (f->m_fieldMetaDataMap.count(
"MappingType"))
220 if (f->m_fieldMetaDataMap[
"MappingType"] ==
"Expression")
225 if (f->m_fieldMetaDataMap.count(
"MappingExpression"))
227 funcName = f->m_fieldMetaDataMap[
"MappingExpression"];
233 if (f->m_fieldMetaDataMap.count(
"MappingVelExpression"))
235 velFuncName = f->m_fieldMetaDataMap[
"MappingVelExpression"];
244 for (
int i = 0; i < 3; i++)
248 f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
251 std::string s_FieldStr;
252 for (
int i = 0; i < 3; i++)
254 s_FieldStr = fieldNames[i];
255 if (f->m_session->DefinesFunction(funcName, s_FieldStr))
258 f->m_session->GetFunction(funcName, s_FieldStr);
259 ffunc->Evaluate(coords[0], coords[1], coords[2], time,
269 if (f->m_session->DefinesFunction(velFuncName))
271 for (
int i = 0; i < 3; i++)
273 s_FieldStr = velFieldNames[i];
274 if (f->m_session->DefinesFunction(velFuncName, s_FieldStr))
277 f->m_session->GetFunction(velFuncName, s_FieldStr);
278 ffunc->Evaluate(coords[0], coords[1], coords[2], time,
285 mapping->SetFromFunction(
false);
286 mapping->UpdateMapping(time, coords_new, coords_vel);
288 else if (f->m_fieldMetaDataMap[
"MappingType"] ==
"File")
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;
296 f->FieldIOForFile(fileName)->Import(fileName, FieldDef, FieldData);
298 for (
int j = 0; j < spacedim; ++j)
300 int ncoeffs = f->m_exp[0]->GetNcoeffs();
302 for (
int i = 0; i < FieldData.size(); ++i)
304 f->m_exp[j]->ExtractDataToCoeffs(
305 FieldDef[i], FieldData[i], fieldNames[j], fieldcoeffs);
307 bool wavespace = f->m_exp[0]->GetWaveSpace();
308 f->m_exp[0]->SetWaveSpace(
false);
310 f->m_exp[0]->BwdTrans(fieldcoeffs, coords_new[j]);
313 if (
std::find(FieldDef[0]->m_fields.begin(),
314 FieldDef[0]->m_fields.end(),
315 velFieldNames[j]) != FieldDef[0]->m_fields.end())
317 for (
int i = 0; i < FieldData.size(); ++i)
319 f->m_exp[j]->ExtractDataToCoeffs(
320 FieldDef[i], FieldData[i], velFieldNames[j],
323 f->m_exp[0]->BwdTrans(fieldcoeffs, coords_vel[j]);
325 f->m_exp[0]->SetWaveSpace(wavespace);
328 mapping->SetFromFunction(
false);
329 mapping->UpdateMapping(time, coords_new, coords_vel);
337 for (
int i = 0; i < 3; i++)
342 f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
343 mapping->SetFromFunction(
false);
344 mapping->UpdateMapping(time, coords, coords_vel);
#define ASSERTL0(condition, msg)
virtual ~ProcessMapping()
pair< ModuleType, string > ModuleKey
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.
virtual void Process(po::variables_map &vm)
Write mesh to output file.
boost::shared_ptr< Equation > EquationSharedPtr
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Abstract base class for processing modules.
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()
FieldSharedPtr m_f
Field object.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.