Search in sources :

Example 16 with VectorNd

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;
}
Also used : VectorNd(maspack.matrix.VectorNd) Point(artisynth.core.mechmodels.Point)

Example 17 with VectorNd

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;
        }
    }
}
Also used : VectorNd(maspack.matrix.VectorNd) Point(artisynth.core.mechmodels.Point)

Example 18 with VectorNd

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;
}
Also used : DynamicAttachment(artisynth.core.mechmodels.DynamicAttachment) Point(artisynth.core.mechmodels.Point) ModelComponent(artisynth.core.modelbase.ModelComponent) Vector3d(maspack.matrix.Vector3d) VectorNd(maspack.matrix.VectorNd) Map(java.util.Map) HueColorMap(maspack.render.color.HueColorMap) HashMap(java.util.HashMap)

Example 19 with VectorNd

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;
}
Also used : VectorNd(maspack.matrix.VectorNd) Point(artisynth.core.mechmodels.Point)

Example 20 with VectorNd

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;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) PointAttachment(artisynth.core.mechmodels.PointAttachment) PolygonalMesh(maspack.geometry.PolygonalMesh) BVFeatureQuery(maspack.geometry.BVFeatureQuery) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Vector2d(maspack.matrix.Vector2d) Point3d(maspack.matrix.Point3d) VectorNd(maspack.matrix.VectorNd) Face(maspack.geometry.Face) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Aggregations

VectorNd (maspack.matrix.VectorNd)136 Point (artisynth.core.mechmodels.Point)29 Point3d (maspack.matrix.Point3d)16 Vector3d (maspack.matrix.Vector3d)15 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)11 ArrayList (java.util.ArrayList)11 ContactPoint (artisynth.core.mechmodels.ContactPoint)9 MatrixNd (maspack.matrix.MatrixNd)9 Vertex3d (maspack.geometry.Vertex3d)8 SparseMatrixNd (maspack.matrix.SparseMatrixNd)8 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)7 PointAttachment (artisynth.core.mechmodels.PointAttachment)7 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)6 FemNode (artisynth.core.femmodels.FemNode)5 PolygonalMesh (maspack.geometry.PolygonalMesh)5 ReaderTokenizer (maspack.util.ReaderTokenizer)5 FemNode3d (artisynth.core.femmodels.FemNode3d)4 IntegrationData3d (artisynth.core.femmodels.IntegrationData3d)4 StringReader (java.io.StringReader)4 HashMap (java.util.HashMap)4