use of artisynth.core.femmodels.FemElement3d in project artisynth_core by artisynth.
the class FemDisplayProbe method getStrainValue.
// computes strain of a point inside the model based on FEM shape
// function interpolation
private static double getStrainValue(Point3d pnt, FemModel3d model) {
Point3d loc = new Point3d();
FemElement3d elem = model.findNearestElement(loc, pnt);
Vector3d coords = new Vector3d();
double strain = 0;
if (elem != null) {
elem.getNaturalCoordinates(coords, pnt);
FemNode3d[] nodes = elem.getNodes();
for (int i = 0; i < elem.numNodes(); i++) {
strain += elem.getN(i, coords) * nodes[i].getVonMisesStrain();
}
}
return strain;
}
use of artisynth.core.femmodels.FemElement3d in project artisynth_core by artisynth.
the class MFreeMeshComp method getFaceElement.
public MFreeElement3d getFaceElement(Face face) {
// Form the intersection of all the element dependencies of all three
// nodes associated with the face. If the face is on the surface,
// there should be only one element left.
HashSet<MFreeNode3d> nodes = new HashSet<MFreeNode3d>();
HalfEdge he0 = face.firstHalfEdge();
HalfEdge he = he0;
do {
addVertexNodes(nodes, he.getHead());
he = he.getNext();
} while (he != he0);
HashSet<FemElement3d> elems = null;
for (MFreeNode3d node : nodes) {
if (elems == null) {
elems = new HashSet<>(node.getElementDependencies());
} else {
elems.retainAll(node.getElementDependencies());
}
}
if (elems.size() != 1) {
MFreeElement3d[] elemArray = elems.toArray(new MFreeElement3d[0]);
int[] idxs = face.getVertexIndices();
System.out.print("Error: couldn't get element for face [ ");
for (int i = 0; i < idxs.length; i++) {
System.out.print("" + idxs[i] + " ");
}
System.out.println("]");
System.out.println("Candidate elements are:");
for (int i = 0; i < elemArray.length; i++) {
System.out.println(" element " + elemArray[i].getNumber());
}
return null;
// ignore for now ...
// throw new InternalErrorException (
// "Face "+face+" associated with "+elems.size()+" elements");
}
return (MFreeElement3d) elems.toArray()[0];
}
use of artisynth.core.femmodels.FemElement3d in project artisynth_core by artisynth.
the class MFreeModel3d method findNearestElement.
/**
* Finds the nearest element and node coordinates
* @param nearest nearest point
* @param N shape function evaluation at point
* @return the nearest element
*/
public FemElement3d findNearestElement(Point3d nearest, Point3d pnt, VectorNd N) {
BVFeatureQuery query = new BVFeatureQuery();
NearestIPointCalculator dcalc = new NearestIPointCalculator(pnt);
query.nearestObject(getElementBVTree(), dcalc);
FemElement3d elem = dcalc.nearestObject();
MFreeIntegrationPoint3d ipnt = dcalc.nearestIPoint();
nearest.set(ipnt.getPosition());
N.set(ipnt.getShapeWeights());
return elem;
}
use of artisynth.core.femmodels.FemElement3d in project artisynth_core by artisynth.
the class MFreeModel3d method findNaturalCoordinates.
/**
* Finds the containing element and node coordinates
* @param pnt 3D point in world coordinates to find natural coordinates of
* @param coords natural coordinates
* @param N shape function values
* @return the containing element if it exists
*/
public FemNode3d[] findNaturalCoordinates(Point3d pnt, Point3d coords, VectorNd N) {
BVFeatureQuery query = new BVFeatureQuery();
NearestIPointCalculator dcalc = new NearestIPointCalculator(pnt);
query.nearestObject(getElementBVTree(), dcalc);
FemElement3d elem = dcalc.nearestObject();
MFreeIntegrationPoint3d ipnt = dcalc.nearestIPoint();
// try to compute coords
coords.set(ipnt.getRestPosition());
int n = ((MFreeElement3d) elem).getNaturalCoordinates(coords, pnt, 1000, N);
return elem.getNodes();
}
use of artisynth.core.femmodels.FemElement3d in project artisynth_core by artisynth.
the class MFreeModel3d method computeConsistentMassMatrix.
public SparseMatrixNd computeConsistentMassMatrix() {
int nNodes = myNodes.size();
SparseMatrixNd M = new SparseMatrixNd(nNodes, nNodes);
updateJacobians();
for (FemElement3d e : myElements) {
for (int k = 0; k < e.numIntegrationPoints(); k++) {
IntegrationPoint3d ipnt = e.getIntegrationPoints()[k];
IntegrationData3d idat = e.getIntegrationData()[k];
VectorNd shapeCoords = ipnt.getShapeWeights();
for (int i = 0; i < e.numNodes(); i++) {
for (int j = i; j < e.numNodes(); j++) {
// if (e.isTermActive(i, j)) {
int bi = e.getNodes()[i].getNumber();
int bj = e.getNodes()[j].getNumber();
double m = myDensity * shapeCoords.get(i) * shapeCoords.get(j) * ipnt.getWeight() * ipnt.getDetF() * idat.getDetJ0();
M.set(bi, bj, M.get(bi, bj) + m);
if (i != j) {
M.set(bj, bi, M.get(bj, bi) + m);
}
// }
}
}
}
}
return M;
}
Aggregations