19using namespace std::string_literals;
26template <
short_t d,
typename T>
29 static_assert(
d >= 1 &&
d <= 3,
"Spatial dimension must be between 1 and 3");
42 using space_type =
typename gismo::gsExprAssembler<T>::space;
51 gismo::gsBoundaryConditions<T>
bc_;
74 u.setup(
bc_, gismo::dirichlet::l2Projection, 0);
107 typename gismo::gsSparseSolver<T>::CGDiagonal
solver;
124 const std::array<int64_t, d> ncoeffs,
125 const std::array<int64_t, d> npatches,
130 :
d == 2 ?
"2*pi^2*sin(pi*x)*sin(pi*y)"
131 :
"2*pi^2*sin(pi*x)*sin(pi*y)*sin(pi*z)",
136 gismo::gsOptionList
Aopt = gismo::gsExprAssembler<>::defaultOptions();
146 auto patch =
bdr.patch;
148 auto bc =
bcMap_[patch][
side] = { gismo::gsFunctionExpr<T>(
"0",
d),
149 gismo::condition_type::dirichlet,
154 for (
auto const &
p :
bcMap_) {
155 std::size_t patch =
p.first;
157 for (
auto const &
bc :
p.second) {
158 auto side =
static_cast<gismo::boundary::side
>(
bc.first);
160 bc_.addCondition(patch,
side,
bc.second.type,
bc.second.function, 0,
bc.second.isParametric);
176 return "GismoPoisson" + std::to_string(
d) +
"d";
181 return "G+Smo Poisson model in " + std::to_string(
d) +
" dimensions";
188 "description" : "Solution of the Poisson equation",
191 "description" : "Right-hand side function",
203 auto json = nlohmann::json::array();
208 const std::string &name,
209 const std::string &
label,
210 const std::string &
group,
213 const Value &value) {
215 item[
"patch"] = patch;
221 item[
"value"] = value;
222 item[
"default"] = value;
230 const std::string &name,
const std::string &
label,
235 item[
"patch"] = patch;
241 item[
"value"] = value;
247 add_json(0,
"rhs",
"Rhs function",
"rhs",
"Right-hand side function",
"text",
249 add_json(0,
"rhs_parametric",
"Parametric",
"rhs",
250 "Right-hand side function defined in parametric domain",
"bool",
253 for (
auto const &
p :
bcMap_) {
254 std::size_t patch =
p.first;
256 for (
auto const &
bc :
p.second) {
257 auto side =
static_cast<gismo::boundary::side
>(
bc.first);
260 add_json(patch,
"bc["s + std::to_string(patch) +
":" +
str +
"]"s,
"Value",
str,
261 "Boundary value at the "s +
str +
" boundary of patch "s + std::to_string(patch),
"text",
262 bc.second.function.expression(0));
263 add_json(patch,
"bc_parametric["s + std::to_string(patch) +
":" +
str +
"]",
"Parametric",
str,
264 "Boundary value at the "s +
str +
265 " boundary of patch "s + std::to_string(patch) +
"defined in parametric domain"s,
266 "bool",
bc.second.isParametric);
268 "Type of boundary condition at the "s +
str +
" boundary of patch "s + std::to_string(patch),
"select",
269 R
"([ "Dirichlet", "Neumann" ])"_json,
270 bc.second.type == gismo::condition_type::dirichlet ? "Dirichlet" :
"Neumann");
281 const nlohmann::json &
json)
override {
287 std::size_t patch =
p.first;
289 for (
auto &
bc :
p.second) {
290 auto side =
static_cast<gismo::boundary::side
>(
bc.first);
294 if (
attribute ==
"bc_parametric["s + std::to_string(patch) +
":" +
str +
"]"s) {
295 if (!
json.contains(
"data"))
297 if (!
json[
"data"].
contains(
"bc_parametric["s + std::to_string(patch) +
":" +
str +
"]"s))
300 bc.second.isParametric =
301 json[
"data"][
"bc_parametric["s + std::to_string(patch) +
":" +
str +
"]"s].template
get<bool>();
304 gismo::give(gismo::gsFunctionExpr<T>(
bc.second.function.expression(0),
305 bc.second.isParametric ?
d : 3));
312 else if (
attribute ==
"bc_type["s + std::to_string(patch) +
":" +
str +
"]"s) {
313 if (!
json.contains(
"data"))
315 if (!
json[
"data"].
contains(
"bc_type["s + std::to_string(patch) +
":" +
str +
"]"s))
322 bc.second.type = gismo::condition_type::type::dirichlet;
324 bc.second.type = gismo::condition_type::type::neumann;
333 else if (
attribute ==
"bc["s + std::to_string(patch) +
":" +
str +
"]"s) {
334 if (!
json.contains(
"data"))
339 bc.second.function =gismo::give(gismo::gsFunctionExpr<T>(
341 bc.second.isParametric ?
d : 3));
351 if (!
json.contains(
"data"))
362 if (!
json.contains(
"data"))
366 rhsFunc_ = gismo::give(gismo::gsFunctionExpr<T>(
378 std::size_t patch =
p.first;
380 for (
auto &
bc :
p.second) {
381 auto side =
static_cast<gismo::boundary::side
>(
bc.first);
383 bc_.addCondition(patch,
side,
bc.second.type,
bc.second.function, 0,
bc.second.isParametric);
396 const nlohmann::json &
json)
const override {
404 return R
"({ INVALID REQUEST })"_json;
412 result[
"degrees"] = nlohmann::json::array();
418 result[
"ncoeffs"] = nlohmann::json::array();
422 for (std::size_t
i = 0;
i <
bspline->parDim(); ++
i)
424 else if (
auto bspline =
dynamic_cast<const gismo::gsTensorBSpline<d, T> *
>(
426 for (std::size_t
i = 0;
i <
bspline->parDim(); ++
i)
429 return R
"({ INVALID REQUEST })"_json;
432 result[
"nknots"] = nlohmann::json::array();
436 for (std::size_t
i = 0;
i <
bspline->parDim(); ++
i)
438 else if (
auto bspline =
dynamic_cast<const gismo::gsTensorBSpline<d, T> *
>(
440 for (std::size_t
i = 0;
i <
bspline->parDim(); ++
i)
443 return R
"({ INVALID REQUEST })"_json;
446 result[
"knots"] = nlohmann::json::array();
450 for (std::size_t
i = 0;
i <
bspline->parDim(); ++
i)
452 else if (
auto bspline =
dynamic_cast<const gismo::gsTensorBSpline<d, T> *
>(
454 for (std::size_t
i = 0;
i <
bspline->parDim(); ++
i)
457 return R
"({ INVALID REQUEST })"_json;
489 if (
json.contains(
"data"))
503 if (
json.contains(
"data")) {
505 num =
json[
"data"][
"num"].get<
int>();
532 if (
json.contains(
"data"))
546 if (
json.contains(
"data")) {
548 num =
json[
"data"][
"num"].get<
int>();
575 if (
json.contains(
"data"))
589 if (
json.contains(
"data")) {
591 num =
json[
"data"][
"num"].get<
int>();
622 throw std::runtime_error(
"Adding patches is not yet implemented in G+Smo");
630 const nlohmann::json &
json =
NULL)
override {
646 auto patch =
bdr.patch;
648 auto bc =
bcMap_[patch][
side] = { gismo::gsFunctionExpr<T>(
"0",
d),
649 gismo::condition_type::dirichlet,
657 for (
auto const &
p :
bcMap_) {
658 std::size_t patch =
p.first;
660 for (
auto const &
bc :
p.second) {
661 auto side =
static_cast<gismo::boundary::side
>(
bc.first);
663 bc_.addCondition(patch,
side,
bc.second.type,
bc.second.function, 0,
bc.second.isParametric);
virtual void addPatch(const nlohmann::json &json)=0
Adds a patch to a model.
virtual void elevate(const nlohmann::json &json)=0
Elevates the model's degrees, preserves smoothness.
virtual nlohmann::json eval(const std::string &patch, const std::string &component, const nlohmann::json &json) const =0
Evaluates model.
virtual nlohmann::json getOutputs() const =0
Returns the model's outputs.
virtual nlohmann::json updateAttribute(const std::string &patch, const std::string &component, const std::string &attribute, const nlohmann::json &json)
Updates the attributes of the model.
Definition model.hpp:297
virtual void increase(const nlohmann::json &json)=0
Increases the model's degrees, preserves multiplicity.
virtual void refine(const nlohmann::json &json)=0
Refines model.
virtual void removePatch(const std::string &patch, const nlohmann::json &json)=0
Adds a patch to a model.
gismo::gsMultiPatch< T > geo_
Multi-patch geometry.
Definition GismoGeometryModel.hpp:39
G+Smo PDE model.
Definition GismoPdeModel.hpp:58
gismo::gsMultiPatch< T > solution_
Solution.
Definition GismoPdeModel.hpp:190
G+Smo Poisson model.
Definition GismoPoissonModel.hpp:27
~GismoPoissonModel()
Destructor.
Definition GismoPoissonModel.hpp:172
void refine(const nlohmann::json &json=NULL) override
Refines the model.
Definition GismoPoissonModel.hpp:571
typename gismo::gsExprAssembler< T >::solution solution_type
Type of the solution.
Definition GismoPoissonModel.hpp:45
void elevate(const nlohmann::json &json=NULL) override
Elevates the model's degrees, preserves smoothness.
Definition GismoPoissonModel.hpp:485
gismo::gsExprAssembler< T > assembler_
Expression assembler.
Definition GismoPoissonModel.hpp:64
void addPatch(const nlohmann::json &json=NULL) override
Add new patch to the model.
Definition GismoPoissonModel.hpp:614
gismo::gsBoundaryConditions< T > bc_
Boundary conditions.
Definition GismoPoissonModel.hpp:51
GismoPoissonModel()=delete
Default constructor.
void removePatch(const std::string &patch, const nlohmann::json &json=NULL) override
Remove existing patch from the model.
Definition GismoPoissonModel.hpp:629
typename gismo::gsExprAssembler< T >::space space_type
Type of the function space.
Definition GismoPoissonModel.hpp:42
nlohmann::json eval(const std::string &patch, const std::string &component, const nlohmann::json &json) const override
Evaluates the model.
Definition GismoPoissonModel.hpp:395
nlohmann::json getParameters() const override
Returns the model's parameters.
Definition GismoPoissonModel.hpp:201
void increase(const nlohmann::json &json=NULL) override
Increases the model's degrees, preserves multiplicity.
Definition GismoPoissonModel.hpp:528
gismo::gsFunctionExpr< T > rhsFunc_
Right-hand side function.
Definition GismoPoissonModel.hpp:54
gismo::gsMultiBasis< T > basis_
Multi-patch basis.
Definition GismoPoissonModel.hpp:48
void solve()
Solve the Poisson problem.
Definition GismoPoissonModel.hpp:67
nlohmann::json updateAttribute(const std::string &patch, const std::string &component, const std::string &attribute, const nlohmann::json &json) override
Updates the attributes of the model.
Definition GismoPoissonModel.hpp:278
bool rhsFuncParametric_
Right-hand side function defined on parametric domain (default false)
Definition GismoPoissonModel.hpp:58
typename gismo::gsExprAssembler< T >::geometryMap geometryMap_type
Type of the geometry mapping.
Definition GismoPoissonModel.hpp:36
std::string getDescription() const override
Returns the model's description.
Definition GismoPoissonModel.hpp:180
GismoPoissonModel(const std::array< short_t, d > degrees, const std::array< int64_t, d > ncoeffs, const std::array< int64_t, d > npatches, const std::array< T, d > dimensions)
Constructor for equidistant knot vectors.
Definition GismoPoissonModel.hpp:123
std::string getName() const override
Returns the model's name.
Definition GismoPoissonModel.hpp:175
nlohmann::json getOutputs() const override
Returns the model's outputs.
Definition GismoPoissonModel.hpp:185
GismoBoundaryConditionMap< T > bcMap_
Boundary condition look-up table.
Definition GismoPoissonModel.hpp:61
typename gismo::gsExprAssembler< T >::variable variable_type
Type of the variable.
Definition GismoPoissonModel.hpp:39
auto to_json(const torch::TensorAccessor< T, N > &accessor)
Converts a torch::TensorAccessor object to a JSON object.
Definition serialize.hpp:41
degree
Enumerator for specifying the degree of B-splines.
Definition BSplineModel.hpp:23
std::map< int, std::map< int, GismoBoundaryCondition< T > > > GismoBoundaryConditionMap
G+Smo boundary condition look-up table.
Definition GismoPdeModel.hpp:39
Definition boundary.hpp:22
constexpr bool is_SplineType_v
Alias to the value of is_SplineType.
Definition bspline.hpp:3243
side
Identifiers for topological sides.
Definition boundary.hpp:25
InvalidModelAttribute exception.
Definition model.hpp:42