G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsFunctionAdaptor.h
Go to the documentation of this file.
1 
15 #pragma once
16 
18 #include <gsUtils/gsThreaded.h>
19 
20 namespace gismo
21 {
22 
23 
29 template <typename T>
31 {
32  const gsFunction<T> & m_obj;
33 public:
34 
35  gsFunctionAdaptor(const gsFunction<T> & obj)//, const gsVector<T> & ,bool withSupport = true)
36  : m_obj(obj)
37  {
38  m_numDesignVars = obj.domainDim();
39  m_numConstraints = 0;
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 
54 public:
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 
90 private:
91 
95 
98 
101 
104 
106 };
107 
108 } // end namespace gismo
void evalCon_into(const gsAsConstVector< T > &u, gsAsVector< T > &result) const
Returns values of the constraints at design value u.
Definition: gsFunctionAdaptor.h:80
Class defining an optimization problem.
Definition: gsOptProblem.h:24
int m_numConstraints
Number of constraints.
Definition: gsOptProblem.h:174
Creates a mapped object or data pointer to a matrix without copying data.
Definition: gsLinearAlgebra.h:126
T evalObj(const gsAsConstVector< T > &u) const
Returns the gradient value of the objective function at design value u.
Definition: gsFunctionAdaptor.h:56
Provides declaration of an optimization problem.
A function from a n-dimensional domain to an m-dimensional image.
Definition: gsFunction.h:59
gsVector< T > m_desUpperBounds
Upper bounds for the design variables.
Definition: gsOptProblem.h:183
gsFunctionAdaptor(const gsFunction< T > &obj)
Definition: gsFunctionAdaptor.h:35
Creates a mapped object or data pointer to a vector without copying data.
Definition: gsLinearAlgebra.h:129
int m_numDesignVars
Number of design variables.
Definition: gsOptProblem.h:171
Wrapper for thread-local data members.
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
virtual short_t domainDim() const =0
Dimension of the (source) domain.
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.
Definition: gsFunctionAdaptor.h:85
Creates a mapped object or data pointer to a const vector without copying data.
Definition: gsLinearAlgebra.h:130
gsVector< T > m_desLowerBounds
Lower bounds for the design variables.
Definition: gsOptProblem.h:180
Adaptor to see a given gsFunction as (the objective of) an unconstrained optimization problem...
Definition: gsFunctionAdaptor.h:30
int m_numConJacNonZero
Number of nonzero entries in the Constraint Jacobian.
Definition: gsOptProblem.h:177
gsMatrix< T > m_curDesign
Current design variables (and starting point )
Definition: gsOptProblem.h:198