51 "Writes a Fld file."),
54 "Writes a Fld file."),
69 string filename =
m_config[
"outfile"].as<
string>();
76 if (
m_f->m_writeBndFld)
83 if(
m_f->m_comm->GetRank() == 0)
85 cout <<
"OutputFld: Writing boundary file(s): ";
86 for(
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
88 cout <<
m_f->m_bndRegionsToWrite[i];
89 if(i < m_f->m_bndRegionsToWrite.size()-1)
99 if (
m_f->m_fldToBnd) {
100 for (
int i = 0; i <
m_f->m_exp.size(); ++i)
102 m_f->m_exp[i]->FillBndCondFromField();
107 int nfields =
m_f->m_exp.size();
110 for (
int i = 0; i < nfields; ++i)
112 BndExp[i] =
m_f->m_exp[i]->GetBndCondExpansions();
118 m_f->m_exp[0]->GetGraph());
121 SpatialDomains::BoundaryRegionCollection::const_iterator breg_it;
122 map<int,int> BndRegionMap;
124 for(breg_it = bregions.begin(); breg_it != bregions.end();
127 BndRegionMap[breg_it->first] = cnt;
131 int dot = filename.find_last_of(
'.') + 1;
132 string ext = filename.substr(dot, filename.length() - dot);
133 string name = filename.substr(0, dot-1);
135 for(
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
137 string outname = name +
"_b"
138 + boost::lexical_cast<
string>(
m_f->m_bndRegionsToWrite[i])
141 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
142 std::vector<std::vector<NekDouble> > FieldData;
144 if(BndRegionMap.count(
m_f->m_bndRegionsToWrite[i]) == 1)
146 int Border = BndRegionMap[
m_f->m_bndRegionsToWrite[i]];
148 FieldDef = BndExp[0][Border]->GetFieldDefinitions();
149 FieldData.resize(FieldDef.size());
151 for (
int j = 0; j < nfields; ++j)
153 for (
int k = 0; k < FieldDef.size(); ++k)
155 BndExp[j][Border]->AppendFieldData(FieldDef[k],
158 if (
m_f->m_fielddef.size() > 0)
160 FieldDef[k]->m_fields.push_back(
161 m_f->m_fielddef[0]->m_fields[j]);
165 FieldDef[k]->m_fields.push_back(
166 m_f->m_session->GetVariable(j));
171 if(
m_f->m_addNormals)
173 int normdim =
m_f->m_graph->GetMeshDimension();
174 string normstr[3] = {
"Norm_x",
"Norm_y",
"Norm_z"};
180 m_f->m_exp[0]->GetBoundaryToElmtMap(BoundarytoElmtID,
185 for(
int n = 0; n < Border; ++n)
187 cnt += BndExp[0][n]->GetExpSize();
193 for(
int j = 0; j < normdim; ++j)
199 for(
int j=0; j < BndExp[0][Border]->GetExpSize(); ++j,++cnt)
201 int elmtid = BoundarytoElmtID[cnt];
203 elmt =
m_f->m_exp[0]->GetExp(elmtid);
206 int boundary = BoundarytoTraceID[cnt];
215 bc = boost::dynamic_pointer_cast
217 (BndExp[0][Border]->GetExp(j));
220 normals = elmt->GetEdgeNormal(boundary);
222 for(
int k = 0; k < normdim; ++k)
226 tmp_array = NormPhys[k]+
228 GetPhys_Offset(j), 1);
237 bc = boost::dynamic_pointer_cast
239 (BndExp[0][Border]->GetExp(j));
242 normals = elmt->GetFaceNormal(boundary);
244 for(
int k = 0; k < normdim; ++k)
248 tmp_array = NormPhys[k]+
250 GetPhys_Offset(j), 1);
256 ASSERTL0(
false,
"Addnormals requires expdim >=2.");
262 for (
int j = 0; j < normdim; ++j)
264 BndExp[0][Border]->FwdTrans( NormPhys[j],
265 BndExp[0][Border]->UpdateCoeffs());
267 for (
int k = 0; k < FieldDef.size(); ++k)
269 BndExp[0][Border]->AppendFieldData(FieldDef[k],
271 FieldDef[k]->m_fields.push_back(normstr[j]);
277 if (vm.count(
"error"))
279 int rank =
m_f->m_session->GetComm()->GetRank();
281 for (
int j = 0; j < nfields; ++j)
283 BndExp[j][Border]->BwdTrans(BndExp[j][Border]->GetCoeffs(),
284 BndExp[j][Border]->UpdatePhys());
290 ->L2(BndExp[j][Border]->GetPhys());
293 ->Linf(BndExp[j][Border]->GetPhys());
297 cout <<
"L 2 error (variable "
298 << FieldDef[0]->m_fields[j]
299 <<
") : " << l2err << endl;
301 cout <<
"L inf error (variable "
302 << FieldDef[0]->m_fields[j]
303 <<
") : " << linferr << endl;
309 m_f->m_fld->Write(outname, FieldDef, FieldData,
310 m_f->m_fieldMetaDataMap);
318 if(
m_f->m_comm->GetRank() == 0)
320 cout <<
"OutputFld: Writing file..." << endl;
324 fs::path writefile(filename);
326 if(fs::exists(writefile)&&(vm.count(
"forceoutput") == 0))
329 int rank = comm->GetRank();
335 cout <<
"Did you wish to overwrite " << filename <<
" (y/n)? ";
337 if(answer.compare(
"y") == 0)
343 cout <<
"Not writing file " << filename <<
" because it already exists" << endl;
353 m_f->m_fld->Write(filename,
m_f->m_fielddef,
m_f->m_data,
354 m_f->m_fieldMetaDataMap);
358 if (vm.count(
"error"))
360 int rank =
m_f->m_session->GetComm()->GetRank();
362 for (
int j = 0; j <
m_f->m_exp.size(); ++j)
364 if (
m_f->m_exp[j]->GetPhysState() ==
false)
366 m_f->m_exp[j]->BwdTrans(
367 m_f->m_exp[j]->GetCoeffs(),
368 m_f->m_exp[j]->UpdatePhys());
372 m_f->m_exp[j]->GetPhys());
375 m_f->m_exp[j]->GetPhys());
378 cout <<
"L 2 error (variable "
379 <<
m_f->m_fielddef[0]->m_fields[j]
380 <<
") : " << l2err << endl;
382 cout <<
"L inf error (variable "
383 <<
m_f->m_fielddef[0]->m_fields[j]
384 <<
") : " << linferr << endl;
391 if(
m_f->m_comm->GetRank() == 0)
397 ss << cpuTime <<
"s";
398 cout <<
"OutputFld CPU Time: " << setw(8) << left
#define ASSERTL0(condition, msg)
pair< ModuleType, string > ModuleKey
Abstract base class for output modules.
map< string, ConfigOption > m_config
List of configuration values.
FieldSharedPtr m_f
Field object.
boost::shared_ptr< StdExpansion2D > StdExpansion2DSharedPtr
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
boost::shared_ptr< StdExpansion1D > StdExpansion1DSharedPtr
boost::shared_ptr< Field > FieldSharedPtr
const BoundaryRegionCollection & GetBoundaryRegions(void) const
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.