IgANet
IGAnets - Isogeometric Analysis Networks
Loading...
Searching...
No Matches
igasolver.hpp
Go to the documentation of this file.
1
15#pragma once
16
17#include <net/igabase.hpp>
18#include <splines/boundary.hpp>
20#include <utils/solver.hpp>
21
22namespace iganet {
23
27template <typename Inputs, typename Outputs, typename CollPts = void>
28class IgASolver : public IgABase<Inputs, Outputs, CollPts>,
30
31protected:
33 torch::Tensor lhs_;
34
36 torch::Tensor rhs_;
37
38public:
41
43 using Base::IgABase;
44
46 inline constexpr const auto &lhs() const { return lhs_; }
47
49 inline constexpr auto &lhs() { return lhs_; }
50
52 inline constexpr const auto &rhs() const { return rhs_; }
53
55 inline constexpr auto &rhs() { return rhs_; }
56
58 virtual void init() = 0;
59
61 virtual void assemble() {
64 }
65
67 virtual void assembleLhs() = 0;
68
70 virtual void assembleRhs() = 0;
71
73 torch::Tensor solve() const {
74 auto [x, iter, res] = utils::solve_bicgstab(lhs(), rhs());
75 return x;
76 }
77
79 inline void pretty_print(std::ostream &os) const noexcept override {
80 os << name() << "(\n";
81
82 os << "inputs[" << Base::ninputs() << "] = (";
83 std::apply([&os](const auto &...elems) { ((os << elems << "\n"), ...); },
84 Base::inputs());
85 os << ")";
86
87 os << "outputs [" << Base::noutputs() << "]= (";
88 std::apply([&os](const auto &...elems) { ((os << elems << "\n"), ...); },
89 Base::inputs());
90 os << ")";
91
92 os << "collPts [" << Base::ncollPts() << "]= (";
93 std::apply([&os](const auto &...elems) { ((os << elems << "\n"), ...); },
94 Base::collPts());
95 os << ")";
96 }
97};
98
100template <typename Inputs, typename Outputs, typename CollPts>
101inline std::ostream &
102operator<<(std::ostream &os,
104 obj.pretty_print(os);
105 return os;
106}
107
108} // namespace iganet
Boundary treatment.
IgA base class.
Definition iganet.hpp:46
IgA solver.
Definition igasolver.hpp:29
torch::Tensor lhs_
Left-hand side tensor.
Definition igasolver.hpp:33
torch::Tensor rhs_
Right-hand side tensor.
Definition igasolver.hpp:36
virtual void assembleLhs()=0
Assembles the left-hand side of the solver.
constexpr const auto & rhs() const
Returns a constant reference to the right-hand side object.
Definition igasolver.hpp:52
virtual void assembleRhs()=0
Assembles the right-hand side of the solver.
virtual void assemble()
Assembles the solver.
Definition igasolver.hpp:61
torch::Tensor solve() const
Computes the solution vector.
Definition igasolver.hpp:73
constexpr auto & rhs()
Returns a non-constant reference to the right-hand side object.
Definition igasolver.hpp:55
constexpr const auto & lhs() const
Returns a constant reference to the left-hand side object.
Definition igasolver.hpp:46
constexpr auto & lhs()
Returns a non-constant reference to the left-hand side object.
Definition igasolver.hpp:49
virtual void init()=0
Initializes the solver.
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the IgASolver object.
Definition igasolver.hpp:79
Full qualified name descriptor.
Definition fqn.hpp:22
virtual const std::string & name() const noexcept
Returns the full qualified name of the object.
Definition fqn.hpp:28
Function spaces.
auto solve_bicgstab(const torch::Tensor &A, const torch::Tensor b, int max_iter=1000, double tol=1e-10)
Solves the linear system A * x = b using the Bi-Conjugate Gradient Stabilized (BiCGStab) method.
Definition solver.hpp:57
Definition core.hpp:72
std::ostream & operator<<(std::ostream &os, const MemoryDebugger< id > &obj)
Print (as string) a memory debugger object.
Definition memory.hpp:125
Solver utility functions.