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 61 of file InputXml.cpp.

61 : InputModule(f)
62{
63 m_allowedFiles.insert("xml");
64 m_allowedFiles.insert("xml.gz");
65 m_config["range"] = ConfigOption(false, "", "range values");
66}
InputModule(FieldSharedPtr p_m)
Definition: Module.cpp:61
std::set< std::string > m_allowedFiles
List of allowed file formats.
Definition: Module.h:274
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272

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

◆ ~InputXml()

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

Definition at line 71 of file InputXml.cpp.

72{
73}

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 78 of file InputXml.cpp.

79{
80 string range = m_config["range"].as<string>();
81
82 LibUtilities::Timer timerpart;
83 if (m_f->m_verbose)
84 {
85 if (m_f->m_comm->TreatAsRankZero())
86 {
87 timerpart.Start();
88 }
89 }
90
91 // check for multiple calls to inputXml due to split xml
92 // files. If so just return
93 if (m_f->m_graph)
94 {
95 return;
96 }
97
98 string xml_ending = "xml";
99 string xml_gz_ending = "xml.gz";
100
101 std::vector<std::string> files;
102 // load .xml ending
103 for (int i = 0; i < m_f->m_inputfiles[xml_ending].size(); ++i)
104 {
105 files.push_back(m_f->m_inputfiles[xml_ending][i]);
106 }
107
108 // load any .xml.gz endings
109 for (int j = 0; j < m_f->m_inputfiles[xml_gz_ending].size(); ++j)
110 {
111 files.push_back(m_f->m_inputfiles[xml_gz_ending][j]);
112 }
113
115
116 // define range to process output
117 if (vm.count("range"))
118 {
120 "The command line option \"range\" (FieldConvert -r xmin,xmax,"
121 "ymin,ymax) is deprecated. Please use the InputXml "
122 "option instead, i.e. \n \t"
123 "FieldConvert myfile.xml:xml:range=\"xmin,xmax,ymin,ymax\" "
124 "out.vtu");
125 }
126
127 if (vm.count("range") || range.size())
128 {
129 vector<NekDouble> values;
130
131 if (range.size())
132 {
134 "Failed to interpret range string");
135 }
136 else
137 {
138 ASSERTL0(
139 ParseUtils::GenerateVector(vm["range"].as<string>(), values),
140 "Failed to interpret range string");
141 }
142
143 ASSERTL0(values.size() > 1, "Do not have minimum values of xmin,xmax");
144 ASSERTL0(values.size() % 2 == 0,
145 "Do not have an even number of range values");
146
147 int nvalues = values.size() / 2;
149
150 rng->m_doZrange = false;
151 rng->m_doYrange = false;
152 rng->m_checkShape = false;
153
154 switch (nvalues)
155 {
156 case 3:
157 rng->m_doZrange = true;
158 rng->m_zmin = values[4];
159 rng->m_zmax = values[5];
160 /* Falls through. */
161 case 2:
162 rng->m_doYrange = true;
163 rng->m_ymin = values[2];
164 rng->m_ymax = values[3];
165 /* Falls through. */
166 case 1:
167 rng->m_doXrange = true;
168 rng->m_xmin = values[0];
169 rng->m_xmax = values[1];
170 break;
171 default:
173 "too many values specfied in range");
174 }
175 }
176
177 // define range to only take a single shape.
178 if (vm.count("onlyshape"))
179 {
181 {
183 rng->m_doXrange = false;
184 rng->m_doYrange = false;
185 rng->m_doZrange = false;
186 }
187
188 rng->m_checkShape = true;
189
190 string shapematch = boost::to_upper_copy(vm["onlyshape"].as<string>());
191 int i;
192 for (i = 0; i < LibUtilities::SIZE_ShapeType; ++i)
193 {
194 string shapeval = LibUtilities::ShapeTypeMap[i];
195 boost::to_upper(shapeval);
196 if (shapematch.compare(shapeval) == 0)
197 {
198 rng->m_shapeType = (LibUtilities::ShapeType)i;
199 break;
200 }
201 }
203 "Failed to find shape type in -onlyshape command line "
204 "argument");
205 }
206
207 // Set up command lines options that will be passed through to SessionReader
208 vector<string> cmdArgs;
209 cmdArgs.push_back("FieldConvert");
210
211 if (m_f->m_verbose)
212 {
213 cmdArgs.push_back("--verbose");
214 }
215
216 if (vm.count("part-only"))
217 {
218 cmdArgs.push_back("--part-only");
219 cmdArgs.push_back(
220 boost::lexical_cast<string>(vm["part-only"].as<int>()));
221 }
222
223 if (vm.count("part-only-overlapping"))
224 {
225 cmdArgs.push_back("--part-only-overlapping");
226 cmdArgs.push_back(
227 boost::lexical_cast<string>(vm["part-only-overlapping"].as<int>()));
228 }
229
230 if (vm.count("npz"))
231 {
232 cmdArgs.push_back("--npz");
233 cmdArgs.push_back(boost::lexical_cast<string>(vm["npz"].as<int>()));
234 }
235
236 // Parallel-in-time
237 if (vm.count("npt"))
238 {
239 cmdArgs.push_back("--npt");
240 cmdArgs.push_back(boost::lexical_cast<string>(vm["npt"].as<int>()));
241 }
242
243 int argc = cmdArgs.size();
244 const char **argv = new const char *[argc];
245 for (int i = 0; i < argc; ++i)
246 {
247 argv[i] = cmdArgs[i].c_str();
248 }
249
251 argc, (char **)argv, files, m_f->m_comm);
252
253 if (vm.count("nparts"))
254 {
255 // make sure have pre-partitioned mesh for nparts option
256 ASSERTL0(boost::icontains(files[0], "_xml"),
257 "Expect the mesh to have been pre-partitioned when "
258 " using the \"--nparts\" option. Please use \"--part-only\" "
259 "option to prepartition xml file.");
260 }
261
262 // Free up memory.
263 delete[] argv;
264
265 if (m_f->m_verbose)
266 {
267 if (m_f->m_comm->TreatAsRankZero())
268 {
269 timerpart.Stop();
270 NekDouble cpuTime = timerpart.TimePerTest(1);
271
272 stringstream ss;
273 ss << cpuTime << "s";
274 cout << "\t InputXml session reader CPU Time: " << setw(8) << left
275 << ss.str() << endl;
276 timerpart.Start();
277 }
278 }
279
280 m_f->m_graph = SpatialDomains::MeshGraphIO::Read(m_f->m_session, rng);
281
282 if (m_f->m_verbose)
283 {
284 if (m_f->m_comm->TreatAsRankZero())
285 {
286 timerpart.Stop();
287 NekDouble cpuTime = timerpart.TimePerTest(1);
288
289 stringstream ss;
290 ss << cpuTime << "s";
291 cout << "\t InputXml mesh graph setup CPU Time: " << setw(8)
292 << left << ss.str() << endl;
293 timerpart.Start();
294 }
295 }
296}
#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.
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: MeshGraphIO.cpp:53
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::ErrorUtil::ewarning, Nektar::ParseUtils::GenerateVector(), Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, NEKERROR, Nektar::LibUtilities::NullDomainRangeShPtr, Nektar::SpatialDomains::MeshGraphIO::Read(), Nektar::LibUtilities::ShapeTypeMap, Nektar::LibUtilities::SIZE_ShapeType, and Nektar::LibUtilities::Timer::Start().

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.
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.