Skip to content

Commit

Permalink
Add example 10 for FEM-Spring coupling
Browse files Browse the repository at this point in the history
  • Loading branch information
David Levin committed Nov 16, 2017
1 parent d7094d1 commit d543bab
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/Examples/example10.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <functional>

#include <Qt3DIncludes.h>
#include <GaussIncludes.h>
#include <FEMIncludes.h>

//Any extra things I need such as constraints
#include <ConstraintFixedPoint.h>
#include <TimeStepperEulerImplicitLinear.h>

using namespace Gauss;
using namespace FEM;
using namespace ParticleSystem; //For Force Spring

/* Tetrahedral finite elements */

//typedef physical entities I need

//typedef scene
typedef PhysicalSystemFEM<double, NeohookeanTet> FEMLinearTets;

typedef World<double, std::tuple<FEMLinearTets *,PhysicalSystemParticleSingle<double> *>,
std::tuple<ForceSpringFEMParticle<double> *>,
std::tuple<ConstraintFixedPoint<double> *> > MyWorld;
typedef TimeStepperEulerImplictLinear<double, AssemblerEigenSparseMatrix<double>,
AssemblerEigenVector<double> > MyTimeStepper;

typedef Scene<MyWorld, MyTimeStepper> MyScene;


void preStepCallback(MyWorld &world) {
// This is an example callback
}

int main(int argc, char **argv) {
std::cout<<"Test Neohookean FEM \n";

//Setup Physics
MyWorld world;

//new code -- load tetgen files
Eigen::MatrixXd V;
Eigen::MatrixXi F;

readTetgen(V, F, dataDir()+"/meshesTetgen/Beam/Beam.node", dataDir()+"/meshesTetgen/Beam/Beam.ele");

FEMLinearTets *test = new FEMLinearTets(V,F);
PhysicalSystemParticleSingle<double> *test1 = new PhysicalSystemParticleSingle<double>();
test1->getImpl().setMass(100);
//ForceSpring<double> *forceSpring = new ForceSpring<double>(&test->getQ()[0], &test1->getQ(), 12.08, 2.0);
ForceSpringFEMParticle<double> *forceSpring = new ForceSpringFEMParticle<double>(PosFEM<double>(&test->getQ()[0],0, &test->getImpl().getV()),
PosParticle<double>(&test1->getQ()),
2, 100000.0);

world.addSystem(test);
world.addSystem(test1);
world.addForce(forceSpring);
fixDisplacementMin(world, test);
world.finalize(); //After this all we're ready to go (clean up the interface a bit later)

auto q = mapStateEigen(world);
q.setZero();

auto q1 = mapDOFEigen(test1->getQ(), world);
q1[0] = -5.0;


MyTimeStepper stepper(0.01);

//Display
QGuiApplication app(argc, argv);

MyScene *scene = new MyScene(&world, &stepper, preStepCallback);
GAUSSVIEW(scene);

return app.exec();
}

0 comments on commit d543bab

Please sign in to comment.