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 /*! \file FirstOrderLinearR.hpp 19 20 */ 21 #ifndef FirstOrderLinearR_H 22 #define FirstOrderLinearR_H 23 24 #include "FirstOrderR.hpp" 25 /** Pointer to function used for plug-in for matrix-type operators (C,F etc) */ 26 typedef void (*FOMatPtr1)(double, unsigned int, unsigned int, double*, unsigned int, double*); 27 28 /** Pointer to function used for plug-in for square matrix-type operators (D) */ 29 typedef void (*FOMatPtr2)(double, unsigned int, double*, unsigned int, double*); 30 31 /** Pointer to function used for plug-in for vector-type operators (e) */ 32 typedef void (*FOVecPtr)(double, unsigned int, double*, unsigned int, double*); 33 34 /** First Order Linear Relation 35 36 37 Linear Relation for First Order Dynamical Systems: 38 39 \rst 40 41 .. math:: 42 43 y &=& C(t,z)x(t) + F(t,z)z + D(t,z)\lambda + e(t,z) \\ 44 R &=& B(t,z) \lambda 45 46 \endrst 47 48 The following operators can be plugged: \f$ B(t,z), C(t,z), D(t,z), e(t,z), F(t,z)\f$ 49 50 */ 51 class FirstOrderLinearR : public FirstOrderR 52 { 53 54 protected: 55 /** serialization hooks 56 */ 57 ACCEPT_SERIALIZATION(FirstOrderLinearR); 58 59 60 61 SP::SiconosVector _e; 62 63 public: 64 65 /** default constructor, protected 66 */ 67 FirstOrderLinearR(); 68 69 /** Constructor with C and B plugin names 70 \param Cname the plugin name for computing the C matrix 71 \param Bname the plugin name for computing the B matrix 72 **/ 73 FirstOrderLinearR(const std::string& Cname, const std::string& Bname); 74 75 /** Constructor with all plugin names 76 \param Cname the plugin name for computing the C matrix 77 \param Dname the plugin name for computing the D matrix 78 \param Fname the plugin name for computing the F matrix 79 \param Ename the plugin name for computing the e vector 80 \param Bname the plugin name for computing the B matrix 81 **/ 82 FirstOrderLinearR(const std::string& Cname, const std::string& Dname, const std::string& Fname, const std::string& Ename, const std::string& Bname); 83 84 /** create the Relation from a set of data 85 * \param C the C matrix 86 * \param B the B matrix 87 */ 88 FirstOrderLinearR(SP::SimpleMatrix C, SP::SimpleMatrix B); 89 90 /** create the Relation from a set of data 91 * \param C the C matrix 92 * \param D the D matrix 93 * \param F the F matrix 94 * \param e the e matrix 95 * \param B the B matrix 96 */ 97 FirstOrderLinearR(SP::SimpleMatrix C, SP::SimpleMatrix D, SP::SimpleMatrix F, SP::SiconosVector e, SP::SimpleMatrix B); 98 99 /** destructor 100 */ ~FirstOrderLinearR()101 ~FirstOrderLinearR() {}; 102 103 // GETTERS/SETTERS 104 105 /** set a specified function to compute the matrix C 106 * \param pluginPath the complete path to the plugin 107 * \param functionName the function name to use in this plugin 108 */ setComputeCFunction(const std::string & pluginPath,const std::string & functionName)109 void setComputeCFunction(const std::string& pluginPath, const std::string& functionName) 110 { 111 setComputeJachxFunction(pluginPath, functionName); 112 } 113 114 /** set a specified function to compute the matrix D 115 * \param pluginPath the complete path to the plugin 116 * \param functionName the function name to use in this plugin 117 */ setComputeDFunction(const std::string & pluginPath,const std::string & functionName)118 void setComputeDFunction(const std::string& pluginPath, const std::string& functionName) 119 { 120 setComputeJachlambdaFunction(pluginPath, functionName); 121 } 122 123 /** set a specified function to compute the matrix B 124 * \param pluginPath the complete path to the plugin 125 * \param functionName the function name to use in this plugin 126 */ setComputeBFunction(const std::string & pluginPath,const std::string & functionName)127 void setComputeBFunction(const std::string& pluginPath, const std::string& functionName) 128 { 129 setComputeJacglambdaFunction(pluginPath, functionName); 130 } 131 /** initialize the relation (check sizes, memory allocation in workV and workM ...) 132 * \param inter Interaction using this Relation 133 */ 134 virtual void initialize(Interaction& inter); 135 136 /** check sizes of the relation specific operators. 137 * \param inter an Interaction using this relation 138 */ 139 virtual void checkSize(Interaction& inter); 140 /** Function to compute the matrix C 141 * \param time the current time 142 * \param z the auxiliary input vector 143 * \param C the C matrix 144 */ 145 void computeC(double time, BlockVector& z, SimpleMatrix& C); 146 147 /** Function to compute the matrix D 148 * \param time the current time 149 * \param z the auxiliary input vector 150 * \param D the D matrix 151 */ 152 void computeD(double time, BlockVector& z, SimpleMatrix& D); 153 154 /** Function to compute the matrix F 155 * \param time the current time 156 * \param z the auxiliary input vector 157 * \param F the F matrix 158 */ 159 void computeF(double time, BlockVector& z, SimpleMatrix& F); 160 161 /** Function to compute the vector e 162 * \param time the current time 163 * \param z the auxiliary input vector 164 * \param e the e vector 165 */ 166 void computee(double time, BlockVector& z, SiconosVector& e); 167 168 /** Function to compute the matrix B 169 * \param time the current time 170 * \param z the auxiliary input vector 171 * \param B the B matrix 172 */ 173 void computeB(double time, BlockVector& z, SimpleMatrix& B); 174 175 /** to compute the output y = h(t,x,...) of the Relation 176 \param time current time value 177 \param x coordinates of the dynamical systems involved in the relation 178 \param lambda interaction \f$\lambda\f$ vector 179 \param z user defined parameters (optional) 180 \param y the resulting vector 181 */ 182 void computeh(double time, 183 const BlockVector& x, const SiconosVector& lambda, 184 BlockVector& z, SiconosVector& y); 185 186 /** to compute the nonsmooth input r = g(t,x,...) of the Relation 187 \param time current time value 188 \param lambda interaction \f$\lambda\f$ vector 189 \param z user defined parameters (optional) 190 \param r the resulting vector 191 */ 192 void computeg(double time, const SiconosVector& lambda, BlockVector& z, BlockVector& r); 193 194 /** default function to compute y 195 * \param time current time 196 * \param inter Interaction using this Relation 197 * \param level not used 198 */ 199 virtual void computeOutput(double time, Interaction& inter, unsigned int level = 0); 200 201 /** default function to compute r 202 * \param time current time 203 * \param inter Interaction using this Relation 204 * \param level not used 205 */ 206 virtual void computeInput(double time, Interaction& inter, unsigned int level = 0); 207 208 /** print the data to the screen 209 */ 210 void display() const; 211 212 /** set e 213 * \param newe the new value of e 214 */ setePtr(SP::SiconosVector newe)215 inline void setePtr(SP::SiconosVector newe) 216 { 217 _e = newe; 218 } 219 220 /** get e 221 * \return e matrix 222 */ e() const223 inline SP::SiconosVector e() const 224 { 225 return _e; 226 } 227 228 /** determine if the Relation is linear 229 * \return true if the relation is linear. 230 */ isLinear()231 virtual bool isLinear() 232 { 233 return true; 234 } 235 computeJach(double time,Interaction & inter)236 virtual void computeJach(double time, Interaction& inter) {}; computeJacg(double time,Interaction & inter)237 virtual void computeJacg(double time, Interaction& inter) {}; 238 239 240 ACCEPT_STD_VISITORS(); 241 242 }; 243 244 TYPEDEF_SPTR(FirstOrderLinearR) 245 246 #endif 247