Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Nektar::Utilities::OutputFld Class Reference

Converter from fld to vtk. More...

#include <OutputFld.h>

Inheritance diagram for Nektar::Utilities::OutputFld:
Inheritance graph
[legend]
Collaboration diagram for Nektar::Utilities::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...
 
- Public Member Functions inherited from Nektar::Utilities::OutputModule
 OutputModule (FieldSharedPtr p_f)
 
void OpenStream ()
 Open a file for output. More...
 
 OutputModule (MeshSharedPtr p_m)
 
void OpenStream ()
 
- Public Member Functions inherited from Nektar::Utilities::Module
 Module (FieldSharedPtr p_f)
 
void RegisterConfig (string key, string value)
 Register a configuration option with a module. More...
 
void PrintConfig ()
 Print out all configuration options for a module. More...
 
void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
bool GetRequireEquiSpaced (void)
 
void SetRequireEquiSpaced (bool pVal)
 
void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 
 Module (MeshSharedPtr p_m)
 
virtual void Process ()=0
 
void RegisterConfig (string key, string value)
 
void PrintConfig ()
 
void SetDefaults ()
 
MeshSharedPtr GetMesh ()
 
virtual void ProcessVertices ()
 Extract element vertices. More...
 

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::Utilities::Module
 Module ()
 
virtual void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual void ProcessElements ()
 Generate element IDs. More...
 
virtual void ProcessComposites ()
 Generate composites. More...
 
void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
void PrismLines (int prism, PerMap &perFaces, set< int > &prismsDone, vector< ElementSharedPtr > &line)
 
- Protected Attributes inherited from Nektar::Utilities::OutputModule
ofstream m_fldFile
 Output stream. More...
 
std::ofstream m_mshFile
 Output stream. More...
 
- Protected Attributes inherited from Nektar::Utilities::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 
MeshSharedPtr m_mesh
 Mesh object. More...
 

Detailed Description

Converter from fld to vtk.

Definition at line 48 of file OutputFld.h.

Constructor & Destructor Documentation

Nektar::Utilities::OutputFld::OutputFld ( FieldSharedPtr  f)

Definition at line 57 of file OutputFld.cpp.

57  : OutputModule(f)
58 {
59 }
Nektar::Utilities::OutputFld::~OutputFld ( )
virtual

Definition at line 61 of file OutputFld.cpp.

62 {
63 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 52 of file OutputFld.h.

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

52  {
54  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void Nektar::Utilities::OutputFld::Process ( po::variables_map &  vm)
virtual

Write fld to output file.

Implements Nektar::Utilities::Module.

Definition at line 65 of file OutputFld.cpp.

References ASSERTL0, Nektar::SpatialDomains::BoundaryConditions::GetBoundaryRegions(), Nektar::Utilities::Module::m_config, Nektar::Utilities::Module::m_f, Nektar::LibUtilities::ReduceSum, and Vmath::Vcopy().

66 {
67  // Extract the output filename and extension
68  string filename = m_config["outfile"].as<string>();
69 
70  if (m_f->m_writeBndFld)
71  {
72  ModuleKey module;
73 
74  // Extract data to boundaryconditions
75  if (m_f->m_fldToBnd) {
76  for (int i = 0; i < m_f->m_exp.size(); ++i)
77  {
78  m_f->m_exp[i]->FillBndCondFromField();
79  }
80  }
81 
82  if (m_f->m_verbose)
83  {
84  cout << "OutputFld: Writing boundary file(s): ";
85  for(int i = 0; i < m_f->m_bndRegionsToWrite.size(); ++i)
86  {
87  if(i < m_f->m_bndRegionsToWrite.size()-1)
88  {
89  cout << ",";
90  }
91  }
92  cout << endl;
93  }
94 
95  int nfields = m_f->m_exp.size();
97  BndExp(nfields);
98  for (int i = 0; i < nfields; ++i)
99  {
100  BndExp[i] = m_f->m_exp[i]->GetBndCondExpansions();
101  }
102 
103  // get hold of partition boundary regions so we can match it to desired
104  // region extraction
106  m_f->m_exp[0]->GetGraph());
108  bcs.GetBoundaryRegions();
109  SpatialDomains::BoundaryRegionCollection::const_iterator breg_it;
110  map<int,int> BndRegionMap;
111  int cnt =0;
112  for(breg_it = bregions.begin(); breg_it != bregions.end();
113  ++breg_it, ++cnt)
114  {
115  BndRegionMap[breg_it->first] = cnt;
116  }
117 
118  // find ending of output file and insert _b1, _b2
119  int dot = filename.find_last_of('.') + 1;
120  string ext = filename.substr(dot, filename.length() - dot);
121  string name = filename.substr(0, dot-1);
122 
124  m_f->m_session->GetBndRegionOrdering();
125 
126  for(int i = 0; i < m_f->m_bndRegionsToWrite.size(); ++i)
127  {
128  string outname = name + "_b"
129  + boost::lexical_cast<string>(m_f->m_bndRegionsToWrite[i])
130  + "." + ext;
131 
132  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
133  std::vector<std::vector<NekDouble> > FieldData;
134 
135  if(BndRegionMap.count(m_f->m_bndRegionsToWrite[i]) == 1)
136  {
137  int Border = BndRegionMap[m_f->m_bndRegionsToWrite[i]];
138 
139  FieldDef = BndExp[0][Border]->GetFieldDefinitions();
140  FieldData.resize(FieldDef.size());
141 
142  for (int j = 0; j < nfields; ++j)
143  {
144  for (int k = 0; k < FieldDef.size(); ++k)
145  {
146  BndExp[j][Border]->AppendFieldData(FieldDef[k],
147  FieldData[k]);
148 
149  if (m_f->m_fielddef.size() > 0)
150  {
151  FieldDef[k]->m_fields.push_back(
152  m_f->m_fielddef[0]->m_fields[j]);
153  }
154  else
155  {
156  FieldDef[k]->m_fields.push_back(
157  m_f->m_session->GetVariable(j));
158  }
159  }
160  }
161 
162  if(m_f->m_addNormals)
163  {
164  ASSERTL0(m_f->m_exp[0]->GetCoordim(0) == 3,
165  "Add normals to extracted boundaries only set up in 3 dimensions");
166  int normdim = 3; // currently assuming 3D normals;
167  string normstr[3] = {"Norm_x","Norm_y","Norm_z"};
168 
169  // Add normal information
172  Array<OneD, int> BoundarytoElmtID, BoundarytoTraceID;
173 
174  m_f->m_exp[0]->GetBoundaryToElmtMap(BoundarytoElmtID,
175  BoundarytoTraceID);
176 
177  // determine offset of this Bnd Expansion Border
178  int cnt = 0;
179  for(int n = 0; n < Border; ++n)
180  {
181  cnt += BndExp[0][n]->GetExpSize();
182  }
183 
184  Array<OneD, NekDouble> tmp_array;
185  Array<OneD, Array<OneD, NekDouble> > NormCoeff(normdim);
186 
187  for(int j = 0; j < normdim; ++j)
188  {
189  NormCoeff[j] = Array<OneD, NekDouble>(BndExp[0][Border]->GetNcoeffs(),0.0);
190  }
191 
192  // setup coeff arrays of normals.
193  for(int j = 0; j < BndExp[0][Border]->GetExpSize();
194  ++j, cnt++)
195  {
196  // find element and face of this expansion.
197  int elmtid = BoundarytoElmtID[cnt];
198  elmt = m_f->m_exp[0]->GetExp(elmtid);
199 
200  // Get face 2D expansion from element expansion
201  bc = boost::dynamic_pointer_cast<StdRegions::StdExpansion2D> (BndExp[0][Border]->GetExp(j));
202 
203  //identify boundary of element looking at.
204  int boundary = BoundarytoTraceID[cnt];
205 
206  //Get face normals
207  const Array<OneD, const Array<OneD, NekDouble> > normals = elmt->GetFaceNormal(boundary);
208 
209  for(int k = 0; k < normdim; ++k)
210  {
211  bc->FwdTrans(normals[k],tmp_array = NormCoeff[k]+BndExp[0][Border]->GetCoeff_Offset(j));
212  }
213  }
214 
215  // add normal coefficients to list to be dumped
216  for (int j = 0; j < normdim; ++j)
217  {
218  Vmath::Vcopy(BndExp[0][Border]->GetNcoeffs(),
219  NormCoeff[j],1,
220  BndExp[0][Border]->UpdateCoeffs(),1);
221 
222  for (int k = 0; k < FieldDef.size(); ++k)
223  {
224  BndExp[0][Border]->AppendFieldData(FieldDef[k],
225  FieldData[k]);
226  FieldDef[k]->m_fields.push_back(normstr[j]);
227  }
228  }
229  }
230 
231  // output error for regression checking.
232  if (vm.count("error"))
233  {
234  int rank = m_f->m_session->GetComm()->GetRank();
235 
236  for (int j = 0; j < nfields; ++j)
237  {
238  BndExp[j][Border]->BwdTrans(BndExp[j][Border]->GetCoeffs(),
239  BndExp[j][Border]->UpdatePhys());
240 
241  //Note currently these calls will
242  //hange since not all partitions will
243  //call error.
244  NekDouble l2err = BndExp[j][Border]
245  ->L2(BndExp[j][Border]->GetPhys());
246 
247  NekDouble linferr = BndExp[j][Border]
248  ->Linf(BndExp[j][Border]->GetPhys());
249 
250  if (rank == 0)
251  {
252  cout << "L 2 error (variable "
253  << FieldDef[0]->m_fields[j]
254  << ") : " << l2err << endl;
255 
256  cout << "L inf error (variable "
257  << FieldDef[0]->m_fields[j]
258  << ") : " << linferr << endl;
259  }
260  }
261  }
262  }
263 
264  m_f->m_fld->Write(outname, FieldDef, FieldData,
265  m_f->m_fieldMetaDataMap);
266 
267  }
268  }
269  else
270  {
271  if (m_f->m_verbose)
272  {
273  cout << "OutputFld: Writing file..." << endl;
274  }
275 
276  fs::path writefile(filename);
277  int writefld = 1;
278  if(fs::exists(writefile)&&(vm.count("forceoutput") == 0))
279  {
280  LibUtilities::CommSharedPtr comm = m_f->m_session->GetComm();
281  int rank = comm->GetRank();
282  writefld = 0; // set to zero for reduce all to be correct.
283 
284  if(rank == 0)
285  {
286  string answer;
287  cout << "Did you wish to overwrite " << filename << " (y/n)? ";
288  getline(cin,answer);
289  if(answer.compare("y") == 0)
290  {
291  writefld = 1;
292  }
293  else
294  {
295  cout << "Not writing file " << filename << " because it already exists" << endl;
296  }
297  }
298 
299  comm->AllReduce(writefld,LibUtilities::ReduceSum);
300 
301  }
302 
303  if(writefld)
304  {
305  m_f->m_fld->Write(filename, m_f->m_fielddef, m_f->m_data);
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(
318  m_f->m_exp[j]->GetCoeffs(),
319  m_f->m_exp[j]->UpdatePhys());
320  }
321 
322  NekDouble l2err = m_f->m_exp[j]->L2(
323  m_f->m_exp[j]->GetPhys());
324 
325  NekDouble linferr = m_f->m_exp[j]->Linf(
326  m_f->m_exp[j]->GetPhys());
327  if (rank == 0)
328  {
329  cout << "L 2 error (variable "
330  << m_f->m_fielddef[0]->m_fields[j]
331  << ") : " << l2err << endl;
332 
333  cout << "L inf error (variable "
334  << m_f->m_fielddef[0]->m_fields[j]
335  << ") : " << linferr << endl;
336  }
337  }
338  }
339  }
340 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
pair< ModuleType, string > ModuleKey
map< string, ConfigOption > m_config
List of configuration values.
std::map< int, std::vector< unsigned int > > BndRegionOrdering
Definition: MeshPartition.h:53
FieldSharedPtr m_f
Field object.
boost::shared_ptr< StdExpansion2D > StdExpansion2DSharedPtr
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition: Conditions.h:204
double NekDouble
const BoundaryRegionCollection & GetBoundaryRegions(void) const
Definition: Conditions.h:225
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1038

Member Data Documentation

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

Definition at line 55 of file OutputFld.h.