Nektar++
OutputFld.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: OutputFld.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: FLD file format output.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <set>
36 #include <string>
37 using namespace std;
38 
39 #include <boost/core/ignore_unused.hpp>
40 #include <boost/format.hpp>
41 
43 
44 #include "OutputFld.h"
45 
46 namespace Nektar
47 {
48 namespace FieldUtils
49 {
50 
51 ModuleKey OutputFld::m_className[2] = {
53  OutputFld::create,
54  "Writes a Fld file."),
56  OutputFld::create,
57  "Writes a Fld file."),
58 };
59 
60 OutputFld::OutputFld(FieldSharedPtr f) : OutputFileBase(f)
61 {
62  m_config["format"] =
63  ConfigOption(false, "Xml", "Output format of field file");
64 }
65 
67 {
68 }
69 
70 void OutputFld::OutputFromPts(po::variables_map &vm)
71 {
72  boost::ignore_unused(vm);
73  NEKERROR(ErrorUtil::efatal, "OutputFld can't write using Pts information.");
74 }
75 
76 void OutputFld::OutputFromExp(po::variables_map &vm)
77 {
78  boost::ignore_unused(vm);
79  ASSERTL0(m_f->m_variables.size(), "OutputFld: need input data.")
80 
81  // Extract the output filename and extension
82  string filename = m_config["outfile"].as<string>();
83 
84  // Set up FieldIO object.
87  m_f->m_comm, true);
88 
89  int i, j, s;
90  int nfields = m_f->m_variables.size();
91  int nstrips;
92  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
93 
94  if (m_f->m_exp[0]->GetNumElmts() != 0)
95  {
96  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
97  m_f->m_exp[0]->GetFieldDefinitions();
98  std::vector<std::vector<NekDouble>> FieldData(FieldDef.size());
99  for (s = 0; s < nstrips; ++s)
100  {
101  for (j = 0; j < nfields; ++j)
102  {
103  for (i = 0; i < FieldDef.size() / nstrips; ++i)
104  {
105  int n = s * FieldDef.size() / nstrips + i;
106 
107  FieldDef[n]->m_fields.push_back(m_f->m_variables[j]);
108  m_f->m_exp[s * nfields + j]->AppendFieldData(FieldDef[n],
109  FieldData[n]);
110  }
111  }
112  }
113  fld->Write(filename, FieldDef, FieldData, m_f->m_fieldMetaDataMap,
114  false);
115  }
116  else
117  {
118  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
119  std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
120  std::vector<std::vector<NekDouble>> FieldData =
121  std::vector<std::vector<NekDouble>>();
122  fld->Write(filename, FieldDef, FieldData, m_f->m_fieldMetaDataMap);
123  }
124 }
125 
126 void OutputFld::OutputFromData(po::variables_map &vm)
127 {
128  boost::ignore_unused(vm);
129 
130  // Extract the output filename and extension
131  string filename = m_config["outfile"].as<string>();
132  // Set up FieldIO object.
135  m_f->m_comm, true);
136 
137  fld->Write(filename, m_f->m_fielddef, m_f->m_data, m_f->m_fieldMetaDataMap);
138 }
139 
140 fs::path OutputFld::GetPath(std::string &filename, po::variables_map &vm)
141 {
142  boost::ignore_unused(vm);
143  return fs::path(filename);
144 }
145 
146 fs::path OutputFld::GetFullOutName(std::string &filename, po::variables_map &vm)
147 {
148  boost::ignore_unused(vm);
149 
150  int nprocs = m_f->m_comm->GetSize();
151  fs::path specPath(filename), fulloutname;
152  if (nprocs == 1)
153  {
154  fulloutname = specPath;
155  }
156  else
157  {
158  // Guess at filename that might belong to this process.
159  boost::format pad("P%1$07d.%2$s");
160  pad % m_f->m_comm->GetRank() % "fld";
161 
162  // Generate full path name
163  fs::path poutfile(pad.str());
164  fulloutname = specPath / poutfile;
165  }
166  return fulloutname;
167 }
168 
170 {
171  std::string iofmt("Xml");
172  if (m_f->m_session)
173  {
174  if (m_f->m_session->DefinesSolverInfo("IOFormat"))
175  {
176  iofmt = m_f->m_session->GetSolverInfo("IOFormat");
177  }
178  if (m_f->m_session->DefinesCmdLineArgument("io-format"))
179  {
180  iofmt =
181  m_f->m_session->GetCmdLineArgument<std::string>("io-format");
182  }
183  }
184  if (m_config["format"].m_beenSet)
185  {
186  iofmt = m_config["format"].as<string>();
187  }
188  return iofmt;
189 }
190 
191 } // namespace FieldUtils
192 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209
FieldSharedPtr m_f
Field object.
Definition: Module.h:225
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:228
Converter from fld to vtk.
virtual fs::path GetFullOutName(std::string &filename, po::variables_map &vm)
Definition: OutputFld.cpp:146
virtual void OutputFromExp(po::variables_map &vm)
Write from m_exp to output file.
Definition: OutputFld.cpp:76
virtual void OutputFromData(po::variables_map &vm)
Write from data to output file.
Definition: OutputFld.cpp:126
virtual fs::path GetPath(std::string &filename, po::variables_map &vm)
Definition: OutputFld.cpp:140
virtual void OutputFromPts(po::variables_map &vm)
Write from pts to output file.
Definition: OutputFld.cpp:70
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:989
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:285
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
std::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:301
FieldIOFactory & GetFieldIOFactory()
Returns the FieldIO factory.
Definition: FieldIO.cpp:72
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
Represents a command-line configuration option.
Definition: Module.h:131