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"] = ConfigOption(
63  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);
74  "OutputFld can't write using Pts information.");
75 }
76 
77 void OutputFld::OutputFromExp(po::variables_map &vm)
78 {
79  boost::ignore_unused(vm);
80  ASSERTL0(m_f->m_variables.size(),
81  "OutputFld: need input data.")
82 
83  // Extract the output filename and extension
84  string filename = m_config["outfile"].as<string>();
85 
86  // Set up FieldIO object.
89  GetIOFormat(), m_f->m_comm, true);
90 
91  int i, j, s;
92  int nfields = m_f->m_variables.size();
93  int nstrips;
94  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
95 
96  if(m_f->m_exp[0]->GetNumElmts() != 0)
97  {
98  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
99  m_f->m_exp[0]->GetFieldDefinitions();
100  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
101  for (s = 0; s < nstrips; ++s)
102  {
103  for (j = 0; j < nfields; ++j)
104  {
105  for (i = 0; i < FieldDef.size() / nstrips; ++i)
106  {
107  int n = s * FieldDef.size() / nstrips + i;
108 
109  FieldDef[n]->m_fields.push_back(m_f->m_variables[j]);
110  m_f->m_exp[s * nfields + j]->AppendFieldData(
111  FieldDef[n], FieldData[n]);
112  }
113  }
114  }
115  fld->Write(filename, FieldDef, FieldData, m_f->m_fieldMetaDataMap,
116  false);
117  }
118  else
119  {
120  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
121  std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
122  std::vector<std::vector<NekDouble> > FieldData =
123  std::vector<std::vector<NekDouble> >();
124  fld->Write(filename, FieldDef, FieldData, m_f->m_fieldMetaDataMap);
125  }
126 }
127 
128 void OutputFld::OutputFromData(po::variables_map &vm)
129 {
130  boost::ignore_unused(vm);
131 
132  // Extract the output filename and extension
133  string filename = m_config["outfile"].as<string>();
134  // Set up FieldIO object.
137  GetIOFormat(), m_f->m_comm, true);
138 
139  fld->Write(filename, m_f->m_fielddef, m_f->m_data,
140  m_f->m_fieldMetaDataMap);
141 }
142 
143 fs::path OutputFld::GetPath(std::string &filename,
144  po::variables_map &vm)
145 {
146  boost::ignore_unused(vm);
147  return fs::path(filename);
148 }
149 
150 fs::path OutputFld::GetFullOutName(std::string &filename,
151  po::variables_map &vm)
152 {
153  boost::ignore_unused(vm);
154 
155  int nprocs = m_f->m_comm->GetSize();
156  fs::path specPath(filename), fulloutname;
157  if (nprocs == 1)
158  {
159  fulloutname = specPath;
160  }
161  else
162  {
163  // Guess at filename that might belong to this process.
164  boost::format pad("P%1$07d.%2$s");
165  pad % m_f->m_comm->GetRank() % "fld";
166 
167  // Generate full path name
168  fs::path poutfile(pad.str());
169  fulloutname = specPath / poutfile;
170  }
171  return fulloutname;
172 }
173 
175 {
176  std::string iofmt("Xml");
177  if(m_f->m_session)
178  {
179  if (m_f->m_session->DefinesSolverInfo("IOFormat"))
180  {
181  iofmt = m_f->m_session->GetSolverInfo("IOFormat");
182  }
183  if (m_f->m_session->DefinesCmdLineArgument("io-format"))
184  {
185  iofmt =
186  m_f->m_session->GetCmdLineArgument<std::string>("io-format");
187  }
188  }
189  if(m_config["format"].m_beenSet)
190  {
191  iofmt = m_config["format"].as<string>();
192  }
193  return iofmt;
194 }
195 
196 }
197 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:209
std::map< std::string, ConfigOption > m_config
List of configuration values.
Represents a command-line configuration option.
virtual void OutputFromPts(po::variables_map &vm)
Write from pts to output file.
Definition: OutputFld.cpp:70
Converter from fld to vtk.
virtual fs::path GetFullOutName(std::string &filename, po::variables_map &vm)
Definition: OutputFld.cpp:150
STL namespace.
virtual void OutputFromExp(po::variables_map &vm)
Write from m_exp to output file.
Definition: OutputFld.cpp:77
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:762
FieldIOFactory & GetFieldIOFactory()
Returns the FieldIO factory.
Definition: FieldIO.cpp:72
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
std::pair< ModuleType, std::string > ModuleKey
virtual void OutputFromData(po::variables_map &vm)
Write from data to output file.
Definition: OutputFld.cpp:128
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
virtual fs::path GetPath(std::string &filename, po::variables_map &vm)
Definition: OutputFld.cpp:143
std::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:306
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.