void TimeIterationPolicyLinear<mesh_Type, AssemblyPolicy, SolverPolicy>:: iterate ( vectorPtr_Type solution, bcContainerPtr_Type bchandler, const Real& currentTime ) { Real rhsIterNorm ( 0.0 ); // // STEP 1: Updating the system // displayer().leaderPrint ( "Updating the system... " ); *M_rhs = 0.0; M_systemMatrix.reset ( new matrix_Type ( *M_solutionMap ) ); AssemblyPolicy::assembleSystem ( M_systemMatrix, M_rhs, solution, SolverPolicy::preconditioner() ); displayer().leaderPrint ( "done\n" ); // // STEP 2: Applying the boundary conditions // displayer().leaderPrint ( "Applying BC... " ); bcManage ( *M_systemMatrix, *M_rhs, *uFESpace()->mesh(), uFESpace()->dof(), *bchandler, uFESpace()->feBd(), 1.0, currentTime ); M_systemMatrix->globalAssemble(); displayer().leaderPrint ( "done\n" ); // Extra information if we want to know the exact residual if ( M_computeResidual ) { rhsIterNorm = M_rhs->norm2(); } // // STEP 3: Solving the system // displayer().leaderPrint ( "Solving the system... \n" ); SolverPolicy::solve ( M_systemMatrix, M_rhs, solution ); if ( M_computeResidual ) { vector_Type Ax ( solution->map() ); vector_Type res ( *M_rhs ); M_systemMatrix->matrixPtr()->Apply ( solution->epetraVector(), Ax.epetraVector() ); res.epetraVector().Update ( -1, Ax.epetraVector(), 1 ); Real residual; res.norm2 ( &residual ); residual /= rhsIterNorm; displayer().leaderPrint ( "Scaled residual: ", residual, "\n" ); } }
void MonolithicBlockMatrix::applyBoundaryConditions(const Real& time, vectorPtr_Type& rhs, const UInt block) { bcManage( *M_globalMatrix , *rhs, *super_Type::M_FESpace[block]->mesh(), super_Type::M_FESpace[block]->dof(), *super_Type::M_bch[block], super_Type::M_FESpace[block]->feBd(), 1., time); }
void TimeIterationPolicyNonlinear<mesh_Type, AssemblyPolicy, SolverPolicy>:: iterate ( vectorPtr_Type solution, bcContainerPtr_Type bchandler, const Real& currentTime ) { int subiter = 0; Real normRhs ( 0.0 ); Real nonLinearResidual ( 0.0 ); Real rhsIterNorm ( 0.0 ); do { // // STEP 1: Updating the system // displayer().leaderPrint ( "Updating the system... " ); *M_rhs = 0.0; M_systemMatrix.reset ( new matrix_Type ( *M_solutionMap ) ); AssemblyPolicy::assembleSystem ( M_systemMatrix, M_rhs, solution, SolverPolicy::preconditioner() ); displayer().leaderPrint ( "done\n" ); // // STEP 2: Applying the boundary conditions // displayer().leaderPrint ( "Applying BC... " ); bcManage ( *M_systemMatrix, *M_rhs, *uFESpace()->mesh(), uFESpace()->dof(), *bchandler, uFESpace()->feBd(), 1.0, currentTime ); M_systemMatrix->globalAssemble(); displayer().leaderPrint ( "done\n" ); // Norm of the rhs needed for the nonlinear convergence test if ( subiter == 0 ) { normRhs = M_rhs->norm2(); } // // STEP 3: Computing the residual // // Computing the RHS as RHS=b-Ax_k vector_Type Ax ( solution->map() ); M_systemMatrix->matrixPtr()->Apply ( solution->epetraVector(), Ax.epetraVector() ); Ax.epetraVector().Update (-1, M_rhs->epetraVector(), 1); nonLinearResidual = Ax.norm2(); displayer().leaderPrint ( "Nonlinear residual : ", nonLinearResidual, "\n" ); displayer().leaderPrint ( "Nonlinear residual (scaled) : ", nonLinearResidual / normRhs, "\n" ); if ( nonLinearResidual > M_nonLinearTolerance * normRhs ) { displayer().leaderPrint ( "---\nSubiteration [", ++subiter, "]\n" ); // Extra information if we want to know the exact residual if ( M_computeResidual ) { rhsIterNorm = M_rhs->norm2(); } // // Solving the system // displayer().leaderPrint ( "Solving the system... \n" ); *solution = 0.0; SolverPolicy::solve ( M_systemMatrix, M_rhs, solution ); // int numIter = SolverPolicy::solve( M_systemMatrix, M_rhs, solution ); // numIterSum += numIter; // if ( M_computeResidual ) { vector_Type Ax ( solution->map() ); vector_Type res ( *M_rhs ); M_systemMatrix->matrixPtr()->Apply ( solution->epetraVector(), Ax.epetraVector() ); res.epetraVector().Update ( -1, Ax.epetraVector(), 1 ); Real residual; res.norm2 ( &residual ); residual /= rhsIterNorm; displayer().leaderPrint ( "Scaled residual: ", residual, "\n" ); } } } while ( nonLinearResidual > M_nonLinearTolerance * normRhs ); displayer().leaderPrint ( "Nonlinear iterations : ", subiter, "\n" ); }