use of maspack.matrix.SparseBlockMatrix in project artisynth_core by artisynth.
the class FemModel3d method createStiffnessMatrix.
// builds a Stiffness matrix, where entries are ordered by node numbers
public SparseBlockMatrix createStiffnessMatrix() {
if (!myStressesValidP || !myStiffnessesValidP) {
updateStressAndStiffness();
}
SparseBlockMatrix M = new SparseBlockMatrix();
int nnodes = numNodes();
int[] sizes = new int[nnodes];
for (int i = 0; i < nnodes; ++i) {
sizes[i] = 3;
}
M.addRows(sizes, sizes.length);
M.addCols(sizes, sizes.length);
M.setVerticallyLinked(true);
int idx = 0;
for (FemNode3d node : getNodes()) {
node.setIndex(idx++);
}
// create solve blocks
for (FemNode3d node : getNodes()) {
MatrixBlock blk = node.createSolveBlock();
M.addBlock(node.getIndex(), node.getIndex(), blk);
}
for (int i = 0; i < myNodes.size(); i++) {
FemNode3d node = myNodes.get(i);
for (FemNodeNeighbor nbr : getNodeNeighbors(node)) {
FemNode3d other = nbr.getNode();
Matrix3x3Block blk = null;
if (other != node) {
blk = new Matrix3x3Block();
M.addBlock(node.getIndex(), nbr.getNode().getIndex(), blk);
} else {
blk = (Matrix3x3Block) M.getBlock(node.getIndex(), node.getIndex());
}
nbr.addPosJacobian(blk, -1.0);
}
}
return M;
}
use of maspack.matrix.SparseBlockMatrix in project artisynth_core by artisynth.
the class ForceTargetTerm method createForceJacobian.
private void createForceJacobian() {
MechModel mechMod = (MechModel) myMech;
SparseBlockMatrix GT = new SparseBlockMatrix();
VectorNd dg = new VectorNd();
mechMod.getBilateralConstraints(GT, dg);
if (debug) {
System.out.println("num con = " + mechMod.bodyConnectors().size());
System.out.println(GT.colSize());
System.out.println(GT.rowSize());
System.out.println(GT.getSize());
System.out.println(GT.numBlocks());
System.out.println(GT.getBlock(0, 0));
System.out.println(GT.getBlock(0, 1));
System.out.println(GT.getBlock(0, 2));
System.out.println(GT.getBlock(1, 0));
}
// find the number of bilateral constraints for each connector
int[] connectorSizes = new int[mechMod.bodyConnectors().size()];
int[] targetToConnectorMap = new int[myForceTargets.size()];
int targetIdx = 0;
for (ForceTarget ft : myForceTargets) {
int connectorIdx = 0;
for (BodyConnector connector : mechMod.bodyConnectors()) {
if (debug) {
System.out.println(connector.getName());
System.out.println(ft.getName());
}
if (ft.getConnector() == connector) {
targetToConnectorMap[targetIdx] = connectorIdx;
targetIdx++;
}
if (connector.isEnabled() == true) {
if (debug) {
System.out.println(connector.numBilateralConstraints());
}
connectorSizes[connectorIdx] = connector.numBilateralConstraints();
connectorIdx++;
}
}
}
myForJacobian = new SparseBlockMatrix(new int[0], connectorSizes);
for (int i = 0; i < myForceTargets.size(); i++) {
ForceTarget target = myForceTargets.get(i);
// TODO: non-enabled connectors should not add to Jacobian -- need to fix
target.addForceJacobian(myForJacobian, i, targetToConnectorMap[i]);
}
if (debug) {
System.out.println("Jc = " + myForJacobian);
}
}
use of maspack.matrix.SparseBlockMatrix in project artisynth_core by artisynth.
the class MechSystemBase method writeBilateralConstraintMatrix.
public void writeBilateralConstraintMatrix(String fileName, Matrix.WriteFormat matfmt) throws IOException {
PrintWriter pw = ArtisynthIO.newIndentingPrintWriter(fileName);
SparseBlockMatrix GT = mySolver.createActiveBilateralMatrix(0);
NumberFormat fmt = new NumberFormat("%g");
GT.write(pw, fmt, matfmt);
pw.close();
}
use of maspack.matrix.SparseBlockMatrix in project artisynth_core by artisynth.
the class MechSystemBase method writeMassMatrix.
public void writeMassMatrix(String fileName, Matrix.WriteFormat matfmt) throws IOException {
updatePosState();
PrintWriter pw = ArtisynthIO.newIndentingPrintWriter(fileName);
SparseBlockMatrix M = mySolver.createActiveMassMatrix(0);
NumberFormat fmt = new NumberFormat("%g");
M.write(pw, fmt, matfmt);
pw.close();
}
use of maspack.matrix.SparseBlockMatrix in project artisynth_core by artisynth.
the class MechSystemBase method writeStiffnessMatrix.
public void writeStiffnessMatrix(String fileName, double h, Matrix.WriteFormat matfmt) throws IOException {
updatePosState();
SparseBlockMatrix K = mySolver.createActiveStiffnessMatrix(h);
PrintWriter pw = ArtisynthIO.newIndentingPrintWriter(fileName);
int size = getActiveVelStateSize();
NumberFormat fmt = new NumberFormat("%g");
K.write(pw, fmt, matfmt, size, size);
pw.close();
}
Aggregations