本文整理汇总了C++中VectorXs::size方法的典型用法代码示例。如果您正苦于以下问题:C++ VectorXs::size方法的具体用法?C++ VectorXs::size怎么用?C++ VectorXs::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VectorXs
的用法示例。
在下文中一共展示了VectorXs::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: evalgradg
void BodyBodyConstraint::evalgradg( const VectorXs& q, const int col, SparseMatrixsc& G, const FlowableSystem& fsys ) const
{
assert( q.size() % 12 == 0 );
assert( col >= 0 );
assert( col < G.cols() );
const unsigned nbodies{ static_cast<unsigned>( q.size() / 12 ) };
// MUST BE ADDED GOING DOWN THE COLUMN. DO NOT TOUCH ANOTHER COLUMN.
{
assert( 3 * nbodies + 3 * m_idx0 + 2 < unsigned( G.rows() ) );
G.insert( 3 * m_idx0 + 0, col ) = m_n.x();
G.insert( 3 * m_idx0 + 1, col ) = m_n.y();
G.insert( 3 * m_idx0 + 2, col ) = m_n.z();
const Vector3s ntilde_0{ m_r0.cross( m_n ) };
G.insert( 3 * ( m_idx0 + nbodies ) + 0, col ) = ntilde_0.x();
G.insert( 3 * ( m_idx0 + nbodies ) + 1, col ) = ntilde_0.y();
G.insert( 3 * ( m_idx0 + nbodies ) + 2, col ) = ntilde_0.z();
}
{
assert( 3 * nbodies + 3 * m_idx1 + 2 < unsigned( G.rows() ) );
G.insert( 3 * m_idx1 + 0, col ) = - m_n.x();
G.insert( 3 * m_idx1 + 1, col ) = - m_n.y();
G.insert( 3 * m_idx1 + 2, col ) = - m_n.z();
const Vector3s ntilde_1{ m_r1.cross( m_n ) };
G.insert( 3 * ( m_idx1 + nbodies ) + 0, col ) = - ntilde_1.x();
G.insert( 3 * ( m_idx1 + nbodies ) + 1, col ) = - ntilde_1.y();
G.insert( 3 * ( m_idx1 + nbodies ) + 2, col ) = - ntilde_1.z();
}
}
示例2: computeGeneralizedFrictionDisk
// This method and the smooth version share the second half of code. Abstract that out.
void StaticPlaneSphereConstraint::computeGeneralizedFrictionDisk( const VectorXs& q, const VectorXs& v, const int start_column, const int num_samples, SparseMatrixsc& D, VectorXs& drel ) const
{
assert( start_column >= 0 );
assert( start_column < D.cols() );
assert( num_samples > 0 );
assert( start_column + num_samples - 1 < D.cols() );
assert( q.size() % 12 == 0 );
assert( q.size() == 2 * v.size() );
const Vector3s n{ m_plane.n() };
assert( fabs( n.norm() - 1.0 ) <= 1.0e-6 );
std::vector<Vector3s> friction_disk( static_cast<std::vector<Vector3s>::size_type>( num_samples ) );
assert( friction_disk.size() == std::vector<Vector3s>::size_type( num_samples ) );
{
// Compute the relative velocity
Vector3s tangent_suggestion{ computeRelativeVelocity( q, v ) };
if( tangent_suggestion.cross( n ).squaredNorm() < 1.0e-9 )
{
tangent_suggestion = FrictionUtilities::orthogonalVector( n );
}
tangent_suggestion *= -1.0;
// Sample the friction disk
FrictionUtilities::generateOrthogonalVectors( n, friction_disk, tangent_suggestion );
}
assert( unsigned( num_samples ) == friction_disk.size() );
// Compute the displacement from the center of mass to the point of contact
assert( fabs( n.norm() - 1.0 ) <= 1.0e-10 ); assert( m_r >= 0.0 );
const Vector3s r_world{ - m_r * n };
// Cache the velocity of the collision point on the plane
const Vector3s plane_collision_point_vel{ computePlaneCollisionPointVelocity( q ) };
// For each sample of the friction disk
const unsigned nbodies{ static_cast<unsigned>( q.size() / 12 ) };
for( unsigned friction_sample = 0; friction_sample < unsigned( num_samples ); ++friction_sample )
{
const unsigned cur_col{ start_column + friction_sample };
assert( cur_col < unsigned( D.cols() ) );
// Effect on center of mass
D.insert( 3 * m_sphere_idx + 0, cur_col ) = friction_disk[friction_sample].x();
D.insert( 3 * m_sphere_idx + 1, cur_col ) = friction_disk[friction_sample].y();
D.insert( 3 * m_sphere_idx + 2, cur_col ) = friction_disk[friction_sample].z();
// Effect on orientation
{
const Vector3s ntilde{ r_world.cross( friction_disk[friction_sample] ) };
D.insert( 3 * ( nbodies + m_sphere_idx ) + 0, cur_col ) = ntilde.x();
D.insert( 3 * ( nbodies + m_sphere_idx ) + 1, cur_col ) = ntilde.y();
D.insert( 3 * ( nbodies + m_sphere_idx ) + 2, cur_col ) = ntilde.z();
}
// Relative velocity contribution from kinematic scripting
assert( cur_col < drel.size() );
drel( cur_col ) = - friction_disk[friction_sample].dot( plane_collision_point_vel );
}
}
示例3: computeGeneralizedFrictionGivenTangentSample
void BodyBodyConstraint::computeGeneralizedFrictionGivenTangentSample( const VectorXs& q, const VectorXs& t, const unsigned column, SparseMatrixsc& D ) const
{
assert( column < unsigned( D.cols() ) );
assert( q.size() % 12 == 0 );
assert( t.size() == 3 );
assert( fabs( t.norm() - 1.0 ) <= 1.0e-6 );
assert( fabs( m_n.dot( t ) ) <= 1.0e-6 );
assert( m_idx0 < m_idx1 );
const unsigned nbodies{ static_cast<unsigned>( q.size() / 12 ) };
// Effect on center of mass of body i
D.insert( 3 * m_idx0 + 0, column ) = t.x();
D.insert( 3 * m_idx0 + 1, column ) = t.y();
D.insert( 3 * m_idx0 + 2, column ) = t.z();
// Effect on orientation of body i
{
const Vector3s ntilde0{ m_r0.cross( Eigen::Map<const Vector3s>{ t.data() } ) };
D.insert( 3 * ( m_idx0 + nbodies ) + 0, column ) = ntilde0.x();
D.insert( 3 * ( m_idx0 + nbodies ) + 1, column ) = ntilde0.y();
D.insert( 3 * ( m_idx0 + nbodies ) + 2, column ) = ntilde0.z();
}
// Effect on center of mass of body j
D.insert( 3 * m_idx1 + 0, column ) = - t.x();
D.insert( 3 * m_idx1 + 1, column ) = - t.y();
D.insert( 3 * m_idx1 + 2, column ) = - t.z();
// Effect on orientation of body j
{
const Vector3s ntilde1{ m_r1.cross( Eigen::Map<const Vector3s>{ t.data() } ) };
D.insert( 3 * ( m_idx1 + nbodies ) + 0, column ) = - ntilde1.x();
D.insert( 3 * ( m_idx1 + nbodies ) + 1, column ) = - ntilde1.y();
D.insert( 3 * ( m_idx1 + nbodies ) + 2, column ) = - ntilde1.z();
}
}
示例4: computePotential
scalar HertzianPenaltyForce::computePotential( const VectorXs& q, const SparseMatrixsc& M, const VectorXs& r ) const
{
assert( q.size() % 2 == 0 ); assert( q.size() == M.rows() ); assert( q.size() == M.cols() ); assert( r.size() == q.size() / 2 );
scalar U{ 0.0 };
// For each ball
for( unsigned ball0 = 0; ball0 < r.size(); ++ball0 )
{
// For each subsequent ball
for( unsigned ball1 = ball0 + 1; ball1 < r.size(); ++ball1 )
{
// Compute the total radius
const scalar total_radius{ r(ball0) + r(ball1) };
// Compute a vector pointing from ball0 to ball1
const Vector2s n{ q.segment<2>( 2 * ball1 ) - q.segment<2>( 2 * ball0 ) };
// If the squared distance is greater or equal to the sum of the radii squared, no force
if( n.squaredNorm() > total_radius * total_radius )
{
continue;
}
// Compute the penetration depth
const scalar delta{ n.norm() - total_radius };
assert( delta < 0.0 );
// U = 0.5 * k * pen_depth^(5/2)
U += 0.5 * m_k * std::pow( -delta, scalar( 2.5 ) );
}
}
return U;
}
示例5: assert
void RigidBody2DSim::enforcePeriodicBoundaryConditions( VectorXs& q, VectorXs& v )
{
assert( q.size() % 3 == 0 );
assert( q.size() == v.size() );
const unsigned nbodies{ static_cast<unsigned>( q.size() / 3 ) };
// TODO: Probably faster to invert the loop here, only cache xin once per body
// For each portal
for( const PlanarPortal& planar_portal : m_state.planarPortals() )
{
// For each body
for( unsigned bdy_idx = 0; bdy_idx < nbodies; ++bdy_idx )
{
const Vector2s xin{ q.segment<2>( 3 * bdy_idx ) };
// TODO: Calling pointInsidePortal and teleportPointInsidePortal is a bit redundant, clean this up!
// If the body is inside a portal
if( planar_portal.pointInsidePortal( xin ) )
{
// Teleport to the other side of the portal
Vector2s x_out;
planar_portal.teleportPointInsidePortal( xin, x_out );
q.segment<2>( 3 * bdy_idx ) = x_out;
// TODO: This check probably isn't needed, additional_vel should be 0 for non-LE portals
// Lees-Edwards Boundary conditions also update the velocity
if( planar_portal.isLeesEdwards() )
{
const Vector2s additional_vel{ planar_portal.getKinematicVelocityOfPoint( xin ) };
v.segment<2>( 3 * bdy_idx ) += additional_vel;
}
}
}
}
}
示例6: exponentialEuler
void IntegrationTools::exponentialEuler( const VectorXs& q0, const VectorXs& v0, const std::vector<bool>& fixed, const scalar& dt, VectorXs& q1 )
{
assert( q0.size() == q1.size() );
assert( q0.size() % 12 == 0 );
assert( v0.size() * 2 == q0.size() );
assert( 12 * fixed.size() == static_cast<unsigned long>(q0.size()) );
const int nbodies{ static_cast<int>( fixed.size() ) };
// Center of mass update
for( int bdy_num = 0; bdy_num < nbodies; bdy_num++ )
{
if( !fixed[bdy_num] )
{
q1.segment<3>( 3 * bdy_num ) = q0.segment<3>( 3 * bdy_num ) + dt * v0.segment<3>( 3 * bdy_num );
}
else
{
q1.segment<3>( 3 * bdy_num ) = q0.segment<3>( 3 * bdy_num );
}
}
// Orientation update
for( int bdy_num = 0; bdy_num < nbodies; bdy_num++ )
{
if( !fixed[bdy_num] )
{
updateOrientation( nbodies, bdy_num, q0, v0, dt, q1 );
}
else
{
q1.segment<9>( 3 * nbodies + 9 * bdy_num ) = q0.segment<9>( 3 * nbodies + 9 * bdy_num );
}
}
}
示例7: addHessXToTotal
void VortexForce::addHessXToTotal( const VectorXs& x, const VectorXs& v, const VectorXs& m, MatrixXs& hessE )
{
assert( x.size() == v.size() );
assert( x.size() == m.size() );
assert( x.size() == hessE.rows() );
assert( x.size() == hessE.cols() );
assert( x.size()%2 == 0 );
// scalar m1 = m(2*m_particles.second);
// scalar m2 = m(2*m_particles.first);
//
// Vector2s nhat = x.segment<2>(2*m_particles.second)-x.segment<2>(2*m_particles.first);
// scalar r = nhat.norm();
// assert( r != 0.0 );
// nhat /= r;
//
// Matrix2s entry = Matrix2s::Identity()-3.0*nhat*nhat.transpose();
// entry *= m_G*m1*m2/r*r*r;
//
// hessE.block<2,2>(2*m_particles.first,2*m_particles.first) += entry;
// hessE.block<2,2>(2*m_particles.second,2*m_particles.second) += entry;
// hessE.block<2,2>(2*m_particles.first,2*m_particles.second) -= entry;
// hessE.block<2,2>(2*m_particles.second,2*m_particles.first) -= entry;
std::cerr << outputmod::startred << "ERROR IN VORTEXFORCE: " << outputmod::endred << "No addHessXToTotal defined for VortexForce." << std::endl;
exit(1);
}
示例8: computeGeneralizedFrictionGivenTangentSample
void StaticPlaneSphereConstraint::computeGeneralizedFrictionGivenTangentSample( const VectorXs& q, const VectorXs& t, const unsigned column, SparseMatrixsc& D ) const
{
assert( t.size() == 3 );
assert( column < unsigned( D.cols() ) );
assert( q.size() % 12 == 0 );
assert( fabs( t.norm() - 1.0 ) <= 1.0e-6 );
assert( fabs( m_plane.n().dot( t ) ) <= 1.0e-6 );
// Effect on center of mass
D.insert( 3 * m_sphere_idx + 0, column ) = t.x();
D.insert( 3 * m_sphere_idx + 1, column ) = t.y();
D.insert( 3 * m_sphere_idx + 2, column ) = t.z();
// Effect on orientation
{
const unsigned nbodies{ static_cast<unsigned>( q.size() / 12 ) };
// Compute the displacement from the center of mass to the point of contact
assert( fabs( m_plane.n().norm() - 1.0 ) <= 1.0e-10 );
assert( m_r >= 0.0 );
const Vector3s r_world{ - m_r * m_plane.n() };
const Vector3s ntilde{ r_world.cross( Eigen::Map<const Vector3s>( t.data() ) ) };
D.insert( 3 * ( nbodies + m_sphere_idx ) + 0, column ) = ntilde.x();
D.insert( 3 * ( nbodies + m_sphere_idx ) + 1, column ) = ntilde.y();
D.insert( 3 * ( nbodies + m_sphere_idx ) + 2, column ) = ntilde.z();
}
}
示例9: addEnergyToTotal
void DragDampingForce::addEnergyToTotal( const VectorXs& x, const VectorXs& v, const VectorXs& m, scalar& E )
{
assert( x.size() == v.size() );
assert( x.size() == m.size() );
assert( x.size()%3 == 0 );
std::cerr << outputmod::startred << "WARNING IN DRAGDAMPINGFORCE: " << outputmod::endred << "No energy defined for DragDampingForce." << std::endl;
}
示例10: addEnergyToTotal
void SpringForce::addEnergyToTotal( const VectorXs& x, const VectorXs& v, const VectorXs& m, scalar& E )
{
assert( x.size() == v.size() );
assert( x.size()%2 == 0 );
assert( m_endpoints.first >= 0 ); assert( m_endpoints.first < x.size()/2 );
assert( m_endpoints.second >= 0 ); assert( m_endpoints.second < x.size()/2 );
// Add milestone 2 code here.
}
示例11: computeMDPLambda
void FrictionOperatorUtilities::computeMDPLambda( const VectorXs& vrel, VectorXs& lambda )
{
assert( vrel.size() % 2 == 0 );
lambda.conservativeResize( vrel.size() / 2 );
for( int con_num = 0; con_num < lambda.size(); ++con_num )
{
lambda( con_num ) = vrel.segment<2>( 2 * con_num ).norm();
}
}
示例12: accumulateddUdxdv
void TwoDScene::accumulateddUdxdv( MatrixXs& A, const VectorXs& dx, const VectorXs& dv )
{
assert( A.rows() == m_x.size() );
assert( A.cols() == m_x.size() );
assert( dx.size() == dv.size() );
assert( dx.size() == 0 || dx.size() == A.rows() );
if( dx.size() == 0 ) for( std::vector<Force*>::size_type i = 0; i < m_forces.size(); ++i ) m_forces[i]->addHessVToTotal( m_x, m_v, m_m, A );
else for( std::vector<Force*>::size_type i = 0; i < m_forces.size(); ++i ) m_forces[i]->addHessVToTotal( m_x+dx, m_v+dv, m_m, A );
}
示例13: addHessXToTotal
void DragDampingForce::addHessXToTotal( const VectorXs& x, const VectorXs& v, const VectorXs& m, MatrixXs& hessE )
{
assert( x.size() == v.size() );
assert( x.size() == m.size() );
assert( x.size() == hessE.rows() );
assert( x.size() == hessE.cols() );
assert( x.size()%3 == 0 );
// Nothing to do.
}
示例14: addHessVToTotal
void VortexForce::addHessVToTotal( const VectorXs& x, const VectorXs& v, const VectorXs& m, MatrixXs& hessE )
{
assert( x.size() == v.size() );
assert( x.size() == m.size() );
assert( x.size() == hessE.rows() );
assert( x.size() == hessE.cols() );
assert( x.size()%2 == 0 );
std::cerr << outputmod::startred << "ERROR IN VORTEXFORCE: " << outputmod::endred << "No addHessXToTotal defined for VortexForce." << std::endl;
exit(1);
}
示例15: addHessVToTotal
void DragDampingForce::addHessVToTotal( const VectorXs& x, const VectorXs& v, const VectorXs& m, MatrixXs& hessE )
{
assert( x.size() == v.size() );
assert( x.size() == m.size() );
assert( x.size() == hessE.rows() );
assert( x.size() == hessE.cols() );
assert( x.size()%2 == 0 );
// Compute the force Jacboian here!
hessE.diagonal().array() += m_b;
}