Introduction to FEA cables (demo_FEA_cables.cpp)

Tutorial that teaches how to use the FEA module to create basic FEA cables, that fall and swing under the effect of gravity. Some rigid bodies (boxes) are connected to the cables.

// =============================================================================
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2014 projectchrono.org
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file at the top level of the distribution and at
// http://projectchrono.org/license-chrono.txt.
//
// =============================================================================
// Authors: Alessandro Tasora, Radu Serban
// =============================================================================
//
// FEA for 3D beams of 'cable' type (ANCF gradient-deficient beams)
//
// =============================================================================
#include "chrono/physics/ChSystemSMC.h"
#include "chrono/solver/ChDirectSolverLS.h"
#include "chrono/solver/ChIterativeSolverLS.h"
#include "chrono/timestepper/ChTimestepper.h"
#include "chrono_irrlicht/ChVisualSystemIrrlicht.h"
#include "FEAcables.h"
using namespace chrono;
using namespace chrono::fea;
using namespace chrono::irrlicht;
// Select solver type (SPARSE_QR, SPARSE_LU, or MINRES).
int main(int argc, char* argv[]) {
std::cout << "Copyright (c) 2017 projectchrono.org\nChrono version: " << CHRONO_VERSION << std::endl;
// Create a Chrono::Engine physical system
sys.SetNumThreads(std::min(4, ChOMP::GetNumProcs()), 0, 1);
// Create a mesh, that is a container for groups of elements and
// their referenced nodes.
// Create one of the available models (defined in FEAcables.h)
auto model = Model3(sys, mesh);
// Remember to add the mesh to the system!
sys.Add(mesh);
// Visualization of the FEM mesh.
// This will automatically update a triangle mesh (a ChVisualShapeTriangleMesh asset that is internally managed) by
// setting proper coordinates and vertex colors as in the FEM elements. Such triangle mesh can be rendered by
// Irrlicht or POVray or whatever postprocessor that can handle a colored ChVisualShapeTriangleMesh).
vis_beam_A->SetFEMdataType(ChVisualShapeFEA::DataType::ELEM_BEAM_MZ);
vis_beam_A->SetColorscaleMinMax(-0.4, 0.4);
vis_beam_A->SetSmoothFaces(true);
vis_beam_A->SetWireframe(false);
mesh->AddVisualShapeFEA(vis_beam_A);
vis_beam_B->SetFEMglyphType(ChVisualShapeFEA::GlyphType::NODE_DOT_POS);
vis_beam_B->SetFEMdataType(ChVisualShapeFEA::DataType::NONE);
vis_beam_B->SetSymbolsThickness(0.006);
vis_beam_B->SetSymbolsScale(0.01);
vis_beam_B->SetZbufferHide(false);
mesh->AddVisualShapeFEA(vis_beam_B);
// Set solver and solver settings
switch (solver_type) {
std::cout << "Using SparseQR solver" << std::endl;
sys.SetSolver(solver);
solver->UseSparsityPatternLearner(true);
solver->LockSparsityPattern(true);
solver->SetVerbose(false);
break;
}
std::cout << "Using SparseLU solver" << std::endl;
sys.SetSolver(solver);
solver->UseSparsityPatternLearner(true);
solver->LockSparsityPattern(true);
solver->SetVerbose(false);
break;
}
std::cout << "Using MINRES solver" << std::endl;
sys.SetSolver(solver);
solver->SetMaxIterations(200);
solver->SetTolerance(1e-14);
solver->EnableDiagonalPreconditioner(true);
solver->EnableWarmStart(true); // IMPORTANT for convergence when using EULER_IMPLICIT_LINEARIZED
solver->SetVerbose(false);
break;
}
default: {
std::cout << "Solver type not supported." << std::endl;
break;
}
}
// Create the Irrlicht visualization system
vis->SetWindowSize(800, 600);
vis->SetWindowTitle("Cables FEM");
vis->Initialize();
vis->AddLogo();
vis->AddSkyBox();
vis->AddTypicalLights();
vis->AddCamera(ChVector3d(0, 0.6, -1.0));
vis->AttachSystem(&sys);
// Set integrator
sys.SetTimestepperType(ChTimestepper::Type::EULER_IMPLICIT_LINEARIZED);
while (vis->Run()) {
vis->BeginScene();
vis->Render();
vis->EndScene();
sys.DoStepDynamics(0.01);
}
return 0;
}
Type
Available types of solvers.
Definition ChSolver.h:38
@ SPARSE_LU
Sparse supernodal LU factorization.
Definition ChSolver.h:48
@ MINRES
MINimum RESidual method.
Definition ChSolver.h:54
@ SPARSE_QR
Sparse left-looking rank-revealing QR factorization.
Definition ChSolver.h:49
int DoStepDynamics(double step_size)
Advance the dynamics simulation by a single time step of given length.
Definition ChSystem.cpp:1632
void SetTimestepperType(ChTimestepper::Type type)
Set the method for time integration (time stepper type).
Definition ChSystem.cpp:412
virtual void SetNumThreads(int num_threads_chrono, int num_threads_collision=0, int num_threads_eigen=0)
Set the number of OpenMP threads used by Chrono itself, Eigen, and the collision detection system.
Definition ChSystem.cpp:373
virtual void SetSolver(std::shared_ptr< ChSolver > newsolver)
Attach a solver (derived from ChSolver) for use by this system.
Definition ChSystem.cpp:319
void Add(std::shared_ptr< ChPhysicsItem > item)
Attach an arbitrary ChPhysicsItem (e.g.
Definition ChSystem.cpp:196
Class for a physical system in which contact is modeled using a smooth (penalty-based) method.
Definition ChSystemSMC.h:30
Namespace for FEA classes.
Definition ChVisualShapeFEA.h:28
Namespace with classes for the Irrlicht module.
Definition ChApiIrr.h:47
std::shared_ptr< T > make_shared(Args &&... args)
Replacement for make_shared guaranteed to use operator new rather than placement new in order to avoi...
Definition ChTypes.h:66
Main namespace for the Chrono package.
Definition ChCamera.cpp:17
ChVector3< double > ChVector3d
Alias for double-precision vectors.
Definition ChVector3.h:283