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

Output to fld format. More...

#include <OutputFld.h>

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

Public Member Functions

 OutputFld (FieldSharedPtr f)
 
virtual ~OutputFld ()
 
virtual std::string GetModuleName ()
 
- Public Member Functions inherited from Nektar::FieldUtils::OutputFileBase
 OutputFileBase (FieldSharedPtr f)
 
virtual ~OutputFileBase ()
 
virtual void Process (po::variables_map &vm)
 Write fld to output file. More...
 
virtual std::string GetModuleDescription ()
 
virtual ModulePriority GetModulePriority ()
 
- 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)
 
virtual ~Module ()=default
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::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 void AddFile (std::string fileType, std::string fileName)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

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

Static Public Attributes

static ModuleKey m_className []
 

Protected Member Functions

virtual void OutputFromPts (po::variables_map &vm)
 Write from pts to output file. More...
 
virtual void OutputFromExp (po::variables_map &vm)
 Write from m_exp to output file. More...
 
virtual void OutputFromData (po::variables_map &vm)
 Write from data to output file. More...
 
virtual fs::path GetPath (std::string &filename, po::variables_map &vm)
 
virtual fs::path GetFullOutName (std::string &filename, po::variables_map &vm)
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 

Private Member Functions

std::string GetIOFormat ()
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
- Protected Attributes inherited from Nektar::FieldUtils::OutputFileBase
bool m_requireEquiSpaced
 
- Protected Attributes inherited from Nektar::FieldUtils::OutputModule
std::ofstream m_fldFile
 Output stream. More...
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 
std::set< std::string > m_allowedFiles
 List of allowed file formats. More...
 

Detailed Description

Output to fld format.

Definition at line 47 of file OutputFld.h.

Constructor & Destructor Documentation

◆ OutputFld()

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

Definition at line 60 of file OutputFld.cpp.

60  : OutputFileBase(f)
61 {
62  m_config["format"] =
63  ConfigOption(false, "Xml", "Output format of field file");
64 }
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:228

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

◆ ~OutputFld()

Nektar::FieldUtils::OutputFld::~OutputFld ( )
virtual

Definition at line 66 of file OutputFld.cpp.

67 {
68 }

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 51 of file OutputFld.h.

52  {
54  }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

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

◆ GetFullOutName()

fs::path Nektar::FieldUtils::OutputFld::GetFullOutName ( std::string &  filename,
po::variables_map &  vm 
)
protectedvirtual

Implements Nektar::FieldUtils::OutputFileBase.

Definition at line 146 of file OutputFld.cpp.

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 }
FieldSharedPtr m_f
Field object.
Definition: Module.h:225

References CellMLToNektar.pycml::format, and Nektar::FieldUtils::Module::m_f.

◆ GetIOFormat()

std::string Nektar::FieldUtils::OutputFld::GetIOFormat ( )
private

Definition at line 169 of file OutputFld.cpp.

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 }

References Nektar::FieldUtils::Module::m_config, and Nektar::FieldUtils::Module::m_f.

Referenced by OutputFromData(), and OutputFromExp().

◆ GetModuleName()

virtual std::string Nektar::FieldUtils::OutputFld::GetModuleName ( )
inlinevirtual

Reimplemented from Nektar::FieldUtils::OutputFileBase.

Definition at line 60 of file OutputFld.h.

61  {
62  return "OutputFld";
63  }

◆ GetPath()

fs::path Nektar::FieldUtils::OutputFld::GetPath ( std::string &  filename,
po::variables_map &  vm 
)
protectedvirtual

Implements Nektar::FieldUtils::OutputFileBase.

Definition at line 140 of file OutputFld.cpp.

141 {
142  boost::ignore_unused(vm);
143  return fs::path(filename);
144 }

◆ OutputFromData()

void Nektar::FieldUtils::OutputFld::OutputFromData ( po::variables_map &  vm)
protectedvirtual

Write from data to output file.

Implements Nektar::FieldUtils::OutputFileBase.

Definition at line 126 of file OutputFld.cpp.

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 }
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
std::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:301
FieldIOFactory & GetFieldIOFactory()
Returns the FieldIO factory.
Definition: FieldIO.cpp:72

References Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), Nektar::LibUtilities::GetFieldIOFactory(), GetIOFormat(), Nektar::FieldUtils::Module::m_config, and Nektar::FieldUtils::Module::m_f.

◆ OutputFromExp()

void Nektar::FieldUtils::OutputFld::OutputFromExp ( po::variables_map &  vm)
protectedvirtual

Write from m_exp to output file.

Implements Nektar::FieldUtils::OutputFileBase.

Definition at line 76 of file OutputFld.cpp.

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.
85  LibUtilities::FieldIOSharedPtr fld =
86  LibUtilities::GetFieldIOFactory().CreateInstance(GetIOFormat(),
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 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215

References ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), Nektar::LibUtilities::GetFieldIOFactory(), GetIOFormat(), Nektar::FieldUtils::Module::m_config, and Nektar::FieldUtils::Module::m_f.

◆ OutputFromPts()

void Nektar::FieldUtils::OutputFld::OutputFromPts ( po::variables_map &  vm)
protectedvirtual

Write from pts to output file.

Implements Nektar::FieldUtils::OutputFileBase.

Definition at line 70 of file OutputFld.cpp.

71 {
72  boost::ignore_unused(vm);
73  NEKERROR(ErrorUtil::efatal, "OutputFld can't write using Pts information.");
74 }
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209

References Nektar::ErrorUtil::efatal, and NEKERROR.

Member Data Documentation

◆ m_className

ModuleKey Nektar::FieldUtils::OutputFld::m_className
static
Initial value:
= {
"Writes a Fld file."),
"Writes a Fld file."),
}
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
Definition: OutputFld.h:51
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:285
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49

Definition at line 55 of file OutputFld.h.