HcfdPath.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package com.miniframe.solverconfig.hcfd;
  2. import com.miniframe.constant.MFConstant;
  3. import com.miniframe.core.exception.BusinessException;
  4. import com.miniframe.core.ext.UtilTools;
  5. import com.miniframe.model.system.*;
  6. import com.miniframe.model.system.dao.SysFileMapper;
  7. import com.miniframe.tools.XIDateTimeUtils;
  8. import com.miniframe.tools.XIFileUtils;
  9. import java.io.*;
  10. import java.nio.channels.FileChannel;
  11. import java.nio.file.Files;
  12. import java.nio.file.Path;
  13. import java.nio.file.Paths;
  14. import java.nio.file.StandardCopyOption;
  15. import java.util.*;
  16. /**
  17. * 对执行所需要的文件进行文件夹规整已满足求解
  18. */
  19. public class HcfdPath {
  20. /**
  21. *
  22. * @param pid
  23. * @param isVolume 1 物面 2流场
  24. * @param step 步数
  25. * @return
  26. */
  27. public static List<File> getStepFiles(String pid ,String isVolume,String step) throws BusinessException{
  28. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+pid;
  29. String exePath = jobPath+ MFConstant.separator+"hcfd";
  30. String testPath = exePath+ MFConstant.separator+"test";
  31. String exeOutPath = testPath+ MFConstant.separator+"data_out";
  32. File exeOutDir = new File(exeOutPath);
  33. if(!exeOutDir.exists()){
  34. throw new BusinessException("EB4000017");
  35. }
  36. List<File> fileList =new ArrayList<>();
  37. File[] files =exeOutDir.listFiles();
  38. if(isVolume == "1") {//物面数据
  39. for (File sonFile: files) {
  40. if(sonFile.getName().indexOf("tec_volume_timestep"+step+".dat")>-1){//物面
  41. fileList.add(sonFile);
  42. }
  43. }
  44. }else{//流场数据
  45. for (File sonFile: files) {
  46. if(sonFile.getName().indexOf("boundary_timestep"+step+".dat")>-1){//流场
  47. fileList.add(sonFile);
  48. }
  49. }
  50. }
  51. return fileList;
  52. }
  53. public static List<Integer> hcfdTeps(String pid) throws BusinessException{
  54. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+pid;
  55. String exePath = jobPath+ MFConstant.separator+"hcfd";
  56. String testPath = exePath+ MFConstant.separator+"test";
  57. String exeOutPath = testPath+ MFConstant.separator+"data_out";
  58. File exeOutDir = new File(exeOutPath);
  59. if(!exeOutDir.exists()){
  60. throw new BusinessException("EB4000017");
  61. }
  62. List<Integer> steps = new ArrayList<>();
  63. File[] files =exeOutDir.listFiles();
  64. for (File sonFile: files) {
  65. if(sonFile.getName().indexOf("hcfd_tec_boundary_timestep")>-1){
  66. String stip=sonFile.getName().replace("hcfd_tec_boundary_timestep","").replace(".dat","");
  67. steps.add(Integer.valueOf(stip));
  68. }
  69. }
  70. Collections.sort(steps);
  71. return steps;
  72. }
  73. public static void hcfdCreatPath(AdiModeling modeling,
  74. AdiSolverConfig config,
  75. AdiSolverJob job ) throws IOException {
  76. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+job.getPid();
  77. System.out.println(jobPath);
  78. String exePath = jobPath+ MFConstant.separator+"hcfd";
  79. String exeInPath = exePath+ MFConstant.separator+"data_in";
  80. File exeInDir = new File(exeInPath);
  81. if(!exeInDir.exists()){
  82. exeInDir.mkdirs();
  83. }
  84. String testPath = exePath+ MFConstant.separator+"test";
  85. String exeOutPath = testPath+ MFConstant.separator+"data_out";
  86. File exeOutDir = new File(exeOutPath);
  87. if(!exeOutDir.exists()){
  88. exeOutDir.mkdirs();
  89. }
  90. SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class);
  91. SysFile nmlFile= fileMapper.selectByPrimaryKey(config.getNmlFile());
  92. fileMove(nmlFile,testPath+MFConstant.separator+"hcfd.nml");
  93. SysFile mapbcFile= fileMapper.selectByPrimaryKey(config.getMapbcFile());
  94. fileMove(mapbcFile,exeInPath+MFConstant.separator+"hcfd.mapbc");
  95. SysFile grid= fileMapper.selectByPrimaryKey(modeling.getGridFile());
  96. fileMove(grid,exeInPath+MFConstant.separator+"hcfd.ugrid");
  97. }
  98. /**
  99. * 文件移动
  100. * @param file
  101. * @param pathStr
  102. * @throws IOException
  103. */
  104. public static void fileMove(SysFile file ,String pathStr) throws IOException {
  105. Path path = Paths.get(pathStr);
  106. SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class);
  107. Files.move(Paths.get( XIFileUtils.getRootPathStr()+ MFConstant.separator+file.getFilepath()),
  108. path, StandardCopyOption.REPLACE_EXISTING);
  109. String fielRelativePath = XIFileUtils.getRelativizePathStr(path);
  110. file.setFilepath(fielRelativePath);
  111. file.setFilename(path.getFileName().toString());
  112. fileMapper.updateByPrimaryKey(file);
  113. }
  114. public static void main(String[] args) {
  115. String stip="hcfd_tec_boundary_timestep100.dat".replace("hcfd_tec_boundary_timestep","").replace(".dat","");
  116. Integer s ="hcfd_tec_boundary_timestep100.dat".indexOf("hcf2d_tec_boundary_timestep");
  117. System.out.println(s);
  118. }
  119. }