LifeV
MultiscaleAlgorithmNewton.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 File containing the Multiscale Newton Algorithm
30  *
31  * @date 26-10-2009
32  * @author Cristiano Malossi <cristiano.malossi@epfl.ch>
33  *
34  * @maintainer Cristiano Malossi <cristiano.malossi@epfl.ch>
35  */
36 
37 #include <lifev/multiscale/algorithms/MultiscaleAlgorithmNewton.hpp>
38 
39 namespace LifeV
40 {
41 namespace Multiscale
42 {
43 
44 // ===================================================
45 // Constructors & Destructor
46 // ===================================================
49  M_solver (),
50  M_jacobian ()
51 {
52 
53 #ifdef HAVE_LIFEV_DEBUG
54  debugStream ( 8013 ) << "MultiscaleAlgorithmNewton::MultiscaleAlgorithmNewton() \n";
55 #endif
56 
57  M_type = Newton;
58 }
59 
60 // ===================================================
61 // Multiscale Algorithm Virtual Methods
62 // ===================================================
63 void
64 MultiscaleAlgorithmNewton::setupData ( const std::string& fileName )
65 {
66 
67 #ifdef HAVE_LIFEV_DEBUG
68  debugStream ( 8013 ) << "MultiscaleAlgorithmNewton::setupData( fileName ) \n";
69 #endif
70 
71  // Read parameters
72  multiscaleParameterListPtr_Type solverParametersList = Teuchos::rcp ( new Teuchos::ParameterList );
73  solverParametersList = Teuchos::getParametersFromXmlFile ( fileName );
74 
75  // Set main parameters
76  setAlgorithmName ( solverParametersList->sublist ( "Multiscale", true, "" ) );
77  setAlgorithmParameters ( solverParametersList->sublist ( "Multiscale Algorithm", true, "" ) );
78 
79  // Set main parameters
80  M_solver.setCommunicator ( M_comm );
81  M_solver.setParameters ( solverParametersList->sublist ( "Linear Solver List", true, "" ) );
82 }
83 
84 void
85 MultiscaleAlgorithmNewton::subIterate()
86 {
87 
88 #ifdef HAVE_LIFEV_DEBUG
89  debugStream ( 8013 ) << "MultiscaleAlgorithmNewton::subIterate() \n";
90 #endif
91 
92  multiscaleAlgorithm_Type::subIterate();
93 
94  // Verify tolerance
95  if ( checkResidual ( 0 ) )
96  {
97  return;
98  }
99 
100  M_multiscale->exportCouplingVariables ( *M_couplingVariables );
101 
102  multiscaleVectorPtr_Type delta ( new multiscaleVector_Type ( *M_couplingResiduals, Unique ) );
103  *delta = 0.0;
104 
105  for ( UInt subIT (1); subIT <= M_subiterationsMaximumNumber; ++subIT )
106  {
107  // Compute the Jacobian
108  assembleJacobianMatrix();
109 
110  // Set matrix and RHS
111  M_solver.setOperator ( M_jacobian );
112  M_solver.setRightHandSide ( M_couplingResiduals );
113 
114  // Solve Newton (without changing the sign of the residual)
115  M_solver.solve ( delta );
116 
117  // Changing the sign of the solution
118  *delta *= -1;
119 
120  // Update Coupling Variables using the Newton Method
121  *M_couplingVariables += *delta;
122 
123  // Import Coupling Variables inside the coupling blocks
124  M_multiscale->importCouplingVariables ( *M_couplingVariables );
125 
126  // Verify tolerance
127  if ( checkResidual ( subIT ) )
128  {
129  return;
130  }
131  }
132 
133  save ( M_subiterationsMaximumNumber, M_couplingResiduals->norm2() );
134 
135  multiscaleErrorCheck ( Tolerance, "Newton algorithm residual: " + number2string ( M_couplingResiduals->norm2() ) +
136  " (required: " + number2string ( M_tolerance ) + ")\n", M_multiscale->communicator() == 0 );
137 }
138 
139 // ===================================================
140 // Private Methods
141 // ===================================================
142 void
143 MultiscaleAlgorithmNewton::assembleJacobianMatrix()
144 {
145  // Compute the Jacobian matrix (we completely delete the previous matrix)
146  M_jacobian.reset ( new multiscaleMatrix_Type ( M_couplingVariables->map(), 50 ) );
147  M_multiscale->exportJacobian ( *M_jacobian );
148  M_jacobian->globalAssemble();
149 
150  //M_jacobian->spy( multiscaleProblemFolder + multiscaleProblemPrefix + "_AlgorithmJacobianNewtonExported" + "_" + number2string( multiscaleProblemStep ) + "_" + number2string( M_multiscale->globalData()->dataTime()->timeStepNumber() ) );
151 }
152 
153 } // Namespace Multiscale
154 } // Namespace LifeV
MultiscaleAlgorithmNewton - The Multiscale Algorithm implementation of Newton.
void setupData(const std::string &fileName)
Setup the data of the algorithm using a data file.
MultiscaleAlgorithm multiscaleAlgorithm_Type
LinearSolver::parameterListPtr_Type multiscaleParameterListPtr_Type