Search in sources :

Example 1 with IntegrationData3d

use of artisynth.core.femmodels.IntegrationData3d in project artisynth_core by artisynth.

the class MFreeElement3d method addIntegrationPoint.

public void addIntegrationPoint(MFreeIntegrationPoint3d ipnt, IntegrationData3d idata, double iwgt, boolean updateVolumes) {
    if (idata == null) {
        idata = new IntegrationData3d();
        idata.setRestInverseJacobian(new Matrix3d(Matrix3d.IDENTITY), 1);
    }
    int[] idxs = new int[numNodes()];
    for (int j = 0; j < numNodes(); j++) {
        idxs[j] = ipnt.getNodeCoordIdx(myNodes[j]);
        if (idxs[j] < 0) {
            // XXX happens when right on the boundary
            return;
        }
    }
    // int idx = myIntegrationWeights.adjustSize(1);
    // myIntegrationWeights.set(idx, iwgt);
    myIntegrationData.add(idata);
    // ipnt.setNumber(myIntegrationPoints.size());
    ipnt.setNumber(myIntegrationPoints.size());
    myIntegrationPoints.add(ipnt);
    // myIntegrationNodeIdxs.add(idxs);
    myNodalExtrapolationMatrix = null;
    if (updateVolumes) {
        updateAllVolumes();
    }
}
Also used : Matrix3d(maspack.matrix.Matrix3d) IntegrationData3d(artisynth.core.femmodels.IntegrationData3d)

Example 2 with IntegrationData3d

use of artisynth.core.femmodels.IntegrationData3d in project artisynth_core by artisynth.

the class MFreeElement3d method setWarpingPoint.

// public MFreeIntegrationPoint3d getWarpingPoint() {
// return myWarpingPoint;
// }
// 
// public IntegrationData3d getWarpingData() {
// return myWarpingData;
// }
public void setWarpingPoint(MFreeIntegrationPoint3d warp) {
    myWarpingPoint = warp;
    myWarpingData = new IntegrationData3d();
    myWarpingData.setRestJacobian(Matrix3d.IDENTITY);
}
Also used : IntegrationData3d(artisynth.core.femmodels.IntegrationData3d)

Example 3 with IntegrationData3d

use of artisynth.core.femmodels.IntegrationData3d in project artisynth_core by artisynth.

the class MFreeElement3d method getNodalExtrapolationMatrix.

// /**
// * Returns the number of pressure variables associated with this element.
// * All of the linear elements have one pressure variable, whereas some of
// * the quadratic elements have more.
// *
// * @return number of pressure variables
// *
// */
// public int numPressureVals() {
// // higher order elements should override this if necessary
// return 1;
// }
// 
// /**
// * Returns the pressure weight matrix for this element. The pressure
// * weight matrix is given by the inverse of the integral of
// * H^T H, where H is the row vector formed from the pressure
// * shape functions.
// *
// * <p>By default, this method returns a pressure weight matrix for the case
// * where there is only one pressure value. Such matrices always have a
// * single value of 1. Elements with a larger number of pressure values
// * should override this method to return a pressure weight matrix
// * appropriate for that element.
// */
// public Matrix getPressureWeightMatrix () {
// if (myPressureWeightMatrix == null) {
// myPressureWeightMatrix = new Matrix1x1();
// myPressureWeightMatrix.m00 = 1;
// }
// return myPressureWeightMatrix;
// }
// 
public double[] getNodalExtrapolationMatrix() {
    if (myNodalExtrapolationMatrix == null) {
        // build
        IntegrationData3d[] idata = getIntegrationData();
        IntegrationPoint3d[] ipnts = getIntegrationPoints();
        myNodalExtrapolationMatrix = new double[idata.length * myNodes.length];
        for (int k = 0; k < idata.length; ++k) {
            VectorNd N = ipnts[k].getShapeWeights();
            for (int j = 0; j < myNodes.length; ++j) {
                myNodalExtrapolationMatrix[j * ipnts.length + k] = N.get(j);
            }
        }
    }
    return myNodalExtrapolationMatrix;
}
Also used : IntegrationPoint3d(artisynth.core.femmodels.IntegrationPoint3d) VectorNd(maspack.matrix.VectorNd) IntegrationData3d(artisynth.core.femmodels.IntegrationData3d)

Example 4 with IntegrationData3d

use of artisynth.core.femmodels.IntegrationData3d in project artisynth_core by artisynth.

the class MFreeFactory method cloneFem.

public static MFreeModel3d cloneFem(MFreeModel3d model, FemModel3d fem) {
    if (model == null) {
        model = new MFreeModel3d();
    }
    HashMap<FemNode3d, MFreeNode3d> nodeMap = new HashMap<FemNode3d, MFreeNode3d>();
    HashMap<MFreeNode3d, FemNode3d> nodeMapInv = new HashMap<MFreeNode3d, FemNode3d>();
    ArrayList<MFreeNode3d> nodeList = new ArrayList<MFreeNode3d>();
    // duplicate nodes
    for (FemNode3d node : fem.getNodes()) {
        MFreeNode3d mnode = new MFreeNode3d(node.getRestPosition());
        // explicit node masses
        mnode.setMassExplicit(true);
        mnode.setMass(node.getMass());
        MFreeNode3d[] deps = new MFreeNode3d[1];
        deps[0] = mnode;
        VectorNd coords = new VectorNd(new double[] { 1 });
        mnode.setDependentNodes(deps, coords);
        nodeMap.put(node, mnode);
        nodeMapInv.put(mnode, node);
        nodeList.add(mnode);
    }
    // convert surface mesh
    FemMeshComp surfaceFem = fem.getSurfaceMeshComp();
    PolygonalMesh mesh = (PolygonalMesh) surfaceFem.getMesh();
    // build mesh
    PolygonalMesh mesh2 = mesh.copy();
    // index vertices
    int idx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        vtx.setIndex(idx++);
    }
    idx = 0;
    for (Vertex3d vtx : mesh2.getVertices()) {
        vtx.setIndex(idx++);
    }
    MFreeMeshComp surfaceMFree = new MFreeMeshComp(model, "surface");
    surfaceMFree.setMesh(mesh2);
    // manually build surface attachments
    for (Vertex3d vtx : mesh.getVertices()) {
        PointAttachment pa = surfaceFem.getAttachment(vtx.getIndex());
        if (pa instanceof PointFem3dAttachment) {
            PointFem3dAttachment pfa = (PointFem3dAttachment) pa;
            FemNode[] masters = pfa.getNodes();
            MFreeNode3d[] deps = new MFreeNode3d[masters.length];
            VectorNd coords = new VectorNd(masters.length);
            for (int j = 0; j < masters.length; j++) {
                // mlist.add (new ContactMaster (masters[j], pfa.getCoordinate(j)));
                deps[j] = nodeMap.get(masters[j]);
                coords.set(j, pfa.getCoordinate(j));
            }
            surfaceMFree.setVertexAttachment(vtx.getIndex(), coords.getBuffer(), deps);
        } else {
            PointParticleAttachment ppa = (PointParticleAttachment) pa;
            DynamicComponent[] masters = ppa.getMasters();
            MFreeNode3d[] deps = new MFreeNode3d[1];
            deps[0] = nodeMap.get(masters[0]);
            VectorNd coords = new VectorNd(new double[] { 1 });
            surfaceMFree.setVertexAttachment(vtx.getIndex(), coords.getBuffer(), deps);
        }
    }
    // integration regions by copying elements
    ArrayList<MFreeElement3d> elemList = new ArrayList<MFreeElement3d>(fem.numElements());
    HashMap<FemElement3d, MFreeElement3d> elemMap = new HashMap<FemElement3d, MFreeElement3d>(fem.numElements());
    for (FemElement3d elem : fem.getElements()) {
        MFreeNode3d[] elemNodes = new MFreeNode3d[elem.numNodes()];
        FemNode3d[] fnodes = elem.getNodes();
        for (int i = 0; i < elem.numNodes(); i++) {
            elemNodes[i] = nodeMap.get(fnodes[i]);
        }
        MFreeElement3d region = new MFreeElement3d(null, elemNodes);
        // region.setAllTermsActive(true);
        MFreeIntegrationPoint3d[] mpnts = new MFreeIntegrationPoint3d[elem.numIntegrationPoints()];
        IntegrationData3d[] mdata = new IntegrationData3d[elem.numIntegrationPoints()];
        IntegrationPoint3d[] ipnts = elem.getIntegrationPoints();
        IntegrationData3d[] idata = elem.getIntegrationData();
        for (int i = 0; i < ipnts.length; i++) {
            Point3d pos = new Point3d();
            ipnts[i].computePosition(pos, elem.getNodes());
            Vector3d[] gradU = ipnts[i].getGNs();
            ArrayList<Vector3d> grads = new ArrayList<Vector3d>();
            for (Vector3d g : gradU) {
                grads.add(g);
            }
            MFreeIntegrationPoint3d mpnt = MFreeIntegrationPoint3d.create(elemNodes, ipnts[i].getShapeWeights(), grads, ipnts[i].getWeight());
            IntegrationData3d mdat = new IntegrationData3d();
            mdat.setRestInverseJacobian(idata[i].getInvJ0(), idata[i].getDetJ0());
            mpnts[i] = mpnt;
            mdata[i] = mdat;
        }
        // set warping point
        if (region.getWarpingPoint() == null) {
            IntegrationPoint3d wpnt = elem.getWarpingPoint();
            IntegrationData3d wdat = elem.getWarpingData();
            Point3d pos = new Point3d();
            wpnt.computePosition(pos, elem.getNodes());
            // Vector3d [] gradU = wpnt.updateShapeGradient(wdat.getInvJ0());
            Vector3d[] gradU = wpnt.getGNs();
            ArrayList<Vector3d> grads = new ArrayList<Vector3d>();
            for (Vector3d g : gradU) {
                grads.add(g);
            }
            // MFreeIntegrationPoint3d mpnt =
            // MFreeIntegrationPoint3d.create(pos, deps,
            // wpnt.getShapeWeights(), grads, wpnt.getWeight()*wdat.getDetJ0());
            MFreeIntegrationPoint3d mpnt = MFreeIntegrationPoint3d.create(elemNodes, wpnt.getShapeWeights(), grads, wpnt.getWeight());
            region.setWarpingPoint(mpnt);
            IntegrationData3d wdata = new IntegrationData3d();
            wdata.setRestInverseJacobian(wdat.getInvJ0(), wdat.getDetJ0());
            region.setWarpingPoint(mpnt, wdata);
        }
        region.setIntegrationPoints(mpnts, mdata);
        elemList.add(region);
        elemMap.put(elem, region);
    }
    // add everything to model
    model.addNodes(nodeList);
    model.addElements(elemList);
    model.setSurfaceMeshComp(surfaceMFree);
    // copy properties
    model.setDensity(fem.getDensity());
    model.setParticleDamping(fem.getParticleDamping());
    model.setStiffnessDamping(fem.getStiffnessDamping());
    // copy over all masses
    for (FemNode3d node : fem.getNodes()) {
        nodeMap.get(node).setMass(node.getMass());
    }
    for (FemElement3d elem : fem.getElements()) {
        elemMap.get(elem).setMass(elem.getMass());
    }
    model.setMaterial(fem.getMaterial());
    return model;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PointAttachment(artisynth.core.mechmodels.PointAttachment) IntegrationData3d(artisynth.core.femmodels.IntegrationData3d) PolygonalMesh(maspack.geometry.PolygonalMesh) Point3d(maspack.matrix.Point3d) IntegrationPoint3d(artisynth.core.femmodels.IntegrationPoint3d) FemNode3d(artisynth.core.femmodels.FemNode3d) DynamicComponent(artisynth.core.mechmodels.DynamicComponent) FemNode(artisynth.core.femmodels.FemNode) FemElement3d(artisynth.core.femmodels.FemElement3d) FemMeshComp(artisynth.core.femmodels.FemMeshComp) IntegrationPoint3d(artisynth.core.femmodels.IntegrationPoint3d) Vector3d(maspack.matrix.Vector3d) VectorNd(maspack.matrix.VectorNd) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 5 with IntegrationData3d

use of artisynth.core.femmodels.IntegrationData3d in project artisynth_core by artisynth.

the class MFreeModel3d method integrate.

public double integrate(Function3x1 fun) {
    double out = 0;
    if (!myStiffnessesValidP) {
        updateJacobians();
    }
    for (FemElement3d elem : myElements) {
        IntegrationPoint3d[] ipnts = elem.getIntegrationPoints();
        IntegrationData3d[] idata = elem.getIntegrationData();
        for (int i = 0; i < elem.numIntegrationPoints(); i++) {
            IntegrationPoint3d ipnt = ipnts[i];
            IntegrationData3d idat = idata[i];
            VectorNd shapeFunc = ipnt.getShapeWeights();
            for (int j = 0; j < elem.numNodes(); j++) {
                // if (elem.isTermActive(j, j)) {
                double f = fun.eval(((MFreePoint3d) ipnt).getPosition()) * ipnt.getWeight() * shapeFunc.get(j);
                f = f * ipnt.getDetF() * idat.getDetJ0();
                out += f;
            // }
            }
        }
    }
    return out;
}
Also used : FemElement3d(artisynth.core.femmodels.FemElement3d) IntegrationPoint3d(artisynth.core.femmodels.IntegrationPoint3d) VectorNd(maspack.matrix.VectorNd) IntegrationData3d(artisynth.core.femmodels.IntegrationData3d) Point(artisynth.core.mechmodels.Point)

Aggregations

IntegrationData3d (artisynth.core.femmodels.IntegrationData3d)14 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)7 Matrix3d (maspack.matrix.Matrix3d)6 VectorNd (maspack.matrix.VectorNd)4 FemElement3d (artisynth.core.femmodels.FemElement3d)3 Point (artisynth.core.mechmodels.Point)3 SymmetricMatrix3d (maspack.matrix.SymmetricMatrix3d)3 FemMeshComp (artisynth.core.femmodels.FemMeshComp)1 FemNode (artisynth.core.femmodels.FemNode)1 FemNode3d (artisynth.core.femmodels.FemNode3d)1 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)1 SolidDeformation (artisynth.core.materials.SolidDeformation)1 DynamicComponent (artisynth.core.mechmodels.DynamicComponent)1 PointAttachment (artisynth.core.mechmodels.PointAttachment)1 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 Vertex3d (maspack.geometry.Vertex3d)1 Matrix6d (maspack.matrix.Matrix6d)1