LifeV
ZeroDimensionalSolver.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  * @file
29  * @brief Rythmos solver
30  *
31  * @date 16-11-2011
32  * @author Mahmoud Jafargholi
33  *
34  * @contributors Cristiano Malossi <cristiano.malossi@epfl.ch>
35  * @mantainer Cristiano Malossi <cristiano.malossi@epfl.ch>
36  */
37 
38 #include <lifev/zero_dimensional/solver/ZeroDimensionalSolver.hpp>
39 
40 namespace LifeV
41 {
42 
43 #if ( defined(HAVE_NOX_THYRA) && defined(HAVE_TRILINOS_RYTHMOS) )
44 
48 {
49  M_comm.swap ( comm );
50  M_commRCP.reset();
51  M_commRCP = Teuchos::rcp ( M_comm );
53  M_comm.operator ->(),
54  circuitData ) );
56 
58  M_commRCP,
60 
63 
65 
66 }
68 {
69  std::string commandLine = "--linear-solver-params-used-file=";
71  char* argv[1];
72  argv[0] = new char[commandLine.size()];
73  for ( Int i = 0; i < ( (Int) commandLine.size() ); ++i )
74  {
75  ( argv[0] ) [i] = commandLine[i];
76  }
77  Int argc = 1;
78  bool success = true; // determine if the run was successfull
79  try
80  {
81  // catch exceptions
82  if (data.fixTimeStep)
83  {
85  }
86  else
87  {
89  }
90 
91  Int numElements = M_modelInterface->numCircuitElements(); // number of elements in vector
93  Real maxError;
94  Real reltol;
95  Real abstol;
96  Int maxOrder;
97  bool useNOX;
98 
99  if (!data.method.compare ("BE") )
100  {
102  }
103  if (!data.method.compare ("BDF") )
104  {
106  }
107  if (!data.method.compare ("IRK") )
108  {
110  }
111 
114  reltol = data.reltol;
115  abstol = data.abstol;
118  M_outputLevel = min (max (M_outputLevel, -1), 4);
119  useNOX = data.useNOX;
120 
121  switch (M_outputLevel)
122  {
123  case -1:
125  break;
126  case 0:
128  break;
129  case 1:
131  break;
132  case 2:
134  break;
135  case 3:
137  break;
138  case 4:
140  break;
141  default:
142  break;
143  }
145 
146  // Parse the command-line options:
147 
148  Teuchos::CommandLineProcessor clp (false); // Don't throw exceptions
149  clp.addOutputSetupOptions (true);
153  delete argv [0];
155  {
156  return;
157  }
159  if (extraLSParamsFile.length() )
160  {
162  }
163  *M_out << "\nThe parameter list after being read in:\n";
164  lowsfCreator.getParameterList()->print (*M_out, 2, true, false);
165 
166  // Set up the parameter list for the application:
168  params.set ( "NumElements", numElements );
169  // Create the factory for the LinearOpWithSolveBase object
171  W_factory;
173  *M_out
174  << "\nCreated a LinearOpWithSolveFactory described as:\n"
176 
177  // create interface to problem
180 
182 
183  std::string method;
184  if (method_val == METHOD_BE)
185  {
187  if (useNOX)
188  {
191  }
192  else
193  {
198  nonlinearSolverPL->set ("Default Tol", Real (maxError) );
201  }
207  model->description();
212  method = "Backward Euler";
213  }
214  else if (method_val == METHOD_BDF)
215  {
217  if (useNOX)
218  {
221  }
222  else
223  {
228  nonlinearSolverPL->set ("Default Tol", Real (maxError) );
231  }
234  Teuchos::RCP<Teuchos::ParameterList> BDFStepControlPL = Teuchos::sublist (BDFparams, "Step Control Settings");
235  BDFStepControlPL->set ( "maxOrder", maxOrder );
236  BDFStepControlPL->set ( "relErrTol", reltol );
237  BDFStepControlPL->set ( "absErrTol", abstol );
239  method = "Implicit BDF";
240  }
241  else if (method_val == METHOD_IRK)
242  {
244  if (useNOX)
245  {
248  }
249  else
250  {
255  nonlinearSolverPL->set ("Default Tol", Real (maxError) );
258  }
262  Teuchos::RCP<Rythmos::RKButcherTableauBase<Real> > rkbt = Rythmos::createRKBT<Real> ("Implicit 3 Stage 6th order Gauss");
264  method = "Implicit RK";
265  }
266  else
267  {
268  TEST_FOR_EXCEPT (true);
269  }
270 
272 
273  M_method = method;
274  }
276  return;
277 
278 }
279 void
281 {
282 
283  M_finalTime = t1;
284  M_startTime = t0;
285  Real dt = (t1 - t0) / M_numberTimeStep;
286  Real time = t0;
287  Int numSteps = 0;
290 
292  {
293  // Integrate forward with fixed step sizes:
294  for (Int i = 1; i <= M_numberTimeStep; ++i)
295  {
297  numSteps++;
298  if (dt_taken != dt)
299  {
300  cerr << "Error, M_stepper took step of dt = " << dt_taken << " when asked to take step of dt = " << dt << std::endl;
301  break;
302  }
303  time += dt_taken;
304  }
305  }
306  else // M_stepMethod == STEP_METHOD_VARIABLE
307 
308  {
309  while (time < M_finalTime)
310  {
312  numSteps++;
313  if (dt_taken < 0)
314  {
315  cerr << "Error, M_stepper failed for some reason with step taken = " << dt_taken << endl;
316  break;
317  }
318  time += dt_taken;
319  *M_out << "Took stepsize of: " << dt_taken << " time = " << time << endl;
320  }
321  }
322  // Get solution M_out of M_stepper:
327  Rythmos::Array< Teuchos::RCP< const Thyra::VectorBase< Real > > > x_vec;
328  Rythmos::Array< Teuchos::RCP< const Thyra::VectorBase< Real > > > xdot_vec;
330 
332  );
336 
337  // Convert Thyra::VectorBase to Epetra_Vector
340 
343 
344  //---------------Replace the solution as initial solution for the next iteration
345 #ifdef HAVE_LIFEV_DEBUG
346  *M_out << "X_computed" << endl;
348  *M_out << "X_dot_computed" << endl;
350 #endif
351 
355 }
356 
357 #endif /* HAVE_NOX_THYRA && HAVE_TRILINOS_RYTHMOS */
358 
359 } // LifeV namespace
void updateInverseJacobian(const UInt &iQuadPt)