use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class MFreeMeshComp method updateVertexColors.
protected void updateVertexColors() {
if (mySurfaceRendering != SurfaceRender.Stress && mySurfaceRendering != SurfaceRender.Strain) {
return;
}
if (myStressPlotRanging == Ranging.Auto) {
myStressPlotRange.merge(myModel.getNodalPlotRange(mySurfaceRendering));
}
RenderProps rprops = getRenderProps();
float alpha = (float) rprops.getAlpha();
MeshBase mesh = getMesh();
double sval = 0;
for (int i = 0; i < myVertexAttachments.size(); i++) {
PointAttachment attacher = myVertexAttachments.get(i);
sval = 0;
if (attacher instanceof PointFem3dAttachment) {
PointFem3dAttachment pfa = (PointFem3dAttachment) attacher;
FemNode[] nodes = pfa.getNodes();
VectorNd weights = pfa.getCoordinates();
for (int j = 0; j < nodes.length; j++) {
if (nodes[j] instanceof MFreeNode3d) {
// paranoid!
MFreeNode3d node = (MFreeNode3d) nodes[j];
double w = weights.get(j);
if (mySurfaceRendering == SurfaceRender.Strain) {
sval += w * node.getVonMisesStrain();
} else if (mySurfaceRendering == SurfaceRender.Stress) {
sval += w * node.getVonMisesStress();
}
}
}
} else if (attacher instanceof PointParticleAttachment) {
PointParticleAttachment ppa = (PointParticleAttachment) attacher;
MFreeNode3d node = (MFreeNode3d) ppa.getParticle();
if (mySurfaceRendering == SurfaceRender.Strain) {
sval = node.getVonMisesStrain();
} else if (mySurfaceRendering == SurfaceRender.Stress) {
sval = node.getVonMisesStress();
}
}
double smin = myStressPlotRange.getLowerBound();
double srng = myStressPlotRange.getRange();
double c = (sval - smin) / srng;
c = Math.max(0, Math.min(c, 1.0));
myColorMap.getRGB(c, colorArray);
mesh.setColor(i, colorArray[0], colorArray[1], colorArray[2], alpha);
}
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class MFreeModel3d method updateNodeMasses.
public void updateNodeMasses(double totalMass, VectorNd massMatrixDiag) {
if (totalMass <= 0) {
totalMass = integrateMass();
}
if (massMatrixDiag == null) {
SparseMatrixNd massMatrix = computeConsistentMassMatrix();
massMatrixDiag = new VectorNd(massMatrix.rowSize());
for (int i = 0; i < massMatrix.rowSize(); i++) {
double rowSum = 0;
for (int j = 0; j < massMatrix.colSize(); j++) {
rowSum += massMatrix.get(i, j);
}
// rowSum += massMatrix.get(i, i);
massMatrixDiag.set(i, rowSum);
}
}
double mTrace = massMatrixDiag.sum();
for (FemNode3d node : myNodes) {
int i = node.getNumber();
double m = totalMass / mTrace * massMatrixDiag.get(i);
node.setMass(m);
node.setMassExplicit(true);
}
}
use of maspack.matrix.VectorNd 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;
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class ParticleConstraintNdBase method updateEngagement.
protected double updateEngagement(ParticleInfo pi, double maxpen) {
boolean oldEngaged = pi.myEngagedP;
boolean engaged = false;
VectorNd vr = new VectorNd(pi.myDist.length);
VectorNd v = new VectorNd(pi.myPart.getVelocity());
pi.myBlk.mul(vr, v);
for (int j = 0; j < pi.myDist.length; ++j) {
if (pi.myDist[j] < 0) {
engaged = true;
if (-pi.myDist[j] > maxpen) {
maxpen = -pi.myDist[j];
}
}
}
// check if sufficient velocity to break
if (oldEngaged && !engaged) {
boolean breakEngagement = false;
for (int j = 0; j < pi.myDist.length; ++j) {
if (vr.get(j) > myBreakSpeed) {
breakEngagement = true;
}
}
if (breakEngagement) {
pi.myEngagedP = false;
}
} else if (engaged) {
pi.myEngagedP = true;
}
return maxpen;
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class GMLSShapeFunction method eval.
@Override
public double eval(MFreeNode3d node, MFreeNode3d[] nodes, Point3d pnt, MatrixNd MInv) {
VectorNd _p = new VectorNd(nBasis);
VectorNd pi = new VectorNd(nBasis);
computePtMInv(_p, MInv, pnt, nodes);
Point3d xi = node.getRestPosition();
computeDP(pi, xi.x, xi.y, xi.z, myDerivativeIdxs[0], myDerivativeIdxs[1], myDerivativeIdxs[2]);
_p.scale(node.getWeight(pnt));
return _p.dot(pi);
}
Aggregations