51 "Writes a Fld file."),
54 "Writes a Fld file."),
68 string filename =
m_config[
"outfile"].as<
string>();
70 if (
m_f->m_writeBndFld)
76 if(
m_f->m_comm->GetRank() == 0)
78 cout <<
"OutputFld: Writing boundary file(s): ";
79 for(
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
81 cout <<
m_f->m_bndRegionsToWrite[i];
82 if(i < m_f->m_bndRegionsToWrite.size()-1)
92 if (
m_f->m_fldToBnd) {
93 for (
int i = 0; i <
m_f->m_exp.size(); ++i)
95 m_f->m_exp[i]->FillBndCondFromField();
100 int nfields =
m_f->m_exp.size();
103 for (
int i = 0; i < nfields; ++i)
105 BndExp[i] =
m_f->m_exp[i]->GetBndCondExpansions();
111 m_f->m_exp[0]->GetGraph());
114 SpatialDomains::BoundaryRegionCollection::const_iterator breg_it;
115 map<int,int> BndRegionMap;
117 for(breg_it = bregions.begin(); breg_it != bregions.end();
120 BndRegionMap[breg_it->first] = cnt;
124 int dot = filename.find_last_of(
'.') + 1;
125 string ext = filename.substr(dot, filename.length() - dot);
126 string name = filename.substr(0, dot-1);
128 for(
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
130 string outname = name +
"_b"
131 + boost::lexical_cast<
string>(
m_f->m_bndRegionsToWrite[i])
134 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
135 std::vector<std::vector<NekDouble> > FieldData;
137 if(BndRegionMap.count(
m_f->m_bndRegionsToWrite[i]) == 1)
139 int Border = BndRegionMap[
m_f->m_bndRegionsToWrite[i]];
141 FieldDef = BndExp[0][Border]->GetFieldDefinitions();
142 FieldData.resize(FieldDef.size());
144 for (
int j = 0; j < nfields; ++j)
146 for (
int k = 0; k < FieldDef.size(); ++k)
148 BndExp[j][Border]->AppendFieldData(FieldDef[k],
151 if (
m_f->m_fielddef.size() > 0)
153 FieldDef[k]->m_fields.push_back(
154 m_f->m_fielddef[0]->m_fields[j]);
158 FieldDef[k]->m_fields.push_back(
159 m_f->m_session->GetVariable(j));
164 if(
m_f->m_addNormals)
166 int normdim =
m_f->m_graph->GetMeshDimension();
167 string normstr[3] = {
"Norm_x",
"Norm_y",
"Norm_z"};
173 m_f->m_exp[0]->GetBoundaryToElmtMap(BoundarytoElmtID,
178 for(
int n = 0; n < Border; ++n)
180 cnt += BndExp[0][n]->GetExpSize();
186 for(
int j = 0; j < normdim; ++j)
192 for(
int j=0; j < BndExp[0][Border]->GetExpSize(); ++j,++cnt)
194 int elmtid = BoundarytoElmtID[cnt];
196 elmt =
m_f->m_exp[0]->GetExp(elmtid);
199 int boundary = BoundarytoTraceID[cnt];
208 bc = boost::dynamic_pointer_cast
210 (BndExp[0][Border]->GetExp(j));
213 normals = elmt->GetEdgeNormal(boundary);
215 for(
int k = 0; k < normdim; ++k)
219 tmp_array = NormPhys[k]+
221 GetPhys_Offset(j), 1);
230 bc = boost::dynamic_pointer_cast
232 (BndExp[0][Border]->GetExp(j));
235 normals = elmt->GetFaceNormal(boundary);
237 for(
int k = 0; k < normdim; ++k)
241 tmp_array = NormPhys[k]+
243 GetPhys_Offset(j), 1);
249 ASSERTL0(
false,
"Addnormals requires expdim >=2.");
255 for (
int j = 0; j < normdim; ++j)
257 BndExp[0][Border]->FwdTrans( NormPhys[j],
258 BndExp[0][Border]->UpdateCoeffs());
260 for (
int k = 0; k < FieldDef.size(); ++k)
262 BndExp[0][Border]->AppendFieldData(FieldDef[k],
264 FieldDef[k]->m_fields.push_back(normstr[j]);
270 if (vm.count(
"error"))
272 int rank =
m_f->m_session->GetComm()->GetRank();
274 for (
int j = 0; j < nfields; ++j)
276 BndExp[j][Border]->BwdTrans(BndExp[j][Border]->GetCoeffs(),
277 BndExp[j][Border]->UpdatePhys());
283 ->L2(BndExp[j][Border]->GetPhys());
286 ->Linf(BndExp[j][Border]->GetPhys());
290 cout <<
"L 2 error (variable "
291 << FieldDef[0]->m_fields[j]
292 <<
") : " << l2err << endl;
294 cout <<
"L inf error (variable "
295 << FieldDef[0]->m_fields[j]
296 <<
") : " << linferr << endl;
302 m_f->m_fld->Write(outname, FieldDef, FieldData,
303 m_f->m_fieldMetaDataMap);
311 if(
m_f->m_comm->GetRank() == 0)
313 cout <<
"OutputFld: Writing file..." << endl;
317 fs::path writefile(filename);
319 if(fs::exists(writefile)&&(vm.count(
"forceoutput") == 0))
322 int rank = comm->GetRank();
328 cout <<
"Did you wish to overwrite " << filename <<
" (y/n)? ";
330 if(answer.compare(
"y") == 0)
336 cout <<
"Not writing file " << filename <<
" because it already exists" << endl;
346 m_f->m_fld->Write(filename,
m_f->m_fielddef,
m_f->m_data,
347 m_f->m_fieldMetaDataMap);
351 if (vm.count(
"error"))
353 int rank =
m_f->m_session->GetComm()->GetRank();
355 for (
int j = 0; j <
m_f->m_exp.size(); ++j)
357 if (
m_f->m_exp[j]->GetPhysState() ==
false)
359 m_f->m_exp[j]->BwdTrans(
360 m_f->m_exp[j]->GetCoeffs(),
361 m_f->m_exp[j]->UpdatePhys());
365 m_f->m_exp[j]->GetPhys());
368 m_f->m_exp[j]->GetPhys());
371 cout <<
"L 2 error (variable "
372 <<
m_f->m_fielddef[0]->m_fields[j]
373 <<
") : " << l2err << endl;
375 cout <<
"L inf error (variable "
376 <<
m_f->m_fielddef[0]->m_fields[j]
377 <<
") : " << linferr << endl;
#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
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.