IgANet
IgANets - Isogeometric Analysis Networks
Loading...
Searching...
No Matches
GismoPdeModel.hpp
Go to the documentation of this file.
1
15#pragma once
16
18
19namespace iganet {
20
21namespace webapp {
22
24template<typename T>
27 gismo::gsFunctionExpr<T> function;
28
30 gismo::condition_type::type type;
31
35};
36
38template<typename T>
39using GismoBoundaryConditionMap = std::map<int, std::map<int, GismoBoundaryCondition<T>>>;
40
42template<typename T>
45 gismo::gsFunctionExpr<T> function;
46
50};
51
53template<typename T>
54using GismoFunctionMap = std::map<int, std::map<int, GismoFunction<T>>>;
55
57template <short_t d, class T>
58class GismoPdeModel : public GismoGeometryModel<d, T> {
59
60public:
63
65 nlohmann::json to_json(const std::string &patch, const std::string &component,
66 const std::string &attribute) const override {
67
68 if (component == "solution") {
69
70 if (patch == "" && attribute == "") {
71
72 // Return solution as multipatch structure
74 }
75
76 else if (patch != "") {
77
78 // Return individual patch of the solution
79 std::size_t patchIndex(0);
80
81 try {
82 patchIndex = stoi(patch);
83 } catch (...) {
84 // Invalid patchIndex
85 return R"({ INVALID REQUEST })"_json;
86 }
87
88 if (patchIndex >= solution_.nPatches())
89 return R"({ INVALID REQUEST })"_json;
90
91 if (attribute == "") {
92
93 // Return all attributes
94 return utils::to_json(solution_.patch(patchIndex));
95
96 } else {
97
98 nlohmann::json json;
99
100 // Return an individual attribute
101 if (attribute == "degrees") {
102 json["degrees"] = nlohmann::json::array();
103
104 for (std::size_t i = 0; i < solution_.patch(patchIndex).parDim(); ++i)
105 json["degrees"].push_back(solution_.patch(patchIndex).degree(i));
106 }
107
108 else if (attribute == "geoDim")
109 json["geoDim"] = solution_.patch(patchIndex).geoDim();
110
111 else if (attribute == "parDim")
112 json["parDim"] = solution_.patch(patchIndex).parDim();
113
114 else if (attribute == "ncoeffs") {
115 json["ncoeffs"] = nlohmann::json::array();
116
117 if (auto bspline =
118 dynamic_cast<const gismo::gsBSpline<T> *>(&solution_.patch(patchIndex)))
119 for (std::size_t i = 0; i < bspline->parDim(); ++i)
120 json["ncoeffs"].push_back(bspline->basis().size(i));
121 else if (auto bspline = dynamic_cast<const gismo::gsTensorBSpline<d, T> *>(
122 &solution_.patch(patchIndex)))
123 for (std::size_t i = 0; i < bspline->parDim(); ++i)
124 json["ncoeffs"].push_back(bspline->basis().size(i));
125 else
126 return R"({ INVALID REQUEST })"_json;
127 }
128
129 else if (attribute == "nknots") {
130 json["nknots"] = nlohmann::json::array();
131
132 if (auto bspline =
133 dynamic_cast<const gismo::gsBSpline<T> *>(&solution_.patch(patchIndex)))
134 for (std::size_t i = 0; i < bspline->parDim(); ++i)
135 json["nknots"].push_back(bspline->knots(i).size());
136 else if (auto bspline = dynamic_cast<const gismo::gsTensorBSpline<d, T> *>(
137 &solution_.patch(patchIndex)))
138 for (std::size_t i = 0; i < bspline->parDim(); ++i)
139 json["nknots"].push_back(bspline->knots(i).size());
140 else
141 return R"({ INVALID REQUEST })"_json;
142 }
143
144 else if (attribute == "coeffs") {
145
146 if (auto bspline =
147 dynamic_cast<const gismo::gsBSpline<T> *>(&solution_.patch(patchIndex)))
148 json["coeffs"] = utils::to_json(bspline->coefs());
149 else if (auto bspline = dynamic_cast<const gismo::gsTensorBSpline<d, T> *>(
150 &solution_.patch(patchIndex)))
151 json["coeffs"] = utils::to_json(bspline->coefs());
152 else
153 return R"({ INVALID REQUEST })"_json;
154
155 }
156
157 else if (attribute == "knots") {
158 json["knots"] = nlohmann::json::array();
159
160 if (auto bspline =
161 dynamic_cast<const gismo::gsBSpline<T> *>(&solution_.patch(patchIndex)))
162 for (std::size_t i = 0; i < bspline->parDim(); ++i)
163 json["knots"].push_back(bspline->knots(i));
164 else if (auto bspline = dynamic_cast<const gismo::gsTensorBSpline<d, T> *>(
165 &solution_.patch(patchIndex)))
166 for (std::size_t i = 0; i < bspline->parDim(); ++i)
167 json["knots"].push_back(bspline->knots(i));
168 else
169 return R"({ INVALID REQUEST })"_json;
170 }
171
172 else
173 // Invalid attribute
174 return R"({ INVALID REQUEST })"_json;
175
176 return json;
177 }
178 }
179
180 else
181 return R"({ INVALID REQUEST })"_json;
182 }
183
184 // Handle component != "solution"
186 }
187
188protected:
190 gismo::gsMultiPatch<T> solution_;
191};
192
193} // namespace webapp
194} // namespace iganet
G+Smo geometry model.
G+Smo geometry model.
Definition GismoGeometryModel.hpp:33
nlohmann::json to_json(const std::string &patch, const std::string &component, const std::string &attribute) const override
Serializes the model to JSON.
Definition GismoGeometryModel.hpp:334
GismoGeometryModel()=default
Default constructor.
G+Smo PDE model.
Definition GismoPdeModel.hpp:58
gismo::gsMultiPatch< T > solution_
Solution.
Definition GismoPdeModel.hpp:190
nlohmann::json to_json(const std::string &patch, const std::string &component, const std::string &attribute) const override
Serializes the model to JSON.
Definition GismoPdeModel.hpp:65
auto to_json(const torch::TensorAccessor< T, N > &accessor)
Converts a torch::TensorAccessor object to a JSON object.
Definition serialize.hpp:41
gismo::condition_type::type type
Boundary type.
Definition GismoPdeModel.hpp:30
bool isParametric
Flag that indicates whether the boundary conditions is imposed on the parametric of physical domain.
Definition GismoPdeModel.hpp:34
bool isParametric
Flag that indicates whether the function expression is imposed on the parametric of physical domain.
Definition GismoPdeModel.hpp:49
std::map< int, std::map< int, GismoFunction< T > > > GismoFunctionMap
G+Smo function look-up table.
Definition GismoPdeModel.hpp:54
gismo::gsFunctionExpr< T > function
Function expression.
Definition GismoPdeModel.hpp:45
gismo::gsFunctionExpr< T > function
Boundary function expression.
Definition GismoPdeModel.hpp:27
std::map< int, std::map< int, GismoBoundaryCondition< T > > > GismoBoundaryConditionMap
G+Smo boundary condition look-up table.
Definition GismoPdeModel.hpp:39
G+Smo boundary condition POD.
Definition GismoPdeModel.hpp:25
G+Smo function POD.
Definition GismoPdeModel.hpp:43
Definition boundary.hpp:22
constexpr bool is_SplineType_v
Alias to the value of is_SplineType.
Definition bspline.hpp:3243