Nektar++
Loading...
Searching...
No Matches
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.
 
 ~InputXml () override
 
- Public Member Functions inherited from Nektar::FieldUtils::InputModule
 InputModule (FieldSharedPtr p_m)
 
void PrintSummary ()
 Print a brief summary of information.
 
- 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.
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module.
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set.
 
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.
 
- 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.
 

Static Public Attributes

static ModuleKey m_className []
 ModuleKey for class.
 

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 std::vector< ModuleKeyv_GetModulePrerequisites ()
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object.
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values.
 
std::set< std::string > m_allowedFiles
 List of allowed file formats.
 

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 m_config["comprange"] = ConfigOption(false, "", "composite range values");
67}
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 72 of file InputXml.cpp.

73{
74}

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

80{
81 string range = m_config["range"].as<string>();
82 string comprange = m_config["comprange"].as<string>();
83
84 LibUtilities::Timer timerpart;
85 if (m_f->m_verbose)
86 {
87 if (m_f->m_comm->TreatAsRankZero())
88 {
89 timerpart.Start();
90 }
91 }
92
93 // check for multiple calls to inputXml due to split xml
94 // files. If so just return
95 if (m_f->m_graph)
96 {
97 return;
98 }
99
100 string xml_ending = "xml";
101 string xml_gz_ending = "xml.gz";
102
103 std::vector<std::string> files;
104 // load .xml ending
105 for (int i = 0; i < m_f->m_inputfiles[xml_ending].size(); ++i)
106 {
107 files.push_back(m_f->m_inputfiles[xml_ending][i]);
108 }
109
110 // load any .xml.gz endings
111 for (int j = 0; j < m_f->m_inputfiles[xml_gz_ending].size(); ++j)
112 {
113 files.push_back(m_f->m_inputfiles[xml_gz_ending][j]);
114 }
115
117
118 // define range to process output
119 if (vm.count("range"))
120 {
122 "The command line option \"range\" (FieldConvert -r xmin,xmax,"
123 "ymin,ymax) is deprecated. Please use the InputXml "
124 "option instead, i.e. \n \t"
125 "FieldConvert myfile.xml:xml:range=\"xmin,xmax,ymin,ymax\" "
126 "out.vtu");
127 }
128
129 if (vm.count("range") || range.size())
130 {
131 vector<NekDouble> values;
132
133 if (range.size())
134 {
136 "Failed to interpret range string");
137 }
138 else
139 {
140 ASSERTL0(
141 ParseUtils::GenerateVector(vm["range"].as<string>(), values),
142 "Failed to interpret range string");
143 }
144
145 if (values.size())
146 {
147 ASSERTL0(values.size() > 1,
148 "Do not have minimum values of xmin,xmax");
149 ASSERTL0(values.size() % 2 == 0,
150 "Do not have an even number of range values");
151
152 int nvalues = values.size() / 2;
154
155 rng->m_doZrange = false;
156 rng->m_doYrange = false;
157 rng->m_checkShape = false;
158
159 switch (nvalues)
160 {
161 case 3:
162 rng->m_doZrange = true;
163 rng->m_zmin = values[4];
164 rng->m_zmax = values[5];
165 /* Falls through. */
166 case 2:
167 rng->m_doYrange = true;
168 rng->m_ymin = values[2];
169 rng->m_ymax = values[3];
170 /* Falls through. */
171 case 1:
172 rng->m_doXrange = true;
173 rng->m_xmin = values[0];
174 rng->m_xmax = values[1];
175 break;
176 default:
178 "too many values specfied in range");
179 }
180 }
181 }
182
183 if (comprange.size())
184 {
185 if ((m_f->m_comm->GetSize() > 1) && (m_f->m_comm->GetRank() == 0))
186 {
188 "Using the comprange option in parallel may cause "
189 "problems with partitioning (particuarly with Scotch) "
190 "since the elements are not contiguous");
191 }
192
193 vector<unsigned> compvalues;
194
195 ASSERTL0(ParseUtils::GenerateVector(comprange, compvalues),
196 "Failed to interpret comprange string");
197
198 if (compvalues.size())
199 {
201 {
202 rng = MemoryManager<
203 LibUtilities::DomainRange>::AllocateSharedPtr();
204 }
205 // initialise with 3D and check when graph setup
206 rng->m_compElmts = 3;
207
208 for (auto it : compvalues)
209 {
210 rng->m_comps.insert(it);
211 }
212 }
213 }
214
215 // define range to only take a single shape.
216 if (vm.count("onlyshape"))
217 {
219 {
221 rng->m_doXrange = false;
222 rng->m_doYrange = false;
223 rng->m_doZrange = false;
224 }
225
226 rng->m_checkShape = true;
227
228 string shapematch = boost::to_upper_copy(vm["onlyshape"].as<string>());
229 int i;
230 for (i = 0; i < LibUtilities::SIZE_ShapeType; ++i)
231 {
232 string shapeval = LibUtilities::ShapeTypeMap[i];
233 boost::to_upper(shapeval);
234 if (shapematch.compare(shapeval) == 0)
235 {
236 rng->m_shapeType = (LibUtilities::ShapeType)i;
237 break;
238 }
239 }
241 "Failed to find shape type in -onlyshape command line "
242 "argument");
243 }
244
245 // Set up command lines options that will be passed through to SessionReader
246 vector<string> cmdArgs;
247 cmdArgs.push_back("FieldConvert");
248
249 if (m_f->m_verbose)
250 {
251 cmdArgs.push_back("--verbose");
252 }
253
254 if (vm.count("part-only"))
255 {
256 cmdArgs.push_back("--part-only");
257 cmdArgs.push_back(std::to_string(vm["part-only"].as<int>()));
258 }
259
260 if (vm.count("part-only-overlapping"))
261 {
262 cmdArgs.push_back("--part-only-overlapping");
263 cmdArgs.push_back(
264 std::to_string(vm["part-only-overlapping"].as<int>()));
265 }
266
267 if (vm.count("npz"))
268 {
269 cmdArgs.push_back("--npz");
270 cmdArgs.push_back(std::to_string(vm["npz"].as<int>()));
271 }
272
273 // Parallel-in-time
274 if (vm.count("npt"))
275 {
276 cmdArgs.push_back("--npt");
277 cmdArgs.push_back(std::to_string(vm["npt"].as<int>()));
278 }
279
280 int argc = cmdArgs.size();
281 const char **argv = new const char *[argc];
282 for (int i = 0; i < argc; ++i)
283 {
284 argv[i] = cmdArgs[i].c_str();
285 }
286
288 argc, (char **)argv, files, m_f->m_comm);
289
290 if (vm.count("nparts"))
291 {
292 // make sure have pre-partitioned mesh for nparts option
293 ASSERTL0(boost::icontains(files[0], "_xml"),
294 "Expect the mesh to have been pre-partitioned when "
295 " using the \"--nparts\" option. Please use \"--part-only\" "
296 "option to prepartition xml file.");
297 }
298
299 // Free up memory.
300 delete[] argv;
301
302 if (m_f->m_verbose)
303 {
304 if (m_f->m_comm->TreatAsRankZero())
305 {
306 timerpart.Stop();
307 NekDouble cpuTime = timerpart.TimePerTest(1);
308
309 stringstream ss;
310 ss << cpuTime << "s";
311 cout << "\t InputXml session reader CPU Time: " << setw(8) << left
312 << ss.str() << endl;
313 timerpart.Start();
314 }
315 }
316
317 m_f->m_graph = SpatialDomains::MeshGraphIO::Read(m_f->m_session, rng);
318
319 if (m_f->m_verbose)
320 {
321 if (m_f->m_comm->TreatAsRankZero())
322 {
323 timerpart.Stop();
324 NekDouble cpuTime = timerpart.TimePerTest(1);
325
326 stringstream ss;
327 ss << cpuTime << "s";
328 cout << "\t InputXml mesh graph setup CPU Time: " << setw(8)
329 << left << ss.str() << endl;
330 timerpart.Start();
331 }
332 }
333}
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
FieldSharedPtr m_f
Field object.
Definition Module.h:239
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
const char *const ShapeTypeMap[SIZE_ShapeType]
Definition ShapeType.hpp:75
std::shared_ptr< DomainRange > DomainRangeShPtr
Definition DomainRange.h:69
static DomainRangeShPtr NullDomainRangeShPtr
Definition DomainRange.h:70

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.