IgANet
IGAnets - Isogeometric Analysis Networks
Loading...
Searching...
No Matches
patch.hpp
Go to the documentation of this file.
1
15#pragma once
16
17#include <iganet/core/core.hpp>
18
21
22#include <nlohmann/json.hpp>
23#include <pugixml.hpp>
24
25namespace iganet {
26
27namespace detail {
28
29// @brief Concept to identify template parameters that have an
30// as_tensor function
31template <typename T>
32concept HasAsTensor = requires(T a) {
33 { a.as_tensor() };
34};
35
36// @brief Concept to identify template parameters that have an
37// as_tensor_size function
38template <typename T>
39concept HasAsTensorSize = requires(T a) {
40 { a.as_tensor_size() };
41};
42
43// @brief Concept to identify template parameters that have a
44// from_tensor function
45template <typename T>
46concept HasFromTensor = requires(T a) {
47 { a.from_tensor() };
48};
49
50} // namespace detail
51
53template <typename real_t, short_t GeoDim, short_t ParDim> class BSplinePatch {
54public:
56 using value_type = real_t;
57
60 inline static constexpr short_t geoDim() noexcept { return GeoDim; }
61
64 inline static constexpr short_t parDim() noexcept { return ParDim; }
65
67 virtual ~BSplinePatch() = default;
68
71 virtual torch::Device device() const noexcept = 0;
72
75 virtual int32_t device_index() const noexcept = 0;
76
79 virtual torch::Dtype dtype() const noexcept = 0;
80
83 virtual torch::Layout layout() const noexcept = 0;
84
87 virtual bool requires_grad() const noexcept = 0;
88
91 virtual bool pinned_memory() const noexcept = 0;
92
95 virtual bool is_sparse() const noexcept = 0;
96
100 virtual BSplinePatch &set_requires_grad(bool requires_grad) noexcept = 0;
101
104 // @brief Returns all coefficients as a single tensor
105 virtual torch::Tensor as_tensor() const noexcept = 0;
106
110 virtual BSplinePatch &from_tensor(const torch::Tensor &tensor) noexcept = 0;
111
115 virtual int64_t as_tensor_size() const noexcept = 0;
116
125 virtual utils::BlockTensor<torch::Tensor, 1, GeoDim>
126 eval_from_precomputed(const torch::Tensor &basfunc,
127 const torch::Tensor &coeff_indices, int64_t numeval,
128 torch::IntArrayRef sizes) const = 0;
129
136 virtual utils::BlockTensor<torch::Tensor, 1, GeoDim>
137 eval_from_precomputed(const utils::TensorArray<ParDim> &basfunc,
138 const torch::Tensor &coeff_indices, int64_t numeval,
139 torch::IntArrayRef sizes) const = 0;
141
144 [[nodiscard]] virtual nlohmann::json to_json() const = 0;
145
149 virtual BSplinePatch &from_json(const nlohmann::json &json) = 0;
150
156 [[nodiscard]] virtual pugi::xml_document
157 to_xml(int id = 0, const std::string &label = "", int index = -1) const = 0;
158
165 virtual pugi::xml_node &to_xml(pugi::xml_node &root, int id = 0,
166 const std::string &label = "",
167 int index = -1) const = 0;
168
175 virtual BSplinePatch &from_xml(const pugi::xml_document &doc, int id = 0,
176 const std::string &label = "",
177 int index = -1) = 0;
178
185 virtual BSplinePatch &from_xml(const pugi::xml_node &root, int id = 0,
186 const std::string &label = "",
187 int index = -1) = 0;
188
191 virtual void
192 pretty_print(std::ostream &os = Log(log::info)) const noexcept = 0;
193};
194
196template <typename real_t, short_t GeoDim, short_t ParDim>
197inline std::ostream &
198operator<<(std::ostream &os, const BSplinePatch<real_t, GeoDim, ParDim> &obj) {
199 obj.pretty_print(os);
200 return os;
201}
202
203} // namespace iganet
Compile-time block tensor.
Abstract patch function base class.
Definition patch.hpp:53
virtual torch::Layout layout() const noexcept=0
Returns the layout property.
virtual bool pinned_memory() const noexcept=0
Returns the pinned_memory property.
virtual torch::Tensor as_tensor() const noexcept=0
Provides the as_tensor operation.
static constexpr short_t geoDim() noexcept
Dimension of the physical space.
Definition patch.hpp:60
virtual int32_t device_index() const noexcept=0
Returns the device_index property.
virtual nlohmann::json to_json() const =0
Returns the B-spline patch as a JSON object.
virtual bool requires_grad() const noexcept=0
Returns the requires_grad property.
virtual torch::Dtype dtype() const noexcept=0
Returns the dtype property.
virtual BSplinePatch & set_requires_grad(bool requires_grad) noexcept=0
Sets the B-spline object's requires_grad property.
virtual BSplinePatch & from_tensor(const torch::Tensor &tensor) noexcept=0
Sets all coefficients from a single tensor.
virtual BSplinePatch & from_json(const nlohmann::json &json)=0
Updates the B-spline patch from a JSON object.
virtual bool is_sparse() const noexcept=0
Returns if the layout is sparse.
virtual ~BSplinePatch()=default
Destructor.
virtual pugi::xml_document to_xml(int id=0, const std::string &label="", int index=-1) const =0
Returns the B-spline patch as an XML document.
static constexpr short_t parDim() noexcept
Dimension of the parametric space.
Definition patch.hpp:64
real_t value_type
Scalar type.
Definition patch.hpp:56
virtual BSplinePatch & from_xml(const pugi::xml_document &doc, int id=0, const std::string &label="", int index=-1)=0
Updates the B-spline patch from an XML document.
virtual int64_t as_tensor_size() const noexcept=0
Returns the size of the single tensor representation of all coefficients.
virtual void pretty_print(std::ostream &os=Log(log::info)) const noexcept=0
Returns a string representation.
virtual utils::BlockTensor< torch::Tensor, 1, GeoDim > eval_from_precomputed(const torch::Tensor &basfunc, const torch::Tensor &coeff_indices, int64_t numeval, torch::IntArrayRef sizes) const =0
Returns the value of the spline function from precomputed basis function.
virtual torch::Device device() const noexcept=0
Returns the device property.
Definition patch.hpp:32
Definition patch.hpp:39
Definition patch.hpp:46
Core components.
Definition core.hpp:73
struct iganet::@0 Log
Logger.
log
Enumerator for specifying the logging level.
Definition core.hpp:102
short int short_t
Signed short integer type used by IgANet's compact enumerations.
Definition core.hpp:76
STL namespace.
Definition optimizer.hpp:61
TensorArray utility functions.