/** * \return GiNaC exact solution */ ex getSolution(const double & value) const { // check if exact is defined FEELPP_ASSERT( M_exact.size() ).error( "undefined exact solution" ); // check if values is consistant with params FEELPP_ASSERT( parameters.size() == 1 ).error( "inconsistant values and parameters size" ); ex tmp_sol = exact; tmp_sol = substitute(tmp_sol, parameters[0], value); return tmp_sol; }
/** * \return GiNaC exact solution */ ex getSolution(const std::vector<double> & values) const { // check if exact is defined FEELPP_ASSERT( M_exact.size() ).error( "undefined exact solution" ); // check if values is consistant with params FEELPP_ASSERT( values.size() == parameters.size() ).error( "inconsistant values and parameters size" ); ex tmp_sol = exact; for (unsigned int i=0; i<values.size(); i++) // may use boost zip iterator tmp_sol = substitute(tmp_sol, parameters[i], values[i]); return tmp_sol; }
void VectorEpetra<T>::checkInvariants () const { FEELPP_ASSERT( this->localSize() == M_emap.NumMyElements() ) ( this->localSize() ) ( M_emap.NumMyElements() ).error( "Invalid VectorEpetra (Local size)" ); FEELPP_ASSERT( this->size() == M_emap.NumGlobalElements() ) ( this->size() ) ( M_emap.NumGlobalElements() ).error( "Invalid VectorEpetra (Global size)" ); FEELPP_ASSERT( this->firstLocalIndex() == M_emap.MinLID() ) ( this->firstLocalIndex() ) ( M_emap.MinLID() ).error( "Invalid VectorEpetra (Min global index)" ); FEELPP_ASSERT( this->lastLocalIndex() == M_emap.MaxLID()+1 ) ( this->lastLocalIndex() ) ( M_emap.MaxLID() ).error( "Invalid VectorEpetra (Min global index)" ); FEELPP_ASSERT( this->localSize() == M_vec.Map().NumMyElements() ) ( this->localSize() ) ( M_vec.Map().NumMyElements() ).error( "Invalid VectorEpetra (Local size)" ); FEELPP_ASSERT( this->size() == M_vec.Map().NumGlobalElements() ) ( this->size() ) ( M_vec.Map().NumGlobalElements() ).error( "Invalid VectorEpetra (Global size)" ); FEELPP_ASSERT( this->firstLocalIndex() == M_vec.Map().MinLID() ) ( this->firstLocalIndex() ) ( M_vec.Map().MinLID() ).error( "Invalid VectorEpetra (Min global index)" ); FEELPP_ASSERT( this->lastLocalIndex() == M_vec.Map().MaxLID()+1 ) ( this->lastLocalIndex() ) ( M_vec.Map().MaxLID() ).error( "Invalid VectorEpetra (Min global index)" ); }
void MatrixEigenSparse<T>::addMatrix( value_type v, MatrixSparse<value_type> const& _m ) { MatrixEigenSparse<value_type> const* m = dynamic_cast<MatrixEigenSparse<value_type> const*>( &_m ); FEELPP_ASSERT( m != 0 ).error( "invalid sparse matrix type, should be MatrixEigenSparse" ); FEELPP_ASSERT( m->closed() ).error( "invalid sparse matrix type, should be closed" ); if ( !m ) throw std::invalid_argument( "m" ); if ( !this->closed() ) { M_mat += v * m->M_mat; } }
void matrixPtr(int q , matrix_ptrtype& matrix) const { int q_max = M_operators1.size(); FEELPP_ASSERT( q < q_max )( q_max )( q ).error( "OperatorLinearComposite has not enough elements" ); //fill matrix M_operators1.template at(q)->matPtr(matrix); }
/** * clear out all data from the mesh, \p isEmpty() should return * \p true after a \p clear() */ virtual void clear() { this->elements().clear(); this->points().clear(); this->faces().clear(); FEELPP_ASSERT( isEmpty() ).error( "all mesh containers should be empty after a clear." ); }
/** * apply the functional to a polynomial * * * \param p polynomial * \return matrix resulting from the application of the functional to the polynomial */ virtual matrix_type operator()( polynomial_type const& p ) const { FEELPP_ASSERT( p.coeff().size2() == M_coeff.size2() ) ( p.coeff() )( M_coeff ).error( "invalid polynomial" ); return ublas::prod( p.coeff(), ublas::trans( M_coeff ) ); }
//return the sum of matrices given //by all opertors in M_vectors //arguments : a vector of vector of scalars and a bool ( use scalar=1 if true ) void sumAllMatrices2( matrix_ptrtype & matrix, bool use_scalar_one=false ) const { int size1 = M_operators1.size(); int size2 = M_operators2.size(); FEELPP_ASSERT( size2 > 0 )( size1 )( size2 ).error( "OperatorLinearComposite has no elements" ); matrix->zero(); auto temp_matrix = M_backend->newMatrix( _test=this->dualImageSpace(), _trial=this->domainSpace(), _pattern=M_pattern ); auto end = M_operators2.end(); for(auto it=M_operators2.begin(); it!=end; ++it) { auto position = it->first; int q = position.template get<0>(); int m = position.template get<1>(); double scalar=1; if( ! use_scalar_one ) scalar = M_scalars2[q][m]; it->second->matPtr(temp_matrix); matrix->addMatrix( scalar , temp_matrix ); } temp_matrix.reset(); }//sumAllMatrices
void SolverLinearPetsc<T>::clear () { PetscBool pinit; PetscInitialized( &pinit ); if ( pinit && this->initialized() ) { this->setInitialized( false ); int ierr=0; // 2.1.x & earlier style #if (PETSC_VERSION_MAJOR == 2) && (PETSC_VERSION_MINOR <= 1) ierr = SLESDestroy( M_sles ); CHKERRABORT( this->worldComm().globalComm(),ierr ); // 2.2.0 & newer style #else FEELPP_ASSERT( M_ksp != 0 ).error( "invalid ksp" ); ierr = PETSc::KSPDestroy( M_ksp ); CHKERRABORT( this->worldComm().globalComm(),ierr ); #endif // Mimic PETSc default solver and preconditioner this->setSolverType( GMRES ); if ( this->worldComm().globalComm().size() == 1 ) this->setPreconditionerType( LU_PRECOND ); else this->setPreconditionerType( BLOCK_JACOBI_PRECOND ); } }
/** * \f$ U+=v \f$ where \p v is a std::vector<T> * and you * want to specify WHERE to add it */ void addVector ( const std::vector<value_type>& v, const std::vector<size_type>& dof_indices ) { FEELPP_ASSERT ( v.size() == dof_indices.size() ).error( "invalid dof indices" ); for ( size_type i=0; i<v.size(); i++ ) this->add ( dof_indices[i], v[i] ); }
/** * Subtraction operator. * Fast equivalent to \p U.add(-1, V). */ Vector<T> & operator -= ( const Vector<value_type> &V ) { FEELPP_ASSERT( this->closed() ).error( "vector is not closed" ); this->add( -1., V ); return *this; }
/** * \f$U+=V \f$ where U and V are type * uvlas::vector<T> and you * want to specify WHERE to add * the DenseVector<T> V */ void addVector ( const ublas::vector<value_type>& V, const std::vector<size_type>& dof_indices ) { FEELPP_ASSERT ( V.size() == dof_indices.size() ).error( "invalid dof indices" ); for ( size_type i=0; i<V.size(); i++ ) this->add ( dof_indices[i], V( i ) ); }
//Access to a specific vector void vecPtr( int q , vector_ptrtype& vector ) { int q_max = M_functionals1.size(); FEELPP_ASSERT( q < q_max )( q_max )( q ).error( "FsFunctionalLinearComposite has not enough elements" ); //auto vector = M_backend->newVector( this->space() ); M_functionals1.template at(q)->containerPtr(vector); //return vector; }
void MatrixEpetra::addMatrix ( int* rows, int nrows, int* cols, int ncols, value_type* data ) { FEELPP_ASSERT ( this->isInitialized() ).error( "MatrixEpetra<> not properly initialized" ); M_mat->SumIntoGlobalValues( nrows, rows, ncols, cols, data, Epetra_FECrsMatrix::ROW_MAJOR ); }
void setRhs(t_edp_type * edp) { FEELPP_ASSERT( parameters.size() ).error( "setRhs: inconsistant numbers of parameters" ); rhs = (*edp)(exact, vars, parameters); LOG(INFO) << "computed rhs is : " << rhs << "\n"; std::ostringstream rhs_expression; rhs_expression << rhs; M_rhs = rhs_expression.str(); }
void setRhs(std::string const& expression ="") { if ( expression.empty() ) FEELPP_ASSERT( M_rhs.size() ).error( "undefined rhs exact" ); else M_rhs = expression; LOG(INFO) << "Loading rhs function : " << M_rhs << std::endl; rhs = parse(M_rhs, vars, parameters); LOG(INFO) << "rhs is : " << rhs << "\n"; }
// print into Matlab sparse Matrix void MatrixEpetra::printMatlab ( const std::string name ) const { FEELPP_ASSERT ( this->isInitialized() ).error( "epetra matrix not properly initialized" ); FEELPP_ASSERT ( this->closed() ).warn( "epetra matrix not closed" ); if ( !this->closed() ) const_cast<MatrixEpetra*>( this )->close(); DVLOG(2) << "[printMatlab] print matrix in matlab file " << name << "\n"; //std::cout << "[printMatlab] print matrix in matlab file " << name << "\n"; //this->printKonsole(); //std::cout << "[printMatlab] print matrix in matlab file done\n"; int ret = EpetraExt::RowMatrixToMatlabFile( name.c_str(), *M_mat ); //int ret = EpetraExt::RowMatrixToMatrixMarketFile( name.c_str(), *M_mat, "toto", "tutu" ); if ( ret != 0 ) std::cout << "error in printMatlab\n"; }
// disable VectorPetsc( VectorPetsc const & v ) : super( v ), M_destroy_vec_on_exit( true ) { FEELPP_ASSERT( v.closed() ).error( "copied vector is not closed" ); VecDuplicate( v.M_vec, &M_vec ); VecCopy( v.M_vec, M_vec ); this->M_is_initialized = true; this->close(); }
/** * Call the assemble functions */ void close () { FEELPP_ASSERT ( this->isInitialized() ).error( "VectorPetsc<> not initialized" ); int ierr=0; ierr = VecAssemblyBegin( M_vec ); CHKERRABORT( this->comm(),ierr ); ierr = VecAssemblyEnd( M_vec ); CHKERRABORT( this->comm(),ierr ); this->M_is_closed = true; }
void VectorEpetra<T>::printMatlab ( const std::string name, bool renumber ) const { FEELPP_ASSERT ( this->closed() ).warn( "epetra vector not closed" ); #if 0 if ( !this->closed() ) const_cast<VectorEpetra<T>*>( this )->close(); #endif VLOG(1) << "[printMatlab] print vector in matlab file " << name << "\n"; EpetraExt::MultiVectorToMatlabFile( name.c_str(), M_vec ); }
void VectorEpetra<T>::set ( size_type i, const value_type& value ) { FEELPP_ASSERT( i<size() )( i )( size() ).error( "invalid index" ); int i_val = static_cast<int>( i ); value_type epetra_value = static_cast<value_type>( value ); //M_vec[i_val] = epetra_value; M_vec.ReplaceGlobalValues( 1, &i_val, &epetra_value ); DVLOG(2) << "[Vector] Replacing value in row " << i << " for " << value << "\n"; }
// print to console void MatrixEpetra::printKonsole () const { FEELPP_ASSERT ( this->isInitialized() ).error( "epetra matrix not properly initialized" ); std::cout << "\n+---------------Information about the Matrix---------------+\n" << std::endl; cout << *M_mat; std::cout << "+----------------------------------------------------------+\n" << std::endl; std::cout << "\n+---------------Information about the RowMap------------------+\n" << std::endl; cout << M_mat->RowMap(); std::cout << "+----------------------------------------------------------+\n" << std::endl; std::cout << "\n+---------------Information about the ColMap------------------+\n" << std::endl; cout << M_mat->ColMap(); std::cout << "+----------------------------------------------------------+\n" << std::endl; }
void VectorEpetra<T>::add ( const size_type i, const value_type& value ) { FEELPP_ASSERT( i<size() )( i )( size() ).error( "invalid index" ); int i_val = static_cast<int>( i ); value_type epetra_value = static_cast<value_type>( value ); int ierr; //ierr= M_vec.SumIntoGlobalValues(1,&epetra_value,&i_val); ierr= M_vec.SumIntoGlobalValues( 1,&i_val, &epetra_value ); //indices are in global index space if ( ierr != 0 ) { VLOG(1) << "ERRORCODE SumIntoGlobalValues VECTOR: " << ierr << " in V(" << i_val << ") for value "<< epetra_value << "." << "\n"; } }
ElementType prod( ElementType const& v1, ElementType const& v2, typename boost::enable_if<boost::is_base_of<FunctionSpaceBase::ElementBase,ElementType> >::type* dummy = 0 ) { FEELPP_ASSERT( v1.functionSpace() == v2.functionSpace() ).error( "incompatible function spaces" ); typedef typename type_traits<typename ElementType::value_type>::real_type real_type; ElementType _t( v1.functionSpace() ); size_type s = v1.localSize(); size_type start = v1.firstLocalIndex(); for ( size_type i = 0; i < s; ++i ) _t.operator()( start+i ) = v1.operator()( start + i )* v2.operator()( start + i ); return _t; }
Geo0D<Dim, T>::Geo0D( size_type id, node_type const& __p, bool boundary, bool is_vertex ) : super( id, MESH_ENTITY_INTERNAL ), super2( __p ), M_master_id( id ), M_is_vertex( is_vertex ), M_is_parametric( false ), M_mesh( nullptr ), M_gdim( 0 ), M_gtag( 0 ), M_uv( 2 ) { FEELPP_ASSERT( __p.size() == Dim )( __p )( Dim ).error( "invalid node" ); this->setOnBoundary( boundary ); }
void MatrixEigenSparse<T>::printMatlab( const std::string filename ) const { std::string name = filename; std::string separator = " , "; // check on the file name int i = filename.find( "." ); if ( i <= 0 ) name = filename + ".m"; else { if ( ( size_type ) i != filename.size() - 2 || filename[ i + 1 ] != 'm' ) { std::cerr << "Wrong file name "; name = filename + ".m"; } } std::ofstream file_out( name.c_str() ); FEELPP_ASSERT( file_out )( filename ).error( "[Feel::spy] ERROR: File cannot be opened for writing." ); std::string varName = "var_" + filename.substr(0,filename.find(".")); file_out << varName << " = [ "; file_out.precision( 16 ); file_out.setf( std::ios::scientific ); for (int k=0; k<M_mat.outerSize(); ++k) { for (typename matrix_type::InnerIterator it(M_mat,k); it; ++it) { value_type v = it.value(); file_out << it.row() + 1 << separator << it.col() + 1 << separator << v << std::endl; } } file_out << "];" << std::endl; file_out << "I="<<varName<<"(:,1); J="<<varName<<"(:,2); "<<varName<<"="<<varName<<"(:,3);" << std::endl; file_out << "spy("<<varName<<");" << std::endl; }
void sumAllMatrices(matrix_ptrtype & matrix, bool use_scalar_one=false ) const { int size1 = M_operators1.size(); int size2 = M_operators2.size(); bool size_error=false; if( size1 > 0 && size2 > 0 ) size_error=true; if( (size1 + size2) == 0 ) size_error=true; FEELPP_ASSERT( !size_error )( size1 )( size2 ).error( "OperatorLinearComposite has no elements, or both maps have elements" ); if( size1 > 0 ) sumAllMatrices1( matrix, use_scalar_one ); else sumAllMatrices2( matrix, use_scalar_one ); }
void sumAllVectors( vector_ptrtype & vector, bool use_scalar_one=false ) const { int size1 = M_functionals1.size(); int size2 = M_functionals2.size(); bool size_error=false; if( size1 > 0 && size2 > 0 ) size_error=true; if( (size1 + size2) == 0 ) size_error=true; FEELPP_ASSERT( !size_error )( size1 )( size2 ).error( "FsFunctionalLinearComposite has no elements, or both maps have elements" ); if( size1 > 0 ) sumAllVectors1( vector, use_scalar_one ); else sumAllVectors2( vector, use_scalar_one ); }
void serialize(Archive & ar, const unsigned int version) const { value_type* array; VecGetArray(this->vec(),&array); int n = this->localSize(); int N = this->size(); int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); FEELPP_ASSERT( n==N ).error( "wrong vector type for serialization (!=VECSEQ)" ); for (int i=0; i<n; i++) ar & array[i]; VecRestoreArray(this->vec(), &array); }
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