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 19 #ifndef NSSTOOLS_H 20 #define NSSTOOLS_H 21 22 /*!\file NSSTools.h 23 Header to collect basic tools, structures definition or any usefull things for NSSpack 24 25 */ 26 27 #include "SiconosConfig.h" 28 29 #ifdef __cplusplus 30 #undef restrict 31 #define restrict __restrict 32 #endif 33 34 35 #if defined(__cplusplus) && !defined(BUILD_AS_CPP) 36 extern "C" 37 { 38 #endif 39 40 /** Search for the max. element of a vector 41 \param[in] x the vector 42 \param[in,out] sol the solution, value of the greatest element of x 43 \param[in] n size of x 44 */ 45 void max_part(double* x, double* sol, int n); 46 47 /** compare two double a and b, and return the max. 48 * \param a double* 49 * \param b double* 50 * \param c double*, the max 51 */ 52 void maxf(double* a, double* b , double* c); 53 54 /** Search for the min. element of a vector 55 \param[in] x the vector 56 \param[in,out] sol solution, value of the smallest element of x 57 \param[in] n size of x 58 */ 59 void min_part(double* x, double* sol , int n); 60 61 /** compare two double a and b, and return the min. 62 * \param a double* 63 * \param b double* 64 * \param c double*, the min 65 */ 66 void minf(double* a, double* b, double* c); 67 68 /** Positive part values of the components of a vector 69 \param[in] n size of x 70 \param[in] x the vector 71 \param[out] x_plus solution vector of positive part values of x components 72 */ 73 void pos_part(unsigned n, double* x, double* x_plus); 74 75 /** Absolute values of the components of a vector 76 \param[in] x the vector 77 \param[in,out] sol solution, vector of absolute values of x components 78 \param[in] n size of x 79 */ 80 void abs_part(double* x, double* sol, int n); 81 82 /** 83 Input na, a, nb, b 84 Output nc, c 85 a and b: interger vectors in increasing order 86 c : vector of integers of a that are not in b. 87 */ 88 void diffns(int *na, int *a, int *nb, int * b, int *nc, int *c); 89 90 /** */ 91 void sortsn_(int*ddl_i, int *sort, int *n); 92 93 #if defined(__cplusplus) && !defined(BUILD_AS_CPP) 94 } 95 #include <algorithm> 96 using std::min; 97 using std::max; 98 99 #else 100 #define min(a,b) ((a)>(b)?(b):(a)) 101 #define max(a,b) ((a) >= (b) ? (a) : (b)) 102 #endif 103 104 #endif 105