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

71{
72}

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

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