MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mbdyn_siconos.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/modules/module-nonsmooth-node/mbdyn_siconos.cc,v 1.9 2017/01/12 14:55:58 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 /*
32  * Author: Matteo Fancello <matteo.fancello@gmail.com>
33  * Nonsmooth dynamics element;
34  * uses SICONOS <http://siconos.gforge.inria.fr/>
35  */
36 
37 #include "SiconosNumerics.h"
38 #include <iostream>
39 #include "mbdyn_siconos.h"
40 
41 
42 void
43 mbdyn_siconos_LCP_call(int sizep, double W_NN[], double bLCP[], double Pkp1[], double wlem[], solver_parameters& solparam)
44 {
45  solparam.info = 0;
46 
47  LCPsolver lcpsol = solparam.solver;
48  double tolerance = solparam.solvertol;
49  int maxiternum = solparam.solveritermax;
50 
51  // LCP problem description:
52  LinearComplementarityProblem OSNSProblem;
53  OSNSProblem.size = sizep;
54  OSNSProblem.q = bLCP;
55 
56  NumericsMatrix MM;
57  MM.storageType = 0;
58  MM.matrix0 = W_NN; // W_delassus
59  MM.size0 = sizep;
60  MM.size1 = sizep;
61  OSNSProblem.M = &MM;
62 
63  SolverOptions numerics_solver_options = { 0 };
64 
65  solparam.resulting_error = 0.;
66 
67  // Solving LCP problem
68  // FIXME: initialize once, keep alive?
69  switch (lcpsol) {
70  case LEXICO_LEMKE:
71  linearComplementarity_lexicolemke_setDefaultSolverOptions(&numerics_solver_options);
72  numerics_solver_options.iparam[0] = maxiternum;
73  lcp_lexicolemke(&OSNSProblem, Pkp1, wlem, &solparam.info, &numerics_solver_options);
74  solparam.processed_iterations = numerics_solver_options.iparam[1];
75  break;
76 
77  case RPGS:
78  linearComplementarity_rpgs_setDefaultSolverOptions(&numerics_solver_options);
79  numerics_solver_options.iparam[0] = maxiternum;
80  numerics_solver_options.dparam[0] = tolerance;
81  lcp_rpgs(&OSNSProblem, Pkp1, wlem, &solparam.info, &numerics_solver_options);
82  solparam.processed_iterations = numerics_solver_options.iparam[1];
83  solparam.resulting_error = numerics_solver_options.dparam[1];
84  break;
85 
86  case QP:
87  linearComplementarity_qp_setDefaultSolverOptions(&numerics_solver_options);
88  numerics_solver_options.dparam[0] = tolerance;
89  lcp_qp(&OSNSProblem, Pkp1, wlem, &solparam.info, &numerics_solver_options);
90  break;
91 
92  case CPG:
93  linearComplementarity_cpg_setDefaultSolverOptions(&numerics_solver_options);
94  numerics_solver_options.iparam[0] = maxiternum;
95  numerics_solver_options.dparam[0] = tolerance;
96  lcp_cpg(&OSNSProblem, Pkp1, wlem, &solparam.info, &numerics_solver_options);
97  solparam.processed_iterations = numerics_solver_options.iparam[1];
98  solparam.resulting_error = numerics_solver_options.dparam[1];
99  break;
100 
101  case PGS:
102  linearComplementarity_pgs_setDefaultSolverOptions(&numerics_solver_options);
103  numerics_solver_options.iparam[0] = maxiternum;
104  numerics_solver_options.dparam[0] = tolerance;
105  lcp_pgs(&OSNSProblem, Pkp1, wlem, &solparam.info, &numerics_solver_options);
106  solparam.processed_iterations = numerics_solver_options.iparam[1];
107  solparam.resulting_error = numerics_solver_options.dparam[1];
108  break;
109 
110  case PSOR:
111  linearComplementarity_psor_setDefaultSolverOptions(&numerics_solver_options);
112  numerics_solver_options.iparam[0] = maxiternum;
113  numerics_solver_options.dparam[0] = tolerance;
114  lcp_psor(&OSNSProblem, Pkp1, wlem, &solparam.info, &numerics_solver_options);
115  solparam.processed_iterations = numerics_solver_options.iparam[1];
116  solparam.resulting_error = numerics_solver_options.dparam[1];
117  break;
118 
119  case NSQP:
120  linearComplementarity_nsqp_setDefaultSolverOptions(&numerics_solver_options);
121  numerics_solver_options.dparam[0] = tolerance;
122  lcp_nsqp(&OSNSProblem, Pkp1, wlem, &solparam.info, &numerics_solver_options);
123  break;
124 
125  case LATIN:
126  linearComplementarity_latin_setDefaultSolverOptions(&numerics_solver_options);
127  numerics_solver_options.iparam[0] = maxiternum;
128  numerics_solver_options.dparam[0] = tolerance;
129  lcp_latin(&OSNSProblem, Pkp1, wlem, &solparam.info, &numerics_solver_options);
130  break;
131 
132  case LATIN_W:
133  linearComplementarity_latin_w_setDefaultSolverOptions(&numerics_solver_options);
134  numerics_solver_options.iparam[0] = maxiternum;
135  numerics_solver_options.dparam[0] = tolerance;
136  lcp_latin_w(&OSNSProblem, Pkp1, wlem, &solparam.info, &numerics_solver_options);
137  break;
138 
139  case NEWTON_MIN:
140  linearComplementarity_newton_min_setDefaultSolverOptions(&numerics_solver_options);
141  numerics_solver_options.iparam[0] = maxiternum;
142  numerics_solver_options.dparam[0] = tolerance;
143  lcp_newton_min(&OSNSProblem, Pkp1, wlem, &solparam.info, &numerics_solver_options);
144  solparam.processed_iterations = numerics_solver_options.iparam[1];
145  solparam.resulting_error = numerics_solver_options.dparam[1];
146  break;
147 
148  case NEWTON_FB:
149  linearComplementarity_newton_FB_setDefaultSolverOptions(&numerics_solver_options);
150  numerics_solver_options.iparam[0] = maxiternum;
151  numerics_solver_options.dparam[0] = tolerance;
152  lcp_newton_FB(&OSNSProblem, Pkp1, wlem, &solparam.info, &numerics_solver_options);
153  solparam.processed_iterations = numerics_solver_options.iparam[1];
154  solparam.resulting_error = numerics_solver_options.dparam[1];
155  break;
156  }
157 
158 #if 0
159  // analyzing the LCP solver final status
160  switch (solparam.info) {
161  case 0: // convergence
162  break;
163 
164  case 1: // iter=itermax
165  std::cout << std::endl
166  << "loadable element nonsmooth node: max iterations reached in LCP solver "
167  << std::endl;
168  std::cout << "processed_iterations "<< solparam.processed_iterations
169  << " resulting_error " << solparam.resulting_error <<std::endl;
170  break;
171 
172  default: // other problem
173  std::cout << std::endl
174  <<"loadable element nonsmooth node: problem in solution of LCP"
175  << std::endl;
176  std::cout << "processed_iterations "<< solparam.processed_iterations
177  << " resulting_error " << solparam.resulting_error <<std::endl;
178  break;
179  }
180 #endif
181 
182  deleteSolverOptions(&numerics_solver_options);
183 }
184 
void mbdyn_siconos_LCP_call(int sizep, double W_NN[], double bLCP[], double Pkp1[], double wlem[], solver_parameters &solparam)
LCPsolver
Definition: mbdyn_siconos.h:40