예제 #1
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)
        {
            GH_Structure <GH_Brep> iDomain;
            int iMeshSize = 0;

            DA.GetDataTree(0, out iDomain);
            DA.GetData(1, ref iMeshSize);

            DataTree <Brep> convertedGeomTree = new DataTree <Brep>();

            int  x             = 0;
            Brep convertedBrep = null;

            foreach (GH_Path path in iDomain.Paths)
            {
                foreach (var geom in iDomain.get_Branch(path))
                {
                    GH_Convert.ToBrep(geom, ref convertedBrep, 0);
                    convertedGeomTree.Add(convertedBrep, new GH_Path(x));
                    convertedBrep = null;
                }
                x += 1;
            }

            List <Point3d> vertexList    = new List <Point3d>();
            string         blockVertices = "";

            Point3d[] edgePoints;
            for (int i = 0; i < 6; i++)
            {
                foreach (var edge in convertedGeomTree.Branch(i)[0].Edges)
                {
                    edge.DivideByCount(Convert.ToInt32(edge.GetLength()), true, out edgePoints);
                    foreach (var point in edgePoints)
                    {
                        vertexList.Add(point);
                    }
                }
            }


            vertexList = vertexList.OrderBy(p => p.X).ToList();
            double xLength = Math.Abs(vertexList[0].X - vertexList[vertexList.Count - 1].X);
            double xMid    = (vertexList[0].X + vertexList[vertexList.Count - 1].X) / 2;

            vertexList = vertexList.OrderBy(p => p.Y).ToList();
            double yLength = Math.Abs(vertexList[0].Y - vertexList[vertexList.Count - 1].Y);
            double yMid    = (vertexList[0].Y + vertexList[vertexList.Count - 1].Y) / 2;

            vertexList = vertexList.OrderBy(p => p.Z).ToList();
            double zLength = Math.Abs(vertexList[0].Z - vertexList[vertexList.Count - 1].Z);
            double zMid    = (vertexList[0].Z + vertexList[vertexList.Count - 1].Z) / 2;

            double        xMin    = xMid - Math.Ceiling(xLength / 2 / iMeshSize + 1) * iMeshSize;
            double        xMax    = xMid + Math.Ceiling(xLength / 2 / iMeshSize + 1) * iMeshSize;
            List <double> xValues = new List <double> {
                xMin, xMax
            };

            double        yMin    = yMid - Math.Ceiling(yLength / 2 / iMeshSize + 1) * iMeshSize;
            double        yMax    = yMid + Math.Ceiling(yLength / 2 / iMeshSize + 1) * iMeshSize;
            List <double> yValues = new List <double> {
                yMin, yMax
            };

            double        zMin    = zMid - Math.Ceiling(zLength / 2 / iMeshSize + 1) * iMeshSize;
            double        zMax    = zMid + Math.Ceiling(zLength / 2 / iMeshSize + 1) * iMeshSize;
            List <double> zValues = new List <double> {
                zMin, zMax
            };

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        blockVertices += "    (" + xValues[k] + " " + yValues[j] + " " + zValues[i] + ")\n";
                    }

                    xValues.Reverse();
                }
            }

            int noBlocksX = Convert.ToInt32((xMax - xMin) / iMeshSize);
            int noBlocksY = Convert.ToInt32((yMax - yMin) / iMeshSize);
            int noBlocksZ = Convert.ToInt32((zMax - zMin) / iMeshSize);

            string noBlocks = noBlocksX + " " + noBlocksY + " " + noBlocksZ;

            #region shellstring
            string shellString =
                ("/*--------------------------------*- C++ -*----------------------------------*\\\n" +
                 "| =========                 |                                                 |\n" +
                 "| \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |\n" +
                 "|  \\\\    /   O peration     | Website:  www.OpenFOAM.org                      |\n" +
                 "|   \\\\  /    A nd           | Version: 6                                      |\n" +
                 "|    \\\\/     M anipulation  |                                                 |\n" +
                 "\\*---------------------------------------------------------------------------*/\n" +
                 "FoamFile\n" +
                 "{{\n" +
                 "     version     2.0;\n" +
                 "     format      ascii;\n" +
                 "     class       dictionary;\n" +
                 "     object      blockMeshDict;\n" +
                 "}}\n" +
                 "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\r" +
                 "\n" +

                 "convertToMeters 1;\n" +
                 "\n" +
                 "vertices\n" +
                 "(\n" +
                 "{0}" +
                 ");\n" +
                 "\nblocks\n" +
                 "(\n" +
                 "    hex (0 1 2 3 4 5 6 7) ({1}) simpleGrading (1 1 1)\n" +
                 ");\n\r" +
                 "edges\n" +
                 "(\n" +
                 ");\n\r" +
                 "boundary\n" +
                 "(\n" +
                 ");\n\r" +
                 "mergePatchPairs\n" +
                 "(\n" +
                 ");\n\r" +
                 "// ************************************************************************* //");
            #endregion

            string blockMeshDict = string.Format(shellString, blockVertices, noBlocks);

            var oBlockMeshTextFile = new TextFile(blockMeshDict, "blockMeshDict");

            DA.SetData(0, oBlockMeshTextFile);
        }
예제 #2
0
        /// This is the method that actually does the work.
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <GH_Brep> iGeometry;
            List <Brep>            iRefBoxes = new List <Brep>();
            Point3d iLocationInMesh          = new Point3d();
            int     iCellsBetweenLvls        = 0;


            DA.GetDataTree(0, out iGeometry);
            DA.GetDataList(1, iRefBoxes);
            if (!DA.GetData(2, ref iLocationInMesh))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Specify a point in the mesh");
                return;
            }
            DA.GetData(3, ref iCellsBetweenLvls);


            DataTree <Brep> convertedGeomTree = new DataTree <Brep>();

            int  x             = 0;
            Brep convertedBrep = null;

            foreach (GH_Path path in iGeometry.Paths)
            {
                foreach (var geom in iGeometry.get_Branch(path))
                {
                    GH_Convert.ToBrep(geom, ref convertedBrep, 0);
                    convertedGeomTree.Add(convertedBrep, new GH_Path(x));
                    convertedBrep = null;
                }
                x += 1;
            }

            string geomInsert    = "";
            string geomRefInsert = "";

            foreach (GH_Path path in convertedGeomTree.Paths)
            {
                geomInsert += " " + convertedGeomTree.Branch(path)[0].GetUserString("Name") + ".stl\n" +
                              "   {\n" +
                              "       name " + convertedGeomTree.Branch(path)[0].GetUserString("Name") + ";\n" +
                              "       type triSurfaceMesh;\n" +
                              "   }\n";

                geomRefInsert += "  " + convertedGeomTree.Branch(path)[0].GetUserString("Name") + "\n" +
                                 "   {\n" +
                                 "       level\n" +
                                 "       (\n" +
                                 "         " + convertedGeomTree.Branch(path)[0].GetUserString("RefLvl") + "\n" +
                                 "         " + convertedGeomTree.Branch(path)[0].GetUserString("RefLvl") + "\n" +
                                 "       );\n" +
                                 "       gapLevelIncrement 0;\n" +
                                 "   }\n";
            }



            string        refBoxInsert    = "";
            string        refBoxLvlInsert = "";
            List <string> refBoxNames     = new List <string>();

            foreach (var box in iRefBoxes)
            {
                if (refBoxNames.Contains(box.GetUserString("Name")))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Some refinement boxes have the same name!");
                    return;
                }

                refBoxInsert += " " + box.GetUserString("Name") + "\n" +
                                "    {\n" +
                                "      type searchableBox;\n" +
                                "      min (" + box.GetUserString("MinCoord") + "); \n" +
                                "      max (" + box.GetUserString("MaxCoord") + "); \n" +
                                "    }\n";


                refBoxLvlInsert += "        " + box.GetUserString("Name") + "\n" +
                                   "           {\n" +
                                   "               mode inside;\n" +
                                   "               levels ((1E15 " + box.GetUserString("RefLvl") + "));\n" +
                                   "           }\n";
                refBoxNames.Add(box.GetUserString("Name"));
            }

            string eMeshString = "";

            foreach (GH_Path path in convertedGeomTree.Paths)
            {
                eMeshString +=
                    "       {\n" +
                    "         file \"" + convertedGeomTree.Branch(path)[0].GetUserString("Name") + ".eMesh\";\n" +
                    "         level 1;\n" +
                    "       }\n\r";
            }
            string locationInMesh = "(" + iLocationInMesh.ToString().Replace(",", " ") + ");";

            #region shellString
            string shellString =
                "/*--------------------------------*- C++ -*----------------------------------*\\\n" +
                "| =========                 |                                                 |\n" +
                "| \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |\n" +
                "|  \\\\    /   O peration     |                                                 |\n" +
                "|   \\\\  /    A nd           | Web:      www.OpenFOAM.org                      |\n" +
                "|    \\\\/     M anipulation  |                                                 |\n" +
                "\\*---------------------------------------------------------------------------*/\n" +
                "FoamFile\n" +
                "{{\n" +
                "     version     2.0;\n" +
                "     format      ascii;\n" +
                "     class       dictionary;\n" +
                "     object      snappyHexMeshDict;\n" +
                "}}\n" +
                "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\r" +
                "\n" +

                "castellatedMesh true;\n\r" +
                "snap true;\n\r" +
                "addLayers false;\n\r" +

                "\n\r" +
                "//\n" +
                "// GEOMETRY\n" +
                "//\n\r" +

                "geometry\n" +
                "{{\n" +
                "{0}\n" +


                "{1}\n" +

                "}}\n\r" +

                "castellatedMeshControls\n" +
                "{{\n" +
                "  maxLocalCells 40000000;\n" +
                "  maxGlobalCells 70000000;\n" +
                "  minRefinementCells 0;\n" +
                "  maxLoadUnbalance 0.1;\n" +
                "  nCellsBetweenLevels {2};\n" +
                "  features\n" +
                "     {3}\n" +
                "     (\n\r" +

                "{4}\n" +

                "     );\n\r" +


                "\n\r" +
                " //\n" +
                " // MESH REFINEMENT\n" +
                " //\n\r" +

                " refinementSurfaces\n" +
                " {{\n" +
                "{5}\n" +


                " }}\n\r" +

                " resolveFeatureAngle 30; \n\r" +

                " refinementRegions\n" +
                " {{\n" +
                "{6}" +
                " }}\n\r" +

                "\n\r" +
                " //\n" +
                " // MESH CONTROLS\n" +
                " //\n\r" +

                " locationInMesh\n" +
                " {7}\n\r" +

                " allowFreeStandingZoneFaces false;\n" +
                "}}\n\r" +

                "snapControls\n" +
                "{{\n" +
                "  nSmoothPatch 5;\n" +
                "  tolerance 010.0;\n" +
                "  nSolveIter 30;\n" +
                "  nRelaxIter 5;\n" +
                "  nFeatureSnapIter 10;\n" +
                "  implicitFeatureSnap true;\n" +
                "  explicitFeatureSnap true;\n" +
                "  multiRegionFeatureSnap true;\n" +
                "  globalFeatureEdges true;\n" +
                "}}\n\r" +

                "\n\r" +
                "//\n" +
                "// BOUNDARY LEVEL\n" +
                "//\n\r" +

                "addLayersControls\n" +
                "{{\n" +
                "  relativeSizes true;\n" +
                "  layers\n" +
                "  {{\n\r" +

                "  }}\n" +
                "  expansionRatio 1.0;\n" +
                "  finalLayerThickness 0.10;\n" +
                "  minThickness 0.05;\n" +
                "  nGrow 0;\n" +
                "  featureAngle 60;\n" +
                "  nRelaxIter 3;\n" +
                "  nSmoothSurfaceNormals 1;\n" +
                "  nSmoothNormals 3;\n" +
                "  nSmoothThickness 2;\n" +
                "  maxFaceThicknessRatio 0.5;\n" +
                "  maxThicknessToMedialRatio 0.3;\n" +
                "  minMedianAxisAngle 90;\n" +
                "  nBufferCellsNoExtrude 0;\n" +
                "  nLayerIter 30;\n" +
                "}}\n\r" +

                "\n\r" +
                "//\n" +
                "// MESH QUALITY\n" +
                "//\n\r" +

                "meshQualityControls\n" +
                "{{\n" +
                "  maxNonOrtho 70;\n" +
                "  maxBoundarySkewness 20;\n" +
                "  maxInternalSkewness 4;\n" +
                "  maxConcave 80;\n" +
                "  minFlatness 0.5;\n" +
                "  minVol 1e-13;\n" +
                "  minTetQuality -1;\n" +
                "  minArea -1;\n" +
                "  minTwist 0.02;\n" +
                "  minDeterminant 0.001;\n" +
                "  minFaceWeight 0.02;\n" +
                "  minVolRatio 0.01;\n" +
                "  minTriangleTwist -1;\n" +
                "  nSmoothScale 4;\n" +
                "  errorReduction 0.75;\n" +
                "}}\n\r" +

                "debug 0;\n\r" +

                "mergeTolerance 1e-07;";
            #endregion

            string snappyHexMeshDict = string.Format(shellString, geomInsert, refBoxInsert, iCellsBetweenLvls, convertedGeomTree.Branches.Count.ToString(), eMeshString, geomRefInsert, refBoxLvlInsert, locationInMesh);

            var oSnappyTextFile = new TextFile(snappyHexMeshDict, "snappyHexMeshDict");

            DA.SetData(0, oSnappyTextFile);
        }
예제 #3
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)
        {
            int             iStartFrom     = 0;
            int             iStopAt        = 0;
            string          iStartTime     = "";
            string          iEndTime       = "";
            string          iDeltaT        = "";
            string          iWriteInterval = "";
            List <TextFile> iFunctions     = new List <TextFile>();

            DA.GetData(0, ref iStartFrom);
            DA.GetData(1, ref iStopAt);
            DA.GetData(2, ref iStartTime);
            DA.GetData(3, ref iEndTime);
            DA.GetData(4, ref iDeltaT);
            DA.GetData(5, ref iWriteInterval);
            DA.GetDataList(6, iFunctions);

            string startFrom = "";
            string stopAt    = "";

            if (iStartFrom < 1 || iStartFrom > 2)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Entry unknown! To set where to start add ValueList component.");
                return;
            }
            switch (iStartFrom)
            {
            case 1:
                startFrom = "startTime";
                break;

            case 2:
                startFrom = "latestTime";
                break;
            }

            if (iStopAt < 1 || iStopAt > 2)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Entry unknown! To set where to stop add ValueList component.");
                return;
            }
            switch (iStopAt)
            {
            case 1:
                stopAt = "endTime";
                break;

            case 2:
                stopAt = "writeNow";
                break;
            }

            string functions = "";

            foreach (var function in iFunctions)
            {
                functions += "    #include \"" + function.GetName() + "\"\n";
            }

            #region shellstring
            string shellString =
                "/*--------------------------------*- C++ -*----------------------------------*\\\n" +
                "| =========                 |                                                 |\n" +
                "| \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |\n" +
                "|  \\\\    /   O peration     | Website:  www.OpenFOAM.org                      |\n" +
                "|   \\\\  /    A nd           | Version: 6                                      |\n" +
                "|    \\\\/     M anipulation  |                                                 |\n" +
                "\\*---------------------------------------------------------------------------*/\n" +
                "FoamFile\n" +
                "{{\n" +
                "     version     2.0;\n" +
                "     format      ascii;\n" +
                "     class       dictionary;\n" +
                "     object      controlDict;\n" +
                "}}\n" +
                "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\r" +
                "\n" +

                "application pimpleFoam;\n\r" +
                "startFrom {0};\n\r" +
                "startTime {1};\n\r" +
                "stopAt {2};\n\r" +
                "endTime {3};\n\r" +
                "deltaT {4};\n\r" +
                "writeControl runTime;\n\r" +
                "writeInterval {5};\n\r" +
                "writeFormat binary;\n\r" +
                "writePrecision 7;\n\r" +
                "//writeCompression compressed;\n\r" +
                "timeFormat general;\n\r" +
                "timePrecision 5;\n\r" +
                "runTimeModifiable yes;\n\r" +
                "adjustTimeStep no;\n\r" +
                "maxCo 100;\n\r" +
                "maxDeltaT 0.100;\n\r" +
                "maxCoMultiplier 2;\n\r" +
                "UBoundMin -500;\n\r" +
                "UBoundMax 500;\n\r" +
                "maxNonOrtho 60;\n\r" +
                "libs\n" +
                "(\n" +
                "    \"libOpenFOAM.so\"\n" +
                "    \"libincompressibleTurbulenceModels.so\"\n" +
                "    //\"libincompressibleTurbulenceModel.so\" FOR OLDER OpenFOAM versions\n" +
                "    //\"libincompressibleRASModels.so\" FOR OLDER OpenFOAM versions\n" +
                "    //\"libincompressibleLESModels.so\" FOR OLDER OpenFOAM versions\n" +
                ");\n" +
                "functions\n" +
                "{{\n" +
                "{6}\n" +
                "}}";

            #endregion

            string controlDict = string.Format(shellString, startFrom, iStartTime, stopAt, iEndTime, iDeltaT, iWriteInterval, functions);

            var oControlDictTextFile = new TextFile(controlDict, "controlDict");

            DA.SetData(0, oControlDictTextFile);
        }
예제 #4
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)
        {
            List <Brep> iGeometry = new List <Brep>();

            DA.GetDataList(0, iGeometry);

            string patchInsert = "";

            for (int i = 6; i < iGeometry.Count; i++)
            {
                patchInsert += "    " + iGeometry[i].GetUserString("Name") + "\n" +
                               "    {\n" +
                               "           type           zeroGradient;\n" +
                               "    }\n" +
                               "\n";
            }


            string shellString =
                "/*--------------------------------*- C++ -*----------------------------------*\\\n" +
                "| =========                 |                                                 |\n" +
                "| \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |\n" +
                "|  \\\\    /   O peration     | Version:  2.2.0                                 |\n" +
                "|   \\\\  /    A nd           | Web:      www.OpenFOAM.org                      |\n" +
                "|    \\\\/     M anipulation  |                                                 |\n" +
                "\\*---------------------------------------------------------------------------*/\n" +
                "FoamFile\n" +
                "{{\n" +
                "     version     2.0;\n" +
                "     format      ascii;\n" +
                "     class       volScalarField;\n" +
                "     object      p;\n" +
                "}}\n" +
                "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\r" +
                "\n" +

                "dimensions       [0 2 -2 0 0 0 0];\n\r" +

                "internalField    uniform 0;\n\r" +

                "boundaryField\n\r" +
                "{{\n" +

                "    INLET\n" +
                "    {{\n" +
                "           type            zeroGradient;\n" +
                "    }}\n\r" +

                "    OUTLET\n" +
                "    {{\n" +
                "           type            fixedValue;\n" +
                "           value           uniform 0;\n" +
                "    }}\n\r" +

                "    LEFTSIDE\n" +
                "    {{\n" +
                "           type            symmetry;\n" +
                "    }}\n\r" +

                "    RIGHTSIDE\n" +
                "    {{\n" +
                "           type            symmetry;\n" +
                "    }}\n\r" +

                "    BOTTOM\n" +
                "    {{\n" +
                "           type            zeroGradient;\n" +
                "    }}\n\r" +

                "    TOP\n" +
                "    {{\n" +
                "           type            symmetry;\n" +
                "    }}\n\r" +

                "{0}\n" +

                "}}";

            string oPressureString = string.Format(shellString, patchInsert);

            var oPressureTextFile = new TextFile(oPressureString, "p");

            DA.SetData(0, oPressureTextFile);
        }
예제 #5
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 iPath   = "";
            bool   iButton = false;
            GH_Structure <GH_Brep> iGeometry;
            var iConstantFolder = new List <TextFile>();
            var iSystemFolder   = new List <TextFile>();
            var iZeroFolder     = new List <TextFile>();
            var iWind           = new TextFile();

            DA.GetData(0, ref iPath);
            DA.GetData(1, ref iButton);
            DA.GetDataTree(2, out iGeometry);
            DA.GetDataList(3, iConstantFolder);
            DA.GetDataList(4, iSystemFolder);
            DA.GetDataList(5, iZeroFolder);
            DA.GetData(6, ref iWind);

            DataTree <Brep> convertedGeomTree = new DataTree <Brep>();

            int  x             = 0;
            Brep convertedBrep = null;

            foreach (GH_Path path in iGeometry.Paths)
            {
                foreach (var geom in iGeometry.get_Branch(path))
                {
                    GH_Convert.ToBrep(geom, ref convertedBrep, 0);
                    convertedGeomTree.Add(convertedBrep, new GH_Path(x));
                    convertedBrep = null;
                }
                x += 1;
            }


            string fileLocation   = "";
            string folderLocation = "";

            if (iPath != "")
            {
                folderLocation = iPath;
            }
            else
            {
                fileLocation = this.OnPingDocument().FilePath;

                if (fileLocation == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Either save the GH definition or manually assign a path to write to.");
                }
                else
                {
                    folderLocation = new DirectoryInfo(fileLocation).Parent.FullName + @"\";
                }
            }

            if (iButton)
            {
                // Specify names and generate directories

                string openFoamFolder   = System.IO.Path.Combine(folderLocation, convertedGeomTree.Branch(0)[0].GetUserString("RotAngle") + "deg");
                string constantPath     = System.IO.Path.Combine(openFoamFolder, "constant");
                string systemPath       = System.IO.Path.Combine(openFoamFolder, "system");
                string zeroPath         = System.IO.Path.Combine(openFoamFolder, "0");
                string polyMeshPath     = System.IO.Path.Combine(constantPath, "polyMesh\\");
                string triSurfacePath   = System.IO.Path.Combine(constantPath, "triSurface\\");
                string boundaryDataPath = System.IO.Path.Combine(constantPath, "boundaryData\\");

                Directory.CreateDirectory(zeroPath);
                Directory.CreateDirectory(polyMeshPath);
                Directory.CreateDirectory(triSurfacePath);
                Directory.CreateDirectory(boundaryDataPath);
                Directory.CreateDirectory(systemPath);


                // Write text files
                foreach (var constantFile in iConstantFolder)
                {
                    File.WriteAllText(System.IO.Path.Combine(polyMeshPath, constantFile.GetName()), constantFile.GetFileText());
                }

                foreach (var systemFile in iSystemFolder)
                {
                    File.WriteAllText(System.IO.Path.Combine(systemPath, systemFile.GetName()), systemFile.GetFileText());
                }

                foreach (var bcFile in iZeroFolder)
                {
                    File.WriteAllText(System.IO.Path.Combine(zeroPath, bcFile.GetName()), bcFile.GetFileText());
                }

                // Generate turbulent WIND data if included
                if (DA.GetData(6, ref iWind))
                {
                    string windFolder = System.IO.Path.Combine(folderLocation, "WIND");
                    Directory.CreateDirectory(windFolder);
                    File.WriteAllText(System.IO.Path.Combine(windFolder, iWind.GetName()), iWind.GetFileText());
                }

                // Export .stl's
                foreach (GH_Path path in convertedGeomTree.Paths)
                {
                    ExportStl(convertedGeomTree.Branch(path), triSurfacePath + convertedGeomTree.Branch(path)[0].GetUserString("Name"));
                }


                // Write static text files.
                List <Brep> tempGeomList = new List <Brep>();
                foreach (GH_Path path in convertedGeomTree.Paths)
                {
                    tempGeomList.Add(convertedGeomTree.Branch(path)[0]);
                }

                File.WriteAllText(System.IO.Path.Combine(openFoamFolder, "foam.job"), StaticTextFiles.GetFoam(tempGeomList));
                File.WriteAllText(System.IO.Path.Combine(openFoamFolder, "mesh.job"), StaticTextFiles.GetMesh(tempGeomList));

                File.WriteAllText(System.IO.Path.Combine(constantPath, "RASProperties"), StaticTextFiles.GetRASProperties());
                File.WriteAllText(System.IO.Path.Combine(constantPath, "transportProperties"), StaticTextFiles.GetTransportProperties());
                File.WriteAllText(System.IO.Path.Combine(constantPath, "turbulenceProperties"), StaticTextFiles.GetTurbulenceProperties());

                File.WriteAllText(System.IO.Path.Combine(systemPath, "decomposeParDict"), StaticTextFiles.GetDecomposeParDict());
                File.WriteAllText(System.IO.Path.Combine(systemPath, "fvSolution"), StaticTextFiles.GetFVSolution());
                File.WriteAllText(System.IO.Path.Combine(systemPath, "fvSchemes"), StaticTextFiles.GetFVSchemes());
                File.WriteAllText(System.IO.Path.Combine(systemPath, "surfaceFeatureExtractDict"), StaticTextFiles.GetSurfaceFeatureExtractDict(tempGeomList));

                File.WriteAllText(System.IO.Path.Combine(zeroPath, "p"), StaticTextFiles.GetP(tempGeomList));
                File.WriteAllText(System.IO.Path.Combine(zeroPath, "nut"), StaticTextFiles.GetNut(tempGeomList));
                File.WriteAllText(System.IO.Path.Combine(zeroPath, "nuTilda"), StaticTextFiles.GetNuTilda(tempGeomList));
            }
        }
예제 #6
0
파일: U.cs 프로젝트: sippanspojk/strWIND
        /// <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)
        {
            GH_Structure <GH_Brep> iDomain;
            Vector3d iVelocityVec = new Vector3d(0, 0, 0);
            Vector3d iInletVec    = new Vector3d(0, 0, 0);

            DA.GetDataTree(0, out iDomain);
            DA.GetData(1, ref iVelocityVec);
            DA.GetData(2, ref iInletVec);

            DataTree <Brep> convertedGeomTree = new DataTree <Brep>();

            int  x             = 0;
            Brep convertedBrep = null;

            foreach (GH_Path path in iDomain.Paths)
            {
                foreach (var geom in iDomain.get_Branch(path))
                {
                    GH_Convert.ToBrep(geom, ref convertedBrep, 0);
                    convertedGeomTree.Add(convertedBrep, new GH_Path(x));
                    convertedBrep = null;
                }
                x += 1;
            }

            convertedGeomTree.Branch(0)[0].SetUserString("BC", iInletVec.ToString().Replace(",", " "));



            string geomInsert = "";

            for (int i = 6; i < convertedGeomTree.Paths.Count; i++)
            {
                GH_Path path = convertedGeomTree.Path(i);
                geomInsert += "   " + convertedGeomTree.Branch(path)[0].GetUserString("Name") + "\n" +
                              "    {\n" +
                              "        type           fixedValue;\n" +
                              "        value          uniform (0 0 0);\n" +
                              "    }\n" +
                              "\n";
            }


            #region shellString
            string shellString =
                "/*--------------------------------*- C++ -*----------------------------------*\\\n" +
                "| =========                 |                                                 |\n" +
                "| \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |\n" +
                "|  \\\\    /   O peration     | Website:  www.OpenFOAM.org                      |\n" +
                "|   \\\\  /    A nd           | Version: 6                                      |\n" +
                "|    \\\\/     M anipulation  |                                                 |\n" +
                "\\*---------------------------------------------------------------------------*/\n" +
                "FoamFile\n" +
                "{{\n" +
                "     version     2.0;\n" +
                "     format      ascii;\n" +
                "     class       volVectorField;\n" +
                "     object      U;\n" +
                "}}\n" +
                "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\r" +
                "\n" +

                "dimensions     [0 1 -1 0 0 0 0];\n\r" +

                "internalField  uniform (" + iVelocityVec.ToString().Replace(",", " ") + ");\n\r" +

                "boundaryField\n" +
                "{{\n\r" +

                "    INLET\n" +
                "    {{\n" +
                "           type            timeVaryingMappedFixedValue;\n" +
                "           setAverage	    0;\n"+
                "           offset          (0 0 0);\n" +
                "           //type            fixedValue;\n" +
                "           //value           uniform (" + iInletVec.ToString().Replace(",", " ") + ");\n\r" +
                "    }}\n\r" +

                "    OUTLET\n" +
                "    {{\n" +
                "           type            zeroGradient;\n" +
                "    }}\n\r" +

                "    LEFTSIDE\n" +
                "    {{\n" +
                "           type            symmetry;\n" +
                "    }}\n\r" +

                "    RIGHTSIDE\n" +
                "    {{\n" +
                "           type            symmetry;\n" +
                "    }}\n\r" +

                "    BOTTOM\n" +
                "    {{\n" +
                "           type            fixedValue;\n" +
                "           value           uniform (0 0 0);\n" +
                "    }}\n\r" +

                "    TOP\n" +
                "    {{\n" +
                "           type            symmetry;\n" +
                "    }}\n\r" +

                "{0}\n" +
                "}}";
            #endregion

            string oVelocityString = string.Format(shellString, geomInsert);

            var oVelocityTextFile = new TextFile(oVelocityString, "U");

            DA.SetData(0, oVelocityTextFile);
        }