|
@@ -0,0 +1,786 @@
|
|
|
+package com.miniframe.solverconfig.fem;
|
|
|
+
|
|
|
+import com.miniframe.constant.MFConstant;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.lang.reflect.Array;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+public class VTK {
|
|
|
+
|
|
|
+
|
|
|
+ public static String CreateVTKFile(File dbfFile,String uuid) {
|
|
|
+ if(!dbfFile.exists()){
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ File vtkFile =new File(dbfFile.getParent()+ MFConstant.separator+uuid+".vtk");
|
|
|
+ InputStreamReader reader = null;
|
|
|
+ FileInputStream bdfInputSteam=null;
|
|
|
+ BufferedReader bfreader=null;
|
|
|
+ FileWriter writer = null;
|
|
|
+
|
|
|
+ if(vtkFile.exists()){
|
|
|
+ vtkFile.delete();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ vtkFile.createNewFile();
|
|
|
+ ArrayList<ArrayList<Integer>> cells = new ArrayList<>();
|
|
|
+ ArrayList<Integer> cellTypes = new ArrayList<>();
|
|
|
+ ArrayList<ArrayList<Float>> points = new ArrayList<>();
|
|
|
+
|
|
|
+ bdfInputSteam=new FileInputStream(dbfFile);
|
|
|
+ reader=new InputStreamReader(bdfInputSteam,"UTF-8");
|
|
|
+ bfreader=new BufferedReader(reader);
|
|
|
+ String patCQUAD = "^CQUAD.*";
|
|
|
+// String patGRID = "^GRID.*";
|
|
|
+ String line;
|
|
|
+ Integer nele =0;
|
|
|
+ Integer neln =0;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ while((line=bfreader.readLine())!=null) {//包含该行内容的字符串,不包含任何行终止符,如果已到达流末尾,则返回 null
|
|
|
+
|
|
|
+ /**
|
|
|
+ * CROD 1 1 1 2
|
|
|
+ */
|
|
|
+ if(line.indexOf("CROD")>-1){
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(3);
|
|
|
+
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+2;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else if(line.indexOf("CBAR")>-1){
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(3);
|
|
|
+
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+2;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //单元数据
|
|
|
+ // CQUAD4 1 1 6 7 16 15
|
|
|
+ // 第1列表示单元类型代号;
|
|
|
+ // 第2列表示单元编号;
|
|
|
+ // 第3列表示单元对应的材料编号(转vtk不需要此列);
|
|
|
+ // 第4列表示单元第1个节点的编号;
|
|
|
+ // 第5列表示单元第2个节点的编号;
|
|
|
+ // 第6列表示单元第3个节点的编号;
|
|
|
+ // 第7列表示单元第4个节点的编号
|
|
|
+ else if(line.indexOf("CQUAD4")>-1){
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cellst.add(tmp.get(5)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(9);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+4;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // CQUAD4 1 1 6 7 16 15 16 15
|
|
|
+ // * 12 12
|
|
|
+ else if(line.indexOf("CQUAD8")>-1){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ String line2=bfreader.readLine();
|
|
|
+ ArrayList<Integer> tmp2=patInts(line2);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cellst.add(tmp.get(5)-1);
|
|
|
+ cellst.add(tmp.get(6)-1);
|
|
|
+ cellst.add(tmp.get(7)-1);
|
|
|
+ cellst.add(tmp2.get(0)-1);
|
|
|
+ cellst.add(tmp2.get(1)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(23);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+8;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //CTRIA3 21 1 31 5 6 0. 0.
|
|
|
+ else if(line.indexOf("CTRIA3")>-1){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(5);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+3;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //CTRIA6 21 1 31 5 6 3 4 2
|
|
|
+ else if(line.indexOf("CTRIA3")>-1){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cellst.add(tmp.get(5)-1);
|
|
|
+ cellst.add(tmp.get(6)-1);
|
|
|
+ cellst.add(tmp.get(7)-1);
|
|
|
+
|
|
|
+
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(22);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+6;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //第一种
|
|
|
+ //CPENTA 1 1 1 2 8 29 30 36
|
|
|
+
|
|
|
+ //第二种
|
|
|
+ //CPENTA 1 1 1 2 8 29 30 36
|
|
|
+ // 1 1 1 2 8 29 30 36
|
|
|
+ // 1
|
|
|
+ else if(line.indexOf("CPENTA")>-1){
|
|
|
+ bfreader.mark(2000);
|
|
|
+ String cpentatype=null;
|
|
|
+ if(line.indexOf("CPENTA")>-1){
|
|
|
+ String line2= bfreader.readLine();
|
|
|
+ String sbtmp =line2.substring(0,8);
|
|
|
+ if("".equals(sbtmp.trim())){
|
|
|
+ cpentatype="two";
|
|
|
+ }else{
|
|
|
+ cpentatype="one";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bfreader.reset();
|
|
|
+ if(cpentatype.equals("one")){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cellst.add(tmp.get(5)-1);
|
|
|
+ cellst.add(tmp.get(6)-1);
|
|
|
+ cellst.add(tmp.get(7)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(13);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+6;
|
|
|
+ }else {
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cellst.add(tmp.get(5)-1);
|
|
|
+ cellst.add(tmp.get(6)-1);
|
|
|
+ cellst.add(tmp.get(7)-1);
|
|
|
+ String line2=bfreader.readLine();
|
|
|
+ ArrayList<Integer> tmp2=patInts(line2);
|
|
|
+ cellst.add(tmp2.get(0)-1);
|
|
|
+ cellst.add(tmp2.get(1)-1);
|
|
|
+ cellst.add(tmp2.get(2)-1);
|
|
|
+ cellst.add(tmp2.get(3)-1);
|
|
|
+ cellst.add(tmp2.get(4)-1);
|
|
|
+ cellst.add(tmp2.get(5)-1);
|
|
|
+ cellst.add(tmp2.get(6)-1);
|
|
|
+ cellst.add(tmp2.get(7)-1);
|
|
|
+ String line3=bfreader.readLine();
|
|
|
+ ArrayList<Integer> tmp3=patInts(line2);
|
|
|
+ cellst.add(tmp3.get(0)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(26);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+15;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //第一种
|
|
|
+ //CHEXA 320 1 163 164 173 172 244 245
|
|
|
+ // 254 253
|
|
|
+ //第二种
|
|
|
+ //CHEXA 320 1 163 164 173 172 244 245
|
|
|
+ // 254 253 163 164 173 172 244 245
|
|
|
+ // 254 253 163 164 173
|
|
|
+ else if(line.indexOf("CHEXA")>-1){
|
|
|
+ bfreader.mark(2000);
|
|
|
+ String chexatype=null;
|
|
|
+ if(line.indexOf("CHEXA")>-1){
|
|
|
+ String line2= bfreader.readLine();
|
|
|
+ ArrayList<Integer> tmp=patInts(line2);
|
|
|
+ if(tmp.size()>3){
|
|
|
+ chexatype="two";
|
|
|
+ }else{
|
|
|
+ chexatype="one";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bfreader.reset();
|
|
|
+ if("one".equals(chexatype)){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cellst.add(tmp.get(5)-1);
|
|
|
+ cellst.add(tmp.get(6)-1);
|
|
|
+ cellst.add(tmp.get(7)-1);
|
|
|
+ String line2=bfreader.readLine();
|
|
|
+ ArrayList<Integer> tmp2=patInts(line2);
|
|
|
+ cellst.add(tmp2.get(0)-1);
|
|
|
+ cellst.add(tmp2.get(1)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(12);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+8;
|
|
|
+ }else{
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cellst.add(tmp.get(5)-1);
|
|
|
+ cellst.add(tmp.get(6)-1);
|
|
|
+ cellst.add(tmp.get(7)-1);
|
|
|
+ String line2=bfreader.readLine();
|
|
|
+ ArrayList<Integer> tmp2=patInts(line2);
|
|
|
+ cellst.add(tmp2.get(0)-1);
|
|
|
+ cellst.add(tmp2.get(1)-1);
|
|
|
+ cellst.add(tmp2.get(2)-1);
|
|
|
+ cellst.add(tmp2.get(3)-1);
|
|
|
+ cellst.add(tmp2.get(4)-1);
|
|
|
+ cellst.add(tmp2.get(5)-1);
|
|
|
+ cellst.add(tmp2.get(6)-1);
|
|
|
+ cellst.add(tmp2.get(7)-1);
|
|
|
+ String line3=bfreader.readLine();
|
|
|
+ ArrayList<Integer> tmp3=patInts(line3);
|
|
|
+ cellst.add(tmp3.get(2)-1);
|
|
|
+ cellst.add(tmp3.get(3)-1);
|
|
|
+ cellst.add(tmp3.get(4)-1);
|
|
|
+ cellst.add(tmp3.get(0)-1);
|
|
|
+ cellst.add(tmp3.get(1)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(25);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+20;
|
|
|
+ }
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //第一种
|
|
|
+ //CTETRA 1 1 1 2 8 29
|
|
|
+ //第二种
|
|
|
+ //CTETRA 320 1 163 164 173 172 244 245
|
|
|
+ // 254 253 163 164
|
|
|
+ else if(line.indexOf("CTETRA")>-1){
|
|
|
+
|
|
|
+ bfreader.mark(2000);
|
|
|
+ String ctetratype=null;
|
|
|
+ if(line.indexOf("CTETRA")>-1){
|
|
|
+ String line2= bfreader.readLine();
|
|
|
+ String sbtmp =line2.substring(0,8);
|
|
|
+ if("".equals(sbtmp.trim())){
|
|
|
+ ctetratype="two";
|
|
|
+ }else{
|
|
|
+ ctetratype="one";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ bfreader.reset();
|
|
|
+ if("one".equals(ctetratype)){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cellst.add(tmp.get(5)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(10);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+4;
|
|
|
+ }else{
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cellst.add(tmp.get(5)-1);
|
|
|
+ cellst.add(tmp.get(6)-1);
|
|
|
+ cellst.add(tmp.get(7)-1);
|
|
|
+ String line2=bfreader.readLine();
|
|
|
+ ArrayList<Integer> tmp2=patInts(line2);
|
|
|
+ cellst.add(tmp2.get(0)-1);
|
|
|
+ cellst.add(tmp2.get(1)-1);
|
|
|
+ cellst.add(tmp2.get(2)-1);
|
|
|
+ cellst.add(tmp2.get(3)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(24);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+10;
|
|
|
+ }
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //CONM2 5 21 2500.
|
|
|
+ else if(line.indexOf("CONM2")>-1){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(1)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(1);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+1;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ else if(line.indexOf("TSTEP")>-1||
|
|
|
+ line.indexOf("TSTEPNL")>-1 ){
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //CBEAM 1 1 1 2
|
|
|
+ else if(line.indexOf("CBEAM")>-1){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(3);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+2;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //CBEAM3 1 1 1 2 2
|
|
|
+ else if(line.indexOf("CBEAM3")>-1){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(21);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+3;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //CONROD 1 1 1
|
|
|
+ else if(line.indexOf("CONROD")>-1){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(1)-1);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(3);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+2;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //CTUBE 1 1 1 1
|
|
|
+ else if(line.indexOf("CONROD")>-1){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(3);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+2;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //CSHEAR 1 1 1 1 1 1
|
|
|
+ else if(line.indexOf("CONROD")>-1){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cellst.add(tmp.get(5)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(9);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+4;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //第一种
|
|
|
+ //CELAS1 2 3 4
|
|
|
+ //第二种
|
|
|
+ //CELAS1 2 3 4 5 6
|
|
|
+ else if(line.indexOf("CELAS1")>-1
|
|
|
+ ||line.indexOf("CELAS2")>-1
|
|
|
+ ||line.indexOf("CDAMP1")>-1
|
|
|
+ ||line.indexOf("CDAMP2")>-1
|
|
|
+ ||line.indexOf("CMASS1")>-1
|
|
|
+ ||line.indexOf("CMASS2")>-1
|
|
|
+ ){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ if(tmp.size()>4){
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(3);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+2;
|
|
|
+ }else{
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(1);
|
|
|
+
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //第一种
|
|
|
+ //CTRIAX6 2 3 4 6 8
|
|
|
+ //第二种
|
|
|
+ //CTRIAX6 2 3 4 5 6 7 8 9
|
|
|
+ else if(line.indexOf("CTRIAX6")>-1){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ if(tmp.size()<=6){
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+
|
|
|
+
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(5);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+3;
|
|
|
+ }else{
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(4)-1);
|
|
|
+ cellst.add(tmp.get(6)-1);
|
|
|
+
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cellst.add(tmp.get(5)-1);
|
|
|
+ cellst.add(tmp.get(7)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(22);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+6;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //第一种
|
|
|
+ //CBUSH 2 3 4
|
|
|
+ //第二种
|
|
|
+ //CBUSH 2 3 4 5
|
|
|
+ else if(line.indexOf("CBUSH")>-1){
|
|
|
+ ArrayList<Integer> cellst =new ArrayList<>();
|
|
|
+ ArrayList<Integer> tmp=patInts(line);
|
|
|
+ if(tmp.size()<=3){
|
|
|
+
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(1);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+1;
|
|
|
+ }else{
|
|
|
+ cellst.add(tmp.get(2)-1);
|
|
|
+ cellst.add(tmp.get(3)-1);
|
|
|
+ cells.add(cellst);
|
|
|
+ cellTypes.add(3);
|
|
|
+ nele=nele+1;
|
|
|
+ neln=neln+1+2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(line.indexOf("EIGRL")>-1){
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(line.indexOf("SOL 153")>-1){
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(line.indexOf("SOL 159")>-1){
|
|
|
+
|
|
|
+ }
|
|
|
+ //节点数据
|
|
|
+// GRID 175 .25 .75 0.
|
|
|
+// GRID* 176 -2.98023-8 .75
|
|
|
+// * 0.
|
|
|
+ // 第1列表示节点代号;
|
|
|
+ // 第2列表示节点编号;
|
|
|
+ // 第3列表示节点的X坐标;
|
|
|
+ // 第4列表示节点的Y坐标;
|
|
|
+ // 第5列表示节点的Z坐标;
|
|
|
+ else if(line.indexOf("GRID*")>-1){
|
|
|
+ ArrayList<Float> pointst =new ArrayList<>();
|
|
|
+ ArrayList<Float> tmp=patFloats2(line);
|
|
|
+ String line2=bfreader.readLine();
|
|
|
+ ArrayList<Float> tmp2=patFloats2(line2);
|
|
|
+ pointst.add(tmp.get(1));
|
|
|
+ pointst.add(tmp.get(2));
|
|
|
+ pointst.add(tmp2.get(0));
|
|
|
+ points.add(pointst);
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(line.indexOf("GRID")>-1){
|
|
|
+ ArrayList<Float> pointst =new ArrayList<>();
|
|
|
+ ArrayList<Float> tmp=patFloats(line);
|
|
|
+ pointst.add(tmp.get(1));
|
|
|
+ pointst.add(tmp.get(2));
|
|
|
+ pointst.add(tmp.get(3));
|
|
|
+ points.add(pointst);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ writer=new FileWriter(vtkFile,true);
|
|
|
+ writer.write("# vtk DataFile Version 1.0");
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+ writer.write("Unstructured vtk Grid");
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+ writer.write("ASCII");
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+ writer.write("DATASET UNSTRUCTURED_GRID");
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+ writer.write("POINTS");
|
|
|
+ writer.write(blanks(1));
|
|
|
+ writer.write(fixedString(9,String.valueOf(points.size())));
|
|
|
+ writer.write(blanks(1));
|
|
|
+ writer.write("float");
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+
|
|
|
+ for (ArrayList<Float> point:points) {
|
|
|
+ for (int i = 0; i <point.size() ; i++) {
|
|
|
+ writer.write(blanks(5));
|
|
|
+ writer.write(fixedFloat(point.get(i)));
|
|
|
+ }
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+ }
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+
|
|
|
+ writer.write("CELLS");
|
|
|
+ writer.write(blanks(1));
|
|
|
+ writer.write(fixedString(9,nele.toString()));
|
|
|
+ writer.write(blanks(1));
|
|
|
+ writer.write(fixedString(9,neln.toString()));
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+
|
|
|
+ for (ArrayList<Integer> cell:cells) {
|
|
|
+ writer.write(fixedString(8,String.valueOf(cell.size())));
|
|
|
+ writer.write(blanks(2));
|
|
|
+ for (int i = 0; i <cell.size() ; i++) {
|
|
|
+ writer.write(fixedString(8,String.valueOf(cell.get(i))));
|
|
|
+ }
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+ }
|
|
|
+
|
|
|
+ writer.write("CELL_TYPES");
|
|
|
+ writer.write(blanks(1));
|
|
|
+ writer.write(fixedString(9,String.valueOf(cells.size())));
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+ for (Integer type:cellTypes) {
|
|
|
+ writer.write(blanks(10));
|
|
|
+ writer.write(type.toString());
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+ }
|
|
|
+ writer.write("\r\n");//换行
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ if (writer != null) {
|
|
|
+ try {
|
|
|
+ writer.close();
|
|
|
+ } catch (IOException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (reader != null) {
|
|
|
+ try {
|
|
|
+ reader.close();
|
|
|
+ } catch (IOException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (bdfInputSteam != null) {
|
|
|
+ try {
|
|
|
+ bdfInputSteam.close();
|
|
|
+ } catch (IOException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (bfreader != null) {
|
|
|
+ try {
|
|
|
+ bfreader.close();
|
|
|
+ } catch (IOException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return vtkFile.getPath();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static ArrayList<Integer> patInts(String line){
|
|
|
+ ArrayList<Integer> cells =new ArrayList<>();
|
|
|
+ for (int i = 1; i <9 ; i++) {
|
|
|
+ int min = i*8;
|
|
|
+ if(min>line.length()){
|
|
|
+ min = line.length();
|
|
|
+ }
|
|
|
+ int max = (i+1)*8;
|
|
|
+ if(max>line.length()){
|
|
|
+ max = line.length();
|
|
|
+ }
|
|
|
+ String sbtmp =line.substring(min,max);
|
|
|
+ if(!"".equals(sbtmp.trim())){
|
|
|
+ cells.add(Integer.valueOf(sbtmp.trim().replace(".","")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return cells;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * -2.98023-8 转换 -2.98023E-8
|
|
|
+ */
|
|
|
+ public static String doubeAddE(String lostEdoube){
|
|
|
+ if(lostEdoube.indexOf("e")>0||lostEdoube.indexOf("E")>0){
|
|
|
+ return lostEdoube;
|
|
|
+ }
|
|
|
+ if(lostEdoube.lastIndexOf("-")>1){
|
|
|
+ String addE ="";
|
|
|
+ addE =addE+lostEdoube.substring(0,lostEdoube.lastIndexOf("-"));
|
|
|
+ addE=addE+"E";
|
|
|
+ addE =addE+lostEdoube.substring(lostEdoube.lastIndexOf("-"));
|
|
|
+ return addE;
|
|
|
+ }
|
|
|
+ return lostEdoube;
|
|
|
+ }
|
|
|
+ public static ArrayList<Float> patFloats(String line){
|
|
|
+ ArrayList<Float> cells =new ArrayList<>();
|
|
|
+ for (int i = 1; i <9 ; i++) {
|
|
|
+ int min = i*8;
|
|
|
+ if(min>line.length()){
|
|
|
+ min = line.length();
|
|
|
+ }
|
|
|
+ int max = (i+1)*8;
|
|
|
+ if(max>line.length()){
|
|
|
+ max = line.length();
|
|
|
+ }
|
|
|
+ String sbtmp =line.substring(min,max);
|
|
|
+ if(!"".equals(sbtmp.trim())){
|
|
|
+ cells.add(strToFloat(VTK.doubeAddE(sbtmp.trim())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return cells;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * GRID* 37 -.04 -1.74846-9
|
|
|
+ * * 0.
|
|
|
+ * @param line
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ /**
|
|
|
+ * read(10,'(A8,A16,16X,2A16)')cname,chnnod,chcood2(1:2)
|
|
|
+ * read(10,'(A8,A16)')cname,chcood2(3)
|
|
|
+ */
|
|
|
+ public static ArrayList<Float> patFloats2(String line){
|
|
|
+ ArrayList<Float> cells =new ArrayList<>();
|
|
|
+ String patFloat = "(\\-?\\d+\\.?[\\d\\-\\+E]*|\\.\\d+)";
|
|
|
+ Pattern r = Pattern.compile(patFloat);
|
|
|
+ int matcher_start = 0;
|
|
|
+ Matcher m = r.matcher(line);
|
|
|
+ while (m.find(matcher_start)){
|
|
|
+// System.out.println(m.group(1));
|
|
|
+ cells.add(strToFloat(VTK.doubeAddE(m.group(1))));
|
|
|
+ matcher_start = m.end();
|
|
|
+ }
|
|
|
+ return cells;
|
|
|
+ }
|
|
|
+ public static Float strToFloat(String line){
|
|
|
+ String pat = "^\\..*";
|
|
|
+ if(Pattern.matches(pat,line)){
|
|
|
+ return Float.valueOf("0"+line);
|
|
|
+ }else{
|
|
|
+ return Float.valueOf(line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public static String fixedString(int length ,String str){
|
|
|
+ if(length>0) return String.format("%"+length+"s",str);
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+ public static String fixedFloat(float fl){
|
|
|
+ return String.format("%25f",fl);
|
|
|
+ }
|
|
|
+ public static String blanks(int length){
|
|
|
+ String t="";
|
|
|
+ if(length>0){
|
|
|
+ for (int i = 0; i <length ; i++) {
|
|
|
+ t +=" ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return t;
|
|
|
+ }
|
|
|
+ public static void main(String[] args) {
|
|
|
+// String ling =" 4.000000000000 0.500000000000 -0.500000000000";
|
|
|
+// System.out.println(ling.length());
|
|
|
+// System.out.println(String.format("%25.12f",1.51597));
|
|
|
+// String tmp ="CELL";
|
|
|
+// int nele=12;
|
|
|
+// int melo =1212;
|
|
|
+// System.out.print(VTK.fixedString(0,tmp));
|
|
|
+// System.out.print(VTK.fixedString(0," "));
|
|
|
+// System.out.print(VTK.fixedString(9,String.valueOf(nele)));
|
|
|
+// System.out.print(VTK.fixedString(0," "));
|
|
|
+// System.out.print(VTK.fixedString(9,String.valueOf(melo)));
|
|
|
+// System.out.println(VTK.patInts("CROD 1 1 1 2"));
|
|
|
+// System.out.println(VTK.patFloats("GRID 1735 13.6682 20.9328 24."));
|
|
|
+
|
|
|
+// String tmp="GRID 434 -33.333325. 21.6667";
|
|
|
+// ArrayList<Float> cells =new ArrayList<>();
|
|
|
+// for (int i = 1; i <9 ; i++) {
|
|
|
+// int min = i*8;
|
|
|
+// if(min>tmp.length()){
|
|
|
+// min = tmp.length();
|
|
|
+// }
|
|
|
+// int max = (i+1)*8;
|
|
|
+// if(max>tmp.length()){
|
|
|
+// max = tmp.length();
|
|
|
+// }
|
|
|
+// String sbtmp =tmp.substring(min,max);
|
|
|
+// if(!"".equals(sbtmp.trim())){
|
|
|
+// cells.add(strToFloat(VTK.doubeAddE(sbtmp.trim())));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// System.out.println(cells);
|
|
|
+// System.out.println( tmp.substring(47,47));
|
|
|
+// System.out.println( tmp.substring(9,17));
|
|
|
+// System.out.println( tmp.substring(17,15));
|
|
|
+// tmp.substring(tmp.indexOf(".")).length()
|
|
|
+// String line ="CQUAD 1 1 6 7 16 15";
|
|
|
+// String patCQUAD = "^CQUAD4.*";
|
|
|
+// String patGRID = "^GRID/*.*";
|
|
|
+// System.out.println("GRID 359 .498624 24.995 4.5".indexOf("GRID*"));
|
|
|
+//// System.out.println(Pattern.matches(patCQUAD,line));
|
|
|
+//
|
|
|
+//
|
|
|
+// String line2 ="GRID* 176 -2.98023-8 .75";
|
|
|
+// System.out.println(Pattern.matches(patGRID,line2));
|
|
|
+// System.out.println( VTK.doubeAddE(" -2.980238"));
|
|
|
+
|
|
|
+// String line =".5";
|
|
|
+// String patCQUAD = "^\\..*";
|
|
|
+
|
|
|
+// System.out.println(Pattern.matches(patCQUAD,line));
|
|
|
+ File file =new File("D:\\FEMLab\\ADI.SimWork4.0\\FEMLab\\data\\transient analysis\\2.3_wing-transient.bdf");
|
|
|
+ VTK.CreateVTKFile(file,"tt");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|