本文整理汇总了C++中ChSharedPtr类的典型用法代码示例。如果您正苦于以下问题:C++ ChSharedPtr类的具体用法?C++ ChSharedPtr怎么用?C++ ChSharedPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChSharedPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onCallback
virtual void onCallback(ChSharedPtr<ChBody> wheelBody, double radius, double width) {
wheelBody->GetCollisionModel()->ClearModel();
wheelBody->GetCollisionModel()->AddCylinder(0.46, 0.46, width / 2);
wheelBody->GetCollisionModel()->BuildModel();
wheelBody->GetMaterialSurfaceDEM()->SetFriction(mu_t);
wheelBody->GetMaterialSurfaceDEM()->SetYoungModulus(Y_t);
wheelBody->GetMaterialSurfaceDEM()->SetRestitution(cr_t);
}
示例2: align_spheres
void align_spheres(ChIrrAppInterface& application)
{
for (unsigned int i = 0; i< mspheres.size(); ++i)
{
ChSharedPtr<ChBody> body = mspheres[i];
ChVector<> mpos = body->GetPos();
mpos.x = 0.5;
mpos.z = 0.7;
body->SetPos(mpos);
body->SetRot(QUNIT);
}
}
示例3: AddWall
// -----------------------------------------------------------------------------
// Utility for adding (visible or invisible) walls
// -----------------------------------------------------------------------------
void AddWall(ChSharedPtr<ChBody>& body, const ChVector<>& dim, const ChVector<>& loc, bool visible) {
body->GetCollisionModel()->AddBox(dim.x, dim.y, dim.z, loc);
if (visible == true) {
ChSharedPtr<ChBoxShape> box(new ChBoxShape);
box->GetBoxGeometry().Size = dim;
box->Pos = loc;
box->SetColor(ChColor(1, 0, 0));
box->SetFading(0.6f);
body->AddAsset(box);
}
}
示例4: Initialize
int ChShaftsMotor::Initialize(ChSharedPtr<ChShaft>& mshaft1, ChSharedPtr<ChShaft>& mshaft2)
{
// Parent class initialize
if (!ChShaftsCouple::Initialize(mshaft1, mshaft2)) return false;
ChShaft* mm1 = mshaft1.get_ptr();
ChShaft* mm2 = mshaft2.get_ptr();
this->constraint.SetVariables(&mm1->Variables(), &mm2->Variables());
this->SetSystem(this->shaft1->GetSystem());
return true;
}
示例5: Setup
void ChFunction_Sequence::Setup()
{
double basetime = this->start;
double lastIy = 0;
double lastIy_dt = 0;
double lastIy_dtdt = 0;
for (ChNode<ChFseqNode>* mnode = functions.GetHead(); mnode != NULL; mnode= mnode->next)
{
mnode->data->t_start = basetime;
mnode->data->t_end = basetime + mnode->data->duration;
mnode->data->Iy = 0;
mnode->data->Iydt = 0;
mnode->data->Iydtdt = 0;
if (mnode->data->fx.IsType<ChFunction_Fillet3>()) // C0 C1 fillet
{
ChSharedPtr<ChFunction_Fillet3> mfillet = mnode->data->fx.DynamicCastTo<ChFunction_Fillet3>();
mfillet->Set_y1(lastIy);
mfillet->Set_dy1(lastIy_dt);
if (mnode->next)
{
mfillet->Set_y2(mnode->next->data->fx->Get_y(0));
mfillet->Set_dy2(mnode->next->data->fx->Get_y_dx(0));
}else
{
mfillet->Set_y2(0);
mfillet->Set_dy2(0);
}
mfillet->Set_end(mnode->data->duration);
mnode->data->Iy = mnode->data->Iydt = mnode->data->Iydtdt = 0;
}
else // generic continuity conditions
{
if (mnode->data->y_cont)
mnode->data->Iy = lastIy - mnode->data->fx->Get_y(0);
if (mnode->data->ydt_cont)
mnode->data->Iydt = lastIy_dt - mnode->data->fx->Get_y_dx(0);
if (mnode->data->ydtdt_cont)
mnode->data->Iydtdt = lastIy_dtdt - mnode->data->fx->Get_y_dxdx(0);
}
lastIy = mnode->data->fx->Get_y(mnode->data->duration) +
mnode->data->Iy +
mnode->data->Iydt * mnode->data->duration +
mnode->data->Iydtdt * mnode->data->duration * mnode->data->duration;
lastIy_dt =
mnode->data->fx->Get_y_dx(mnode->data->duration) +
mnode->data->Iydt +
mnode->data->Iydtdt * mnode->data->duration;
lastIy_dtdt =
mnode->data->fx->Get_y_dxdx(mnode->data->duration) +
mnode->data->Iydtdt;
basetime += mnode->data->duration;
}
}
示例6: Initialize
int ChLinkDistance::Initialize(ChSharedPtr<ChBody>& mbody1, ///< first body to link
ChSharedPtr<ChBody>& mbody2, ///< second body to link
bool pos_are_relative,///< true: following posit. are considered relative to bodies. false: pos.are absolute
ChVector<> mpos1, ///< position of distance endpoint, for 1st body (rel. or abs., see flag above)
ChVector<> mpos2, ///< position of distance endpoint, for 2nd body (rel. or abs., see flag above)
bool auto_distance,///< if true, initializes the imposed distance as the distance between mpos1 and mpos2
double mdistance ///< imposed distance (no need to define, if auto_distance=true.)
)
{
this->Body1 = mbody1.get_ptr();
this->Body2 = mbody2.get_ptr();
this->Cx.SetVariables(&this->Body1->Variables(),&this->Body2->Variables());
if (pos_are_relative)
{
this->pos1 = mpos1;
this->pos2 = mpos2;
}
else
{
this->pos1 = this->Body1->Point_World2Body(&mpos1);
this->pos2 = this->Body2->Point_World2Body(&mpos2);
}
ChVector<> AbsDist = Body1->Point_Body2World(&pos1)-Body2->Point_Body2World(&pos2);
this->curr_dist = AbsDist.Length();
if (auto_distance)
{
this->distance = this->curr_dist;
}
else
{
this->distance = mdistance;
}
return true;
}
示例7: add_fancy_items
void add_fancy_items(ChSystemMPI& mySys, double prad, double pmass, double width, double g, double h, int n_batch, int n_curr_spheres)
{
int id_offset=10;
double particle_mass =4.0;
if (pmass>0.0){
particle_mass=pmass;
}
ChSharedPtr<ChBodyDEMMPI> mybody;
double spacing = (width-8*prad)/(n_batch-1);
double first = -(width-8*prad)/2;
for(int jj=0; jj<n_batch; jj++)
{
ChVector<> particle_pos(-g+(ChRandom()*2*prad-prad), h, first+jj*spacing);
if (mySys.nodeMPI->IsInto(particle_pos))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_spheres+jj);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(particle_pos);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*pow(prad,2)*ChVector<>(1,1,1));
mybody->SetMass(particle_mass);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
}
}
示例8: add_batch
void add_batch(ChSystemMPI& mySys, double prad, double box_dim, double pmass, int n_batch, int n_curr_spheres)
{
int id_offset=10;
double particle_mass =4.0;
if (pmass>0.0){
particle_mass=pmass;
}
ChSharedPtr<ChBodyDEMMPI> mybody;
double boxxx=box_dim-4*prad;
double spacing = (boxxx-8*prad)/((n_batch/4)-1);
double first = -boxxx/2;
int cid = 0;
for(int ii=0; ii<n_batch/4; ii++)
{
ChVector<> particle_pos(boxxx/2-2*prad,box_dim/2+2*prad, first+ii*spacing+0.0001);
if (mySys.nodeMPI->IsInto(particle_pos))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_spheres+cid);
mybody->SetCollide(true);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mySys.Add(mybody);
mybody->SetPos(particle_pos);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*pow(prad,2)*ChVector<>(1,1,1));
mybody->SetMass(particle_mass);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
cid++;
}
for(int ii=0; ii<n_batch/4; ii++)
{
ChVector<> particle_pos(boxxx/2-6*prad,box_dim/2+2*prad, first+ii*spacing+0.0001);
if (mySys.nodeMPI->IsInto(particle_pos))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_spheres+cid);
mybody->SetCollide(true);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mySys.Add(mybody);
mybody->SetPos(particle_pos);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*pow(prad,2)*ChVector<>(1,1,1));
mybody->SetMass(particle_mass);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
cid++;
}
//other edge
for(int ii=0; ii<n_batch/4; ii++)
{
ChVector<> particle_pos(first+ii*spacing+0.0001,box_dim/2+2*prad,boxxx/2-2*prad);
if (mySys.nodeMPI->IsInto(particle_pos))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_spheres+cid);
mybody->SetCollide(true);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mySys.Add(mybody);
mybody->SetPos(particle_pos);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*pow(prad,2)*ChVector<>(1,1,1));
mybody->SetMass(particle_mass);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
cid++;
}
for(int ii=0; ii<n_batch/4; ii++)
{
ChVector<> particle_pos(first+ii*spacing+0.0001,box_dim/2+2*prad,boxxx/2-6*prad);
if (mySys.nodeMPI->IsInto(particle_pos))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_spheres+cid);
mybody->SetCollide(true);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mySys.Add(mybody);
mybody->SetPos(particle_pos);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*pow(prad,2)*ChVector<>(1,1,1));
mybody->SetMass(particle_mass);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
cid++;
}
}
示例9: create_falling_items
void create_falling_items(ChSystemMPI& mySys, double prad, int n_bodies,double box_dim, double pmass){
double particle_mass =4.0;
if (pmass>0.0){
particle_mass=pmass;
}
ChSharedPtr<ChBodyDEMMPI> mybody;
double boxxx=box_dim-2*prad;
for (int ii=0; ii<n_bodies; ii++){
ChVector<> particle_pos(ChRandom()*boxxx-boxxx/2,ChRandom()*boxxx/2+boxxx/2+prad, ChRandom()*boxxx-boxxx/2);
if (mySys.nodeMPI->IsInto(particle_pos))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(10+ii);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(particle_pos);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*pow(prad,2)*ChVector<>(1,1,1));
mybody->SetMass(particle_mass);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
}
/*
ChVector<> pp1(0.5*box_dim/2,box_dim/2,0.5*box_dim/2);
if (mySys.nodeMPI->IsInto(pp1))
{
mybody = ChSharedPtr<ChBodyDEMMPI>(new ChBodyDEMMPI);
mybody->SetIdentifier(11);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(pp1);
mybody->SetMass(particle_mass);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*prad*prad*ChVector<>(1.0,1.0,1.0));
}
ChVector<> pp2(-0.5*box_dim/2,box_dim/2,0.5*box_dim/2);
if (mySys.nodeMPI->IsInto(pp2))
{
mybody = ChSharedPtr<ChBodyDEMMPI>(new ChBodyDEMMPI);
mybody->SetIdentifier(22);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(pp2);
mybody->SetMass(particle_mass);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*prad*prad*ChVector<>(1.0,1.0,1.0));
}
ChVector<> pp3(0.5*box_dim/2,box_dim/2,-0.5*box_dim/2);
if (mySys.nodeMPI->IsInto(pp3))
{
mybody = ChSharedPtr<ChBodyDEMMPI>(new ChBodyDEMMPI);
mybody->SetIdentifier(33);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(pp3);
mybody->SetMass(particle_mass);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*prad*prad*ChVector<>(1.0,1.0,1.0));
}
ChVector<> pp4(-0.5*box_dim/2,box_dim/2,-0.5*box_dim/2);
if (mySys.nodeMPI->IsInto(pp4))
{
mybody = ChSharedPtr<ChBodyDEMMPI>(new ChBodyDEMMPI);
mybody->SetIdentifier(44);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(pp4);
mybody->SetMass(particle_mass);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*prad*prad*ChVector<>(1.0,1.0,1.0));
}
*/
}
示例10: add_other_falling_item
void add_other_falling_item(ChSystemMPI& mySys, double prad, double box_dim, double rho, int n_curr_bodies)
{
int id_offset=10;
double m_s = (2/3)*CH_C_PI*pow(prad,3)*rho;
double m_c = CH_C_PI*pow(prad,2)*(2*prad)*rho;
double m_cube = prad*prad*prad*rho;
ChVector<> pos1(0,prad,0);
ChVector<> pos2(0,-prad,0);
ChSharedPtr<ChBodyDEMMPI> mybody;
double boxxx=box_dim-2*prad;
ChVector<> particle_pos(0.8*boxxx/2,box_dim/2+2*prad, 0.6*boxxx/2);
if (mySys.nodeMPI->IsInto(particle_pos))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_bodies+1);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddBox(prad,prad,prad);
//mybody->GetCollisionModel()->AddSphere(prad, &pos1);
//mybody->GetCollisionModel()->AddCylinder(prad,prad,prad);
//mybody->GetCollisionModel()->AddSphere(prad, &pos2);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(particle_pos);
//mybody->SetInertiaXX(ChVector<>(((7.0/12)*m_c+4.3*m_s)*pow(prad,2),(0.5*m_c+0.8*m_s)*pow(prad,2),((7.0/12)*m_c+4.3*m_s)*pow(prad,2)));
//mybody->SetMass(m_c+2*m_s);
mybody->SetInertiaXX((1.0/6.0)*m_cube*pow(prad,2)*ChVector<>(1.0,1.0,1.0));
mybody->SetMass(m_cube);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
ChVector<> particle_pos2(0.8*boxxx/2,box_dim/2+2*prad, 0.2*boxxx/2);
if (mySys.nodeMPI->IsInto(particle_pos2))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_bodies+2);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddBox(prad,prad,prad);
//mybody->GetCollisionModel()->AddSphere(prad, &pos1);
//mybody->GetCollisionModel()->AddCylinder(prad,prad,prad);
//mybody->GetCollisionModel()->AddSphere(prad, &pos2);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(particle_pos2);
//mybody->SetInertiaXX(ChVector<>(((7.0/12)*m_c+4.3*m_s)*pow(prad,2),(0.5*m_c+0.8*m_s)*pow(prad,2),((7.0/12)*m_c+4.3*m_s)*pow(prad,2)));
//mybody->SetMass(m_c+2*m_s);
mybody->SetInertiaXX((1.0/6.0)*m_cube*pow(prad,2)*ChVector<>(1.0,1.0,1.0));
mybody->SetMass(m_cube);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
ChVector<> particle_pos3(0.8*boxxx/2,box_dim/2+2*prad, -0.2*boxxx/2);
if (mySys.nodeMPI->IsInto(particle_pos3))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_bodies+3);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddBox(prad,prad,prad);
//mybody->GetCollisionModel()->AddSphere(prad, &pos1);
//mybody->GetCollisionModel()->AddCylinder(prad,prad,prad);
//mybody->GetCollisionModel()->AddSphere(prad, &pos2);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(particle_pos3);
//mybody->SetInertiaXX(ChVector<>(((7.0/12)*m_c+4.3*m_s)*pow(prad,2),(0.5*m_c+0.8*m_s)*pow(prad,2),((7.0/12)*m_c+4.3*m_s)*pow(prad,2)));
//mybody->SetMass(m_c+2*m_s);
mybody->SetInertiaXX((1.0/6.0)*m_cube*pow(prad,2)*ChVector<>(1.0,1.0,1.0));
mybody->SetMass(m_cube);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
ChVector<> particle_pos4(0.8*boxxx/2,box_dim/2+2*prad, -0.6*boxxx/2);
if (mySys.nodeMPI->IsInto(particle_pos4))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_bodies+4);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddBox(prad,prad,prad);
//mybody->GetCollisionModel()->AddSphere(prad, &pos1);
//mybody->GetCollisionModel()->AddCylinder(prad,prad,prad);
//mybody->GetCollisionModel()->AddSphere(prad, &pos2);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(particle_pos4);
//mybody->SetInertiaXX(ChVector<>(((7.0/12)*m_c+4.3*m_s)*pow(prad,2),(0.5*m_c+0.8*m_s)*pow(prad,2),((7.0/12)*m_c+4.3*m_s)*pow(prad,2)));
//mybody->SetMass(m_c+2*m_s);
mybody->SetInertiaXX((1.0/6.0)*m_cube*pow(prad,2)*ChVector<>(1.0,1.0,1.0));
mybody->SetMass(m_cube);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
}
示例11: add_falling_item
void add_falling_item(ChSystemMPI& mySys, double prad, double box_dim, double pmass, int n_curr_spheres)
{
int id_offset=10;
double particle_mass =4.0;
if (pmass>0.0){
particle_mass=pmass;
}
ChSharedPtr<ChBodyDEMMPI> mybody;
double boxxx=box_dim-2*prad;
ChVector<> particle_pos(0.8*boxxx/2,box_dim/2+2*prad, 0.6*boxxx/2);
if (mySys.nodeMPI->IsInto(particle_pos))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_spheres+1);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(particle_pos);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*pow(prad,2)*ChVector<>(1,1,1));
mybody->SetMass(particle_mass);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
ChVector<> particle_pos2(0.8*boxxx/2,box_dim/2+2*prad, 0.2*boxxx/2);
if (mySys.nodeMPI->IsInto(particle_pos2))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_spheres+2);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(particle_pos2);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*pow(prad,2)*ChVector<>(1,1,1));
mybody->SetMass(particle_mass);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
ChVector<> particle_pos3(0.8*boxxx/2,box_dim/2+2*prad, -0.2*boxxx/2);
if (mySys.nodeMPI->IsInto(particle_pos3))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_spheres+3);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(particle_pos3);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*pow(prad,2)*ChVector<>(1,1,1));
mybody->SetMass(particle_mass);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
ChVector<> particle_pos4(0.8*boxxx/2,box_dim/2+2*prad, -0.6*boxxx/2);
if (mySys.nodeMPI->IsInto(particle_pos4))
{
ChSharedPtr<ChBodyDEMMPI> mybody(new ChBodyDEMMPI);
mybody->SetIdentifier(id_offset+n_curr_spheres+4);
mySys.Add(mybody);
mybody->GetCollisionModel()->ClearModel();
mybody->GetCollisionModel()->AddSphere(prad);
mybody->GetCollisionModel()->BuildModel();
mybody->SetCollide(true);
mybody->SetPos(particle_pos4);
mybody->SetInertiaXX((2.0/5.0)*particle_mass*pow(prad,2)*ChVector<>(1,1,1));
mybody->SetMass(particle_mass);
mybody->GetCollisionModel()->SyncPosition(); // really necessary?
mybody->Update(); // really necessary?
}
}
示例12: main
//.........这里部分代码省略.........
my_system->GetSettings()->perform_thread_tuning = thread_tuning;
// Edit system settings
my_system->GetSettings()->solver.use_full_inertia_tensor = false;
my_system->GetSettings()->solver.tolerance = tolerance;
my_system->GetSettings()->solver.max_iteration_bilateral = max_iteration_bilateral;
my_system->GetSettings()->solver.clamp_bilaterals = clamp_bilaterals;
my_system->GetSettings()->solver.bilateral_clamp_speed = bilateral_clamp_speed;
#ifdef USE_DEM
my_system->GetSettings()->solver.contact_force_model = HERTZ;
my_system->GetSettings()->solver.tangential_displ_mode = MULTI_STEP;
#else
my_system->GetSettings()->solver.solver_mode = SLIDING;
my_system->GetSettings()->solver.max_iteration_normal = max_iteration_normal;
my_system->GetSettings()->solver.max_iteration_sliding = max_iteration_sliding;
my_system->GetSettings()->solver.max_iteration_spinning = max_iteration_spinning;
my_system->GetSettings()->solver.alpha = 0;
my_system->GetSettings()->solver.contact_recovery_speed = contact_recovery_speed;
my_system->ChangeSolverType(APGD);
my_system->GetSettings()->collision.collision_envelope = 0.05 * radius;
#endif
my_system->GetSettings()->collision.bins_per_axis = I3(10, 10, 10);
my_system->GetSettings()->collision.narrowphase_algorithm = NARROWPHASE_HYBRID_MPR;
// Create a ball material (will be used by balls only)
#ifdef USE_DEM
ChSharedPtr<ChMaterialSurfaceDEM> material;
material = ChSharedPtr<ChMaterialSurfaceDEM>(new ChMaterialSurfaceDEM);
material->SetYoungModulus(Y);
material->SetPoissonRatio(nu);
material->SetRestitution(COR);
material->SetFriction(mu);
#else
ChSharedPtr<ChMaterialSurface> material;
material = ChSharedPtr<ChMaterialSurface>(new ChMaterialSurface);
material->SetRestitution(COR);
material->SetFriction(mu);
#endif
// Create a material for all objects other than balls
#ifdef USE_DEM
ChSharedPtr<ChMaterialSurfaceDEM> mat_ext;
mat_ext = ChSharedPtr<ChMaterialSurfaceDEM>(new ChMaterialSurfaceDEM);
mat_ext->SetYoungModulus(Y);
mat_ext->SetPoissonRatio(nu);
mat_ext->SetRestitution(COR);
mat_ext->SetFriction(mu_ext);
#else
ChSharedPtr<ChMaterialSurface> mat_ext;
mat_ext = ChSharedPtr<ChMaterialSurface>(new ChMaterialSurface);
mat_ext->SetRestitution(COR);
mat_ext->SetFriction(mu_ext);
#endif
// Create lower bin
ChSharedPtr<ChBody> bin(new ChBody(new ChCollisionModelParallel, contact_method));
示例13: MySimpleTank
// Build and initialize the tank, creating all bodies corresponding to
// the various parts and adding them to the physical system - also creating
// and adding constraints to the system.
MySimpleTank(ChSystem& my_system, ///< the chrono::engine physical system
ISceneManager* msceneManager, ///< the Irrlicht scene manager for 3d shapes
IVideoDriver* mdriver ///< the Irrlicht video driver
)
{
throttleL = throttleR = 0; // initially, gas throttle is 0.
max_motor_speed = 10;
double my = 0.5; // left back hub pos
double mx = 0;
double shoelength = 0.2;
double shoethickness = 0.06;
double shoewidth = 0.3;
double shoemass = 2;
double radiustrack = 0.31;
double wheeldiameter = 0.280*2;
int nwrap = 6;
int ntiles = 7;
double rlwidth = 1.20;
double passo = (ntiles+1)*shoelength;
ChVector<> cyl_displA(0, 0.075+0.02,0);
ChVector<> cyl_displB(0, -0.075-0.02,0);
double cyl_hthickness = 0.045;
// --- The tank body ---
IAnimatedMesh* bulldozer_bodyMesh = msceneManager->getMesh("../data/bulldozerB10.obj");
truss = (ChBodySceneNode*)addChBodySceneNode(
&my_system, msceneManager, bulldozer_bodyMesh,
350.0,
ChVector<>(mx + passo/2, my + radiustrack , rlwidth/2),
QUNIT);
truss->GetBody()->SetInertiaXX(ChVector<>(13.8, 13.5, 10));
truss->GetBody()->SetBodyFixed(false);
//truss->addShadowVolumeSceneNode();
// --- Right Front suspension ---
// Load a triangle mesh for wheel visualization
IAnimatedMesh* irmesh_wheel_view = msceneManager->getMesh("../data/wheel_view.obj");
// ..the tank right-front wheel
wheelRF = (ChBodySceneNode*) addChBodySceneNode(
&my_system, msceneManager, irmesh_wheel_view,
9.0,
ChVector<>(mx + passo, my+ radiustrack , 0),
chrono::Q_from_AngAxis(CH_C_PI/2, VECT_X) );
wheelRF->GetBody()->GetCollisionModel()->ClearModel();
wheelRF->GetBody()->GetCollisionModel()->AddCylinder(wheeldiameter/2,wheeldiameter/2, cyl_hthickness, &cyl_displA);
wheelRF->GetBody()->GetCollisionModel()->AddCylinder(wheeldiameter/2,wheeldiameter/2, cyl_hthickness, &cyl_displB);
wheelRF->GetBody()->GetCollisionModel()->BuildModel(); // Creates the collision model
wheelRF->GetBody()->SetCollide(true);
wheelRF->GetBody()->SetInertiaXX(ChVector<>(1.2, 1.2, 1.2));
wheelRF->GetBody()->SetFriction(1.0);
video::ITexture* cylinderMap = mdriver->getTexture("../data/bluwhite.png");
wheelRF->setMaterialTexture(0, cylinderMap);
wheelRF->addShadowVolumeSceneNode();
// .. create the revolute joint between the wheel and the truss
link_revoluteRF = ChSharedPtr<ChLinkLockRevolute>(new ChLinkLockRevolute); // right, front, upper, 1
link_revoluteRF->Initialize(wheelRF->GetBody(), truss->GetBody(),
ChCoordsys<>(ChVector<>(mx + passo, my+ radiustrack , 0) , QUNIT ) );
my_system.AddLink(link_revoluteRF);
// --- Left Front suspension ---
// ..the tank left-front wheel
wheelLF = (ChBodySceneNode*) addChBodySceneNode(
&my_system, msceneManager, irmesh_wheel_view,
9.0,
ChVector<>(mx + passo, my+ radiustrack , rlwidth),
chrono::Q_from_AngAxis(CH_C_PI/2, VECT_X) );
wheelLF->GetBody()->GetCollisionModel()->ClearModel();
wheelLF->GetBody()->GetCollisionModel()->AddCylinder(wheeldiameter/2,wheeldiameter/2, cyl_hthickness, &cyl_displA);
wheelLF->GetBody()->GetCollisionModel()->AddCylinder(wheeldiameter/2,wheeldiameter/2, cyl_hthickness, &cyl_displB);
wheelLF->GetBody()->GetCollisionModel()->BuildModel(); // Creates the collision model
wheelLF->GetBody()->SetCollide(true);
wheelLF->GetBody()->SetInertiaXX(ChVector<>(1.2, 1.2, 1.2));
wheelLF->GetBody()->SetFriction(1.0);
wheelLF->setMaterialTexture(0, cylinderMap);
wheelLF->addShadowVolumeSceneNode();
// .. create the revolute joint between the wheel and the truss
link_revoluteLF = ChSharedPtr<ChLinkLockRevolute>(new ChLinkLockRevolute); // left, front, upper, 1
link_revoluteLF->Initialize(wheelLF->GetBody(), truss->GetBody(),
ChCoordsys<>(ChVector<>(mx + passo, my+ radiustrack , rlwidth) , QUNIT ) );
my_system.AddLink(link_revoluteLF);
// --- Right Back suspension ---
//.........这里部分代码省略.........
示例14: main
int main(int argc, char* argv[]) {
// Set path to ChronoVehicle data files
vehicle::SetDataPath(CHRONO_VEHICLE_DATA_DIR);
// --------------------------
// Create output directories.
// --------------------------
if (povray_output) {
if (ChFileutils::MakeDirectory(out_dir.c_str()) < 0) {
cout << "Error creating directory " << out_dir << endl;
return 1;
}
if (ChFileutils::MakeDirectory(pov_dir.c_str()) < 0) {
cout << "Error creating directory " << pov_dir << endl;
return 1;
}
}
// --------------
// Create system.
// --------------
ChSystemParallelDEM* system = new ChSystemParallelDEM();
system->Set_G_acc(ChVector<>(0, 0, -9.81));
// ----------------------
// Enable debug log
// ----------------------
////system->SetLoggingLevel(LOG_INFO, true);
////system->SetLoggingLevel(LOG_TRACE, true);
// ----------------------
// Set number of threads.
// ----------------------
int max_threads = omp_get_num_procs();
if (threads > max_threads)
threads = max_threads;
system->SetParallelThreadNumber(threads);
omp_set_num_threads(threads);
cout << "Using " << threads << " threads" << endl;
system->GetSettings()->perform_thread_tuning = thread_tuning;
// ---------------------
// Edit system settings.
// ---------------------
system->GetSettings()->solver.use_full_inertia_tensor = false;
system->GetSettings()->solver.tolerance = tolerance;
system->GetSettings()->solver.max_iteration_bilateral = max_iteration_bilateral;
system->GetSettings()->solver.contact_force_model = contact_force_model;
system->GetSettings()->solver.tangential_displ_mode = tangential_displ_mode;
system->GetSettings()->collision.narrowphase_algorithm = NARROWPHASE_HYBRID_MPR;
system->GetSettings()->collision.bins_per_axis = I3(20, 20, 10);
// -------------------
// Create the terrain.
// -------------------
// Ground body
ChSharedPtr<ChBody> ground = ChSharedPtr<ChBody>(new ChBody(new collision::ChCollisionModelParallel, ChBody::DEM));
ground->SetIdentifier(-1);
ground->SetMass(1000);
ground->SetBodyFixed(true);
ground->SetCollide(true);
ground->GetMaterialSurfaceDEM()->SetFriction(mu_g);
ground->GetMaterialSurfaceDEM()->SetYoungModulus(Y_g);
ground->GetMaterialSurfaceDEM()->SetRestitution(cr_g);
ground->GetMaterialSurfaceDEM()->SetCohesion(cohesion_g);
ground->GetCollisionModel()->ClearModel();
// Bottom box
utils::AddBoxGeometry(ground.get_ptr(), ChVector<>(hdimX, hdimY, hthick), ChVector<>(0, 0, -hthick),
ChQuaternion<>(1, 0, 0, 0), true);
if (terrain_type == GRANULAR) {
// Front box
utils::AddBoxGeometry(ground.get_ptr(), ChVector<>(hthick, hdimY, hdimZ + hthick),
ChVector<>(hdimX + hthick, 0, hdimZ - hthick), ChQuaternion<>(1, 0, 0, 0), visible_walls);
// Rear box
utils::AddBoxGeometry(ground.get_ptr(), ChVector<>(hthick, hdimY, hdimZ + hthick),
ChVector<>(-hdimX - hthick, 0, hdimZ - hthick), ChQuaternion<>(1, 0, 0, 0), visible_walls);
// Left box
utils::AddBoxGeometry(ground.get_ptr(), ChVector<>(hdimX, hthick, hdimZ + hthick),
ChVector<>(0, hdimY + hthick, hdimZ - hthick), ChQuaternion<>(1, 0, 0, 0), visible_walls);
// Right box
utils::AddBoxGeometry(ground.get_ptr(), ChVector<>(hdimX, hthick, hdimZ + hthick),
ChVector<>(0, -hdimY - hthick, hdimZ - hthick), ChQuaternion<>(1, 0, 0, 0), visible_walls);
}
ground->GetCollisionModel()->BuildModel();
//.........这里部分代码省略.........
示例15: MySimpleForklift
// Build and initialize the forklift, creating all bodies corresponding to
// the various parts and adding them to the physical system - also creating
// and adding constraints to the system.
MySimpleForklift(ChIrrAppInterface* app, ChVector<> offset = ChVector<>(0,0,0))
{
throttle = 0; // initially, gas throttle is 0.
steer = 0;
lift =0;
ChVector<> COG_truss(0, 0.4, 0.5);
ChVector<> COG_wheelRF( 0.566, 0.282, 1.608);
ChVector<> COG_wheelLF(-0.566, 0.282, 1.608);
ChVector<> COG_arm(0, 1.300, 1.855);
ChVector<> COG_fork(0, 0.362, 2.100);
ChVector<> COG_wheelB(0, 0.282, 0.003);
ChVector<> POS_pivotarm(0, 0.150, 1.855);
ChVector<> POS_prismatic(0, 0.150, 1.855);
double RAD_back_wheel =0.28;
double RAD_front_wheel = 0.28;
forkliftTiremap = app->GetVideoDriver()->getTexture("../data/tire_truck.png");
// --- The car body ---
IAnimatedMesh* forklift_bodyMesh = app->GetSceneManager()->getMesh("../data/forklift_body.obj");
truss = (ChBodySceneNode*)addChBodySceneNode(
app->GetSystem(), app->GetSceneManager(), forklift_bodyMesh,
200.0,
COG_truss,
QUNIT);
truss->GetBody()->SetInertiaXX(ChVector<>(100, 100, 100));
truss->setMaterialFlag(irr::video::EMF_NORMALIZE_NORMALS, true);
truss->setMaterialTexture(0, forkliftTiremap);
truss->GetChildMesh()->setPosition(-vector3df(COG_truss.x, COG_truss.y, COG_truss.z));// offset the mesh
truss->addShadowVolumeSceneNode();
truss->GetBody()->GetCollisionModel()->ClearModel();
truss->GetBody()->GetCollisionModel()->AddBox(1.227/2., 1.621/2., 1.864/2., &ChVector<>(-0.003, 1.019, 0.192));
truss->GetBody()->GetCollisionModel()->AddBox(0.187/2., 0.773/2., 1.201/2., &ChVector<>( 0.486 , 0.153,-0.047));
truss->GetBody()->GetCollisionModel()->AddBox(0.187/2., 0.773/2., 1.201/2., &ChVector<>(-0.486 , 0.153,-0.047));
truss->GetBody()->GetCollisionModel()->BuildModel();
truss->GetBody()->SetCollide(true);
// ..the right-front wheel
IAnimatedMesh* forklift_wheelMesh = app->GetSceneManager()->getMesh("../data/wheel.obj");
wheelRF = (ChBodySceneNode*)addChBodySceneNode(
app->GetSystem(), app->GetSceneManager(), forklift_wheelMesh,
20.0,
COG_wheelRF,
QUNIT);
wheelRF->GetBody()->SetInertiaXX(ChVector<>(2, 2, 2));
wheelRF->setMaterialFlag(irr::video::EMF_NORMALIZE_NORMALS, true);
wheelRF->setMaterialTexture(0, forkliftTiremap);
wheelRF->GetChildMesh()->setPosition(-vector3df(COG_wheelRF.x, COG_wheelRF.y, COG_wheelRF.z));// offset the mesh
// Describe the (invisible) colliding shape
ChMatrix33<>Arot(chrono::Q_from_AngAxis(CH_C_PI/2, VECT_Z));
wheelRF->GetBody()->GetCollisionModel()->ClearModel();
wheelRF->GetBody()->GetCollisionModel()->AddCylinder(RAD_front_wheel,RAD_front_wheel, 0.1, &ChVector<>(0,0,0), &Arot);
wheelRF->GetBody()->GetCollisionModel()->BuildModel();
wheelRF->GetBody()->SetCollide(true);
// .. create the revolute joint between the wheel and the truss
link_revoluteRF = ChSharedPtr<ChLinkLockRevolute>(new ChLinkLockRevolute); // right, front, upper, 1
link_revoluteRF->Initialize(wheelRF->GetBody(), truss->GetBody(),
ChCoordsys<>(COG_wheelRF , chrono::Q_from_AngAxis(CH_C_PI/2, VECT_Y)) );
app->GetSystem()->AddLink(link_revoluteRF);
// ..the left-front wheel
wheelLF = (ChBodySceneNode*)addChBodySceneNode(
app->GetSystem(), app->GetSceneManager(), forklift_wheelMesh,
20.0,
COG_wheelLF,
chrono::Q_from_AngAxis(CH_C_PI, VECT_Y)); // reuse RF wheel shape, flipped
wheelLF->GetBody()->SetInertiaXX(ChVector<>(2, 2, 2));
wheelLF->setMaterialFlag(irr::video::EMF_NORMALIZE_NORMALS, true);
wheelLF->setMaterialTexture(0, forkliftTiremap);
wheelLF->GetChildMesh()->setPosition(-vector3df(COG_wheelRF.x, COG_wheelRF.y, COG_wheelRF.z));// offset the mesh (reuse RF)
// Describe the (invisible) colliding shape
wheelLF->GetBody()->GetCollisionModel()->ClearModel();
wheelLF->GetBody()->GetCollisionModel()->AddCylinder(RAD_front_wheel,RAD_front_wheel, 0.1, &ChVector<>(0,0,0), &Arot);
wheelLF->GetBody()->GetCollisionModel()->BuildModel();
wheelLF->GetBody()->SetCollide(true);
// .. create the revolute joint between the wheel and the truss
link_revoluteLF = ChSharedPtr<ChLinkLockRevolute>(new ChLinkLockRevolute); // right, front, upper, 1
link_revoluteLF->Initialize(wheelLF->GetBody(), truss->GetBody(),
ChCoordsys<>(COG_wheelLF , chrono::Q_from_AngAxis(CH_C_PI/2, VECT_Y)) );
app->GetSystem()->AddLink(link_revoluteLF);
// ..the back steering spindle (invisible, no mesh)
spindleB = (ChBodySceneNode*)addChBodySceneNode(
app->GetSystem(), app->GetSceneManager(), 0,
10.0,
COG_wheelB,
QUNIT);
//.........这里部分代码省略.........