1 /* Siconos is a program dedicated to modeling, simulation and control
2  * of non smooth dynamical systems.
3  *
4  * Copyright 2021 INRIA.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17 */
18 #ifndef NCP_PROBLEM_H
19 #define NCP_PROBLEM_H
20 
21 #include "NumericsFwd.h"  // for NonlinearComplementarityProblem, NumericsMa...
22 #include "SiconosConfig.h" // for BUILD_AS_CPP // IWYU pragma: keep
23 
24 
25 /*!\file NonlinearComplementarityProblem.h
26  * \brief data structure to formalize a Nonlinear Complementarity Problem (NCP)
27  *
28 */
29 
30 /** type for user defined function used to compute F and its jacobian.
31  */
32 typedef void (*ptrFunctionNCP)(void* env, int n, double* z, double* F);
33 typedef void (*ptrFunctionJacNCP)(void* env, int n, double* z, NumericsMatrix* jacF);
34 
35 /** \struct  NonlinearComplementarityProblem NonlinearComplementarityProblem.h
36  * The structure that defines a Nonlinear Complementarity Problem (NCP) : Find two vectors \f$(z,w \in {{\mathrm{I\!R}}}^{n})\f$ such that:
37 
38   \f[
39   w &= F(z) \\ 0 &\le w \perp z \ge 0
40   \f]
41  */
42 struct NonlinearComplementarityProblem
43 {
44   unsigned n; /**< size of the problem */
45   ptrFunctionNCP compute_F; /**< pointer to the function used to compute \f$F(z)\f$ */
46   ptrFunctionJacNCP compute_nabla_F; /**< pointer to the function used to compute \f$\nabla_z F(z)\f$ */
47   NumericsMatrix* nabla_F; /**< storage for \f$\nabla_z F\f$*/
48   void* env; /**< environment for the compute_Fmcp and compute_nabla_F function.
49                When called from Python, it contains an object with compute_F and compute_nabla_F as methods.
50                When called from C, it can reference a data struct containing variables needed for the computations.*/
51 };
52 
53 #if defined(__cplusplus) && !defined(BUILD_AS_CPP)
54 extern "C"
55 {
56 #endif
57   /** free an NCP problem
58    * \param ncp structure to free
59    */
60   void freeNCP(NonlinearComplementarityProblem* ncp);
61 
62   /** create an empty NCP problem
63    * \return an MixedComplementarityProblem instance
64    */
65   NonlinearComplementarityProblem* newNCP(void);
66 
67 #if defined(__cplusplus) && !defined(BUILD_AS_CPP)
68 }
69 #endif
70 
71 #endif
72