SolverFemOrderUtil.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package com.caesolver.server;
  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.nio.file.Files;
  6. import java.nio.file.Path;
  7. import java.nio.file.Paths;
  8. import java.util.List;
  9. import java.util.regex.Matcher;
  10. import java.util.regex.Pattern;
  11. import java.util.stream.Collectors;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.stereotype.Component;
  14. @Component
  15. public class SolverFemOrderUtil {
  16. @Value("${FEM.workdir}")
  17. private String fem_workdir;
  18. @Value("${FEM.exePath}")
  19. private String exePath;
  20. @Value("${FEM.postPath}")
  21. private String postPath;
  22. @Value("${FEM.rootPath}")
  23. private String rootPath;
  24. public String createOrder(String projectId) throws IOException {
  25. String jobOrder="";
  26. if(this.isWindows()) {//windows
  27. jobOrder=createWindowBat(projectId);
  28. }else {//Linux
  29. // jobOrder=createUnixexe(projectId);
  30. }
  31. return jobOrder;
  32. }
  33. private String getUgriName(String flow_dir) {
  34. String short_1=flow_dir.substring(0, flow_dir.length()-1);
  35. short_1.lastIndexOf("/");
  36. String ugrname =short_1.substring(short_1.lastIndexOf("/")+1,short_1.length());
  37. return ugrname;
  38. }
  39. /**
  40. * 创建 windows 下bat 执行文件
  41. * @param caeProject
  42. * @param reader
  43. * @return
  44. * @throws IOException
  45. */
  46. private String createWindowBat(String projectId) throws IOException {
  47. Path pFilePaths = Files.walk(Paths.get(this.fem_workdir+"/"+projectId))
  48. .filter(path -> !path.toFile().isDirectory())
  49. .filter(path->path.endsWith("fem_analysis.in"))
  50. .collect(Collectors.toList()).get(0);
  51. String flow_dir =pFilePaths.toString().replace("fem_analysis.in", "").replace("\\", "/");
  52. String flow_wind_dir =flow_dir;
  53. Path dbfPath = Files.walk(Paths.get(this.fem_workdir+"/"+projectId))
  54. .filter(path -> !path.toFile().isDirectory())
  55. .filter(path-> path.toString().endsWith(".bdf"))
  56. .collect(Collectors.toList()).get(0);
  57. String dateInDbf =dbfPath.toString().replace("\\", "/");
  58. String gridname =getUgriName(flow_dir);
  59. String dateOutFE =flow_dir+"data_out/"+gridname+"_FE.rst";
  60. String dateOutFENS =flow_dir+"data_out/"+gridname+"_FE_NS.rst";
  61. String dateOutTransient=flow_dir+"data_out/"+"dynamicResponse-transient";
  62. File batFile = new File(flow_dir+ "fem.bat");
  63. FileWriter writer =null;
  64. try {
  65. if (batFile.exists()) {
  66. batFile.delete();
  67. }
  68. batFile.createNewFile();
  69. writer = new FileWriter(batFile,true);
  70. writer.write(rootPath+":");
  71. writer.write("\r\n");//换行
  72. writer.write("cd "+flow_wind_dir);
  73. writer.write("\r\n");//换行
  74. writer.write(exePath+" -p "+"\""+flow_wind_dir+"\"" +" -c fem_analysis.in");
  75. writer.write("\r\n");//换行
  76. writer.write(postPath +" "+dateInDbf+" "+dateOutFE+" "+dateOutFENS+" "+dateOutTransient);
  77. writer.write("\r\n");//换行
  78. writer.close();
  79. }catch (Exception o){
  80. o.printStackTrace();
  81. }finally {
  82. if (writer != null) {
  83. try {
  84. writer.close();
  85. } catch (IOException e1) {
  86. e1.printStackTrace();
  87. }
  88. }
  89. }
  90. return flow_wind_dir+"fem.bat";
  91. }
  92. private boolean isWindows() {
  93. return System.getProperty("os.name").toUpperCase().indexOf("WINDOWS")>=0?true:false;
  94. }
  95. }