void AdvectionDiffusion::update( parameter_type const& mu ) { *D = *M_Aqm[0][0]; for ( size_type q = 1; q < M_Aqm.size(); ++q ) { for ( size_type m = 0; m < mMaxA(q); ++m ) { D->addMatrix( M_betaAqm[q][m] , M_Aqm[q][m] ); //std::cout << "[affine decomp] scale q=" << q << " with " << M_betaAqm[q][0] << "\n"; } } F->close(); F->zero(); for ( size_type q = 0; q < M_Fqm[0].size(); ++q ) { for ( size_type m = 0; m < mMaxF(0,q); ++m ) { //std::cout << "[affine decomp] scale q=" << q << " with " << M_betaFqm[0][q][0] << "\n"; F->add( M_betaFqm[0][q][m], M_Fqm[0][q][m] ); } } }
void BlocksBaseVector<T>::localize( vector_ptrtype const& vb, size_type _start_i ) { vb->close(); size_type _start_iloc=0; for ( uint16_type i=0; i<this->nRow(); ++i ) { size_type nBlockRow = this->operator()( i,0 )->localSize(); if ( !this->vector() ) { for ( size_type k=0; k<nBlockRow; ++k ) { this->operator()( i,0 )->set( k, vb->operator()( _start_i+k ) ); } } else { for ( size_type k=0; k<nBlockRow; ++k ) { const T val = vb->operator()( _start_i+k ); this->operator()( i,0 )->set( k, val ); this->vector()->set( _start_iloc+k, val ); } } this->operator()( i,0 )->close(); _start_i += nBlockRow; _start_iloc += nBlockRow; } }
void VectorBlockBase<T>::updateBlockVec( vector_ptrtype const& m, size_type start_i ) { auto const& blockmap = m->map(); const size_type size = blockmap.nLocalDofWithGhost() ; for ( size_type i=0; i<size; ++i ) M_vec->set( start_i+i,m->operator()( i ) ); }
/** * copy subblock from global vector */ void localize( vector_ptrtype const& vb ) { vb->close(); size_type _start_i=0; for ( uint16_type i=0; i<this->nRow(); ++i ) { size_type nBlockRow = this->operator()( i,0 )->localSize(); for ( size_type k=0; k<nBlockRow; ++k ) { this->operator()( i,0 )->set( k, vb->operator()( _start_i+k ) ); } this->operator()( i,0 )->close(); _start_i += nBlockRow; } }
static void Ublas2Epetra( element_type const& x, vector_ptrtype& v ) { epetra_vector_type& _v( dynamic_cast<epetra_vector_type&>( *v ) ); Epetra_Map v_map( _v.Map() ); DVLOG(2) << "Local size of ublas vector" << x.localSize() << "\n"; DVLOG(2) << "Local size of epetra vector" << v->localSize() << "\n"; const size_type L = v->localSize(); for ( size_type i=0; i<L; i++ ) { DVLOG(2) << "v[" << v_map.GID( i ) << "] = " << "x(" << x.firstLocalIndex() + i << ")=" << x( x.firstLocalIndex() + i ) << "\n"; v->set( v_map.GID( i ), x( x.firstLocalIndex() + i ) ); } }
void Microphone::update( parameter_type const& mu ) { *D = *M_Aqm[0]; for ( size_type q = 1; q < M_Aqm.size(); ++q ) { //std::cout << "[affine decomp] scale q=" << q << " with " << M_betaAqm[q] << "\n"; D->addMatrix( M_betaAqm[q], M_Aqm[q] ); } F->close(); F->zero(); for ( size_type q = 0; q < M_Fqm[0].size(); ++q ) { //std::cout << "[affine decomp] scale q=" << q << " with " << M_betaFqm[0][q] << "\n"; F->add( M_betaFqm[0][q], M_Fqm[0][q] ); } }
void sumAllVectors1( vector_ptrtype & vector, bool use_scalar_one=false ) const { int size1 = M_functionals1.size(); int size2 = M_functionals2.size(); FEELPP_ASSERT( size1 > 0 )( size1 )( size2 ).error( "FsFunctionalLinearComposite has no elements" ); vector->zero(); auto temp_vector = M_backend->newVector( this->space() ); auto end = M_functionals1.end(); for(auto it=M_functionals1.begin(); it!=end; ++it) { int position = it->first; double scalar=1; if( ! use_scalar_one ) scalar = M_scalars1[position]; it->second->containerPtr(temp_vector); vector->add( scalar , temp_vector ); } }//sumAllVectors
//return the sum of all vectors virtual void containerPtr( vector_ptrtype & vector_to_fill ) { //vector_to_fill = sumAllVectors(true); sumAllVectors( vector_to_fill , true ); vector_to_fill->close(); }
std::pair<int, typename SolverNonLinearTrilinos<T>::real_type> SolverNonLinearTrilinos<T>::solve ( sparse_matrix_ptrtype& jac_in, // System Jacobian Matrix vector_ptrtype& x_in, // Solution vector vector_ptrtype& r_in, // Residual vector const double, // Stopping tolerance const unsigned int ) { //printf("Entering solve...\n"); MatrixEpetra* jac = dynamic_cast<MatrixEpetra *>( jac_in.get() ); VectorEpetra<T>* x = dynamic_cast<VectorEpetra<T>*>( x_in.get() ); // We cast to pointers so we can be sure that they succeeded // by comparing the result against NULL. // assert(jac != NULL); assert(jac->mat() != NULL); // assert(x != NULL); assert(x->vec() != NULL); // assert(r != NULL); assert(r->vec() != NULL); // Create the top level parameter list Teuchos::RCP<Teuchos::ParameterList> nlParamsPtr = Teuchos::rcp( new Teuchos::ParameterList ); Teuchos::ParameterList& nlParams = *( nlParamsPtr.get() ); // Set the nonlinear solver method nlParams.set( "Nonlinear Solver", "Line Search Based" ); // Set the printing parameters in the "Printing" sublist Teuchos::ParameterList& printParams = nlParams.sublist( "Printing" ); printParams.set( "Output Precision", 10 ); printParams.set( "Output Processor", 0 ); printParams.set( "Output Information", NOX::Utils::OuterIteration + NOX::Utils::OuterIterationStatusTest + NOX::Utils::InnerIteration + NOX::Utils::Parameters + NOX::Utils::Details + NOX::Utils::Warning ); // start definition of nonlinear solver parameters // Sublist for line search Teuchos::ParameterList& searchParams = nlParams.sublist( "Line Search" ); searchParams.set( "Method", "Polynomial" ); // Sublist for direction Teuchos::ParameterList& dirParams = nlParams.sublist( "Direction" ); dirParams.set( "Method", "Newton" ); Teuchos::ParameterList& newtonParams = dirParams.sublist( "Newton" ); newtonParams.set( "Forcing Term Method", "Constant" ); // Sublist for linear solver for the Newton method Teuchos::ParameterList& lsParams = newtonParams.sublist( "Linear Solver" ); lsParams.set( "Aztec Solver", "GMRES" ); lsParams.set( "Max Iterations", 800 ); lsParams.set( "Tolerance", 1e-7 ); lsParams.set( "Output Frequency", 50 ); lsParams.set( "Aztec Preconditioner", "ilu" ); // -> A : Jacobian for the first iteration // -> InitialGuess : first value x0 //printf("convert vectors...\n"); boost::shared_ptr<Epetra_Vector> InitialGuess = x->epetraVector(); // has_ownership=false in order to let the matrix jac be destroyed by boost // and not by Teuchos::RCP Teuchos::RCP<Epetra_CrsMatrix> A = Teuchos::rcp( ( ( boost::shared_ptr<Epetra_CrsMatrix> )( jac->matrix() ) ).get(),false ); //std::cout << "A.has_ownership()=" << A.has_ownership() << std::endl; Teuchos::RCP<NOX::Epetra::Interface::Required> iReq = Teuchos::rcp( new SolverNonLinearTrilinosInterface( this ) ); Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac = Teuchos::rcp( new SolverNonLinearTrilinosInterface( this ) ); Teuchos::RCP<NOX::Epetra::LinearSystemAztecOO> linSys = Teuchos::rcp( new NOX::Epetra::LinearSystemAztecOO( printParams, lsParams, iReq, iJac, A, *InitialGuess ) ); // Need a NOX::Epetra::Vector for constructor NOX::Epetra::Vector noxInitGuess( *InitialGuess, NOX::DeepCopy ); Teuchos::RCP<NOX::Epetra::Group> grpPtr = Teuchos::rcp( new NOX::Epetra::Group( printParams, iReq, noxInitGuess, linSys ) ); // Set up the status tests Teuchos::RCP<NOX::StatusTest::NormF> testNormF = Teuchos::rcp( new NOX::StatusTest::NormF( 1.0e-7 ) ); Teuchos::RCP<NOX::StatusTest::MaxIters> testMaxIters = Teuchos::rcp( new NOX::StatusTest::MaxIters( 20 ) ); // this will be the convergence test to be used Teuchos::RCP<NOX::StatusTest::Combo> combo = Teuchos::rcp( new NOX::StatusTest::Combo( NOX::StatusTest::Combo::OR, testNormF, testMaxIters ) ); // Create the solver Teuchos::RCP<NOX::Solver::Generic> solver = NOX::Solver::buildSolver( grpPtr, combo, nlParamsPtr ); // Solve the nonlinesar system NOX::StatusTest::StatusType status = solver->solve(); if ( NOX::StatusTest::Converged != status ) std::cout << "\n" << "-- NOX solver did not converged --" << "\n"; else std::cout << "\n" << "-- NOX solver converged --" << "\n"; // Print the answer std::cout << "\n" << "-- Parameter List From Solver --" << "\n"; solver->getList().print( cout ); // Get the Epetra_Vector with the final solution from the solver const NOX::Epetra::Group & finalGroup = dynamic_cast<const NOX::Epetra::Group&>( solver->getSolutionGroup() ); const Epetra_Vector & finalSolution = ( dynamic_cast<const NOX::Epetra::Vector&>( finalGroup.getX() ) ).getEpetraVector(); //cout << "Computed solution : " << endl; //cout << finalSolution; x_in = boost::shared_ptr<VectorEpetra<T> > ( new VectorEpetra<T>( &finalSolution ) ); //std::cout << "InitialGuess.use_count()=" << InitialGuess.use_count() << std::endl; //std::cout << "jac.use_count()=" << jac->matrix().use_count() << std::endl; //std::cout << "x_in.use_count()=" << x_in.use_count() << std::endl; return std::make_pair( 1,finalGroup.getNormF() ); }