G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsStaticOpt.hpp
1
15
16#ifdef gsHLBFGS_ENABLED
17#include <gsHLBFGS/gsHLBFGS.h>
18#endif
19
20#ifdef gsOptim_ENABLED
21#include <gsOptim/gsOptim.h>
22#endif
23
24#ifdef gsIpOpt_ENABLED
25#include <gsIpOpt/gsIpOpt.h>
26#endif
27
28#pragma once
29
30namespace gismo
31{
32
33template <class T, class Optimizer>
35{
36 Base::defaultOptions();
37}
38
39template <class T, class Optimizer>
41{
42 m_U.setZero(m_dofs);
43 m_DeltaU.setZero(m_dofs);
44
45 defaultOptions();
46
47 m_status = gsStatus::NotStarted;
48 m_numIterations = 0;
49
50 // m_optProblem = gsOptProblemStatic<T>(m_residualFun, m_dofs);
51 // m_optimizer = Optimizer(&m_optProblem);
52}
53
54template <class T, class Optimizer>
56{
57 Base::getOptions();
58
59 m_optimizer.options().setInt("MaxIterations",m_maxIterations);
60 m_optimizer.options().setInt("Verbose",m_verbose);
61 if (dynamic_cast<gsGradientDescent<T>*>(&m_optimizer))
62 {
63 m_optimizer.options().setReal("MinGradientLength",m_tolF);
64 m_optimizer.options().setReal("MinStepLength",m_tolU);
65 }
66#ifdef gsHLBFGS_ENABLED
67 else if (dynamic_cast<gsHLBFGS<T>*>(&m_optimizer))
68 {
69 m_optimizer.options().setReal("MinGradLen",m_tolF);
70 m_optimizer.options().setReal("MinStepLen",m_tolU);
71 }
72#endif
73#ifdef gsOptim_ENABLED
74 else if (dynamic_cast<gsOptim<T>*>(&m_optimizer))
75 {
76 m_optimizer.options().setReal("RelObjFnChangeTol",m_tolF);
77 m_optimizer.options().setReal("RelSolChangeTol",m_tolU);
78 }
79#endif
80#ifdef gsIpOpt_ENABLED
81 else if (dynamic_cast<gsIpOpt<T>*>(&m_optimizer))
82 {
83 m_optimizer.options().setReal("MinGradientLength",m_tolF);
84 m_optimizer.options().setReal("MinStepLength",m_tolU);
85 }
86#endif
87 else
88 GISMO_ERROR("Optimizer not recognized\n");
89}
90
91template <class T, class Optimizer>
93{
94 this->getOptions();
95 m_optimizer.solve(m_U+m_DeltaU);
96
97 m_DeltaU = m_optimizer.currentDesign() - m_U;
98 m_U += m_DeltaU;
99
100 m_numIterations = m_optimizer.iterations();
101 return gsStatus::Success;
102}
103} // namespace gismo
This class describes the gradient descent method.
Definition gsGradientDescent.h:72
Class defining an optimization problem.
Definition gsIpOpt.h:31
Base class for the Optim wrapper.
Definition gsOptim.h:130
void _init()
Initializes the method.
Definition gsStaticOpt.hpp:40
void defaultOptions() override
See gsStaticBase.
Definition gsStaticOpt.hpp:34
void getOptions() override
See gsStaticBase.
Definition gsStaticOpt.hpp:55
gsStatus solve() override
gsStaticBase base functions
Definition gsStaticOpt.hpp:92
#define GISMO_ERROR(message)
Definition gsDebug.h:118
Provides declaration of the gradient descent method.
Provides declaration of an optimization problem.
Provides declaration of an optimization problem.
The G+Smo namespace, containing all definitions for the library.
gsStatus
Definition gsStructuralAnalysisTypes.h:21
@ Success
Successful.
@ NotStarted
ALM has not started yet.