package com.miniframe.solverconfig.fem; import com.miniframe.constant.MFConstant; import com.miniframe.core.exception.BusinessException; import com.miniframe.core.ext.UtilTools; import com.miniframe.model.system.AdiModeling; import com.miniframe.model.system.AdiSolverConfig; import com.miniframe.model.system.AdiSolverJob; import com.miniframe.model.system.SysFile; import com.miniframe.model.system.dao.SysFileMapper; import com.miniframe.tools.XIFileUtils; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * 对执行所需要的文件进行文件夹规整已满足求解 */ public class FEMPath { /** * * @param pid * @param step 步数 * @return */ public static List getStepFiles(String pid , String step) throws BusinessException { String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+pid; String exePath = jobPath+ MFConstant.separator+"fem"; String exeOutPath = exePath+ MFConstant.separator+"data_out"; File exeOutDir = new File(exeOutPath); if(!exeOutDir.exists()){ throw new BusinessException("EB4000017"); } List fileList =new ArrayList<>(); File[] files =exeOutDir.listFiles(); for (File sonFile: files) { if(sonFile.getName().indexOf("dynamicResponse-transient"+step+".vtk")>-1){ fileList.add(sonFile); } } return fileList; } public static List femTeps(String pid) throws BusinessException{ String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+pid; String exePath = jobPath+ MFConstant.separator+"fem"; String exeOutPath = exePath+ MFConstant.separator+"data_out"; File exeOutDir = new File(exeOutPath); if(!exeOutDir.exists()){ throw new BusinessException("EB4000017"); } List steps = new ArrayList<>(); File[] files =exeOutDir.listFiles(); for (File sonFile: files) { if(!"dynamicResponse-transient.vtk".equals(sonFile.getName()) &&sonFile.getName().indexOf("dynamicResponse-transient")>-1){ String stip=sonFile.getName().replace("dynamicResponse-transient","").replace(".vtk",""); steps.add(Integer.valueOf(stip)); } } Collections.sort(steps); return steps; } public static void femCreatePath(AdiModeling modeling, AdiSolverConfig config, AdiSolverJob job ) throws IOException { String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+job.getPid(); System.out.println(jobPath); String exePath = jobPath+ MFConstant.separator+"fem"; String exeInPath = exePath+ MFConstant.separator+"data_in"; File exeInDir = new File(exeInPath); if(!exeInDir.exists()){ exeInDir.mkdirs(); } String exeOutPath = exePath+ MFConstant.separator+"data_out"; File exeOutDir = new File(exeOutPath); if(!exeOutDir.exists()){ exeOutDir.mkdirs(); } SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class); SysFile nmlFile= fileMapper.selectByPrimaryKey(config.getNmlFile()); fileMove(nmlFile,exePath+MFConstant.separator+"fem_analysis.in"); // SysFile mapbcFile= fileMapper.selectByPrimaryKey(config.getMapbcFile()); // fileMove(mapbcFile,exeInPath+MFConstant.separator+"fem.bdf"); SysFile grid= fileMapper.selectByPrimaryKey(modeling.getFemGridFile()); fileMove(grid,exeInPath+MFConstant.separator+"fem.bdf"); } /** * 文件移动 * @param file * @param pathStr * @throws IOException */ public static void fileMove(SysFile file ,String pathStr) throws IOException { Path path = Paths.get(pathStr); SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class); Files.move(Paths.get( XIFileUtils.getRootPathStr()+ MFConstant.separator+file.getFilepath()), path, StandardCopyOption.REPLACE_EXISTING); String fielRelativePath = XIFileUtils.getRelativizePathStr(path); file.setFilepath(fielRelativePath); file.setFilename(path.getFileName().toString()); fileMapper.updateByPrimaryKey(file); } }