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::v_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::v_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(
109  FieldDef[n], FieldData[n],
110  m_f->m_exp[s * nfields + j]->UpdateCoeffs());
111  }
112  }
113  }
114  fld->Write(filename, FieldDef, FieldData, m_f->m_fieldMetaDataMap,
115  false);
116  }
117  else
118  {
119  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
120  std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
121  std::vector<std::vector<NekDouble>> FieldData =
122  std::vector<std::vector<NekDouble>>();
123  fld->Write(filename, FieldDef, FieldData, m_f->m_fieldMetaDataMap);
124  }
125 }
126 
127 void OutputFld::v_OutputFromData(po::variables_map &vm)
128 {
129  boost::ignore_unused(vm);
130 
131  // Extract the output filename and extension
132  string filename = m_config["outfile"].as<string>();
133  // Set up FieldIO object.
136  m_f->m_comm, true);
137 
138  fld->Write(filename, m_f->m_fielddef, m_f->m_data, m_f->m_fieldMetaDataMap);
139 }
140 
141 fs::path OutputFld::v_GetPath(std::string &filename, po::variables_map &vm)
142 {
143  boost::ignore_unused(vm);
144  return fs::path(filename);
145 }
146 
147 fs::path OutputFld::v_GetFullOutName(std::string &filename,
148  po::variables_map &vm)
149 {
150  boost::ignore_unused(vm);
151 
152  int nprocs = m_f->m_comm->GetSpaceComm()->GetSize();
153  fs::path specPath(filename), fulloutname;
154  if (nprocs == 1)
155  {
156  fulloutname = specPath;
157  }
158  else
159  {
160  // Guess at filename that might belong to this process.
161  boost::format pad("P%1$07d.%2$s");
162  pad % m_f->m_comm->GetSpaceComm()->GetRank() % "fld";
163 
164  // Generate full path name
165  fs::path poutfile(pad.str());
166  fulloutname = specPath / poutfile;
167  }
168  return fulloutname;
169 }
170 
172 {
173  std::string iofmt("Xml");
174  if (m_f->m_session)
175  {
176  if (m_f->m_session->DefinesSolverInfo("IOFormat"))
177  {
178  iofmt = m_f->m_session->GetSolverInfo("IOFormat");
179  }
180  if (m_f->m_session->DefinesCmdLineArgument("io-format"))
181  {
182  iofmt =
183  m_f->m_session->GetCmdLineArgument<std::string>("io-format");
184  }
185  }
186  if (m_config["format"].m_beenSet)
187  {
188  iofmt = m_config["format"].as<string>();
189  }
190  return iofmt;
191 }
192 
193 } // namespace FieldUtils
194 } // 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:234
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:263
Converter from fld to vtk.
virtual void v_OutputFromData(po::variables_map &vm) override
Write from data to output file.
Definition: OutputFld.cpp:127
virtual void v_OutputFromExp(po::variables_map &vm) override
Write from m_exp to output file.
Definition: OutputFld.cpp:76
virtual fs::path v_GetPath(std::string &filename, po::variables_map &vm) override
Definition: OutputFld.cpp:141
virtual void v_OutputFromPts(po::variables_map &vm) override
Write from pts to output file.
Definition: OutputFld.cpp:70
virtual fs::path v_GetFullOutName(std::string &filename, po::variables_map &vm) override
Definition: OutputFld.cpp:147
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:991
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
std::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:327
FieldIOFactory & GetFieldIOFactory()
Returns the FieldIO factory.
Definition: FieldIO.cpp:72
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
Represents a command-line configuration option.
Definition: Module.h:131