コード例 #1
0
        public static string Create(
            string inputJson,
            byte[] geometryFile,
            List <Dictionary <string, byte[]> > refinementRegions,
            bool create
            )
        {
            var inputData  = new Inputs().FromJson(inputJson);
            var tokens     = inputData.Auth;
            var parentTask = inputData.Task;
            var project    = inputData.Project;
            var solution   = inputData.CFDSolution;

            if (parentTask == null)
            {
                return(null);
                //throw new System.Exception("Cannot upload a case without a parent task.");
            }

            if (project == null)
            {
                return(null);
                //throw new System.Exception("Cannot upload a case without a project.");
            }

            if (create && !(solution.Overrides != null && solution.Overrides.ContainsKey("keep_mesh") &&
                            (bool)solution.Overrides["keep_mesh"]))
            {
                Upload.UploadGeometry(tokens, inputData.Url, parentTask.UID, geometryFile,
                                      "foam/constant/triSurface",
                                      "cfdGeom", refinementRegions);
            }

            // Tasks to Handle MagPy Celery Actions
            // First Action to create Mesh Files
            var actionTask = Action.CreateCFDActionTask(tokens, inputData.Url,
                                                        $"/api/project/{project.UID}/task/", parentTask.UID, inputData.Mesh, solution,
                                                        geometryFile.Length, solution.Overrides, create);

            // Task to Handle Meshing
            var includeSetSet = inputData.Mesh.BaseMesh.setSetRegions.Count > 0;

            var tasks = new List <Task>
            {
                actionTask,
            };

            if (solution.CaseType.ToLower() == "meshindependencestudy")
            {
                var meshIndependenceTasks = Tasks.Mesh.CreateMeshIndependenceTasks(tokens, inputData.Url, project.UID,
                                                                                   parentTask.UID, actionTask.UID, includeSetSet, solution, inputData.Mesh, create);
                tasks.AddRange(meshIndependenceTasks);
            }
            else
            {
                var meshTask = Tasks.Mesh.CreateMeshTask(tokens, inputData.Url, project.UID, parentTask.UID,
                                                         actionTask.UID,
                                                         solution.CPUs,
                                                         includeSetSet, solution.Overrides, create);
                if (meshTask != null)
                {
                    tasks.Add(meshTask);
                }

                var cfdTask = new Task();
                if (solution.CaseType.ToLower() == "virtualwindtunnel")
                {
                    cfdTask = CFD.CreateVWTCase(tokens,
                                                inputData.Url,
                                                $"/api/project/{project.UID}/task/",
                                                parentTask.UID,
                                                meshTask?.UID,
                                                solution,
                                                create
                                                );
                }
                else if (solution.CaseType.ToLower() == "simplecase")
                {
                    cfdTask = CFD.CreateSimpleCase(tokens,
                                                   inputData.Url,
                                                   $"/api/project/{project.UID}/task/",
                                                   parentTask.UID,
                                                   meshTask.UID,
                                                   solution,
                                                   create
                                                   );
                }

                tasks.Add(cfdTask);
            }

            inputData.SubTasks = tasks;

            return(inputData.ToJson());
        }
コード例 #2
0
        public static List <Task> CreateMeshIndependenceTasks(
            AuthTokens tokens,
            string url,
            string projectId,
            string parentTaskId,
            string actionTaskId,
            bool includeSetSet,
            CFDSolution solution,
            CFDMesh meshConfig,
            bool create
            )
        {
            var overrides = solution.Overrides;
            var cpus      = solution.CPUs;
            var path      = $"/api/project/{projectId}/task/";
            var parentIndependenceTask = Utils.CreateParent(
                tokens,
                url,
                path,
                "Mesh Independence Study",
                new Dictionary <string, object> {
                { "parent", parentTaskId }
            },
                create);
            var tasks = new List <Task> {
                parentIndependenceTask
            };

            var cellSizes         = GetBaseCellSizes(meshConfig, overrides);
            var duplicateBaseMesh = (BaseMesh)meshConfig.BaseMesh.Clone();
            var duplicateSolution = (CFDSolution)solution.Clone();

            duplicateSolution.CaseType = "SimpleCase";

            foreach (var cellSize in cellSizes)
            {
                var parentTask = Utils.CreateParent(
                    tokens,
                    url,
                    path,
                    $"Cell Size {cellSize}",
                    new Dictionary <string, object> {
                    { "parent", parentIndependenceTask.UID }, { "case_dir", $"independence/mesh_{cellSize}/foam" }, { "show_meta_data", true }
                },
                    create);
                tasks.Add(parentTask);

                // create action task
                duplicateBaseMesh.CellSize = cellSize;
                var actionTask = Action.CreateIndependenceActionTask(
                    tokens,
                    url,
                    path,
                    parentTask.UID,
                    actionTaskId,
                    duplicateBaseMesh,
                    create
                    );
                tasks.Add(actionTask);

                // create mesh
                var meshTask = CreateMeshTask(tokens, url, projectId, parentTask.UID, actionTask.UID, cpus,
                                              includeSetSet, overrides, create);
                tasks.Add(meshTask);

                // create solver task
                var cfdTask = CFD.CreateSimpleCase(tokens, url, path, parentTask.UID, meshTask.UID, duplicateSolution, create);
                tasks.Add(cfdTask);
            }

            return(tasks);
        }