37 std::vector<torch::Tensor> &v) {
39 std::filesystem::path path(location);
41 if (std::filesystem::exists(path)) {
42 if (std::filesystem::is_regular_file(path)) {
44 pugi::xml_document doc;
45 doc.load_file(path.c_str());
46 v.emplace_back(obj.from_xml(doc).as_tensor());
49 }
else if (std::filesystem::is_directory(path)) {
50 for (
const auto &file : std::filesystem::directory_iterator(path)) {
51 if (file.is_regular_file() && file.path().extension() ==
".xml") {
53 pugi::xml_document doc;
54 doc.load_file(file.path().c_str());
55 v.emplace_back(obj.from_xml(doc).as_tensor());
61 throw std::runtime_error(
62 "The path refers to neither a file nor a directory");
64 throw std::runtime_error(
"The path does not exist");
78 public torch::data::Dataset<
80 torch::data::Example<torch::Tensor, torch::data::example::NoTarget>> {
83 std::vector<torch::Tensor>
G_;
86 std::vector<torch::Tensor>
f_;
91 torch::data::Example<torch::Tensor, torch::data::example::NoTarget>;
99 read_from_xml(location, obj, G_);
108 read_from_xml(location, obj, G_);
119 template <
typename T>
121 const std::string &label =
"") {
122 G_.emplace_back(obj.from_xml(doc.child(
"xml"),
id, label).as_tensor());
131 template <
typename T>
133 const std::string &label =
"") {
134 G_.emplace_back(obj.from_xml(doc.child(
"xml"),
id, label).as_tensor());
145 template <
typename T>
147 const std::string &label =
"") {
148 G_.emplace_back(obj.from_xml(root,
id, label).as_tensor());
157 template <
typename T>
159 const std::string &label =
"") {
160 G_.emplace_back(obj.from_xml(root,
id, label).as_tensor());
170 read_from_xml(location, obj, f_);
179 read_from_xml(location, obj, f_);
190 template <
typename T>
192 const std::string &label =
"") {
193 f_.emplace_back(obj.from_xml(doc.child(
"xml"),
id, label).as_tensor());
202 template <
typename T>
204 const std::string &label =
"") {
205 f_.emplace_back(obj.from_xml(doc.child(
"xml"),
id, label).as_tensor());
216 template <
typename T>
218 const std::string &label =
"") {
219 f_.emplace_back(obj.from_xml(root,
id, label).as_tensor());
228 template <
typename T>
230 const std::string &label =
"") {
231 f_.emplace_back(obj.from_xml(root,
id, label).as_tensor());
241 template <
typename T,
typename Func>
243 f_.emplace_back(obj.transform(
func).as_tensor());
253 template <
typename T,
typename Func>
255 f_.emplace_back(obj.transform(
func).as_tensor());
264 std::size_t geo_index = index / (f_.empty() ? 1 : f_.size());
265 std::size_t ref_index = index - geo_index * f_.size();
269 return torch::cat({G_.at(geo_index), f_.at(ref_index)});
271 return G_.at(geo_index);
274 return f_.at(ref_index);
276 throw std::runtime_error(
"No geometry maps and reference data");
285 [[nodiscard]]
inline torch::optional<std::size_t>
size()
const override {
286 return (G_.empty() ? 1 : G_.size()) * (f_.empty() ? 1 : f_.size());
293 public torch::data::Dataset<IgADataset<true>, torch::data::Example<>> {
296 std::vector<torch::Tensor>
G_;
299 std::vector<torch::Tensor>
f_;
302 std::vector<torch::Tensor>
u_;
311 read_from_xml(location, obj, G_);
320 read_from_xml(location, obj, G_);
331 template <
typename T>
333 const std::string &label =
"") {
334 G_.emplace_back(obj.from_xml(doc.child(
"xml"),
id, label).as_tensor());
343 template <
typename T>
345 const std::string &label =
"") {
346 G_.emplace_back(obj.from_xml(doc.child(
"xml"),
id, label).as_tensor());
357 template <
typename T>
359 const std::string &label =
"") {
360 G_.emplace_back(obj.from_xml(root,
id, label).as_tensor());
369 template <
typename T>
371 const std::string &label =
"") {
372 G_.emplace_back(obj.from_xml(root,
id, label).as_tensor());
382 read_from_xml(location, obj, f_);
391 read_from_xml(location, obj, f_);
402 template <
typename T>
404 const std::string &label =
"") {
405 f_.emplace_back(obj.from_xml(doc.child(
"xml"),
id, label).as_tensor());
414 template <
typename T>
416 const std::string &label =
"") {
417 f_.emplace_back(obj.from_xml(doc.child(
"xml"),
id, label).as_tensor());
428 template <
typename T>
430 const std::string &label =
"") {
431 f_.emplace_back(obj.from_xml(root,
id, label).as_tensor());
440 template <
typename T>
442 const std::string &label =
"") {
443 f_.emplace_back(obj.from_xml(root,
id, label).as_tensor());
453 template <
typename T,
typename Func>
455 f_.emplace_back(obj.transform(
func).as_tensor());
465 template <
typename T,
typename Func>
467 f_.emplace_back(obj.transform(
func).as_tensor());
476 template <
typename T>
void add_solution(T &obj, std::string location) {
477 read_from_xml(location, obj, u_);
485 template <
typename T>
void add_solution(T &&obj, std::string location) {
486 read_from_xml(location, obj, u_);
497 template <
typename T>
499 const std::string &label =
"") {
500 u_.emplace_back(obj.from_xml(doc.child(
"xml"),
id, label).as_tensor());
509 template <
typename T>
511 const std::string &label =
"") {
512 u_.emplace_back(obj.from_xml(doc.child(
"xml"),
id, label).as_tensor());
523 template <
typename T>
525 const std::string &label =
"") {
526 u_.emplace_back(obj.from_xml(root,
id, label).as_tensor());
535 template <
typename T>
537 const std::string &label =
"") {
538 u_.emplace_back(obj.from_xml(root,
id, label).as_tensor());
545 inline torch::data::Example<>
get(std::size_t index)
override {
547 std::size_t geo_index = index / (f_.empty() ? 1 : f_.size());
548 std::size_t ref_index = index - geo_index * f_.size();
552 return {torch::cat({G_.at(geo_index), f_.at(ref_index)}), u_.at(index)};
554 return {G_.at(geo_index), u_.at(index)};
557 return {f_.at(ref_index), u_.at(index)};
559 throw std::runtime_error(
"No geometry maps and reference data");
566 [[nodiscard]]
inline torch::optional<std::size_t>
size()
const override {
567 return (G_.empty() ? 1 : G_.size()) * (f_.empty() ? 1 : f_.size());
void add_referenceData(T &&obj, std::string location)
Provides the add_referenceData operation.
Definition igabase.hpp:178
void add_referenceData(T &obj, Func func)
Adds a reference data set from XML node.
Definition igabase.hpp:242
void add_referenceData(T &obj, const pugi::xml_document &doc, int id=0, const std::string &label="")
Adds a reference data set from XML object.
Definition igabase.hpp:191
std::vector< torch::Tensor > G_
Vector of tensors representing the geometry maps.
Definition igabase.hpp:83
void add_referenceData(T &&obj, const pugi::xml_document &doc, int id=0, const std::string &label="")
Provides the add_referenceData operation.
Definition igabase.hpp:203
std::vector< torch::Tensor > f_
Vector of tensors representing the reference data.
Definition igabase.hpp:86
void add_referenceData(T &obj, std::string location)
Adds a reference data set from file.
Definition igabase.hpp:169
void add_referenceData(T &obj, const pugi::xml_node &root, int id=0, const std::string &label="")
Adds a reference data set from XML node.
Definition igabase.hpp:217
void add_geometryMap(T &&obj, const pugi::xml_document &doc, int id=0, const std::string &label="")
Provides the add_geometryMap operation.
Definition igabase.hpp:132
void add_geometryMap(T &&obj, const pugi::xml_node &root, int id=0, const std::string &label="")
Provides the add_geometryMap operation.
Definition igabase.hpp:158
void add_referenceData(T &&obj, const pugi::xml_node &root, int id=0, const std::string &label="")
Provides the add_referenceData operation.
Definition igabase.hpp:229
void add_geometryMap(T &obj, const pugi::xml_document &doc, int id=0, const std::string &label="")
Adds a geometry map from XML object.
Definition igabase.hpp:120
void add_geometryMap(T &&obj, std::string location)
Provides the add_geometryMap operation.
Definition igabase.hpp:107
torch::data::Example< torch::Tensor, torch::data::example::NoTarget > example_type
Example type.
Definition igabase.hpp:91
void add_geometryMap(T &obj, std::string location)
Adds a geometry map from file.
Definition igabase.hpp:98
void add_referenceData(T &&obj, Func func)
Provides the add_referenceData operation.
Definition igabase.hpp:254
example_type get(std::size_t index) override
Returns the data set at location index.
Definition igabase.hpp:262
torch::optional< std::size_t > size() const override
Provides the size operation.
Definition igabase.hpp:285
void add_geometryMap(T &obj, const pugi::xml_node &root, int id=0, const std::string &label="")
Adds a geometry map from XML node.
Definition igabase.hpp:146
torch::optional< std::size_t > size() const override
Provides the size operation.
Definition igabase.hpp:566
void add_referenceData(T &obj, const pugi::xml_document &doc, int id=0, const std::string &label="")
Adds a reference data set from XML object.
Definition igabase.hpp:403
std::vector< torch::Tensor > G_
Vector of tensors representing the geometry maps.
Definition igabase.hpp:296
void add_referenceData(T &&obj, const pugi::xml_document &doc, int id=0, const std::string &label="")
Provides the add_referenceData operation.
Definition igabase.hpp:415
void add_solution(T &obj, const pugi::xml_node &root, int id=0, const std::string &label="")
Adds a solution from XML node.
Definition igabase.hpp:524
void add_referenceData(T &obj, Func func)
Adds a reference data set from XML node.
Definition igabase.hpp:454
void add_solution(T &&obj, const pugi::xml_node &root, int id=0, const std::string &label="")
Provides the add_solution operation.
Definition igabase.hpp:536
std::vector< torch::Tensor > f_
Vector of tensors representing the reference data.
Definition igabase.hpp:299
void add_geometryMap(T &obj, const pugi::xml_node &root, int id=0, const std::string &label="")
Adds a geometry map from XML node.
Definition igabase.hpp:358
void add_referenceData(T &&obj, Func func)
Provides the add_referenceData operation.
Definition igabase.hpp:466
void add_solution(T &&obj, const pugi::xml_document &doc, int id=0, const std::string &label="")
Provides the add_solution operation.
Definition igabase.hpp:510
void add_solution(T &obj, const pugi::xml_document &doc, int id=0, const std::string &label="")
Adds a solution from XML object.
Definition igabase.hpp:498
void add_geometryMap(T &&obj, std::string location)
Provides the add_geometryMap operation.
Definition igabase.hpp:319
void add_referenceData(T &&obj, std::string location)
Provides the add_referenceData operation.
Definition igabase.hpp:390
torch::data::Example get(std::size_t index) override
Returns the data set at location index.
Definition igabase.hpp:545
void add_referenceData(T &obj, const pugi::xml_node &root, int id=0, const std::string &label="")
Adds a reference data set from XML node.
Definition igabase.hpp:429
void add_referenceData(T &obj, std::string location)
Adds a reference data set from file.
Definition igabase.hpp:381
void add_geometryMap(T &&obj, const pugi::xml_node &root, int id=0, const std::string &label="")
Provides the add_geometryMap operation.
Definition igabase.hpp:370
void add_geometryMap(T &obj, const pugi::xml_document &doc, int id=0, const std::string &label="")
Adds a geometry map from XML object.
Definition igabase.hpp:332
void add_geometryMap(T &&obj, const pugi::xml_document &doc, int id=0, const std::string &label="")
Provides the add_geometryMap operation.
Definition igabase.hpp:344
void add_solution(T &obj, std::string location)
Adds a solution from file.
Definition igabase.hpp:476
void add_solution(T &&obj, std::string location)
Provides the add_solution operation.
Definition igabase.hpp:485
void add_referenceData(T &&obj, const pugi::xml_node &root, int id=0, const std::string &label="")
Provides the add_referenceData operation.
Definition igabase.hpp:441
std::vector< torch::Tensor > u_
Vector of tensors representing the solution data.
Definition igabase.hpp:302
void add_geometryMap(T &obj, std::string location)
Adds a geometry map from file.
Definition igabase.hpp:310
IgA dataset base class.
Definition igabase.hpp:28
void read_from_xml(const std::string &location, T &obj, std::vector< torch::Tensor > &v)
Reads a function space from file.
Definition igabase.hpp:36
IgA dataset class.
Definition igabase.hpp:73