Пример #1
0
        private static Task SendCFDTask(
            AuthTokens tokens,
            string url,
            string path,
            CFDSolution solution,
            string parentTaskId,
            string dependentOnId,
            Dictionary <string, object> createParams,
            bool create
            )
        {
            var queryParams = new Dictionary <string, object>
            {
                { "name", solution.CaseType },
                { "parent", parentTaskId }
            };

            if (!string.IsNullOrEmpty(dependentOnId))
            {
                createParams.Add("dependent_on", dependentOnId);
            }
            var cfdTask = new GenericViewSet <Task>(
                tokens,
                url,
                path
                ).GetOrCreate(
                queryParams,
                createParams,
                create
                );

            return(cfdTask);
        }
Пример #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string inputJson = null;
            var    cpus      = 4;

            var solver             = 0;
            var caseType           = 0;
            var boundaryConditions = new List <string>();

            var iterations = new List <int>();

            var    numberOfAngles = new GH_Structure <GH_Number>();
            string overrides      = null;


            if (!DA.GetData(0, ref inputJson))
            {
                return;
            }
            if (!DA.GetData(1, ref cpus))
            {
                return;
            }
            DA.GetData(2, ref solver);
            DA.GetData(3, ref caseType);
            if (!DA.GetDataList(4, boundaryConditions))
            {
                return;
            }
            DA.GetDataList(5, iterations);
            DA.GetDataTree(6, out numberOfAngles);
            DA.GetData(7, ref overrides);

            var outputs = CFDSolution.Setup(
                inputJson,
                ComponentUtils.ValidateCPUs(cpus),
                Solvers[solver],
                CaseTypes[caseType],
                boundaryConditions,
                ConvertIterations(iterations),
                ConvertAnglesToList(numberOfAngles),
                overrides
                );


            DA.SetData(0, outputs);
        }
Пример #3
0
        public static Task CreateVWTCase(
            AuthTokens tokens,
            string url,
            string path,
            string parentTaskId,
            string meshTaskId,
            CFDSolution solution,
            bool create)
        {
            var config = new Dictionary <string, object>
            {
                { "task_type", "cfd" },
                { "cmd", "wind_tunnel" },
                { "commands", solution.Angles },
                { "cpus", solution.CPUs },
                { "iterations", solution.Iterations },
                { "solver", solution.Solver }
            };

            if (solution.Overrides != null)
            {
                if (solution.Overrides.ContainsKey("copy_folder"))
                {
                    config.Add("overrides",
                               new Dictionary <string, object> {
                        { "copy_folder", solution.Overrides["copy_folder"] }
                    });
                }

                if (solution.Overrides.ContainsKey("webhook"))
                {
                    config.Add("webhook", solution.Overrides["webhook"]);
                }
            }

            var createParams = new Dictionary <string, object>
            {
                {
                    "config", config
                }
            };

            return(SendCFDTask(tokens, url, path, solution, parentTaskId, meshTaskId, createParams, create));
        }
Пример #4
0
        public static Task CreateSimpleCase(
            AuthTokens tokens,
            string url,
            string path,
            string parentTaskId,
            string meshTaskId,
            CFDSolution solution,
            bool create)
        {
            var config = new Dictionary <string, object>
            {
                { "task_type", "cfd" },
                { "cmd", "pipeline" },
                {
                    "commands", new List <string>
                    {
                        solution.Solver,
                        "reconstructPar -noZero"
                    }
                },
                { "cpus", solution.CPUs },
                { "iterations", solution.Iterations }
            };

            if (solution.Overrides != null && solution.Overrides.ContainsKey("webhook"))
            {
                config.Add("webhook", solution.Overrides["webhook"]);
            }

            var createParams = new Dictionary <string, object>
            {
                {
                    "config", config
                }
            };

            return(createParams.ContainsKey("config")
                ? SendCFDTask(tokens, url, path, solution, parentTaskId, meshTaskId, createParams, create): null);
        }
Пример #5
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);
        }
Пример #6
0
        public static Task CreateCFDActionTask(
            AuthTokens tokens,
            string url,
            string path,
            string parentId,
            CFDMesh meshData,
            CFDSolution solution,
            int geometryFileSize,
            Dictionary <string, object> overrides,
            bool create
            )
        {
            if (overrides != null && overrides.ContainsKey("keep_mesh") && (bool)overrides["keep_mesh"])
            {
                create = false;
            }

            var actionTask = new GenericViewSet <Task>(
                tokens,
                url,
                path
                ).GetOrCreate(
                new Dictionary <string, object>
            {
                { "name", "Actions" },
                { "parent", parentId }
            },
                new Dictionary <string, object>
            {
                {
                    "config", new Dictionary <string, object>
                    {
                        { "task_type", "magpy" },
                        { "cmd", "cfd.io.tasks.write_mesh" },
                        { "base_mesh", meshData.BaseMesh },
                        { "snappyhex_mesh", meshData.SnappyHexMesh.ToDict() },
                    }
                }
            },
                create
                );

            // Then Action Task to create CFD files
            if (create)
            {
                if (solution != null && geometryFileSize > 0)
                {
                    new GenericViewSet <Task>(
                        tokens,
                        url,
                        path
                        ).Update(
                        actionTask.UID,
                        new Dictionary <string, object>
                    {
                        { "name", "Actions" },
                        { "status", "pending" },
                        {
                            "config", new Dictionary <string, object>
                            {
                                { "task_type", "magpy" },
                                { "cmd", "cfd.io.tasks.write_solution" },
                                { "solution", solution }
                            }
                        }
                    }
                        );
                }
                else
                {
                    // TODO - We need to handle if there is no solution given. Then we need to create the controlDict so people can do the meshing.
                }
            }

            return(actionTask);
        }