G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsStaticOpt.h
1 
15 
16 namespace gismo
17 {
18 
26 template <class T>
27 class gsStaticOpt : public gsStaticBase<T>
28 {
29 protected:
30 
31  typedef gsStaticBase<T> Base;
32 
33  typedef typename Base::Residual_t Residual_t;
34  typedef typename Base::ALResidual_t ALResidual_t;
35 
36 public:
37 
43  gsStaticOpt( const Residual_t &Residual )
44  :
45  m_residualFun(Residual),
46  m_ALresidualFun(nullptr),
47  m_jacobian(nullptr)
48  {
49  this->_init();
50  }
51 
58  gsStaticOpt( const Residual_t &Residual,
59  const Jacobian_t &Jacobian )
60  :
61  m_residualFun(Residual),
62  m_ALresidualFun(nullptr),
63  m_jacobian(Jacobian)
64  {
65  this->_init();
66  }
67 
68 
75  gsStaticOpt( const ALResidual_t & ALResidual )
76  :
77  m_ALresidualFun(ALResidual),
78  m_jacobian(nullptr)
79  {
80  m_L = 1.0;
81  m_residualFun = [this](gsVector<T> const & x, gsVector<T> & result) -> bool
82  {
83  return m_ALresidualFun(x,m_L,result);
84  };
85  this->_init();
86  }
87 
94  gsStaticOpt( const ALResidual_t & ALResidual,
95  const Jacobian_t &Jacobian )
96  :
97  m_ALresidualFun(ALResidual),
98  m_jacobian(Jacobian)
99  {
100  m_L = 1.0;
101  m_residualFun = [this](gsVector<T> const & x, gsVector<T> & result) -> bool
102  {
103  return m_ALresidualFun(x,m_L,result);
104  };
105  this->_init();
106  }
107 
109 public:
111  gsStatus solve() override;
112 
114  void initialize() override;
115 
117  void initOutput() override;
118 
120  void stepOutput(index_t k) override;
121 
123  void defaultOptions() override;
124 
126  void reset() override;
127 
129  void getOptions() override;
130 
131 protected:
133  void _solve();
135  void _init();
136 
137  gsVector<T> _computeResidual(const gsVector<T> & U);
138 
139 public:
140 
142  T residualNorm() const { return m_R.norm(); }
143 
144 protected:
145  Residual_t m_residualFun;
146  const ALResidual_t m_ALresidualFun;
147  const Jacobian_t m_jacobian;
148 
149  // Solution
150  using Base::m_U;
151  using Base::m_DeltaU;
152  using Base::m_deltaU;
153 
154  using Base::m_L;
155  using Base::m_DeltaL;
156  using Base::m_deltaL;
157 
158  // Iterations
159  using Base::m_numIterations;
160  using Base::m_maxIterations;
161 
162  // Residuals
163  using Base::m_R;
164 
165  // Tolerances
166  using Base::m_tolF;
167  using Base::m_tolU;
168 
169  // Residual norms
170  using Base::m_residual;
171  using Base::m_residualIni;
172  using Base::m_residualOld;
173 
174  // Options
175  using Base::m_options;
176  using Base::m_verbose;
177 
178  // DoFs
179  using Base::m_dofs;
180 
181  // Headstart
182  using Base::m_headstart;
183 
184  // Solver status
185  using Base::m_status;
186 };
187 
189 template <typename T>
192 {
193 public:
194 
196 
197 public:
198 
199  T evalObj( const gsAsConstVector<T> & u ) const;
200 
201  void gradObj_into( const gsAsConstVector<T> & u, gsAsVector<T> & result) const;
202 
203  void evalCon_into( const gsAsConstVector<T> & u, gsAsVector<T> & result) const;
204 
205  void jacobCon_into( const gsAsConstVector<T> & u, gsAsVector<T> & result) const;
206 
207 private:
208 
209  // Lastly, we forward the memebers of the base clase gsOptProblem
213 
216 
219 
222 
224 };
226 
227 } //namespace
228 
229 
230 #ifndef GISMO_BUILD_LIB
231 #include GISMO_HPP_HEADER(gsStaticOpt.hpp)
232 #endif
void jacobCon_into(const gsAsConstVector< T > &u, gsAsVector< T > &result) const
Returns Jacobian of the constraints at design value u. Format of result is sparse, complying to m_conJacRows and m_conJacCols.
Base class for static solvers.
Class defining an optimization problem.
Definition: gsOptProblem.h:24
void _init()
Initializes the method.
Definition: gsStaticOpt.hpp:165
void initOutput() override
See gsStaticBase.
Definition: gsStaticOpt.hpp:43
void reset() override
See gsStaticBase.
Definition: gsStaticOpt.hpp:158
gsStaticOpt(const ALResidual_t &ALResidual, const Jacobian_t &Jacobian)
Constructs a new instance.
Definition: gsStaticOpt.h:94
#define index_t
Definition: gsConfig.h:32
gsStatus
Definition: gsStructuralAnalysisTypes.h:20
void getOptions() override
See gsStaticBase.
Definition: gsStaticOpt.hpp:37
Creates a mapped object or data pointer to a vector without copying data.
Definition: gsLinearAlgebra.h:129
void _solve()
See solve()
Definition: gsStaticOpt.hpp:101
Static solver using the Dynamic Relaxation method.
Definition: gsStaticOpt.h:27
void gradObj_into(const gsAsConstVector< T > &u, gsAsVector< T > &result) const
Returns the gradient of the objective function at design value u By default it uses finite difference...
void defaultOptions() override
See gsStaticBase.
Definition: gsStaticOpt.hpp:31
T residualNorm() const
Return the residual norm.
Definition: gsStaticOpt.h:142
void evalCon_into(const gsAsConstVector< T > &u, gsAsVector< T > &result) const
Returns values of the constraints at design value u.
[OptProblemExample Class]
Definition: gsStaticOpt.h:190
T evalObj(const gsAsConstVector< T > &u) const
Returns the gradient value of the objective function at design value u.
gsStaticOpt(const ALResidual_t &ALResidual)
Constructs a new instance.
Definition: gsStaticOpt.h:75
Creates a mapped object or data pointer to a const vector without copying data.
Definition: gsLinearAlgebra.h:130
gsStaticOpt(const Residual_t &Residual)
Constructor.
Definition: gsStaticOpt.h:43
void initialize() override
See gsStaticBase.
Definition: gsStaticOpt.hpp:151
gsStaticOpt(const Residual_t &Residual, const Jacobian_t &Jacobian)
Constructor.
Definition: gsStaticOpt.h:58
gsStatus solve() override
gsStaticBase base functions
Definition: gsStaticOpt.hpp:75
void stepOutput(index_t k) override
See gsStaticBase.
Definition: gsStaticOpt.hpp:59
Base class for static solvers.
Definition: gsStaticBase.h:37