void erase(element_type const & elem) { typedef std::pair<uint64_t,uint64_t> upair; typedef std::pair<int,upair> q_element; std::deque< q_element > todo; if ( elem.getTo() > elem.getFrom() ) { todo.push_back(q_element(k,upair(elem.getFrom(),elem.getTo()))); while ( todo.size() ) { q_element q = todo.front(); todo.pop_front(); int const level = k-q.first; uint64_t const basebin = (1ull << level)-1; uint64_t const div = (1ull<<(q.first+1)); uint64_t const mask = (q.first >= 0) ? (1<<q.first) : 0; uint64_t const low = q.second.first; uint64_t const high = q.second.second; uint64_t const bin = basebin + low/div; // std::cerr << level << "," << q.first << "," << q.second.first << "," << q.second.second << "," << basebin << "," << div << "," << bin << std::endl; assert ( high > low ); bool const cross = ((high-1)&mask) != (low & mask); if ( cross || q.first < 0 ) { if ( bins.find(bin) != bins.end() ) { std::vector<element_type> & V = bins.find(bin)->second; uint64_t o = 0; for ( uint64_t i = 0; i < V.size(); ++i ) if ( !(V[i] == elem) ) V[o++] = V[i]; V.resize(o); } break; } else { assert ( q.first >= 0 ); todo.push_back(q_element(q.first-1,upair(low,high))); } } } }
static void create_boundary_elements(element_type & element, inserter_type & inserter) { BoundaryElementType boundary_element( inserter.get_physical_container_collection() ); int index = 0; for (int i = 0; i < boundary_elements<simplex_tag<n>, vertex_tag >::num; ++i) for (int j = i+1; j < boundary_elements<simplex_tag<n>, vertex_tag >::num; ++j) { boundary_element.container(dimension_tag<0>()).set_handle( element.container( dimension_tag<0>() ).handle_at(i), 0 ); boundary_element.container(dimension_tag<0>()).set_handle( element.container( dimension_tag<0>() ).handle_at(j), 1 ); element.set_boundary_element( boundary_element, inserter.template insert<true, true>(boundary_element), index++ ); } }
void Navierstokes::exportResults( double time, element_type& U ) { auto u = U.element<0>(); auto p = U.element<1>(); auto v = V.element<0>(); auto q = V.element<1>(); #if defined( FEELPP_USE_LM ) auto lambda = U.element<2>(); auto nu = V.element<2>(); LOG(INFO) << "value of the Lagrange multiplier lambda= " << lambda( 0 ) << "\n"; #endif double div_u_error_L2 = normL2( _range=elements( u.mesh() ), _expr=divv( u ) ); LOG(INFO) << "[navierstokes] ||div(u)||_2=" << div_u_error_L2 << "\n"; if ( exporter->doExport() ) { exporter->step( time )->setMesh( U.functionSpace()->mesh() ); exporter->step( time )->addRegions(); exporter->step( time )->add( {"u","p","l"}, U ); exporter->save(); } } // NavierStokes::export
void SparseVector<T_Element,T_Alloc>::insert_element(element_type ele) { assert_space(1); assert_is_sorted(); // Find the insertion point if( nz() ) { typedef SparseVectorUtilityPack::SpVecIndexLookup<T_Element> SpVecIndexLookup; typedef typename SpVecIndexLookup::poss_type poss_type; index_lookup_.validate_state(); poss_type poss = ( nz() ? index_lookup_.find_poss(ele.index(), SpVecIndexLookup::LOWER_ELE) : poss_type(0,SpVecIndexLookup::BEFORE_ELE) ); // Make sure this element does not already exist! #ifdef TEUCHOS_DEBUG TEUCHOS_TEST_FOR_EXCEPTION( nz() && poss.rel == SpVecIndexLookup::EQUAL_TO_ELE, std::length_error ,"SparseVector<...>::insert_element(...) : Error, this index" " all ready exists!" ); #endif const size_type insert_poss = (poss.rel == SpVecIndexLookup::BEFORE_ELE ? poss.poss : poss.poss+1); // Copy elements out of the way to make room for inserted element std::copy_backward( // This assumes element_type supports assignment! index_lookup_.ele() + insert_poss, index_lookup_.ele() + index_lookup_.nz() , index_lookup_.ele() + index_lookup_.nz() + 1 ); index_lookup_.ele()[insert_poss] = ele; index_lookup_.incr_nz(); } else { // The first element we are adding! index_lookup_.ele()[0] = ele; index_lookup_.incr_nz(); } }
void AdvectionDiffusion::exportResults( element_type& U , parameter_type const& mu ) { if ( M_do_export ) { LOG(INFO) << "exportResults starts\n"; std::string exp_name; export_ptrtype exporter; std::string mu_str; for ( int i=0; i<mu.size(); i++ ) { mu_str= mu_str + ( boost::format( "_%1%" ) %mu[i] ).str() ; } exp_name = "solution_with_parameters_" + mu_str; exporter = export_ptrtype( Exporter<mesh_type>::New( "ensight", exp_name ) ); exporter->step( 0 )->setMesh( U.functionSpace()->mesh() ); exporter->step( 0 )->add( "u", U ); exporter->save(); } } // AdvectionDiffusion::export
void insert(element_type const & elem) { typedef std::pair<uint64_t,uint64_t> upair; typedef std::pair<int,upair> q_element; std::deque< q_element > todo; if ( elem.getTo() > elem.getFrom() ) { todo.push_back(q_element(k,upair(elem.getFrom(),elem.getTo()))); while ( todo.size() ) { q_element q = todo.front(); todo.pop_front(); int const level = k-q.first; uint64_t const basebin = (1ull << level)-1; uint64_t const div = (1ull<<(q.first+1)); uint64_t const mask = (q.first >= 0) ? (1<<q.first) : 0; uint64_t const low = q.second.first; uint64_t const high = q.second.second; uint64_t const bin = basebin + low/div; // std::cerr << level << "," << q.first << "," << q.second.first << "," << q.second.second << "," << basebin << "," << div << "," << bin << std::endl; assert ( high > low ); bool const cross = ((high-1)&mask) != (low & mask); if ( cross || q.first < 0 ) { bins[bin].push_back(elem); break; } else { assert ( q.first >= 0 ); todo.push_back(q_element(q.first-1,upair(low,high))); } } } }
// apply the functional virtual value_type operator()( const element_type& x ) const { //auto vector = sumAllVectors( true ); auto vector = M_backend->newVector( this->space() ); sumAllVectors( vector, true ); vector->close(); return M_backend->dot( *vector, x.container() ); }
// apply the functional virtual value_type operator()( const element_type& x ) const { auto vector = M_backend->newVector( this->space() ); form1( _test=this->space(),_vector=vector) = M_expr; vector->close(); return M_backend->dot( *vector, x.container() ); }
void CSVDocument::_write_optional_enclosure_field( std::ostream& out_stream, const element_type& elem, bool last_elem ) { if (elem.find("\"") != std::string::npos) { std::string new_elem = elem; _replace_all(new_elem, "\"", "\"\""); out_stream << "\"" << new_elem << "\""; } else if (elem.find(",") != std::string::npos || elem.find("\n") != std::string::npos) { out_stream << "\"" << elem << "\""; } else { out_stream << elem; } out_stream << (last_elem ? "\n" : ","); }
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 ConvectionCrb::solve( sparse_matrix_ptrtype& D, element_type& u, vector_ptrtype& F ) { vector_ptrtype U( M_backend->newVector( u.functionSpace() ) ); M_backend->solve( D, D, U, F ); u = *U; }
void Beam<nDim,nOrder>::exportResults( double time, element_type const& u, element_type const &v ) { timers["export"].first.restart(); exporter->step( time )->setMesh( u.functionSpace()->mesh() ); exporter->step( time )->add( "displ", u ); exporter->step( time )->add( "P", v ); exporter->save(); timers["export"].second = timers["export"].first.elapsed(); } // Beam::export
static void Epetra2Ublas( vector_ptrtype const& u, element_type& x ) { epetra_vector_ptrtype const& _v( dynamic_cast<epetra_vector_ptrtype const&>( u ) ); Epetra_Map v_map( _v->Map() ); vector_type v = *u; //DVLOG(2) << "Initial EpetraVector " << v << "\n"; const size_type L = v.localSize(); for ( size_type i=0; i<L; i++ ) { DVLOG(2) << "x(" << x.firstLocalIndex() + i << ")=" << "v[" << v_map.GID( i ) << "] = " << v( i ) << "\n"; x( x.firstLocalIndex() + i ) = v( i ); } DVLOG(2) << "Epetra2Ublas:" << x << "\n"; }
void Microphone::exportResults( element_type& U ) { if ( M_do_export ) { LOG(INFO) << "exportResults starts\n"; exporter->step( 0 )->setMesh( U.functionSpace()->mesh() ); exporter->step( 0 )->add( "u", U ); exporter->save(); } } // Microphone::export
void AnisotropicWavespeed::exportResults( element_type& U ) { if ( M_do_export ) { LOG(INFO) << "exportResults starts\n"; exporter->step( 0 )->setMesh( U.functionSpace()->mesh() ); exporter->step( 0 )->add( "u", U ); exporter->save(); } } // AnisotropicWavespeed::export
void DrivenCavity<Dim>::exportResults( element_type const& U ) { auto uex=unitX(); auto u_exact=vf::project(Vh->template functionSpace<0>(), markedfaces(mesh, "wall2"), uex ); if ( exporter->doExport() ) { exporter->step( 0 )->setMesh( U.functionSpace()->mesh() ); exporter->step( 0 )->addRegions(); exporter->step( 0 )->add( "u", U.template element<0>() ); exporter->step( 0 )->add( "p", U.template element<1>() ); exporter->step( 0 )->add( "uex", u_exact); exporter->save(); } }
static void create_boundary_elements(element_type & element, inserter_type & inserter) { BoundaryElementType boundary_element( inserter.get_physical_container_collection() ); int index = 0; boundary_element.container(dimension_tag<0>()).set_handle( element.container( dimension_tag<0>() ).handle_at(0), 0 ); boundary_element.container(dimension_tag<0>()).set_handle( element.container( dimension_tag<0>() ).handle_at(1), 1 ); element.set_boundary_element( boundary_element, inserter.template insert<true, true>(boundary_element), index++ ); boundary_element.container(dimension_tag<0>()).set_handle( element.container( dimension_tag<0>() ).handle_at(0), 0 ); boundary_element.container(dimension_tag<0>()).set_handle( element.container( dimension_tag<0>() ).handle_at(2), 1 ); element.set_boundary_element( boundary_element, inserter.template insert<true, true>(boundary_element), index++ ); boundary_element.container(dimension_tag<0>()).set_handle( element.container( dimension_tag<0>() ).handle_at(1), 0 ); boundary_element.container(dimension_tag<0>()).set_handle( element.container( dimension_tag<0>() ).handle_at(3), 1 ); element.set_boundary_element( boundary_element, inserter.template insert<true, true>(boundary_element), index++ ); boundary_element.container(dimension_tag<0>()).set_handle( element.container( dimension_tag<0>() ).handle_at(2), 0 ); boundary_element.container(dimension_tag<0>()).set_handle( element.container( dimension_tag<0>() ).handle_at(3), 1 ); element.set_boundary_element( boundary_element, inserter.template insert<true, true>(boundary_element), index++ ); }
bool transaction_order_calculator::visit(element_type element) { bool reenter = false; transaction_entry::list required; for (auto& parent : element->parents()) if (!parent->is_anchor() && !has_encountered(parent)) required.push_back(parent); if (required.size() > 0) { reenter = true; enqueue(element); for (auto entry : required) enqueue(entry); } else ordered_.push_back(element); return !reenter; }
// apply the functional virtual value_type operator()( const element_type& x ) const { M_vector->close(); return M_backend->dot( *M_vector, x.container() ); }
std::vector<element_type const *> search(element_type const & elem) const { std::vector<element_type const *> R; typedef std::pair<uint64_t,uint64_t> upair; typedef std::pair<int,upair> q_element; std::deque< q_element > todo; if ( elem.getTo() > elem.getFrom() ) todo.push_back(q_element(k,upair(elem.getFrom(),elem.getTo()))); while ( todo.size() ) { q_element q = todo.front(); todo.pop_front(); int const level = k-q.first; uint64_t const basebin = (1ull << level)-1; uint64_t const div = (1ull<<(q.first+1)); uint64_t const mask = (q.first >= 0) ? (1<<q.first) : 0; uint64_t const low = q.second.first; uint64_t const high = q.second.second; uint64_t const bin = basebin + low/div; if ( bins.find(bin) != bins.end() ) { std::vector<element_type> const & V = bins.find(bin)->second; for ( uint64_t i = 0; i < V.size(); ++i ) { libmaus2::math::IntegerInterval<uint64_t> I0(elem.getFrom(),elem.getTo()-1); libmaus2::math::IntegerInterval<uint64_t> I1(V[i].getFrom(),V[i].getTo()-1); if ( !I0.intersection(I1).isEmpty() ) R.push_back(&V[i]); } } // std::cerr << level << "," << q.first << "," << q.second.first << "," << q.second.second << "," << basebin << "," << div << "," << bin << std::endl; assert ( high > low ); bool const cross = ((high-1)&mask) != (low & mask); if ( cross ) { uint64_t const mid = ((low >> q.first)+1)<<q.first; // std::cerr << "low=" << low << ",mid=" << mid << ",high=" << high << std::endl; assert ( mid > low ); assert ( high > mid ); todo.push_back(q_element(q.first-1,upair(low,mid))); todo.push_back(q_element(q.first-1,upair(mid,high))); } else if ( q.first >= 0 ) { todo.push_back(q_element(q.first-1,upair(low,high))); } else { // std::cerr << "base " << low << "," << high << " bin " << bin << std::endl; } }
void set_id( element_type & element, id_type id ) { element.id(id); }