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

#include <InputXml.h>

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

Public Member Functions

 InputXml (FieldSharedPtr f)
 Set up InputXml object. More...
 
 ~InputXml () override
 
- Public Member Functions inherited from Nektar::FieldUtils::InputModule
 InputModule (FieldSharedPtr p_m)
 
void PrintSummary ()
 Print a brief summary of information. More...
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
virtual ~Module ()=default
 
void Process (po::variables_map &vm)
 
std::string GetModuleName ()
 
std::string GetModuleDescription ()
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
ModulePriority GetModulePriority ()
 
std::vector< ModuleKeyGetModulePrerequisites ()
 
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 ModuleSharedPtr create (FieldSharedPtr f)
 Creates an instance of this class. More...
 
- Static Public Member Functions inherited from Nektar::FieldUtils::InputModule
static FIELD_UTILS_EXPORT std::string GuessFormat (std::string fileName)
 Tries to guess the format of the input file. More...
 

Static Public Attributes

static ModuleKey m_className []
 ModuleKey for class. More...
 

Protected Member Functions

void v_Process (po::variables_map &vm) override
 
std::string v_GetModuleName () override
 
std::string v_GetModuleDescription () override
 
ModulePriority v_GetModulePriority () override
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
virtual void v_Process (po::variables_map &vm)
 
virtual std::string v_GetModuleName ()
 
virtual std::string v_GetModuleDescription ()
 
virtual ModulePriority v_GetModulePriority ()
 
virtual std::vector< ModuleKeyv_GetModulePrerequisites ()
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. 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

Input module for Xml files.

Definition at line 46 of file InputXml.h.

Constructor & Destructor Documentation

◆ InputXml()

Nektar::FieldUtils::InputXml::InputXml ( FieldSharedPtr  f)

Set up InputXml object.

Definition at line 60 of file InputXml.cpp.

60 : InputModule(f)
61{
62 m_allowedFiles.insert("xml");
63 m_allowedFiles.insert("xml.gz");
64}
InputModule(FieldSharedPtr p_m)
Definition: Module.cpp:61
std::set< std::string > m_allowedFiles
List of allowed file formats.
Definition: Module.h:274

References Nektar::FieldUtils::Module::m_allowedFiles.

◆ ~InputXml()

Nektar::FieldUtils::InputXml::~InputXml ( )
override

Definition at line 69 of file InputXml.cpp.

70{
71}

Member Function Documentation

◆ create()

static ModuleSharedPtr Nektar::FieldUtils::InputXml::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 52 of file InputXml.h.

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

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

◆ v_GetModuleDescription()

std::string Nektar::FieldUtils::InputXml::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 67 of file InputXml.h.

68 {
69 return "Processing input xml file";
70 }

◆ v_GetModuleName()

std::string Nektar::FieldUtils::InputXml::v_GetModuleName ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 62 of file InputXml.h.

63 {
64 return "InputXml";
65 }

◆ v_GetModulePriority()

ModulePriority Nektar::FieldUtils::InputXml::v_GetModulePriority ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 72 of file InputXml.h.

73 {
74 return eCreateGraph;
75 }

References Nektar::FieldUtils::eCreateGraph.

◆ v_Process()

void Nektar::FieldUtils::InputXml::v_Process ( po::variables_map &  vm)
overrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 76 of file InputXml.cpp.

77{
78 LibUtilities::Timer timerpart;
79 if (m_f->m_verbose)
80 {
81 if (m_f->m_comm->TreatAsRankZero())
82 {
83 timerpart.Start();
84 }
85 }
86
87 // check for multiple calls to inputXml due to split xml
88 // files. If so just return
89 if (m_f->m_graph)
90 {
91 return;
92 }
93
94 string xml_ending = "xml";
95 string xml_gz_ending = "xml.gz";
96
97 std::vector<std::string> files;
98 // load .xml ending
99 for (int i = 0; i < m_f->m_inputfiles[xml_ending].size(); ++i)
100 {
101 files.push_back(m_f->m_inputfiles[xml_ending][i]);
102 }
103
104 // load any .xml.gz endings
105 for (int j = 0; j < m_f->m_inputfiles[xml_gz_ending].size(); ++j)
106 {
107 files.push_back(m_f->m_inputfiles[xml_gz_ending][j]);
108 }
109
111
112 // define range to process output
113 if (vm.count("range"))
114 {
115 vector<NekDouble> values;
116 ASSERTL0(ParseUtils::GenerateVector(vm["range"].as<string>(), values),
117 "Failed to interpret range string");
118
119 ASSERTL0(values.size() > 1, "Do not have minimum values of xmin,xmax");
120 ASSERTL0(values.size() % 2 == 0,
121 "Do not have an even number of range values");
122
123 int nvalues = values.size() / 2;
125
126 rng->m_doZrange = false;
127 rng->m_doYrange = false;
128 rng->m_checkShape = false;
129
130 switch (nvalues)
131 {
132 case 3:
133 rng->m_doZrange = true;
134 rng->m_zmin = values[4];
135 rng->m_zmax = values[5];
136 /* Falls through. */
137 case 2:
138 rng->m_doYrange = true;
139 rng->m_ymin = values[2];
140 rng->m_ymax = values[3];
141 /* Falls through. */
142 case 1:
143 rng->m_doXrange = true;
144 rng->m_xmin = values[0];
145 rng->m_xmax = values[1];
146 break;
147 default:
149 "too many values specfied in range");
150 }
151 }
152
153 // define range to only take a single shape.
154 if (vm.count("onlyshape"))
155 {
157 {
159 rng->m_doXrange = false;
160 rng->m_doYrange = false;
161 rng->m_doZrange = false;
162 }
163
164 rng->m_checkShape = true;
165
166 string shapematch = boost::to_upper_copy(vm["onlyshape"].as<string>());
167 int i;
168 for (i = 0; i < LibUtilities::SIZE_ShapeType; ++i)
169 {
170 string shapeval = LibUtilities::ShapeTypeMap[i];
171 boost::to_upper(shapeval);
172 if (shapematch.compare(shapeval) == 0)
173 {
174 rng->m_shapeType = (LibUtilities::ShapeType)i;
175 break;
176 }
177 }
179 "Failed to find shape type in -onlyshape command line "
180 "argument");
181 }
182
183 // Set up command lines options that will be passed through to SessionReader
184 vector<string> cmdArgs;
185 cmdArgs.push_back("FieldConvert");
186
187 if (m_f->m_verbose)
188 {
189 cmdArgs.push_back("--verbose");
190 }
191
192 if (vm.count("part-only"))
193 {
194 cmdArgs.push_back("--part-only");
195 cmdArgs.push_back(
196 boost::lexical_cast<string>(vm["part-only"].as<int>()));
197 }
198
199 if (vm.count("part-only-overlapping"))
200 {
201 cmdArgs.push_back("--part-only-overlapping");
202 cmdArgs.push_back(
203 boost::lexical_cast<string>(vm["part-only-overlapping"].as<int>()));
204 }
205
206 if (vm.count("npz"))
207 {
208 cmdArgs.push_back("--npz");
209 cmdArgs.push_back(boost::lexical_cast<string>(vm["npz"].as<int>()));
210 }
211
212 // Parallel-in-time
213 if (vm.count("npt"))
214 {
215 cmdArgs.push_back("--npt");
216 cmdArgs.push_back(boost::lexical_cast<string>(vm["npt"].as<int>()));
217 }
218
219 int argc = cmdArgs.size();
220 const char **argv = new const char *[argc];
221 for (int i = 0; i < argc; ++i)
222 {
223 argv[i] = cmdArgs[i].c_str();
224 }
225
227 argc, (char **)argv, files, m_f->m_comm);
228
229 if (vm.count("nparts"))
230 {
231 // make sure have pre-partitioned mesh for nparts option
232 ASSERTL0(boost::icontains(files[0], "_xml"),
233 "Expect the mesh to have been pre-partitioned when "
234 " using the \"--nparts\" option. Please use \"--part-only\" "
235 "option to prepartition xml file.");
236 }
237
238 // Free up memory.
239 delete[] argv;
240
241 if (m_f->m_verbose)
242 {
243 if (m_f->m_comm->TreatAsRankZero())
244 {
245 timerpart.Stop();
246 NekDouble cpuTime = timerpart.TimePerTest(1);
247
248 stringstream ss;
249 ss << cpuTime << "s";
250 cout << "\t InputXml session reader CPU Time: " << setw(8) << left
251 << ss.str() << endl;
252 timerpart.Start();
253 }
254 }
255
256 m_f->m_graph = SpatialDomains::MeshGraph::Read(m_f->m_session, rng);
257
258 if (m_f->m_verbose)
259 {
260 if (m_f->m_comm->TreatAsRankZero())
261 {
262 timerpart.Stop();
263 NekDouble cpuTime = timerpart.TimePerTest(1);
264
265 stringstream ss;
266 ss << cpuTime << "s";
267 cout << "\t InputXml mesh graph setup CPU Time: " << setw(8)
268 << left << ss.str() << endl;
269 timerpart.Start();
270 }
271 }
272}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
Definition: Timer.cpp:65
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
Definition: ParseUtils.cpp:130
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
Definition: MeshGraph.cpp:115
const char *const ShapeTypeMap[SIZE_ShapeType]
Definition: ShapeType.hpp:75
std::shared_ptr< DomainRange > DomainRangeShPtr
Definition: DomainRange.h:64
static DomainRangeShPtr NullDomainRangeShPtr
Definition: DomainRange.h:65
double NekDouble

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::SessionReader::CreateInstance(), Nektar::ErrorUtil::efatal, Nektar::ParseUtils::GenerateVector(), Nektar::FieldUtils::Module::m_f, NEKERROR, Nektar::LibUtilities::NullDomainRangeShPtr, Nektar::SpatialDomains::MeshGraph::Read(), Nektar::LibUtilities::ShapeTypeMap, Nektar::LibUtilities::SIZE_ShapeType, Nektar::LibUtilities::Timer::Start(), Nektar::LibUtilities::Timer::Stop(), and Nektar::LibUtilities::Timer::TimePerTest().

Member Data Documentation

◆ m_className

ModuleKey Nektar::FieldUtils::InputXml::m_className
static
Initial value:
= {
ModuleKey(eInputModule, "xml"), InputXml::create, "Reads Xml file."),
ModuleKey(eInputModule, "xml.gz"), InputXml::create, "Reads Xml file."),
}
static ModuleSharedPtr create(FieldSharedPtr f)
Creates an instance of this class.
Definition: InputXml.h:52
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47

ModuleKey for class.

Definition at line 57 of file InputXml.h.