11 using namespace Nektar;
17 if ( stat( filename, &buffer ) )
return 0 ;
21 int main(
int argc,
char *argv[])
27 fprintf(stderr,
"Usage: FldToVtk meshfile fieldfile(s)\n");
36 vSession->LoadParameter(
"OutputExtraPoints", nExtraPoints,0);
44 for (
int n = 1; n < argc; ++n)
46 string fname = std::string(argv[n]);
47 if (fname.substr(fname.length() - 1, 1) ==
"/")
49 fname = fname.substr(0, fname.length() - 1);
51 int fdot = fname.find_last_of(
'.');
52 if (fdot != std::string::npos)
54 string ending = fname.substr(fdot);
59 if (ending ==
".chk" || ending ==
".fld")
61 fname = fname.substr(0,fdot);
63 else if (ending ==
".gz")
65 fname = fname.substr(0,fdot);
66 fdot = fname.find_last_of(
'.');
68 "Error: expected file extension before .gz.");
69 ending = fname.substr(fdot);
71 "Compressed non-xml files are not supported.");
74 else if (ending ==
".xml")
79 fname = fname +
".vtu";
85 cout <<
"Skipping converted file: " << argv[n] << endl;
88 cout <<
"Processing " << argv[n] << endl;
93 string fieldfile(argv[n]);
94 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
95 vector<vector<NekDouble> > fielddata;
98 bool dealiasing =
false;
103 for(i = 0; i < fielddef.size(); ++i)
105 vector<LibUtilities::PointsType> ptype;
106 for(j = 0; j < 3; ++j)
111 fielddef[i]->m_pointsDef =
true;
112 fielddef[i]->m_points = ptype;
114 vector<unsigned int> porder;
115 if(fielddef[i]->m_numPointsDef ==
false)
117 for(j = 0; j < fielddef[i]->m_numModes.size(); ++j)
119 porder.push_back(fielddef[i]->m_numModes[j]+nExtraPoints);
122 fielddef[i]->m_numPointsDef =
true;
126 for(j = 0; j < fielddef[i]->m_numPoints.size(); ++j)
128 porder.push_back(fielddef[i]->m_numPoints[j]+nExtraPoints);
131 fielddef[i]->m_numPoints = porder;
134 graphShPt->SetExpansions(fielddef);
140 int expdim = graphShPt->GetMeshDimension();
141 int nfields = fielddef[0]->m_fields.size();
142 Array<OneD, MultiRegions::ExpListSharedPtr> Exp(nfields);
148 ASSERTL0(fielddef[0]->m_numHomogeneousDir <= 2,
"NumHomogeneousDir is only set up for 1 or 2");
150 if(fielddef[0]->m_numHomogeneousDir == 1)
157 vSession->LoadParameter(
"HomModesZ",nplanes,fielddef[0]->m_numModes[1]);
162 NekDouble ly = fielddef[0]->m_homogeneousLengths[0];
166 for(i = 1; i < nfields; ++i)
171 else if(fielddef[0]->m_numHomogeneousDir == 2)
181 vSession->LoadParameter(
"HomModesY",nylines,fielddef[0]->m_numModes[1]);
182 vSession->LoadParameter(
"HomModesZ",nzlines,fielddef[0]->m_numModes[2]);
192 NekDouble ly = fielddef[0]->m_homogeneousLengths[0];
193 NekDouble lz = fielddef[0]->m_homogeneousLengths[1];
198 for(i = 1; i < nfields; ++i)
209 for(i = 1; i < nfields; ++i)
219 ASSERTL0(fielddef[0]->m_numHomogeneousDir <= 1,
"NumHomogeneousDir is only set up for 1");
221 if(fielddef[0]->m_numHomogeneousDir == 1)
229 vSession->LoadParameter(
"HomModesZ",nplanes,fielddef[0]->m_numModes[2]);
235 NekDouble lz = fielddef[0]->m_homogeneousLengths[0];
240 for(i = 1; i < nfields; ++i)
252 for(i = 1; i < nfields; ++i)
267 for(i = 1; i < nfields; ++i)
275 ASSERTL0(
false,
"Expansion dimension not recognised");
282 for(j = 0; j < nfields; ++j)
284 for(
int i = 0; i < fielddata.size(); ++i)
286 Exp[j]->ExtractDataToCoeffs(fielddef [i],
288 fielddef [i]->m_fields[j],
289 Exp[j]->UpdateCoeffs());
291 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(),Exp[j]->UpdatePhys());
299 ofstream outfile(fname.c_str());
300 Exp[0]->WriteVtkHeader(outfile);
303 for(i = 0; i < Exp[0]->GetNumElmts(); ++i)
305 Exp[0]->WriteVtkPieceHeader(outfile,i);
307 for(j = 0; j < Exp.num_elements(); ++j)
309 Exp[j]->WriteVtkPieceData(outfile,i, fielddef[0]->m_fields[j]);
311 Exp[0]->WriteVtkPieceFooter(outfile,i);
313 Exp[0]->WriteVtkFooter(outfile);
314 cout <<
"Written file: " << fname << endl;