Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Nektar::FieldUtils::OutputFld Class Reference

Converter from fld to vtk. More...

#include <OutputFld.h>

Inheritance diagram for Nektar::FieldUtils::OutputFld:
Inheritance graph
[legend]
Collaboration diagram for Nektar::FieldUtils::OutputFld:
Collaboration graph
[legend]

Public Member Functions

 OutputFld (FieldSharedPtr f)
 
virtual ~OutputFld ()
 
virtual void Process (po::variables_map &vm)
 Write fld to output file. More...
 
virtual std::string GetModuleName ()
 
- Public Member Functions inherited from Nektar::FieldUtils::OutputModule
 OutputModule (FieldSharedPtr p_f)
 
FIELD_UTILS_EXPORT void OpenStream ()
 Open a file for output. More...
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
FIELD_UTILS_EXPORT void RegisterConfig (string key, string value)
 Register a configuration option with a module. More...
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
FIELD_UTILS_EXPORT bool GetRequireEquiSpaced (void)
 
FIELD_UTILS_EXPORT void SetRequireEquiSpaced (bool pVal)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

static boost::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 

Static Public Attributes

static ModuleKey m_className []
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
- Protected Attributes inherited from Nektar::FieldUtils::OutputModule
ofstream m_fldFile
 Output stream. More...
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 

Detailed Description

Converter from fld to vtk.

Definition at line 48 of file OutputFld.h.

Constructor & Destructor Documentation

Nektar::FieldUtils::OutputFld::OutputFld ( FieldSharedPtr  f)

Definition at line 57 of file OutputFld.cpp.

References Nektar::FieldUtils::Module::m_config.

57  : OutputModule(f)
58 {
59  m_config["format"] = ConfigOption(
60  false, "Xml", "Output format of field file");
61 }
map< string, ConfigOption > m_config
List of configuration values.
Nektar::FieldUtils::OutputFld::~OutputFld ( )
virtual

Definition at line 63 of file OutputFld.cpp.

64 {
65 }

Member Function Documentation

static boost::shared_ptr<Module> Nektar::FieldUtils::OutputFld::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 52 of file OutputFld.h.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

53  {
55  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
virtual std::string Nektar::FieldUtils::OutputFld::GetModuleName ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 64 of file OutputFld.h.

65  {
66  return "OutputFld";
67  }
void Nektar::FieldUtils::OutputFld::Process ( po::variables_map &  vm)
virtual

Write fld to output file.

Implements Nektar::FieldUtils::Module.

Definition at line 67 of file OutputFld.cpp.

References CellMLToNektar.enum::answer, Nektar::LibUtilities::NekFactory< tKey, tBase, >::CreateInstance(), Nektar::SpatialDomains::BoundaryConditions::GetBoundaryRegions(), Nektar::LibUtilities::GetCommFactory(), Nektar::LibUtilities::GetFieldIOFactory(), Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, Nektar::LibUtilities::ReduceSum, and CellMLToNektar.CellMLToNektar::writefile().

68 {
69  // Extract the output filename and extension
70  string filename = m_config["outfile"].as<string>();
71 
72  // Get IO format
73  std::string iofmt("Xml");
74  if(m_f->m_session)
75  {
76  if (m_f->m_session->DefinesSolverInfo("IOFormat"))
77  {
78  iofmt = m_f->m_session->GetSolverInfo("IOFormat");
79  }
80  if (m_f->m_session->DefinesCmdLineArgument("io-format"))
81  {
82  iofmt =
83  m_f->m_session->GetCmdLineArgument<std::string>("io-format");
84  }
85  }
86  if(m_config["format"].m_beenSet)
87  {
88  iofmt = m_config["format"].as<string>();
89  }
90 
91  // Set up communicator and FieldIO object.
92  LibUtilities::CommSharedPtr c = m_f->m_session ? m_f->m_session->GetComm() :
96 
97  if (m_f->m_writeBndFld)
98  {
99  ModuleKey module;
100 
101  if (m_f->m_verbose)
102  {
103  if (m_f->m_comm->TreatAsRankZero())
104  {
105  cout << "OutputFld: Writing boundary file(s): ";
106  for (int i = 0; i < m_f->m_bndRegionsToWrite.size(); ++i)
107  {
108  cout << m_f->m_bndRegionsToWrite[i];
109  if (i < m_f->m_bndRegionsToWrite.size() - 1)
110  {
111  cout << ",";
112  }
113  }
114  cout << endl;
115  }
116  }
117 
118  // Extract data to boundaryconditions
119  if (m_f->m_fldToBnd)
120  {
121  for (int i = 0; i < m_f->m_exp.size(); ++i)
122  {
123  m_f->m_exp[i]->FillBndCondFromField();
124  }
125  }
126 
127  int nfields = m_f->m_exp.size();
128  Array<OneD, Array<OneD, const MultiRegions::ExpListSharedPtr> > BndExp(
129  nfields);
130  for (int i = 0; i < nfields; ++i)
131  {
132  BndExp[i] = m_f->m_exp[i]->GetBndCondExpansions();
133  }
134 
135  // get hold of partition boundary regions so we can match it to desired
136  // region extraction
137  SpatialDomains::BoundaryConditions bcs(m_f->m_session,
138  m_f->m_exp[0]->GetGraph());
140  bcs.GetBoundaryRegions();
141  SpatialDomains::BoundaryRegionCollection::const_iterator breg_it;
142  map<int, int> BndRegionMap;
143  int cnt = 0;
144  for (breg_it = bregions.begin(); breg_it != bregions.end();
145  ++breg_it, ++cnt)
146  {
147  BndRegionMap[breg_it->first] = cnt;
148  }
149 
150  // find ending of output file and insert _b1, _b2
151  int dot = filename.find_last_of('.') + 1;
152  string ext = filename.substr(dot, filename.length() - dot);
153  string name = filename.substr(0, dot - 1);
154 
155  for (int i = 0; i < m_f->m_bndRegionsToWrite.size(); ++i)
156  {
157  string outname =
158  name + "_b" +
159  boost::lexical_cast<string>(m_f->m_bndRegionsToWrite[i]) + "." +
160  ext;
161 
162  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
163  std::vector<std::vector<NekDouble> > FieldData;
164 
165  if (BndRegionMap.count(m_f->m_bndRegionsToWrite[i]) == 1)
166  {
167  int Border = BndRegionMap[m_f->m_bndRegionsToWrite[i]];
168 
169  FieldDef = BndExp[0][Border]->GetFieldDefinitions();
170  FieldData.resize(FieldDef.size());
171 
172  for (int j = 0; j < nfields; ++j)
173  {
174  for (int k = 0; k < FieldDef.size(); ++k)
175  {
176  BndExp[j][Border]->AppendFieldData(FieldDef[k],
177  FieldData[k]);
178 
179  if (m_f->m_fielddef.size() > 0)
180  {
181  FieldDef[k]->m_fields.push_back(
182  m_f->m_fielddef[0]->m_fields[j]);
183  }
184  else
185  {
186  FieldDef[k]->m_fields.push_back(
187  m_f->m_session->GetVariable(j));
188  }
189  }
190  }
191 
192  if (m_f->m_addNormals)
193  {
194  int normdim = m_f->m_graph->GetMeshDimension();
195  string normstr[3] = {"Norm_x", "Norm_y", "Norm_z"};
196 
197  // Get normals
198  Array<OneD, Array<OneD, NekDouble> > NormPhys;
199  m_f->m_exp[0]->GetBoundaryNormals(Border, NormPhys);
200 
201  // add normal coefficients to list to be dumped
202  for (int j = 0; j < normdim; ++j)
203  {
204  BndExp[0][Border]->FwdTrans(
205  NormPhys[j], BndExp[0][Border]->UpdateCoeffs());
206 
207  for (int k = 0; k < FieldDef.size(); ++k)
208  {
209  BndExp[0][Border]->AppendFieldData(FieldDef[k],
210  FieldData[k]);
211  FieldDef[k]->m_fields.push_back(normstr[j]);
212  }
213  }
214  }
215 
216  // output error for regression checking.
217  if (vm.count("error"))
218  {
219  int rank = m_f->m_session->GetComm()->GetRank();
220 
221  for (int j = 0; j < nfields; ++j)
222  {
223  BndExp[j][Border]->BwdTrans(
224  BndExp[j][Border]->GetCoeffs(),
225  BndExp[j][Border]->UpdatePhys());
226 
227  // Note currently these calls will
228  // hange since not all partitions will
229  // call error.
230  NekDouble l2err =
231  BndExp[j][Border]->L2(BndExp[j][Border]->GetPhys());
232 
233  NekDouble linferr = BndExp[j][Border]->Linf(
234  BndExp[j][Border]->GetPhys());
235 
236  if (rank == 0)
237  {
238  cout << "L 2 error (variable "
239  << FieldDef[0]->m_fields[j] << ") : " << l2err
240  << endl;
241 
242  cout << "L inf error (variable "
243  << FieldDef[0]->m_fields[j]
244  << ") : " << linferr << endl;
245  }
246  }
247  }
248  }
249 
250  fld->Write(outname, FieldDef, FieldData, m_f->m_fieldMetaDataMap);
251  }
252  }
253  else
254  {
255  if (m_f->m_verbose)
256  {
257  if (m_f->m_comm->TreatAsRankZero())
258  {
259  cout << "OutputFld: Writing file..." << endl;
260  }
261  }
262 
263  fs::path writefile(filename);
264  int writefld = 1;
265  if (fs::exists(writefile) && (vm.count("forceoutput") == 0))
266  {
267  int rank = 0;
269 
270  if (m_f->m_session)
271  {
272  comm = m_f->m_session->GetComm();
273  rank = comm->GetRank();
274  }
275  else
276  {
278  "Serial", 0, 0);
279  }
280 
281  writefld = 0; // set to zero for reduce all to be correct.
282 
283  if (rank == 0)
284  {
285  string answer;
286  cout << "Did you wish to overwrite " << filename << " (y/n)? ";
287  getline(cin, answer);
288  if (answer.compare("y") == 0)
289  {
290  writefld = 1;
291  }
292  else
293  {
294  cout << "Not writing file " << filename
295  << " because it already exists" << endl;
296  }
297  }
298 
299  comm->AllReduce(writefld, LibUtilities::ReduceSum);
300  }
301 
302  if (writefld)
303  {
304  fld->Write(filename, m_f->m_fielddef, m_f->m_data,
305  m_f->m_fieldMetaDataMap);
306  }
307 
308  // output error for regression checking.
309  if (vm.count("error"))
310  {
311  int rank = m_f->m_session->GetComm()->GetRank();
312 
313  for (int j = 0; j < m_f->m_exp.size(); ++j)
314  {
315  if (m_f->m_exp[j]->GetPhysState() == false)
316  {
317  m_f->m_exp[j]->BwdTrans(m_f->m_exp[j]->GetCoeffs(),
318  m_f->m_exp[j]->UpdatePhys());
319  }
320 
321  NekDouble l2err = m_f->m_exp[j]->L2(m_f->m_exp[j]->GetPhys());
322 
323  NekDouble linferr =
324  m_f->m_exp[j]->Linf(m_f->m_exp[j]->GetPhys());
325  if (rank == 0)
326  {
327  cout << "L 2 error (variable "
328  << m_f->m_fielddef[0]->m_fields[j] << ") : " << l2err
329  << endl;
330 
331  cout << "L inf error (variable "
332  << m_f->m_fielddef[0]->m_fields[j] << ") : " << linferr
333  << endl;
334  }
335  }
336  }
337  }
338 }
map< string, ConfigOption > m_config
List of configuration values.
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:162
pair< ModuleType, string > ModuleKey
FieldIOFactory & GetFieldIOFactory()
Returns the FieldIO factory.
Definition: FieldIO.cpp:74
CommFactory & GetCommFactory()
Definition: Comm.cpp:61
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition: Conditions.h:217
boost::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:309
double NekDouble
FieldSharedPtr m_f
Field object.

Member Data Documentation

ModuleKey Nektar::FieldUtils::OutputFld::m_className
static
Initial value:

Definition at line 56 of file OutputFld.h.