huangxingxing il y a 6 mois
Parent
commit
5f404646f9

+ 87 - 72
src/main/java/com/miniframe/bisiness/mdo/MDO0039Service.java

@@ -20,6 +20,10 @@ import com.miniframe.model.mdo.dao.MdoProComvalMapper;
 import com.miniframe.model.mdo.dao.MdoProPythonMapper;
 import com.miniframe.model.mdo.dao.MdoProjectMapper;
 import com.miniframe.modo.temp.TemplateGenerator;
+import com.miniframe.modo.temp.cpacs.CpacsVo;
+import com.miniframe.modo.temp.problem.ProblemVo;
+import com.miniframe.modo.temp.problem.Solver;
+import com.miniframe.modo.temp.problem.WorkflowVo;
 import com.miniframe.tools.XIFileUtils;
 import com.miniframe.tools.XiJsonUtil;
 import com.miniframe.tools.docker.DockerExe;
@@ -45,9 +49,7 @@ public class MDO0039Service extends MDO0039BaseModel implements ExecProcessFlow
 		if(pro==null){
 			throw new BusinessException("MDO000001");
 		}
-		if(StringUtil.isEmpty(pro.getStype())){
-			throw new BusinessException("MDO000011");
-		}
+
 		//创建文件路径
 		XIFileUtils.mkdir(LogService.BPATH);
 		XIFileUtils.mkdir(LogService.BPATH+"/"+pro.getId());
@@ -65,15 +67,90 @@ public class MDO0039Service extends MDO0039BaseModel implements ExecProcessFlow
 		//日志文件清空
 		LogService.clearLog(pid);
 
+		ProblemVo provo = TemplateGenerator.findProblemVo(pid);
+
+		CpacsVo cspvo = TemplateGenerator.getCpacsVo(pid);
+
+		WorkflowVo wvo = TemplateGenerator.getWorkflowVo(pid);
 		//创建cpace
-		String cpacsPath =TemplateGenerator.createcCpacsXml(pid);
+		String cpacsPath =TemplateGenerator.createcCpacsXml(pid,cspvo);
 		//创建workflow
-		String workflowPath =TemplateGenerator.createcWorkflowXml(pid);
-		//创建problem.xml
-		TemplateGenerator.createProblemXml(pid);
-		//创建run.py
-		TemplateGenerator.createRunpy(pid);
-		run(pid,pro.getStype());
+		String workflowPath =TemplateGenerator.createcWorkflowXml(pid,wvo);
+
+		if(cpacsPath!=null&&workflowPath!=null){
+			List<Solver> solvers =new ArrayList<>();
+			Solver solver =new Solver();
+			solver.setWorkflowPath(workflowPath);
+			solver.setCpacsPath(cpacsPath);
+			solvers.add(solver);
+			provo.setSolvers(solvers);
+
+			//创建problem.xml
+			TemplateGenerator.createProblemXml(pid,provo);
+			//创建run.py
+			TemplateGenerator.createRunpy2(pid);
+			run2(pid);
+		}else{
+			if(StringUtil.isEmpty(pro.getStype())){
+				throw new BusinessException("MDO000011");
+			}
+			//TODO 目前只有函数求解器
+			MdoProjectMapper pDao = UtilTools.getBean(MdoProjectMapper.class);
+			MdoProject p = pDao.selectByPrimaryKey(pid);
+			List<Solver> solvers =new ArrayList<>();
+			//ptyon py.py 文件 写入
+			String ppPath=TemplateGenerator.writePython(pid);
+			if(!StringUtil.isEmpty(ppPath)){
+				Solver solver =new Solver();
+				solver.setPythonPath(ppPath);
+				solver.setStype(p.getStype());
+				solvers.add(solver);
+			}
+			provo.setSolvers(solvers);
+			//创建problem.xml
+			TemplateGenerator.createProblemXml(pid,provo);
+			//创建run.py
+			TemplateGenerator.createRunpy(pid);
+			run(pid,pro.getStype());
+		}
+
+
+	}
+
+	private void run2(String pid) {
+		LogService.addLog(pid,"求解——————————————————开始");
+		DockerExe.stopDocker2(pid);
+		DockerExe.runMdo2(pid);
+		CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()-> {try {
+			DockerExe.getDockerLogs(pid,new ResultCallback.Adapter<Frame>() {
+				@Override
+				public void onNext(Frame frame) {
+					String line =new String(frame.getPayload());
+					LogService.addLog(pid,line);
+					System.out.print(new String(frame.getPayload()));
+					super.onNext(frame);
+				}
+
+				@Override
+				public void onError(Throwable throwable) {
+					System.err.println("日志获取失败");
+					throwable.printStackTrace();
+					super.onError(throwable);
+				}
+				@Override
+				public void onComplete() {
+					System.out.println("日志获取完成");
+					super.onComplete();
+				}
+			});
+			LogService.addLog(pid,"求解——————————————————成功");
+		} catch (Exception e) {
+			LogService.addLog(pid,"求解——————————————————失败");
+
+			e.printStackTrace();
+		}
+			return null;
+		});
 	}
 
 	//异步执行
@@ -89,76 +166,16 @@ public class MDO0039Service extends MDO0039BaseModel implements ExecProcessFlow
 		DockerExe.stopDocker(pid);
 		DockerExe.runMdo(pid);
 
-		// ------20250210 保存 日志  弃用
-		List<MdoProComval> comvals =new ArrayList<>();
-		final List<String>[] vals = new List[]{new ArrayList<>()};
-		final boolean[] flag = {true};//步数是否结束
-		final int[] valNSiz = {0};
-		//-------20250210 保存 日志  弃用
-
 		CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()-> {try {
 			DockerExe.getDockerLogs(pid,new ResultCallback.Adapter<Frame>() {
 				@Override
 				public void onNext(Frame frame) {
-//					LogService.addLog(pid,new String(frame.getPayload()));
 					String line =new String(frame.getPayload());
 					LogService.addLog(pid,line);
 					System.out.print(new String(frame.getPayload()));
-//					saveLog(line);
 					super.onNext(frame);
 				}
 
-				/**
-				 * 20250210 保存 日志  弃用
-				 * @param line
-				 */
-				private void saveLog(String line) {
-					//存储每步数据
-					if("Forrester".equals(stype)||"Branin".equals(stype)||"Rastrigin".equals(stype)
-							||"Rosenbrock".equals(stype)||"G9".equals(stype)
-					){
-						if(line.startsWith("[")){
-							MdoProComval v=null;
-							if(comvals.isEmpty()){
-								v= new MdoProComval();
-								comvals.add(v);
-							}
-							if(flag[0]){//没有结束
-								v=comvals.get(comvals.size()-1);
-							}else{
-								v= new MdoProComval();
-								comvals.add(v);
-							}
-							String[] valts = line.replace("[","").replace("]","").split(" ");
-							valNSiz[0] = valts.length;
-							List<String> valtsl = Arrays.asList(valts);
-							vals[0].addAll(valtsl);
-						}
-						if(line.startsWith(" gen =")){
-							String step = line.split("=")[1].trim();
-							MdoProComval comval=comvals.get(comvals.size()-1);;
-							comval.setId(UtilTools.getUUid());
-							comval.setPid(pid);
-							comval.setStep(step);
-							List<String> x_nL = new ArrayList<>();
-							for (int i = 0; i < valNSiz[0]; i++) {
-								x_nL.add("x"+i);
-							}
-							comval.setVars(x_nL.toString().replace("[","").replace("]",""));
-							comval.setVals(vals[0].toString().replace("[","").replace("]","").replace(","," "));
-							comvalDao.insert(comval);
-							vals[0] = new ArrayList<>();
-							flag[0] =false;
-
-							try {
-								LogService.addLog(pid, XiJsonUtil.objectToJson(comval));
-							} catch (JsonProcessingException e) {
-								e.printStackTrace();
-							}
-						}
-					}
-				}
-
 				@Override
 				public void onError(Throwable throwable) {
 					System.err.println("日志获取失败");
@@ -171,11 +188,9 @@ public class MDO0039Service extends MDO0039BaseModel implements ExecProcessFlow
 					super.onComplete();
 				}
 			});
-			saveNsga2_history2(pid, stype, comvalDao);
 			LogService.addLog(pid,"求解——————————————————成功");
 		} catch (Exception e) {
 			LogService.addLog(pid,"求解——————————————————失败");
-
 			e.printStackTrace();
 		}
 			return null;

+ 118 - 68
src/main/java/com/miniframe/modo/temp/TemplateGenerator.java

@@ -41,13 +41,35 @@ public class TemplateGenerator {
         fileWriter.write(writer.toString());
         fileWriter.close();
     }
+    /**
+     * 创建 执行文件
+     * @param pid
+     * @throws IOException
+     * @throws TemplateException
+     */
+    public static void createRunpy2(String pid) throws IOException, TemplateException {
+        Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
+        // 设置模板所在目录
+        cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
+        // 获取模板对象
+        Template template = cfg.getTemplate("run2.ftl");
+        // 定义数据模型(Map)
+        Map<String, Object> dataModel = new HashMap<>();
+        dataModel.put("problemPath",LogService.BPATH + "/" + pid + "/in/problem.xml");
+        // 将数据模型传入模板进行处理
+        StringWriter writer = new StringWriter();
+        template.process(dataModel, writer);
+        FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/run.py");
+        fileWriter.write(writer.toString());
+        fileWriter.close();
+    }
     /**
      * 创建problem.xml
      * @param pid
      * @throws IOException
      * @throws TemplateException
      */
-    public static void createProblemXml(String pid) throws IOException, TemplateException {
+    public static void createProblemXml(String pid,ProblemVo vo) throws IOException, TemplateException {
         //Problem.xml 写入
         Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
         // 设置模板所在目录
@@ -57,7 +79,7 @@ public class TemplateGenerator {
         // 定义数据模型(Map)
         Map<String, Object> dataModel = new HashMap<>();
 
-        ProblemVo vo = findProblemVo(pid);
+//        ProblemVo vo = findProblemVo(pid);
 
         dataModel.put("vo",vo);
 //        dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
@@ -87,8 +109,7 @@ public class TemplateGenerator {
         vo.setSurro(surro);
         MdoProGrad grad = findGrad(pid);
         vo.setGrad(grad);
-        List<Solver> solvers = findSolvers(pid);
-        vo.setSolvers(solvers);
+
         return vo;
     }
 
@@ -96,8 +117,11 @@ public class TemplateGenerator {
      * TODO 创建 cpacsxml
      * @return
      */
-    public static String createcCpacsXml(String pid)  {
+    public static String createcCpacsXml(String pid,CpacsVo vo)  {
         try {
+            if(vo ==null){
+                return null;
+            }
             Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
             // 设置模板所在目录
             cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
@@ -105,20 +129,46 @@ public class TemplateGenerator {
             Template template = cfg.getTemplate("cpacs.ftl");
             // 定义数据模型(Map)
             Map<String, Object> dataModel = new HashMap<>();
-            CpacsVo vo = new CpacsVo();
-            HeaderVo header =new HeaderVo();
-            header.setName(pid);
-            header.setTimestamp(new Date());
-            vo.setHeader(header);
-
-            MdoProXfoil xfoil = findXfoil(pid);
-            vo.setXfoil(xfoil);
-            MdoProAdflow adflow = findAdflow(pid);
-            vo.setAdflow(adflow);
-            //不用生成
-            if(xfoil==null&& adflow==null){
-                return "";
-            }
+
+            dataModel.put("vo",vo);
+            //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
+            // 将数据模型传入模板进行处理
+            StringWriter writer = new StringWriter();
+            template.process(dataModel, writer);
+            FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/cpacs.xml");
+            fileWriter.write(writer.toString());
+            fileWriter.close();
+            return  LogService.BPATH + "/" + pid + "/in/cpacs.xml";
+        }catch (Exception e){
+            return null;
+        }
+    }
+    public static WorkflowVo getWorkflowVo(String pid) {
+        WorkflowVo vo = new WorkflowVo();
+        MdoProXfoil xfoil = findXfoil(pid);
+        MdoProAdflow adflow = findAdflow(pid);
+        //不用生成
+        if(xfoil==null&& adflow==null){
+            return null;
+        }
+        return vo;
+    }
+    public static CpacsVo getCpacsVo(String pid) {
+        CpacsVo vo = new CpacsVo();
+        HeaderVo header =new HeaderVo();
+        header.setName(pid);
+        header.setTimestamp(new Date());
+        vo.setHeader(header);
+
+        MdoProXfoil xfoil = findXfoil(pid);
+        vo.setXfoil(xfoil);
+        MdoProAdflow adflow = findAdflow(pid);
+        vo.setAdflow(adflow);
+        //不用生成
+        if(xfoil==null&& adflow==null){
+            return null;
+        }
+        if(xfoil!=null){
             List<MdoProInoutPara> xInoutList = findMdoProInoutParas(pid, xfoil.getId());
             XfoilInVo xinvo = new XfoilInVo();
             // alpha mach reynolds
@@ -134,8 +184,8 @@ public class TemplateGenerator {
             xoutvo.setXtr_upper(getValByParaListAndCode(xInoutList,"xtr_upper"));
             xoutvo.setXtr_lower(getValByParaListAndCode(xInoutList,"xtr_lower"));
             vo.setXoutvo(xoutvo);
-
-
+        }
+        if(adflow!=null){
             List<MdoProInoutPara> adInoutList = findMdoProInoutParas(pid, adflow.getId());
             AdflowInVo adinvo = new AdflowInVo();
             adinvo.setMode(getValByParaListAndCode(adInoutList,"mode"));
@@ -151,24 +201,16 @@ public class TemplateGenerator {
             adoutvo.setCd(getValByParaListAndCode(adInoutList,"cd"));
             adoutvo.setCmz(getValByParaListAndCode(adInoutList,"cmz"));
             vo.setAdoutvo(adoutvo);
+        }
 
-            MdoProCst cst = findCst(pid);
-            vo.setCst(cst);
-            MdoProFfd ffd = getFfd(pid);
-            vo.setFfd(ffd);
 
-            dataModel.put("vo",vo);
-            //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
-            // 将数据模型传入模板进行处理
-            StringWriter writer = new StringWriter();
-            template.process(dataModel, writer);
-            FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/cpacs.xml");
-            fileWriter.write(writer.toString());
-            fileWriter.close();
-            return  LogService.BPATH + "/" + pid + "/in/cpacs.xml";
-        }catch (Exception e){
-            return null;
-        }
+
+
+        MdoProCst cst = findCst(pid);
+        vo.setCst(cst);
+        MdoProFfd ffd = getFfd(pid);
+        vo.setFfd(ffd);
+        return vo;
     }
 
     private static List<MdoProInoutPara> findMdoProInoutParas(String pid, String fatherid) {
@@ -200,7 +242,7 @@ public class TemplateGenerator {
         xsc.andCheckedEqualTo(1);
         List<MdoProFfd> xList = xdao.selectByExample(xsb);
         MdoProFfd ffd =null;
-        if(xList!=null&&xList.isEmpty()){
+        if(xList!=null&&!xList.isEmpty()){
             ffd=xList.get(0);
         }
         return ffd;
@@ -214,7 +256,7 @@ public class TemplateGenerator {
         xsc.andCheckedEqualTo(1);
         List<MdoProCst> xList = xdao.selectByExample(xsb);
         MdoProCst cst =null;
-        if(xList!=null&&xList.isEmpty()){
+        if(xList!=null&&!xList.isEmpty()){
             cst=xList.get(0);
         }
         return cst;
@@ -228,7 +270,7 @@ public class TemplateGenerator {
         xsc.andCheckedEqualTo(1);
         List<MdoProAdflow> xList = xdao.selectByExample(xsb);
         MdoProAdflow adflow =null;
-        if(xList!=null&&xList.isEmpty()){
+        if(xList!=null&&!xList.isEmpty()){
             adflow=xList.get(0);
         }
         return adflow;
@@ -242,7 +284,7 @@ public class TemplateGenerator {
         xsc.andCheckedEqualTo(1);
         List<MdoProXfoil> xList = xdao.selectByExample(xsb);
         MdoProXfoil xfoil =null;
-        if(xList!=null&&xList.isEmpty()){
+        if(xList!=null&&!xList.isEmpty()){
             xfoil=xList.get(0);
         }
         return xfoil;
@@ -252,34 +294,36 @@ public class TemplateGenerator {
      * TODO 创建 workflowXml
      * @return
      */
-    public static String createcWorkflowXml(String pid){
-
-        return null;
-    }
+    public static String createcWorkflowXml(String pid,WorkflowVo vo){
+        try {
+            if(vo ==null){
+                return null;
+            }
+            Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
+            // 设置模板所在目录
+            cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
+            // 获取模板对象
+            Template template = cfg.getTemplate("workflow.ftl");
+            // 定义数据模型(Map)
+            Map<String, Object> dataModel = new HashMap<>();
+//            CpacsVo vo = getCpacsVo(pid);
 
-    /**
-     * 获取 求解器配置
-     * @param pid
-     * @return
-     * @throws IOException
-     */
-    private static List<Solver> findSolvers(String pid) throws IOException {
-        //TODO 目前只有函数求解器
-        MdoProjectMapper pDao = UtilTools.getBean(MdoProjectMapper.class);
-        MdoProject p = pDao.selectByPrimaryKey(pid);
-        List<Solver> solvers =new ArrayList<>();
-        //ptyon py.py 文件 写入
-        String ppPath=writePython(pid);
-        if(!StringUtil.isEmpty(ppPath)){
-            Solver solver =new Solver();
-            solver.setPythonPath(ppPath);
-            solver.setStype(p.getStype());
-            solvers.add(solver);
+            dataModel.put("vo",vo);
+            //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
+            // 将数据模型传入模板进行处理
+            StringWriter writer = new StringWriter();
+            template.process(dataModel, writer);
+            FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/workflow.xml");
+            fileWriter.write(writer.toString());
+            fileWriter.close();
+            return  LogService.BPATH + "/" + pid + "/in/workflow.xml";
+        }catch (Exception e){
+            return null;
         }
-        return solvers;
     }
 
 
+
     private static MdoProGrad findGrad(String pid) {
         MdoProGrad grad = null;
         MdoProGradMapper edao = UtilTools.getBean(MdoProGradMapper.class);
@@ -337,7 +381,7 @@ public class TemplateGenerator {
         List<MdoProjectConstraint> cList = cdao.selectByExample(csb);
         for (MdoProjectConstraint c:cList) {
             Constraint vc =new Constraint();
-            vc.setuID(c.getId());
+            vc.setuID(c.getUid()!=null?c.getUid():c.getId());
             vc.setName(c.getName());
             vc.setValue(c.getReference());
             vc.setLower(c.getLower());
@@ -355,7 +399,7 @@ public class TemplateGenerator {
         List<MdoProjectObjfun> objList =objdao.selectByExample(objsb);
         for (MdoProjectObjfun obj:objList) {
             Objective  vObj =new Objective();
-            vObj.setuID(obj.getId());
+            vObj.setuID(obj.getUid()!=null?obj.getUid():obj.getId());
             vObj.setName(obj.getName());
             vObj.setValue(obj.getReference());
             vObj.setWeight(obj.getWeight());
@@ -398,7 +442,11 @@ public class TemplateGenerator {
             List<String> values = new ArrayList<>();
             List<String> lowerbounds = new ArrayList<>();
             List<String> upperbounds = new ArrayList<>();
+            String uid = null;
             for (MdoProjectVariate tv:tVlist) {
+                if(!StringUtil.isEmpty(tv.getUid())){
+                    uid=tv.getUid();
+                }
                 values.add(tv.getReference());
                 lowerbounds.add(tv.getLower());
                 upperbounds.add(tv.getUpper());
@@ -406,7 +454,7 @@ public class TemplateGenerator {
             dv.setValue(values);
             dv.setLowerbound(lowerbounds);
             dv.setUpperbound(upperbounds);
-            dv.setuID(UtilTools.getUUid());//TODO 目前结构不清
+            dv.setuID(uid!=null?uid:UtilTools.getUUid());//TODO 目前结构不清
             designVariables.add(dv);
         }
         return designVariables;
@@ -418,7 +466,7 @@ public class TemplateGenerator {
      * @return
      * @throws IOException
      */
-    private static String writePython(String pid) throws IOException {
+    public static String writePython(String pid) throws IOException {
         MdoProPythonMapper ppDao = UtilTools.getBean(MdoProPythonMapper.class);
         MdoProPythonSQLBuilder ppsb = new MdoProPythonSQLBuilder();
         ppsb.createCriteria().andPidEqualTo(pid);
@@ -433,4 +481,6 @@ public class TemplateGenerator {
         }
         return "";
     }
+
+
 }

+ 4 - 0
src/main/java/com/miniframe/modo/temp/problem/WorkflowVo.java

@@ -0,0 +1,4 @@
+package com.miniframe.modo.temp.problem;
+
+public class WorkflowVo {
+}

+ 43 - 4
src/main/java/com/miniframe/tools/docker/DockerExe.java

@@ -2,10 +2,7 @@ package com.miniframe.tools.docker;
 
 import com.github.dockerjava.api.DockerClient;
 import com.github.dockerjava.api.async.ResultCallback;
-import com.github.dockerjava.api.command.CreateContainerResponse;
-import com.github.dockerjava.api.command.InspectContainerResponse;
-import com.github.dockerjava.api.command.LogContainerCmd;
-import com.github.dockerjava.api.command.RemoveContainerCmd;
+import com.github.dockerjava.api.command.*;
 import com.github.dockerjava.api.model.Frame;
 import com.github.dockerjava.api.model.HostConfig;
 import com.github.dockerjava.api.model.Mount;
@@ -156,5 +153,47 @@ public class DockerExe {
     }
 
 
+    public static void stopDocker2(String pid) {
 
+    }
+
+    public static void runMdo2(String pid) {
+        DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
+                .withDockerHost(DOCKERHOST) // 设置 Docker 主机地址
+                .withDockerTlsVerify(false) // 启用 TLS 验证
+                .withApiVersion(APIVERSION) // 设置 API 版本
+                .build();
+        DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder()
+                .dockerHost(config.getDockerHost())
+                .sslConfig(config.getSSLConfig())
+                .build();
+        DockerClient dockerClient = DockerClientBuilder.getInstance(config)
+                .withDockerHttpClient(httpClient)
+                .build();
+
+        Mount wokerMount = new Mount()
+                .withType(MountType.BIND)
+                .withSource("/cephfs/mdo/"+pid +"/")
+                .withTarget("/workspace/")
+                .withReadOnly(false);
+        List<Mount> am =new ArrayList<>();
+        am.add(wokerMount);
+
+        //创建容器
+        CreateContainerResponse container = dockerClient
+                .createContainerCmd("surromdao:test")//镜像名称
+                .withName(pid)//容器名称
+                .withHostConfig(
+                        HostConfig.newHostConfig()
+                                .withMounts(am)
+                ).exec();
+        dockerClient.startContainerCmd(container.getId()).exec();
+        // 执行命令(你也可以在这里直接使用execStartCmd)
+        ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(container.getId())
+                .withCmd("bash", "-c", "source /home/mdo/aeroelastic.sh && cd /workspace && mpiexec -n 1 python run.py")
+                .exec();
+        dockerClient.startContainerCmd(execCreateCmdResponse.getId()).exec();
+        System.out.println("容器启动成功,ID: " + container.getId());
+
+    }
 }

+ 3 - 3
src/main/resources/templates/cpacs.ftl

@@ -15,10 +15,10 @@
                     <description>airfoil</description>
                     <cst2D mapType="complex">
                         <N>${vo.cst.cstn}</N>
-                        <lowerB mapType="vector">${string_replace(vo.cst.lowerb, ",", ";")}</lowerB>
+                        <lowerB mapType="vector">${vo.cst.lowerb?replace( ",", ";")}</lowerB>
                         <lowerN1 mapType="dobule">${vo.cst.lowern1}</lowerN1>
                         <lowerN2 mapType="dobule">${vo.cst.lowern2}</lowerN2>
-                        <upperB mapType="vector">${string_replace(vo.cst.upperb, ",", ";")</upperB>
+                        <upperB mapType="vector">${vo.cst.upperb?replace(",", ";")}</upperB>
                         <upperN1 mapType="dobule">${vo.cst.uppern1}</upperN1>
                         <upperN2 mapType="dobule">${vo.cst.uppern2}</upperN2>
                         <trailingEdgeThickness mapType="dobule">0</trailingEdgeThickness>
@@ -58,7 +58,7 @@
                     <Nz mapType="integer">${vo.ffd.nz}</Nz>
                 </Controlpoints>
                 <vars mapType="complex">
-                    <sample mapType="vector">${string_replace(vo.ffd.vars, ",", ";")}</sample>
+                    <sample mapType="vector">${vo.ffd.vars?replace( ",", ";")}</sample>
                     <local_shape_dv mapType="boolean">1</local_shape_dv>
                 </vars>
          </FFD>

+ 7 - 0
src/main/resources/templates/run2.ftl

@@ -0,0 +1,7 @@
+from surromdao.utils import *
+prob = Problem.load_problem_from_xml('${problemPath}')
+opt = OptTask(prob, "tz")
+opt.run()
+history = opt.get_history()
+history.save_history_to_txt(file_path="history_all.txt")
+history.save_best_obj_history_to_txt(file_path="history_optimum.txt")

+ 55 - 0
src/main/resources/templates/workflow.ftl

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<opcs>
+    <header>
+        <name>SurroMDAO</name>
+        <creator>NWPU</creator>
+        <timestamp>2025-02-06T14:23:17</timestamp>
+        <version>0.1</version>
+        <opcsVersion>1.0</opcsVersion>
+    </header>
+    <schema>
+        <solvers>
+            <component uID="xfoil">
+                <name>pyXFoil</name>
+                <input>
+                    <parameterUID>/cpacs/vehicles/profiles/wingAirfoils/wingAirfoil/cst2D/lowerB</parameterUID>
+                </input>
+                <input>
+                    <parameterUID>/cpacs/vehicles/profiles/wingAirfoils/wingAirfoil/cst2D/upperB</parameterUID>
+                </input>
+                <output>
+                    <parameterUID>/cpacs/toolspecific/CFD/XFOIL/evalFuncs/cd</parameterUID>
+                </output>
+                <execute tpye="component">execute</execute>
+            </component>
+        </solvers>
+        <executeOrder>
+            <componentUID position="1">xfoil</componentUID>
+        </executeOrder>
+        <segments>
+            <segment uID="Seg1">
+                <fromParameterUID>/cpacs/vehicles/profiles/wingAirfoils/wingAirfoil/cst2D/lowerB</fromParameterUID>
+                <toComponentUID>xfoil</toComponentUID>
+            </segment>
+            <segment uID="Seg2">
+                <fromParameterUID>/cpacs/vehicles/profiles/wingAirfoils/wingAirfoil/cst2D/upperB</fromParameterUID>
+                <toComponentUID>xfoil</toComponentUID>
+            </segment>
+            <segment uID="Seg3">
+                <fromComponentUID>xfoil</fromComponentUID>
+                <toParameterUID>/cpacs/toolspecific/CFD/XFOIL/evalFuncs/cd</toParameterUID>
+            </segment>
+        </segments>
+        <parameters>
+            <parameter uID="/cpacs/vehicles/profiles/wingAirfoils/wingAirfoil/cst2D/lowerB">
+                <label>lowerB</label>
+            </parameter>
+            <parameter uID="/cpacs/vehicles/profiles/wingAirfoils/wingAirfoil/cst2D/upperB">
+                <label>upperB</label>
+            </parameter>
+            <parameter uID="/cpacs/toolspecific/CFD/XFOIL/evalFuncs/cd">
+                <label>cd</label>
+            </parameter>
+        </parameters>
+    </schema>
+</opcs>