use of artisynth.core.materials.LinearMaterial in project artisynth_core by artisynth.
the class SingleHex method build.
public void build(String[] args) {
mod = new FemModel3d();
double[] coords = new double[] { -2, -2, -2, 2, -2, -2, -2, 2, -2, 2, 2, -2, -2, -2, 2, 2, -2, 2, -2, 2, 2, 2, 2, 2 };
FemNode3d[] nodes = new FemNode3d[8];
for (int i = 0; i < 8; i++) {
nodes[i] = new FemNode3d(coords[i * 3], coords[i * 3 + 1], coords[i * 3 + 2]);
mod.addNode(nodes[i]);
}
HexElement hex = new HexElement(nodes[4], nodes[5], nodes[7], nodes[6], nodes[0], nodes[1], nodes[3], nodes[2]);
mod.addElement(hex);
// FemNode3d dummy = new FemNode3d(0.0, 0.5, 0.01);
// dummy.setDynamic(false);
// mod.addNode(dummy);
mod.setSurfaceRendering(SurfaceRender.Shaded);
RenderProps.setShading(mod, Renderer.Shading.FLAT);
RenderProps.setFaceColor(mod, Color.PINK);
RenderProps.setShininess(mod, mod.getRenderProps().getShininess() * 10);
RenderProps.setVisible(mod, true);
RenderProps.setFaceStyle(mod, Renderer.FaceStyle.FRONT);
mechMod = new MechModel("mech");
mechMod.addModel(mod);
mechMod.setIntegrator(MechSystemSolver.Integrator.ConstrainedBackwardEuler);
addModel(mechMod);
// addModel (mod);
RenderProps.setPointStyle(mod, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(mod, 0.05);
mod.setGravity(0, 0, -9.8);
mod.setIncompressible(FemModel.IncompMethod.OFF);
// mod.setGravity (0, 0, -1);
LinearMaterial linMat = new LinearMaterial();
linMat.setYoungsModulus(1000);
linMat.setPoissonsRatio(0);
IncompNeoHookeanMaterial inhMat = new IncompNeoHookeanMaterial();
inhMat.setBulkModulus(30000);
inhMat.setShearModulus(3000);
MooneyRivlinMaterial monMat = new MooneyRivlinMaterial();
monMat.setBulkModulus(15000000);
monMat.setC10(150000);
monMat.setJLimit(0.2);
// mod.setMaterial (new StVenantKirchoffMaterial());
// mod.setMaterial (new NeoHookeanMaterial());
mod.setMaterial(monMat);
// mod.setMaterial (linMat);
mod.setDensity(10000);
// nodes[0].setDynamic(false);
// nodes[3].setDynamic(false);
FemMarker mkr = new FemMarker(0, -1, 0);
mod.addMarker(mkr, mod.findContainingElement(mkr.getPosition()));
if (true) {
// fix the top nodes
for (int i = 4; i < 8; i++) {
nodes[i].setDynamic(false);
}
}
if (false) {
// fix the side nodes
nodes[0].setDynamic(false);
nodes[2].setDynamic(false);
nodes[4].setDynamic(false);
nodes[6].setDynamic(false);
}
// nodes[1].setPosition (-0.40, -2.13, -5.86);
// nodes[5].setPosition (3.73, -2.02, -3.56);
// nodes[7].setPosition (3.73, 2.02, -3.56);
// nodes[3].setPosition (-0.40, 2.13, -5.86);
// set to invert elements
// nodes[1].setPosition (-3.001, -2, -2);
// nodes[5].setPosition (-3.001, -2, 2);
// nodes[7].setPosition (-3.001, 2, 2);
// nodes[3].setPosition (-3.001, 2, -2);
createControlPanel(mechMod, mod);
mod.setSoftIncompMethod(IncompMethod.AUTO);
SolveMatrixTest tester = new SolveMatrixTest();
// System.out.println ("error=" + tester.testStiffness (mod, 1e-8));
// System.out.println ("K=\n" + tester.getK().toString ("%10.1f"));
// System.out.println ("N=\n" + tester.getKnumeric().toString ("%10.1f"));
System.out.println("gravity weights=" + hex.computeGravityWeights().toString("%8.3f"));
}
use of artisynth.core.materials.LinearMaterial in project artisynth_core by artisynth.
the class TransverseIsotropyTest method build.
@Override
public void build(String[] args) throws IOException {
super.build(args);
MechModel mech = new MechModel("mech");
addModel(mech);
double h = 0.1;
double r = 0.005;
FemModel3d fem = createCylinder(h, r);
fem.setName("transverse");
mech.addModel(fem);
TransverseLinearMaterial mat = new TransverseLinearMaterial();
mat.setYoungsModulus(50000, 50000);
mat.setPoissonsRatio(0.45, 0.45);
double G = 50000 / (2 * (1 + 0.45));
mat.setShearModulus(G);
mat.setCorotated(true);
fem.setMaterial(mat);
FemModel3d fem2 = createCylinder(h, r);
fem2.setName("linear");
LinearMaterial lmat = new LinearMaterial(50000, 0.45, true);
fem2.setMaterial(lmat);
mech.addModel(fem2);
RigidTransform3d rot = new RigidTransform3d(Vector3d.ZERO, AxisAngle.ROT_Y_90);
fem.transformGeometry(rot);
fem2.transformGeometry(rot);
fem2.transformGeometry(new RigidTransform3d(new Vector3d(0, 2 * r, 0), AxisAngle.IDENTITY));
RenderProps.setFaceColor(fem2, Color.MAGENTA);
}
use of artisynth.core.materials.LinearMaterial in project artisynth_core by artisynth.
the class FemCollisions method build.
@Override
public void build(String[] args) throws IOException {
super.build(args);
// Reduce step size to better resolve collisions
setMaxStepSize(0.0002);
// Create and add main MechModel
MechModel mech = new MechModel("mech");
addModel(mech);
// -------------------------------------------------------------
// BEAM
// -------------------------------------------------------------
// Create FEM beam
FemModel3d beam = new FemModel3d("beam");
mech.addModel(beam);
// widths
double[] size = { 0.003, 0.0015, 0.0015 };
// resolution
int[] res = { 4, 2, 2 };
FemFactory.createGrid(beam, FemElementType.Hex, size[0], size[1], size[2], res[0], res[1], res[2]);
// Set properties
beam.setDensity(1000);
beam.setMaterial(new LinearMaterial(300, 0.33));
// -------------------------------------------------------------
// ELLIPSOID
// -------------------------------------------------------------
// Create FEM ellipsoid
FemModel3d ellipsoid = new FemModel3d("ellipsoid");
mech.addModel(ellipsoid);
// radii (z, x, y)
double[] radii = { 0.002, 0.001, 0.001 };
// resolution (theta, phi, r)
int[] eres = { 16, 4, 3 };
FemFactory.createEllipsoid(ellipsoid, radii[0], radii[1], radii[2], eres[0], eres[1], eres[2]);
// Set properties
ellipsoid.setDensity(1000);
ellipsoid.setMaterial(new LinearMaterial(300, 0.33));
// Transform: rotate 90 degrees about X-Axis
// translate up by 0.003
RigidTransform3d trans = new RigidTransform3d();
trans.setRotation(new AxisAngle(1, 0, 0, Math.PI / 2));
trans.setTranslation(new Vector3d(0, 0.0005, 0.003));
ellipsoid.transformGeometry(trans);
// -------------------------------------------------------------
// BLOCK WITH EMBEDDED SPHERE
// -------------------------------------------------------------
// Create FEM block
FemModel3d block = new FemModel3d("block");
mech.addModel(block);
FemFactory.createHexGrid(block, 0.002, 0.002, 0.002, 3, 3, 3);
// Set properties
block.setDensity(1000);
block.setMaterial(new LinearMaterial(300, 0.33));
// Create embedded sphere
double r = 0.0008;
// level of refinement
int ref = 2;
PolygonalMesh sphere = MeshFactory.createOctahedralSphere(r, ref);
FemMeshComp embeddedSphere = block.addMesh("embedded", sphere);
// Transform: rotate 90 degrees about X-Axis
// translate left by 0.003
trans = new RigidTransform3d();
trans.setTranslation(new Vector3d(0, 0.003, 0));
block.transformGeometry(trans);
// -------------------------------------------------------------
// TABLE AND COLLISIONS
// -------------------------------------------------------------
RigidBody table = RigidBody.createBox("table", 0.005, 0.0075, 0.0008, 0);
table.setDynamic(false);
table.setPose(new RigidTransform3d(new Vector3d(0, 0.0015, -0.002), AxisAngle.IDENTITY));
mech.addRigidBody(table);
// Set up collisions
mech.setCollisionBehavior(ellipsoid, beam, true, 0.1);
mech.setCollisionBehavior(ellipsoid, table, true, 0.1);
mech.setCollisionBehavior(embeddedSphere, table, true, 0.1);
mech.setCollisionBehavior(ellipsoid, embeddedSphere, true, 0.1);
mech.setCollisionBehavior(table, beam, true, 0.1);
// -------------------------------------------------------------
// RENDER PROPERTIES
// -------------------------------------------------------------
// Draw beam element widgets
beam.setElementWidgetSize(0.8);
RenderProps.setLineWidth(beam.getElements(), 0);
// Make beam blue, and give it a transparent surface
RenderProps.setFaceColor(beam, Color.BLUE);
beam.setSurfaceRendering(SurfaceRender.Shaded);
RenderProps.setAlpha(beam.getMeshComp("surface"), 0.4);
// Make the ellipsoid red
RenderProps.setFaceColor(ellipsoid, Color.RED);
RenderProps.setLineColor(ellipsoid, Color.RED.darker());
ellipsoid.setSurfaceRendering(SurfaceRender.Shaded);
// Make the block green
RenderProps.setFaceColor(block, Color.GREEN);
RenderProps.setLineColor(block, Color.GREEN.darker());
}
use of artisynth.core.materials.LinearMaterial in project artisynth_core by artisynth.
the class FemMuscleHeart method build.
// Model builder
@Override
public void build(String[] args) throws IOException {
super.build(args);
setMaxStepSize(0.005);
// Root mechanical model
MechModel mech = new MechModel("mech");
mech.setGravity(0, 0, -9.8);
addModel(mech);
// -------------------------------------------------------------
// HEART LOAD / ADD GEOMETRY
// -------------------------------------------------------------
// Heart surface mesh, with texture
String heartFile = ArtisynthPath.getSrcRelativePath(this, "data/HumanHeart.obj");
WavefrontReader wfr = new WavefrontReader(new File(heartFile));
PolygonalMesh heartMesh = new PolygonalMesh();
wfr.readMesh(heartMesh);
// triangulate for interaction
heartMesh.triangulate();
// FEM heart:
// - FEM mesh of heart convex hull
// - embedded heart surface geometry
FemMuscleModel heart = new FemMuscleModel("heart");
TetGenReader.read(heart, ArtisynthPath.getSrcRelativePath(this, "data/HumanHeartHull.node"), ArtisynthPath.getSrcRelativePath(this, "data/HumanHeartHull.ele"));
// add real-looking mesh
FemMeshComp embeddedHeart = heart.addMesh(heartMesh);
embeddedHeart.setName("embedded");
// Allow inverted elements (poor quality mesh)
heart.setWarnOnInvertedElements(false);
heart.setAbortOnInvertedElements(false);
// Convert unites to metres (original was cm)
heart.scaleDistance(0.01);
heart.setGravity(0, 0, -9.8);
heart.setStiffnessDamping(0.02);
// Set material properties
heart.setDensity(1000);
FemMaterial femMat = new LinearMaterial(2500, 0.33, true);
// simple muscle
MuscleMaterial muscleMat = new SimpleForceMuscle(500.0);
heart.setMaterial(femMat);
// Add heart to model
mech.addModel(heart);
// -------------------------------------------------------------
// MUSCLE BUNDLES
// -------------------------------------------------------------
// One "long" direction muscle bundle
// One "radial" muscle bundle
// LONG BUNDLE
// Compute the "long" direction of the heart
PolygonalMesh hull = heart.getSurfaceMesh();
RigidTransform3d trans = hull.computePrincipalAxes();
Vector3d longAxis = new Vector3d();
// first column of rotation
trans.R.getColumn(0, longAxis);
// Create the long axis muscle bundle
MuscleBundle longBundle = new MuscleBundle("long");
for (FemElement3d elem : heart.getElements()) {
longBundle.addElement(elem, longAxis);
}
longBundle.setMuscleMaterial(muscleMat);
heart.addMuscleBundle(longBundle);
// RADIAL BUNDLE
// Compute a plane through centre of heart
Plane plane = new Plane(longAxis, new Point3d(trans.p));
Point3d centroid = new Point3d();
Vector3d radialDir = new Vector3d();
// Create the radial muscle bundle
MuscleBundle radialBundle = new MuscleBundle("radial");
for (FemElement3d elem : heart.getElements()) {
elem.computeCentroid(centroid);
// project to plane and compute radial direction
plane.project(centroid, centroid);
radialDir.sub(centroid, trans.p);
radialDir.normalize();
radialBundle.addElement(elem, radialDir);
}
radialBundle.setMuscleMaterial(muscleMat);
heart.addMuscleBundle(radialBundle);
// -------------------------------------------------------------
// RIGID TABLE AND COLLISION
// -------------------------------------------------------------
// Create a rigid box for the heart to fall on
RigidBody box = RigidBody.createBox("box", 0.2, 0.2, 0.02, 0, /*addnormals*/
true);
box.setPose(new RigidTransform3d(new Vector3d(0, 0, -0.2), AxisAngle.IDENTITY));
box.setDynamic(false);
mech.addRigidBody(box);
// Enable collisions between the heart and table
mech.setCollisionBehavior(heart, box, true);
// -------------------------------------------------------------
// RENDER PROPERTIES
// -------------------------------------------------------------
// Hide elements and nodes
RenderProps.setVisible(heart.getElements(), false);
RenderProps.setVisible(heart.getNodes(), false);
RenderProps.setLineColor(radialBundle, Color.BLUE);
RenderProps.setLineColor(longBundle, Color.RED);
radialBundle.setDirectionRenderLen(0.1);
longBundle.setDirectionRenderLen(0.1);
RenderProps.setVisible(radialBundle, false);
RenderProps.setVisible(longBundle, false);
RenderProps.setVisible(heart.getSurfaceMeshComp(), false);
// adjust table render properties
RenderProps.setShading(box, Shading.METAL);
RenderProps.setSpecular(box, new Color(0.8f, 0.8f, 0.8f));
// adjust heart mesh render properties
RenderProps rprops = embeddedHeart.getRenderProps();
rprops.getBumpMap().setScaling(0.01f);
// don't modify specular
rprops.getColorMap().setSpecularColoring(false);
rprops.setShading(Shading.SMOOTH);
rprops.setFaceColor(new Color(0.8f, 0.8f, 0.8f));
rprops.getColorMap().setColorMixing(ColorMixing.MODULATE);
rprops.setSpecular(new Color(0.4f, 0.4f, 0.4f));
rprops.setShininess(128);
// -------------------------------------------------------------
// INPUT PROBES
// -------------------------------------------------------------
// Add heart probe
addHeartProbe(longBundle, radialBundle);
}
Aggregations