use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class DoubleField method initialize.
private void initialize(String fmtStr) {
myFmt = new NumberFormat(fmtStr);
myTextField.setHorizontalAlignment(JTextField.RIGHT);
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class Main method saveModelFile.
public void saveModelFile(File file, String fmtStr) throws IOException {
RootModel root = getRootModel();
if (root != null) {
IndentingPrintWriter pw = ArtisynthIO.newIndentingPrintWriter(file);
if (!root.getClass().isAssignableFrom(RootModel.class)) {
pw.println(ClassAliases.getAliasOrName(root.getClass()));
}
root.write(pw, new NumberFormat(fmtStr), root);
pw.close();
}
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class FemModel3d method printANSYSElements.
/**
* Prints the elements of this FEM in a format which is compatible with
* ANSYS.
*
* @param pw
* PrintWriter to which elements are written
*/
public void printANSYSElements(PrintWriter pw) {
NumberFormat dfmt = new NumberFormat("%6d");
int femIdx = 1;
for (FemElement3d e : myElements) {
FemNode3d[] nodes = e.getNodes();
int[] nums = new int[13];
if (e instanceof TetElement) {
int idx0 = myNodes.indexOf(nodes[0]) + 1;
int idx1 = myNodes.indexOf(nodes[1]) + 1;
int idx2 = myNodes.indexOf(nodes[2]) + 1;
int idx3 = myNodes.indexOf(nodes[3]) + 1;
nums[0] = idx0;
nums[1] = idx1;
nums[2] = idx2;
nums[3] = idx2;
nums[4] = idx3;
nums[5] = idx3;
nums[6] = idx3;
nums[7] = idx3;
} else {
throw new IllegalArgumentException("Unknown element type: " + e.getClass().getName());
}
for (int i = 8; i < 12; i++) {
nums[i] = 1;
}
nums[12] = 0;
for (int i = 0; i < nums.length; i++) {
pw.print(dfmt.format(nums[i]));
}
pw.println(" " + femIdx);
femIdx++;
}
pw.flush();
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class AnsysWriter method writeElemFile.
public static void writeElemFile(FemModel3d fem, PrintWriter elemWriter) {
NumberFormat dfmt = new NumberFormat("%6d");
int nodeOffset = (fem.getByNumber(0) == null) ? 0 : 1;
int elemOffset = (fem.getElementByNumber(0) == null) ? 0 : 1;
for (FemElement3d e : fem.getElements()) {
FemNode3d[] nodes = e.getNodes();
int[] firstRow = new int[13];
int[] secondRow = null;
if (e instanceof TetElement) {
firstRow[0] = nodes[0].getNumber() + nodeOffset;
firstRow[1] = nodes[1].getNumber() + nodeOffset;
firstRow[2] = nodes[2].getNumber() + nodeOffset;
firstRow[3] = nodes[3].getNumber() + nodeOffset;
firstRow[4] = 0;
firstRow[5] = 0;
firstRow[6] = 0;
firstRow[7] = 0;
} else if (e instanceof PyramidElement) {
firstRow[0] = nodes[0].getNumber() + nodeOffset;
firstRow[1] = nodes[1].getNumber() + nodeOffset;
firstRow[2] = nodes[2].getNumber() + nodeOffset;
firstRow[3] = nodes[3].getNumber() + nodeOffset;
firstRow[4] = nodes[4].getNumber() + nodeOffset;
firstRow[5] = nodes[4].getNumber() + nodeOffset;
firstRow[6] = nodes[4].getNumber() + nodeOffset;
firstRow[7] = nodes[4].getNumber() + nodeOffset;
} else if (e instanceof WedgeElement) {
firstRow[0] = nodes[0].getNumber() + nodeOffset;
firstRow[1] = nodes[1].getNumber() + nodeOffset;
firstRow[2] = nodes[2].getNumber() + nodeOffset;
firstRow[3] = nodes[2].getNumber() + nodeOffset;
firstRow[4] = nodes[3].getNumber() + nodeOffset;
firstRow[5] = nodes[4].getNumber() + nodeOffset;
firstRow[6] = nodes[5].getNumber() + nodeOffset;
firstRow[7] = nodes[5].getNumber() + nodeOffset;
} else if (e instanceof HexElement) {
firstRow[0] = nodes[3].getNumber() + nodeOffset;
firstRow[1] = nodes[2].getNumber() + nodeOffset;
firstRow[2] = nodes[1].getNumber() + nodeOffset;
firstRow[3] = nodes[0].getNumber() + nodeOffset;
firstRow[4] = nodes[7].getNumber() + nodeOffset;
firstRow[5] = nodes[6].getNumber() + nodeOffset;
firstRow[6] = nodes[5].getNumber() + nodeOffset;
firstRow[7] = nodes[4].getNumber() + nodeOffset;
} else if (e instanceof QuadtetElement) {
firstRow[0] = nodes[0].getNumber() + nodeOffset;
firstRow[1] = nodes[1].getNumber() + nodeOffset;
firstRow[2] = nodes[2].getNumber() + nodeOffset;
firstRow[3] = nodes[3].getNumber() + nodeOffset;
firstRow[4] = nodes[4].getNumber() + nodeOffset;
firstRow[5] = nodes[5].getNumber() + nodeOffset;
firstRow[6] = nodes[6].getNumber() + nodeOffset;
firstRow[7] = nodes[7].getNumber() + nodeOffset;
secondRow = new int[2];
secondRow[0] = nodes[8].getNumber() + nodeOffset;
secondRow[1] = nodes[9].getNumber() + nodeOffset;
} else if (e instanceof QuadhexElement) {
firstRow[0] = nodes[3].getNumber() + nodeOffset;
firstRow[1] = nodes[2].getNumber() + nodeOffset;
firstRow[2] = nodes[1].getNumber() + nodeOffset;
firstRow[3] = nodes[0].getNumber() + nodeOffset;
firstRow[4] = nodes[7].getNumber() + nodeOffset;
firstRow[5] = nodes[6].getNumber() + nodeOffset;
firstRow[6] = nodes[5].getNumber() + nodeOffset;
firstRow[7] = nodes[4].getNumber() + nodeOffset;
secondRow = new int[12];
secondRow[0] = nodes[10].getNumber() + nodeOffset;
secondRow[1] = nodes[9].getNumber() + nodeOffset;
secondRow[2] = nodes[8].getNumber() + nodeOffset;
secondRow[3] = nodes[11].getNumber() + nodeOffset;
secondRow[4] = nodes[14].getNumber() + nodeOffset;
secondRow[5] = nodes[13].getNumber() + nodeOffset;
secondRow[6] = nodes[12].getNumber() + nodeOffset;
secondRow[7] = nodes[15].getNumber() + nodeOffset;
secondRow[8] = nodes[19].getNumber() + nodeOffset;
secondRow[9] = nodes[18].getNumber() + nodeOffset;
secondRow[10] = nodes[17].getNumber() + nodeOffset;
secondRow[11] = nodes[16].getNumber() + nodeOffset;
} else {
System.out.println("Ignoring unknown element type: " + e.getClass().getName());
continue;
}
int[] elemAttr = fem.ansysElemProps.get(e);
if (elemAttr != null) {
for (int i = 8; i < 13; i++) {
firstRow[i] = elemAttr[i - 8];
}
} else {
for (int i = 8; i < 12; i++) {
firstRow[i] = 1;
}
firstRow[12] = 0;
}
for (int i = 0; i < firstRow.length; i++) {
elemWriter.print(dfmt.format(firstRow[i]));
}
int elemNum = e.getNumber() + elemOffset;
elemWriter.println(" " + elemNum);
if (secondRow != null) {
for (int j = 0; j < secondRow.length; j++) {
elemWriter.print(dfmt.format(secondRow[j]));
}
elemWriter.println();
secondRow = null;
}
}
elemWriter.close();
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class UCDWriter method write.
public static void write(FemModel3d fem, PrintWriter writer) {
NumberFormat fmt = new NumberFormat("%10g");
NumberFormat dfmt = new NumberFormat("%6d");
ComponentList<FemNode3d> nodeList = fem.getNodes();
ComponentList<FemElement3d> elementList = fem.getElements();
writer.println(nodeList.size() + " " + elementList.size() + " 0 0 0");
for (FemNode3d n : nodeList) {
writer.print(n.getNumber());
writer.println(" " + n.getPosition().toString(fmt));
}
for (FemElement3d e : elementList) {
FemNode3d[] nodes = e.getNodes();
int[] elemNodes = null;
String elemType;
if (e instanceof TetElement) {
elemNodes = new int[4];
elemNodes[0] = nodes[0].getNumber();
elemNodes[1] = nodes[1].getNumber();
elemNodes[2] = nodes[2].getNumber();
elemNodes[3] = nodes[3].getNumber();
elemType = "tet";
} else if (e instanceof HexElement) {
elemNodes = new int[8];
elemNodes[0] = nodes[1].getNumber();
elemNodes[1] = nodes[2].getNumber();
elemNodes[2] = nodes[3].getNumber();
elemNodes[3] = nodes[4].getNumber();
elemNodes[4] = nodes[5].getNumber();
elemNodes[5] = nodes[6].getNumber();
elemNodes[6] = nodes[7].getNumber();
elemNodes[7] = nodes[8].getNumber();
elemType = "hex";
} else {
System.out.println("Unknown element type: " + e.getClass().getName());
continue;
}
writer.print(e.getNumber() + " 0 " + elemType + " ");
for (int i = 0; i < elemNodes.length; i++) {
writer.print(dfmt.format(elemNodes[i]));
}
writer.println();
}
}
Aggregations