G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsFunctionAdaptor.h
Go to the documentation of this file.
1
15#pragma once
16
18#include <gsUtils/gsThreaded.h>
19
20namespace gismo
21{
22
23
29template <typename T>
31{
32 const gsFunction<T> & m_obj;
33public:
34
35 gsFunctionAdaptor(const gsFunction<T> & obj)//, const gsVector<T> & ,bool withSupport = true)
36 : m_obj(obj)
37 {
41
44
45 gsMatrix<T> sup = obj.support();
46 m_desLowerBounds = sup.col(0);
47 m_desUpperBounds = sup.col(1);
48
50 //gsDebugVar( m_curDesign.transpose() );
51 }
52
53
54public:
55
56 T evalObj( const gsAsConstVector<T> & u ) const
57 {
58 gsAsVector<T> u1(const_cast<T*>(u.data()), u.size() ); // keep point within bounds
59 u1 = u1.cwiseMax(m_desLowerBounds).cwiseMin(m_desUpperBounds);
60 return m_obj.eval(u).value();
61 }
62
63 mutable util::gsThreaded<gsMatrix<T> > jac;
64 void gradObj_into( const gsAsConstVector<T> & u, gsAsVector<T> & result) const
65 {
66
67 //gsOptProblem<T>::gradObj_into(u,result);
68 //gsDebugVar( result.transpose() );
69 m_obj.deriv_into(u, jac);
70 //gsDebugVar( jac.transpose() );
71 result = jac.mine();
72 }
73
74 void hessObj_into( const gsAsConstVector<T> & u, gsAsMatrix<T> & result) const
75 {
76 m_obj.hessian_into(u, jac);
77 result = jac.mine();
78 }
79
80 void evalCon_into( const gsAsConstVector<T> & u, gsAsVector<T> & result) const
81 {
82
83 }
84
85 void jacobCon_into( const gsAsConstVector<T> & u, gsAsVector<T> & result) const
86 {
87
88 }
89
90private:
91
95
98
101
104
106};
107
108} // end namespace gismo
Creates a mapped object or data pointer to a const vector without copying data.
Definition gsAsMatrix.h:285
Creates a mapped object or data pointer to a matrix without copying data.
Definition gsAsMatrix.h:32
Creates a mapped object or data pointer to a vector without copying data.
Definition gsAsMatrix.h:239
Adaptor to see a given gsFunction as (the objective of) an unconstrained optimization problem.
Definition gsFunctionAdaptor.h:31
T evalObj(const gsAsConstVector< T > &u) const
Returns the gradient value of the objective function at design value u.
Definition gsFunctionAdaptor.h:56
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,...
Definition gsFunctionAdaptor.h:85
void evalCon_into(const gsAsConstVector< T > &u, gsAsVector< T > &result) const
Returns values of the constraints at design value u.
Definition gsFunctionAdaptor.h:80
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...
Definition gsFunctionAdaptor.h:64
gsFunctionAdaptor(const gsFunction< T > &obj)
Definition gsFunctionAdaptor.h:35
gsMatrix< T > eval(const gsMatrix< T > &u) const
Evaluate the function,.
Definition gsFunctionSet.hpp:120
A function from a n-dimensional domain to an m-dimensional image.
Definition gsFunction.h:60
virtual short_t domainDim() const=0
Dimension of the (source) domain.
virtual void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate derivatives of the function at points u into result.
Definition gsFunction.hpp:93
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Class defining an optimization problem.
Definition gsOptProblem.h:25
int m_numConstraints
Number of constraints.
Definition gsOptProblem.h:174
gsVector< T > m_conUpperBounds
Upper bounds for the constraints.
Definition gsOptProblem.h:189
gsVector< T > m_conLowerBounds
Lower bounds for the constraints.
Definition gsOptProblem.h:186
gsVector< T > m_desLowerBounds
Lower bounds for the design variables.
Definition gsOptProblem.h:180
int m_numConJacNonZero
Number of nonzero entries in the Constraint Jacobian.
Definition gsOptProblem.h:177
std::vector< index_t > m_conJacRows
Constraint Jacobian non-zero entries rows.
Definition gsOptProblem.h:192
int m_numDesignVars
Number of design variables.
Definition gsOptProblem.h:171
std::vector< index_t > m_conJacCols
Constraint Jacobian non-zero entries columns.
Definition gsOptProblem.h:195
gsMatrix< T > m_curDesign
Current design variables (and starting point )
Definition gsOptProblem.h:198
gsVector< T > m_desUpperBounds
Upper bounds for the design variables.
Definition gsOptProblem.h:183
Provides declaration of an optimization problem.
Wrapper for thread-local data members.
The G+Smo namespace, containing all definitions for the library.