HcfdPath.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. public static List<Integer> hcfdTeps(String pid) throws Exception{
  21. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+pid;
  22. String exePath = jobPath+ MFConstant.separator+"hcfd";
  23. String testPath = exePath+ MFConstant.separator+"test";
  24. String exeOutPath = testPath+ MFConstant.separator+"data_out";
  25. File exeOutDir = new File(exeOutPath);
  26. if(!exeOutDir.exists()){
  27. throw new BusinessException("EB4000017");
  28. }
  29. List<Integer> steps = new ArrayList<>();
  30. File[] files =exeOutDir.listFiles();
  31. for (File sonFile: files) {
  32. if(sonFile.getName().indexOf("hcfd_tec_boundary_timestep")>-1){
  33. String stip=sonFile.getName().replace("hcfd_tec_boundary_timestep","").replace(".dat","");
  34. steps.add(Integer.valueOf(stip));
  35. }
  36. }
  37. Collections.sort(steps);
  38. return steps;
  39. }
  40. public static void hcfdCreatPath(AdiModeling modeling,
  41. AdiSolverConfig config,
  42. AdiSolverJob job ) throws IOException {
  43. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+job.getPid();
  44. System.out.println(jobPath);
  45. String exePath = jobPath+ MFConstant.separator+"hcfd";
  46. String exeInPath = exePath+ MFConstant.separator+"data_in";
  47. File exeInDir = new File(exeInPath);
  48. if(!exeInDir.exists()){
  49. exeInDir.mkdirs();
  50. }
  51. String testPath = exePath+ MFConstant.separator+"test";
  52. String exeOutPath = testPath+ MFConstant.separator+"data_out";
  53. File exeOutDir = new File(exeOutPath);
  54. if(!exeOutDir.exists()){
  55. exeOutDir.mkdirs();
  56. }
  57. SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class);
  58. SysFile nmlFile= fileMapper.selectByPrimaryKey(config.getNmlFile());
  59. fileMove(nmlFile,testPath+MFConstant.separator+"hcfd.nml");
  60. SysFile mapbcFile= fileMapper.selectByPrimaryKey(config.getMapbcFile());
  61. fileMove(mapbcFile,exeInPath+MFConstant.separator+"hcfd.mapbc");
  62. SysFile grid= fileMapper.selectByPrimaryKey(modeling.getGridFile());
  63. fileMove(grid,exeInPath+MFConstant.separator+"hcfd.ugrid");
  64. }
  65. /**
  66. * 文件移动
  67. * @param file
  68. * @param pathStr
  69. * @throws IOException
  70. */
  71. public static void fileMove(SysFile file ,String pathStr) throws IOException {
  72. Path path = Paths.get(pathStr);
  73. SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class);
  74. Files.move(Paths.get( XIFileUtils.getRootPathStr()+ MFConstant.separator+file.getFilepath()),
  75. path, StandardCopyOption.REPLACE_EXISTING);
  76. String fielRelativePath = XIFileUtils.getRelativizePathStr(path);
  77. file.setFilepath(fielRelativePath);
  78. file.setFilename(path.getFileName().toString());
  79. fileMapper.updateByPrimaryKey(file);
  80. }
  81. public static void main(String[] args) {
  82. String stip="hcfd_tec_boundary_timestep100.dat".replace("hcfd_tec_boundary_timestep","").replace(".dat","");
  83. Integer s ="hcfd_tec_boundary_timestep100.dat".indexOf("hcf2d_tec_boundary_timestep");
  84. System.out.println(s);
  85. }
  86. }