use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class FemModel3d method updateNodalRestVolumes.
private void updateNodalRestVolumes() {
for (FemNode3d n : myNodes) {
n.myRestVolume = 0;
}
for (FemElement3d e : myElements) {
FemNode3d[] nodes = e.myNodes;
if (e instanceof TetElement) {
double vol = e.getRestVolume();
for (int i = 0; i < nodes.length; i++) {
nodes[i].myRestVolume += vol / 4;
}
} else if (e.integrationPointsMapToNodes()) {
IntegrationData3d[] idata = e.getIntegrationData();
IntegrationPoint3d[] ipnts = e.getIntegrationPoints();
for (int i = 0; i < nodes.length; i++) {
nodes[i].myRestVolume += ipnts[i].myWeight * idata[i].myDetJ0;
}
} else if (e.integrationPointsInterpolateToNodes()) {
// distribute based on shape functions
IntegrationData3d[] idata = e.getIntegrationData();
IntegrationPoint3d[] ipnts = e.getIntegrationPoints();
for (int k = 0; k < ipnts.length; ++k) {
VectorNd N = ipnts[k].getShapeWeights();
for (int i = 0; i < nodes.length; i++) {
nodes[i].myRestVolume += ipnts[k].getWeight() * idata[k].getDetJ0() * N.get(i);
}
}
}
}
myNodalRestVolumesValidP = true;
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class FemModel3d method updateNodalPressures.
private void updateNodalPressures(IncompressibleMaterial imat) {
for (FemNode3d n : myNodes) {
n.myVolume = 0;
}
for (FemElement3d e : myElements) {
FemNode3d[] nodes = e.myNodes;
if (e instanceof TetElement) {
double vol = e.getVolume();
for (int i = 0; i < nodes.length; i++) {
nodes[i].myVolume += vol / 4;
}
} else if (e.integrationPointsMapToNodes()) {
IntegrationData3d[] idata = e.getIntegrationData();
for (int i = 0; i < nodes.length; i++) {
nodes[i].myVolume += idata[i].getDv();
}
} else if (e.integrationPointsInterpolateToNodes()) {
// distribute using shape function
IntegrationPoint3d[] ipnts = e.getIntegrationPoints();
IntegrationData3d[] idata = e.getIntegrationData();
for (int k = 0; k < ipnts.length; ++k) {
VectorNd N = ipnts[k].getShapeWeights();
for (int i = 0; i < nodes.length; i++) {
nodes[i].myVolume += idata[k].getDv() * N.get(i);
}
}
}
}
for (FemNode3d n : myNodes) {
if (volumeIsControllable(n)) {
n.myPressure = imat.getEffectivePressure(n.myVolume / n.myRestVolume);
} else {
n.myPressure = 0;
}
}
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class FemModel3d method copy.
@Override
public FemModel3d copy(int flags, Map<ModelComponent, ModelComponent> copyMap) {
if (copyMap == null) {
copyMap = new HashMap<ModelComponent, ModelComponent>();
flags = CopyableComponent.COPY_REFERENCES;
}
FemModel3d fem = (FemModel3d) super.copy(flags, copyMap);
// fem.myFrame was created in super.copy(), but we redo this
// so as to create an exact copy of the orginal frame
FemModelFrame newFrame = myFrame.copy(flags, copyMap);
newFrame.setName(myFrame.getName());
copyMap.put(myFrame, newFrame);
fem.myFrame = newFrame;
if (myFrameConstraint != null) {
fem.attachFrame(myFrame.getPose());
} else {
fem.attachFrame(null);
}
fem.myFrameRelativeP = myFrameRelativeP;
for (FemNode3d n : myNodes) {
FemNode3d newn = n.copy(flags, copyMap);
newn.setName(n.getName());
copyMap.put(n, newn);
fem.myNodes.addNumbered(newn, n.getNumber());
fem.myNodes.setRenderProps(myNodes.getRenderProps());
}
for (FemElement3d e : myElements) {
FemElement3d newe = e.copy(flags, copyMap);
newe.setName(e.getName());
copyMap.put(e, newe);
fem.myElements.addNumbered(newe, e.getNumber());
fem.myElements.setRenderProps(myElements.getRenderProps());
}
for (FemMarker m : myMarkers) {
FemMarker newm = m.copy(flags, copyMap);
newm.setName(m.getName());
fem.myMarkers.addNumbered(newm, m.getNumber());
fem.myMarkers.setRenderProps(myMarkers.getRenderProps());
}
for (DynamicAttachment a : myAttachments) {
DynamicAttachment newa = a.copy(flags, copyMap);
newa.setName(a.getName());
fem.myAttachments.addNumbered(newa, a.getNumber());
}
fem.ansysElemProps = new HashMap<FemElement3d, int[]>();
for (Map.Entry<FemElement3d, int[]> ent : ansysElemProps.entrySet()) {
FemElement3d newe = (FemElement3d) copyMap.get(ent.getKey());
int[] props = ArraySupport.copy(ent.getValue());
fem.ansysElemProps.put(newe, props);
}
for (int i = 0; i < myMeshList.size(); i++) {
FemMeshComp mc = myMeshList.get(i);
FemMeshComp newFmc = mc.copy(flags, copyMap);
if (i == 0) {
fem.myMeshList.addFixed(newFmc);
} else {
fem.addMeshComp(newFmc);
}
// do this this since addMesh sets collidability by default
newFmc.setCollidable(mc.getCollidable());
}
fem.myAutoGenerateSurface = myAutoGenerateSurface;
fem.mySurfaceMeshValid = mySurfaceMeshValid;
fem.myInternalSurfaceMeshComp = null;
fem.setElementWidgetSizeMode(myElementWidgetSizeMode);
if (myElementWidgetSizeMode == PropertyMode.Explicit) {
fem.setElementWidgetSize(myElementWidgetSize);
}
fem.clearCachedData(null);
fem.myAABBTree = null;
fem.myBVTreeValid = false;
fem.mySolveMatrixFile = null;
fem.myNumIncompressConstraints = 0;
fem.myHardIncompUpdateTime = -1;
fem.myComputeNodalStress = myComputeNodalStress;
fem.myComputeNodalStrain = myComputeNodalStrain;
fem.myHardIncompMethod = myHardIncompMethod;
fem.myHardIncompMethodValidP = myHardIncompMethodValidP;
fem.mySoftIncompMethod = mySoftIncompMethod;
fem.mySoftIncompMethodValidP = mySoftIncompMethodValidP;
fem.myNodalIncompBlocksAllocatedP = false;
fem.myNodalIncompConstraintsAllocatedP = false;
fem.myPressures = new VectorNd(MAX_PRESSURE_VALS);
fem.myKp = new double[MAX_PRESSURE_VALS];
fem.myNodalConstraints = new Vector3d[MAX_NODAL_INCOMP_NODES];
for (int i = 0; i < MAX_NODAL_INCOMP_NODES; i++) {
fem.myNodalConstraints[i] = new Vector3d();
}
return fem;
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class PointFem3dAttachment method setFromElement.
public boolean setFromElement(Point3d pos, FemElement elem, double reduceTol) {
removeBackRefsIfConnected();
FemNode[] nodes = elem.getNodes();
myCoords = new VectorNd(nodes.length);
boolean converged = elem.getMarkerCoordinates(myCoords, pos, false);
int numNodes = 0;
// reduce any weights below reduceTol to 0 ...
for (int i = 0; i < myCoords.size(); i++) {
double w = myCoords.get(i);
if (Math.abs(w) <= reduceTol) {
myCoords.set(i, 0);
w = 0;
}
if (w != 0) {
numNodes++;
}
}
// only create nodes for these whose weights are non zero.
myNodes = new FemNode[numNodes];
int k = 0;
for (int i = 0; i < nodes.length; i++) {
double w = myCoords.get(i);
if (w != 0) {
myNodes[k] = nodes[i];
myCoords.set(k, w);
k++;
}
}
myCoords.setSize(numNodes);
myElement = elem;
invalidateMasters();
addBackRefsIfConnected();
notifyParentOfChange(DynamicActivityChangeEvent.defaultEvent);
return converged;
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class FemMeshComp method createPointAttachment.
public PointFem3dAttachment createPointAttachment(Point pnt) {
if (!(getMesh() instanceof PolygonalMesh)) {
return null;
}
PolygonalMesh mesh = (PolygonalMesh) getMesh();
if (!mesh.isTriangular()) {
return null;
}
// Find nearest face to the point. The vertices of this face will be used
// to find the nodes and weight for the attachment.
BVFeatureQuery query = new BVFeatureQuery();
Point3d near = new Point3d();
Vector2d uv = new Vector2d();
Face face = query.nearestFaceToPoint(near, uv, mesh, pnt.getPosition());
Vertex3d[] vtxs = face.getTriVertices();
double[] wgts = new double[] { 1 - uv.x - uv.y, uv.x, uv.y };
HashMap<FemNode, Double> nodeWeights = new HashMap<FemNode, Double>();
for (int i = 0; i < vtxs.length; i++) {
PointAttachment va = myVertexAttachments.get(vtxs[i].getIndex());
if (va instanceof PointParticleAttachment) {
PointParticleAttachment ppa = (PointParticleAttachment) va;
FemNode node = (FemNode) ppa.getParticle();
accumulateNodeWeights(node, wgts[i], nodeWeights);
} else if (va instanceof PointFem3dAttachment) {
PointFem3dAttachment pfa = (PointFem3dAttachment) va;
for (int k = 0; k < pfa.numMasters(); k++) {
FemNode node = pfa.getNodes()[k];
double w = pfa.getCoordinate(k);
accumulateNodeWeights(node, w * wgts[i], nodeWeights);
}
}
}
// Create a new PointFem3dAttachment
PointFem3dAttachment ax = new PointFem3dAttachment(pnt);
VectorNd weightVec = new VectorNd();
for (Double d : nodeWeights.values()) {
weightVec.append(d);
}
ax.setFromNodes(nodeWeights.keySet(), weightVec);
return ax;
}
Aggregations