use of artisynth.core.femmodels.FemElement3d in project artisynth_core by artisynth.
the class SpongeModel method createGeometry.
public void createGeometry(String name, double widthX, double widthY, double widthZ, int numX, int numY, int numZ, double nodeMass) {
if (numX < 1 || numY < 1 || numZ < 1) {
throw new IllegalArgumentException("number of elements in each direction must be >= 1");
}
// create all the particles
double dx = 1.0 / numX;
double dy = 1.0 / numY;
double dz = 1.0 / numZ;
Point3d p = new Point3d();
for (int k = 0; k <= numZ; k++) {
for (int j = 0; j <= numY; j++) {
for (int i = 0; i <= numX; i++) {
p.x = widthX * (-0.5 + i * dx);
p.y = widthY * (-0.5 + j * dy);
p.z = widthZ * (-0.5 + k * dz);
addNode(new FemNode3d(p));
// getNode(numNodes()-1).setName(Integer.toString(numNodes()-1));
}
}
}
// PolygonalMesh mesh = new PolygonalMesh();
// create all the elements
int wk = (numX + 1) * (numY + 1);
int wj = (numX + 1);
FemNode3d n0, n1, n2, n3, n4, n5, n6, n7;
for (int i = 0; i < numX; i++) {
for (int j = 0; j < numY; j++) {
for (int k = 0; k < numZ; k++) {
n0 = getNodes().get((k + 1) * wk + j * wj + i);
n1 = getNodes().get((k + 1) * wk + j * wj + i + 1);
n2 = getNodes().get((k + 1) * wk + (j + 1) * wj + i + 1);
n3 = getNodes().get((k + 1) * wk + (j + 1) * wj + i);
n4 = getNodes().get(k * wk + j * wj + i);
n5 = getNodes().get(k * wk + j * wj + i + 1);
n6 = getNodes().get(k * wk + (j + 1) * wj + i + 1);
n7 = getNodes().get(k * wk + (j + 1) * wj + i);
TetElement[] elems = TetElement.createCubeTesselation(n0, n1, n2, n3, n4, n5, n6, n7, /* even= */
(i + j + k) % 2 == 0);
// HexElement he = new HexElement (n0, n1, n2, n3, n4, n5, n6, n7);
for (FemElement3d e : elems) {
addElement(e);
// he.addTetElement ((TetElement)e);
}
// add hex element
// he.setTetElements(elems);
// hexElements.add (he);
}
}
}
// TODO create outer Mesh here.
// mesh.setFixed(false);
// setSurfaceMesh(mesh);
RenderProps.setShading(this, Renderer.Shading.SMOOTH);
RenderProps.setFaceStyle(this, Renderer.FaceStyle.FRONT_AND_BACK);
RenderProps.setFaceColor(this, Color.BLUE);
RenderProps.setAlpha(this, 0.9);
RenderProps.setVisible(this, true);
invalidateStressAndStiffness();
}
Aggregations