/** * \brief Align the other item of the collision on the bottom of \a this. * \param info Some informations about the collision. * \param pos The bottom left position to put the other item at. * \param policy The description of how to align the items. */ bool bear::universe::physical_item::collision_align_bottom ( const collision_info& info, const position_type& pos, const collision_align_policy& policy ) { bool result(false); if ( collision_align_at(info.other_item(), pos) ) { result = true; physical_item& that = info.other_item(); switch ( policy.get_contact_mode() ) { case contact_mode::full_contact: that.set_top_contact(); set_bottom_contact(); break; case contact_mode::range_contact: that.set_top_contact( get_left(), get_right() ); set_bottom_contact( that.get_left(), that.get_right() ); break; case contact_mode::no_contact: // nothing to do break; } info.get_collision_repair().set_contact_normal (info.other_item(), vector_type(0, -1)); } return result; } // physical_item::collision_align_bottom()
void test_smooth_r4<float_type>::test() { // place particles along the x-axis within one half of the box, // put every second particle at the origin unsigned int npart = particle->nparticle(); vector_type dx(0); dx[0] = box->edges()(0, 0) / npart / 2; std::vector<vector_type> r_list(particle->nparticle()); std::vector<unsigned int> species(particle->nparticle()); for (unsigned int k = 0; k < r_list.size(); ++k) { r_list[k] = (k % 2) ? k * dx : vector_type(0); species[k] = (k < npart_list[0]) ? 0U : 1U; // set particle type for a binary mixture } BOOST_CHECK( set_position(*particle, r_list.begin()) == r_list.end() ); BOOST_CHECK( set_species(*particle, species.begin()) == species.end() ); // read forces and other stuff from device std::vector<float> en_pot(particle->nparticle()); BOOST_CHECK( get_potential_energy(*particle, en_pot.begin()) == en_pot.end() ); std::vector<vector_type> f_list(particle->nparticle()); BOOST_CHECK( get_force(*particle, f_list.begin()) == f_list.end() ); float const eps = std::numeric_limits<float>::epsilon(); for (unsigned int i = 0; i < npart; ++i) { unsigned int type1 = species[i]; unsigned int type2 = species[(i + 1) % npart]; vector_type r = r_list[i] - r_list[(i + 1) % npart]; vector_type f = f_list[i]; // reference values from host module host_float_type fval, en_pot_; host_float_type rr = inner_prod(r, r); std::tie(fval, en_pot_) = (*host_potential)(rr, type1, type2); if (rr < host_potential->rr_cut(type1, type2)) { double rcut = host_potential->r_cut(type1, type2); // the GPU force module stores only a fraction of these values en_pot_ /= 2; // the first term is from the smoothing, the second from the potential // (see lennard_jones.cpp from unit tests) float const tolerance = 8 * eps * (1 + rcut/(rcut - std::sqrt(rr))) + 10 * eps; BOOST_CHECK_SMALL(norm_inf(fval * r - f), std::max(norm_inf(fval * r), 1.f) * tolerance * 2); BOOST_CHECK_CLOSE_FRACTION(en_pot_, en_pot[i], 2 * tolerance); } else { // when the distance is greater than the cutoff // set the force and the pair potential to zero fval = en_pot_ = 0; BOOST_CHECK_SMALL(norm_inf(f), eps); BOOST_CHECK_SMALL(en_pot[i], eps); } } }
//__attribute__ ((noinline)) inline vector<float, 2> cmin(vector<float, 2> const& v) noexcept { using vector_type = typename vector_traits<float, 2>::vector_type; auto const tmp(float32x2_t(v.data_)); return { vector_type(vpmin_f32(tmp, tmp)) }; }
MenuOrbital::MenuOrbital( const vector_type& pos, const vector_type& ) : Orbital( pos, vector_type(0,0) ) { time = random( 0.0f, 3.0f );; angle = random_angle(); isActive = false; activationDelay = ACTIVATION_DELAY; isDeadly = false; }
//__attribute__ ((noinline)) inline vector<float, 4> cmin(vector<float, 4> const& v) noexcept { using vector_type = typename vector_traits<float, 4>::vector_type; auto tmp(vpmin_f32(vget_low_f32(float32x4_t(v.data_)), vget_high_f32(float32x4_t(v.data_)))); tmp = vpmin_f32(tmp, tmp); return { vector_type(vcombine_f32(tmp, tmp)) }; }
Orbital::Orbital( const Orbital::vector_type& pos, const Orbital::vector_type& vel, bool playSound ) : CircleActor( pos ) { v = vel; activationDelay = ACTIVATION_DELAY; isActive = false; colorIntensity = random( 7.0f, 14.0f ) / 10.0f; g = vector_type( 0, 0 ); if( playSound ) birthSfx[ random(0, N_BIRTH_SFX) ].play(); hitWall = false; }
bare_expr_type::bare_expr_type(const vector_type& x) : bare_type_(vector_type(x.is_data_)) {}
bool bare_expr_type::is_vector_type() const { return order_id() == vector_type().oid(); }
tensor (const vector_expression_type<derived_type> &expr) : tensor( vector_type ( expr ) ) { }
void ADRAssembler< mesh_type, matrix_type, vector_type>:: addMassRhs (vector_type& rhs, const vector_type& f) { // f has to be repeated! if (f.mapType() == Unique) { addMassRhs (rhs, vector_type (f, Repeated) ); return; } // Check that the fespace is set ASSERT (M_fespace != 0, "No FE space for assembling the right hand side (mass)!"); M_massRhsAssemblyChrono.start(); // Some constants const UInt nbElements (M_fespace->mesh()->numElements() ); const UInt fieldDim (M_fespace->fieldDim() ); const UInt nbFEDof (M_massRhsCFE->nbFEDof() ); const UInt nbQuadPt (M_massRhsCFE->nbQuadPt() ); const UInt nbTotalDof (M_fespace->dof().numTotalDof() ); // Temporaries Real localValue (0.0); std::vector<Real> fValues (nbQuadPt, 0.0); // Loop over the elements for (UInt iterElement (0); iterElement < nbElements; ++iterElement) { // Update the diffusion current FE M_massRhsCFE->update ( M_fespace->mesh()->element (iterElement), UPDATE_PHI | UPDATE_WDET ); // Clean the local matrix M_localMassRhs->zero(); // Assemble the local diffusion for (UInt iterFDim (0); iterFDim < fieldDim; ++iterFDim) { localVector_type::vector_view localView = M_localMassRhs->block (iterFDim); // Compute the value of f in the quadrature nodes for (UInt iQuadPt (0); iQuadPt < nbQuadPt; ++iQuadPt) { fValues[iQuadPt] = 0.0; for (UInt iDof (0); iDof < nbFEDof ; ++iDof) { fValues[iQuadPt] += f[ M_fespace->dof().localToGlobalMap (iterElement, iDof) + iterFDim * nbTotalDof] * M_massRhsCFE->phi (iDof, iQuadPt); } } // Loop over the basis functions for (UInt iDof (0); iDof < nbFEDof ; ++iDof) { localValue = 0.0; //Loop on the quadrature nodes for (UInt iQuadPt (0); iQuadPt < nbQuadPt; ++iQuadPt) { localValue += fValues[iQuadPt] * M_massRhsCFE->phi (iDof, iQuadPt) * M_massRhsCFE->wDetJacobian (iQuadPt); } // Add on the local matrix localView (iDof) = localValue; } } // Here add in the global rhs for (UInt iterFDim (0); iterFDim < fieldDim; ++iterFDim) { assembleVector ( rhs, iterElement, *M_localMassRhs, nbFEDof, M_fespace->dof(), iterFDim, iterFDim * M_fespace->dof().numTotalDof() ); } } M_massRhsAssemblyChrono.stop(); }
void ADRAssembler< mesh_type, matrix_type, vector_type>:: addAdvection (matrix_ptrType matrix, const vector_type& beta, const UInt& offsetLeft, const UInt& offsetUp) { // Beta has to be repeated! if (beta.mapType() == Unique) { addAdvection (matrix, vector_type (beta, Repeated), offsetLeft, offsetUp); return; } // Check that the fespace is set ASSERT (M_fespace != 0, "No FE space for assembling the advection!"); ASSERT (M_betaFESpace != 0, "No FE space (beta) for assembling the advection!"); M_advectionAssemblyChrono.start(); // Some constants const UInt nbElements (M_fespace->mesh()->numElements() ); const UInt fieldDim (M_fespace->fieldDim() ); const UInt betaFieldDim (M_betaFESpace->fieldDim() ); const UInt nbTotalDof (M_fespace->dof().numTotalDof() ); const UInt nbQuadPt (M_advCFE->nbQuadPt() ); // Temporaries //Real localValue(0); std::vector< std::vector< Real > > localBetaValue (nbQuadPt, std::vector<Real> ( betaFieldDim, 0.0 ) ); // Loop over the elements for (UInt iterElement (0); iterElement < nbElements; ++iterElement) { // Update the advection current FEs M_advCFE->update ( M_fespace->mesh()->element (iterElement), UPDATE_PHI | UPDATE_DPHI | UPDATE_WDET ); M_advBetaCFE->update (M_fespace->mesh()->element (iterElement), UPDATE_PHI ); // Clean the local matrix M_localAdv->zero(); // Interpolate beta in the quadrature points AssemblyElemental::interpolate (localBetaValue, *M_advBetaCFE, betaFieldDim, M_betaFESpace->dof(), iterElement, beta); // Assemble the advection AssemblyElemental::advection (*M_localAdv, *M_advCFE, 1.0, localBetaValue, fieldDim); // Assembly for (UInt iFieldDim (0); iFieldDim < fieldDim; ++iFieldDim) { assembleMatrix ( *matrix, *M_localAdv, *M_advCFE, *M_advCFE, M_fespace->dof(), M_fespace->dof(), iFieldDim, iFieldDim, iFieldDim * nbTotalDof + offsetLeft, iFieldDim * nbTotalDof + offsetUp ); } } M_advectionAssemblyChrono.stop(); }