use of artisynth.core.materials.GenericMuscle in project artisynth_core by artisynth.
the class FemMuscleDemo method initializeModel.
protected void initializeModel(int xn) throws IOException {
double widthX = 0.09;
double widthY = 0.03;
double widthZ = 0.03;
int numX = xn * 9;
int numY = xn * 3;
int numZ = xn * 3;
tissue = new FemMuscleModel("fem");
FemFactory.createHexGrid(tissue, widthX, widthY, widthZ, numX, numY, numZ);
tissue.setBounds(new Point3d(-widthX, 0, 0), new Point3d(widthX, 0, 0));
// XXX fix the leftmost nodes
double EPS = 1e-9;
double xmin = Double.POSITIVE_INFINITY;
for (FemNode3d n : tissue.getNodes()) {
if (n.getPosition().x < xmin) {
xmin = n.getPosition().x;
}
}
for (FemNode3d n : tissue.getNodes()) {
if (Math.abs(n.getPosition().x - xmin) < 1e-10) {
n.setDynamic(false);
}
}
LinkedList<FemElement3d> topElems = new LinkedList<FemElement3d>();
LinkedList<FemElement3d> midElems = new LinkedList<FemElement3d>();
LinkedList<FemElement3d> botElems = new LinkedList<FemElement3d>();
for (FemElement3d e : tissue.getElements()) {
if (defaultMidElements == ALL) {
midElems.add(e);
}
for (FemNode3d n : e.getNodes()) {
if (Math.abs(n.getPosition().z - widthZ / 2) < EPS) {
topElems.add(e);
break;
} else if (Math.abs(n.getPosition().z + widthZ / 2) < EPS) {
botElems.add(e);
break;
} else if (defaultMidElements == MIDDLE && Math.abs(n.getPosition().z - widthZ / (2 * numZ)) < EPS) {
midElems.add(e);
break;
}
}
}
RenderProps.setLineWidth(tissue, 2);
RenderProps.setLineColor(tissue, Color.PINK);
RenderProps.setPointStyle(tissue, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(tissue, 0.03);
RenderProps.setPointColor(tissue, Color.PINK);
RenderProps.setFaceColor(tissue, Color.PINK.darker());
GenericMuscle mm = new GenericMuscle();
mm.setMaxStress(5000);
BlemkerMuscle bm = new BlemkerMuscle();
// bm.setMaxStress (5000);
tissue.setMuscleMaterial(bm);
MuscleBundle top, mid, bot;
top = createBundle("top", topElems);
mid = createBundle("mid", midElems);
bot = createBundle("bot", botElems);
int k = 0;
setBundleRenderProps(top, getMuscleColor(k++));
if (addMidMuscle) {
setBundleRenderProps(mid, getMuscleColor(k++));
}
setBundleRenderProps(bot, getMuscleColor(k));
tissue.addMuscleBundle(top);
if (addMidMuscle) {
tissue.addMuscleBundle(mid);
}
tissue.addMuscleBundle(bot);
double qt = midQuadTerm;
addStrand(top, -0.035, -0.005, 0.015, 0.035, -0.005, 0.015, 0, 8);
addStrand(top, -0.035, 0.005, 0.015, 0.035, 0.005, 0.015, 0, 8);
if (addMidMuscle) {
addStrand(mid, -0.035, -0.005, 0.000, 0.035, -0.005, 0.000, qt, 8);
addStrand(mid, -0.035, 0.005, 0.000, 0.035, 0.005, 0.000, qt, 8);
}
addStrand(bot, -0.035, -0.005, -0.015, 0.035, -0.005, -0.015, 0, 8);
addStrand(bot, -0.035, 0.005, -0.015, 0.035, 0.005, -0.015, 0, 8);
if (addMidMuscle) {
if (addMidElementsWithin > 0) {
mid.addElementsNearFibres(addMidElementsWithin);
}
if (autoComputeMidDirections) {
mid.computeElementDirections();
}
}
tissue.setDirectionRenderLen(0.5);
RenderProps.setPointRadius(tissue, 0.001);
tissue.setGravity(0, 0, 0);
tissue.setDensity(1000);
tissue.setMaterial(new MooneyRivlinMaterial(1037, 0, 0, 486, 0, 10000));
// tissue.setPoissonsRatio (0.499);
// tissue.setYoungsModulus (6912);
tissue.setParticleDamping(6.22);
// more stable with 0 stiffness damping ...
tissue.setStiffnessDamping(0.01);
// tissue.setMaxStepSize(100*TimeBase.USEC);
tissue.setMaxStepSize(0.01);
tissue.setIntegrator(Integrator.ConstrainedBackwardEuler);
myModel.addModel(tissue);
addModel(myModel);
for (MuscleBundle b : tissue.getMuscleBundles()) {
RenderProps.setVisible(b.getFibres(), false);
}
for (FemMarker m : tissue.markers()) {
RenderProps.setVisible(m, false);
}
addProbes(tissue);
createMusclePanel();
// int numWays = 20;
// double res = 0.1;
// for (int i = 0; i < numWays; i++) {
// addWayPoint (new WayPoint (TimeBase.secondsToTicks ((i + 1) * res)));
// }
}
Aggregations