public override bool CastFrom(object source) { // This function is called when Grasshopper needs to convert other data // into GsaMember. if (source == null) { return(false); } //Cast from GsaMember if (typeof(GsaMember3d).IsAssignableFrom(source.GetType())) { Value = (GsaMember3d)source; return(true); } //Cast from GsaAPI Member if (typeof(Member).IsAssignableFrom(source.GetType())) { Value.Member = (Member)source; return(true); } //Cast from Brep Brep brep = new Brep(); if (GH_Convert.ToBrep(source, ref brep, GH_Conversion.Both)) { GsaMember3d member = new GsaMember3d(brep); this.Value = member; return(true); } //Cast from Mesh Mesh mesh = new Mesh(); if (GH_Convert.ToMesh(source, ref mesh, GH_Conversion.Both)) { GsaMember3d member = new GsaMember3d(mesh); this.Value = member; return(true); } return(false); }
public override bool CastFrom(object source) { // This function is called when Grasshopper needs to convert other data // into GsaMember. if (source == null) { return(false); } //Cast from GsaMember if (typeof(GsaMember2d).IsAssignableFrom(source.GetType())) { Value = (GsaMember2d)source; return(true); } //Cast from GsaAPI Member if (typeof(Member).IsAssignableFrom(source.GetType())) { Value.Member = (Member)source; return(true); } //Cast from Brep Brep brep = new Brep(); if (GH_Convert.ToBrep(source, ref brep, GH_Conversion.Both)) { List <Point3d> pts = new List <Point3d>(); List <Curve> crvs = new List <Curve>(); GsaMember2d mem = new GsaMember2d(brep, crvs, pts); //GsaProp2d prop2d = new GsaProp2d(); //prop2d.ID = 1; //mem.Property = prop2d; this.Value = mem; return(true); } return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Solid input is null"); } GsaMember3d mem = new GsaMember3d(); Brep brep = new Brep(); Mesh mesh = new Mesh(); if (GH_Convert.ToBrep(gh_typ.Value, ref brep, GH_Conversion.Both)) { mem = new GsaMember3d(brep); } else if (GH_Convert.ToMesh(gh_typ.Value, ref mesh, GH_Conversion.Both)) { mem = new GsaMember3d(mesh); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input to a 3D Member"); return; } // 1 prop3d to be implemented GsaAPI // 2 mesh size GH_Number ghmsz = new GH_Number(); if (DA.GetData(2, ref ghmsz)) { GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both); mem.Member.MeshSize = m_size; } DA.SetData(0, new GsaMember3dGoo(mem)); } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Brep ghbrep = new GH_Brep(); if (DA.GetData(0, ref ghbrep)) { Brep brep = new Brep(); if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both)) { // first import points and curves for inclusion before building member // 2 Points List <Point3d> pts = new List <Point3d>(); List <GH_Point> ghpts = new List <GH_Point>(); if (DA.GetDataList(2, ghpts)) { for (int i = 0; i < ghpts.Count; i++) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghpts[i], ref pt, GH_Conversion.Both)) { pts.Add(pt); } } } // 3 Curves List <Curve> crvs = new List <Curve>(); List <GH_Curve> ghcrvs = new List <GH_Curve>(); if (DA.GetDataList(3, ghcrvs)) { for (int i = 0; i < ghcrvs.Count; i++) { Curve crv = null; if (GH_Convert.ToCurve(ghcrvs[i], ref crv, GH_Conversion.Both)) { crvs.Add(crv); } } } // now build new member with brep, crv and pts GsaMember2d mem = new GsaMember2d(brep, crvs, pts); // add the rest // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaProp2d) { gh_typ.CastTo(ref prop2d); } else if (gh_typ.Value is GH_Number) { if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both)) { prop2d.ID = idd; } } } else { prop2d.ID = 1; } mem.Property = prop2d; // 4 mesh size GH_Number ghmsz = new GH_Number(); if (DA.GetData(4, ref ghmsz)) { GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both); mem.Member.MeshSize = m_size; } DA.SetData(0, new GsaMember2dGoo(mem)); } } }
/// <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); }
/// 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); }
/// <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> iGeometry; int iN1exp = 0; int iN2exp = 0; int iN3exp = 0; double iTimeSpacing = 1; double iAlpha = 0.16; double iFactor = 1; double izRef = 10; double ivRef = 25; double iZRefBeonspek = 0; DA.GetDataTree(0, out iGeometry); DA.GetData(1, ref iN1exp); DA.GetData(2, ref iN2exp); DA.GetData(3, ref iN3exp); DA.GetData(4, ref iTimeSpacing); DA.GetData(5, ref iAlpha); DA.GetData(6, ref iFactor); DA.GetData(7, ref izRef); DA.GetData(8, ref ivRef); DA.GetData(9, ref iZRefBeonspek); DataTree <Brep> convertedGeomTree = new DataTree <Brep>(); int newPath = 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(newPath)); convertedBrep = null; } newPath += 1; } double N1 = Math.Pow(2, iN1exp); double N2 = Math.Pow(2, iN2exp); double N3 = Math.Pow(2, iN3exp); string Nstring = "N1=" + N1.ToString() + ",N2=" + N2.ToString() + ",N3=" + N3.ToString(); List <Point3d> cornerPointList = new List <Point3d>(); foreach (var cornerPoint in convertedGeomTree.Branch(0)[0].Vertices) { cornerPointList.Add(new Point3d(cornerPoint.Location)); } double xMin = cornerPointList.OrderBy(p => p.X).ToList()[0].X; double yMin = cornerPointList.OrderBy(p => p.Y).ToList()[0].Y; double yMax = cornerPointList.OrderBy(p => p.Y).ToList()[cornerPointList.Count - 1].Y; double zMin = cornerPointList.OrderBy(p => p.Z).ToList()[0].Z; double zMax = cornerPointList.OrderBy(p => p.Z).ToList()[cornerPointList.Count - 1].Z; double N1out = N1; double N2out = Math.Ceiling((yMax - yMin) / iTimeSpacing * 1.2); double N3out = Math.Ceiling((zMax - zMin) / iTimeSpacing * 1.1); string inletCoordsString = " xinlet = " + xMin + "\n" + " yinlet = " + ((yMax + yMin) / 2 - N2out / 2 * iTimeSpacing) + "\n" + " zinlet = " + zMin; var oInlet = Brep.CreateFromCornerPoints(new Point3d(xMin, (yMax + yMin) / 2 - N2out / 2 * iTimeSpacing, zMin), new Point3d(xMin, (yMax + yMin) / 2 - N2out / 2 * iTimeSpacing, zMin + N3out * iTimeSpacing), new Point3d(xMin, (yMax + yMin) / 2 + N2out / 2 * iTimeSpacing, zMin + N3out * iTimeSpacing), new Point3d(xMin, (yMax + yMin) / 2 + N2out / 2 * iTimeSpacing, zMin), 0.01); string NoutString = "N1out=" + N1out.ToString() + ",N2out=" + N2out.ToString() + ",N3out=" + N3out.ToString(); double L1 = iTimeSpacing * N1; double L2 = iTimeSpacing * N2; double L3 = iTimeSpacing * N3; string Lstring = " L1 = " + L1 + "\n" + " L2 = " + L2 + "\n" + " L3 = " + L3; List <Brep> flattedGeomTree = convertedGeomTree.AllData(); flattedGeomTree.RemoveRange(0, 6); List <double> zCoordList = new List <double>(); foreach (var part in flattedGeomTree) { foreach (var vertex in part.Vertices) { zCoordList.Add(vertex.Location.Z); } } zCoordList.Sort(); double geomHeigth = zCoordList[zCoordList.Count - 1] - zCoordList[0]; if (!DA.GetData(9, ref iZRefBeonspek)) { iZRefBeonspek = Math.Ceiling(1.5 * geomHeigth); } if (8 * 0.59 * iZRefBeonspek >= L1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The length of the generated wind field is too small, currently " + L1.ToString() + " and needs to be bigger than 8L = " + (8 * 0.59 * iZRefBeonspek).ToString()); } if (8 * 0.59 * iZRefBeonspek >= L2) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The width of the generated wind field is too small, currently " + L2.ToString() + " and needs to be bigger than 8L = " + (8 * 0.59 * iZRefBeonspek).ToString()); } if (8 * 0.59 * iZRefBeonspek >= L3) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The height of the generated wind field is too small, currently " + L3.ToString() + " and needs to be bigger than 8L = " + (8 * 0.59 * iZRefBeonspek).ToString()); } List <double> zList = new List <double>(); int i = 0; while (iTimeSpacing * i < Math.Ceiling(geomHeigth)) { i++; zList.Add(iTimeSpacing * i); } List <double> uList = new List <double>(); foreach (var z in zList) { uList.Add(iFactor * ivRef * Math.Pow(z / izRef, iAlpha)); } double uMean = uList.Average(); List <double> turbIntensity = new List <double>(); foreach (var z in zList) { turbIntensity.Add(0.19 * Math.Pow(z / izRef, -iAlpha)); } #region shellString string shellString = "!---------------------------------------------------------------------\n" + " PROGRAM wind FFT 3c3d\n" + "! Program to generate multi correlated wind time series of the \n" + "! 3 components \n" + "! using the spatial 3 dimensional FFT of Numerical Recipes \n" + "\n" + "! Reference:\n" + "! Jakob Mann: \"Wind field simulation\", 1998\n" + "\n" + "! written by A. Michalski 2006/07\n" + "! \n" + "! AMI 12.02.2008 output file for OpenFOAM \n" + "! AMI 04.09.2008 only fourn parts active \n" + "! AMI 14.12.2010 filter to detect maximum gust in defined box\n" + "! filter to detect gust with defined speed \n" + "! parameter iopt\n" + "! AMI 16.12.2010 IFFT omp parallelized\n" + "! AMI 12.01.2011 vtk_structured grid output file\n" + "! AMI 22.02.2011 only output mean wind field \n" + "! parameter imeanwind\n" + "! AMI 31.03.2011 Write OpenFOAM Wind files\n" + "! AMI 06.04.2011 Filter to detect wind field with defined variance\n" + "! DA 17.06.2019 Output adapted for OpenFOAM v.6\n" + "!---------------------------------------------------------------------\n" + " use omp_lib\n" + "! include 'omp_lib.h'\n" + "\n" + "! Openmp parallel\n" + " integer ithr,tnr \n" + " \n" + " integer*4 N1, N2, N3\n" + " integer*4 NDAT,N1I8,N2I8,N3I8\n" + " integer*4 N1out, N2out, N3out,N1vtk\n" + "! PARAMETERS\n" + " parameter(ndim=3)\n" + " parameter({0})\n" + " parameter(N1I8=N1,N2I8=N2,N3I8=N3)\n" + " parameter(NDAT=2*N1I8*N2I8*N3I8)\n" + " parameter({1})\n" + " parameter(N1vtk=256)! ARRAYS\n" + "! - real\n" + " real data1(NDAT)\n" + " real data2(NDAT)\n" + " real data3(NDAT)\n" + " \n" + " real matrix(N3out,N1out)\n" + " \n" + "! VARIABLES\n" + "! - integer\n" + " integer*8 il,nth\n" + " integer*4 thp\n" + " integer*4 ivalue, iflag, iout, iopt, imeanwind\n" + " integer*8 n\n" + " integer*4 nn(3)\n" + " integer*4 j1,j2,j3\n" + "!xxxxxxxx used for debugging xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n" + "! integer*4 i \n" + "!xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n" + " \n" + "\n" + "! for OpenFOAM\n" + "! - string\n" + " character(LEN=18) mkdirname\n" + " character(LEN=14) cddirname\n" + " character(LEN=18) mkdirname2\n" + " character(LEN=14) cddirname2\n" + " integer is,is2\n" + "! real*8 ui\n" + " \n" + "! - real \n" + " real S1re, S1im, S2re, S2im, S3re, S3im\n" + " real*8 sumen1, sumen2, sumen3\n" + "!xxxxxxxx used for debugging xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n" + "! integer item,jtem,iktem\n" + "! real tsimtem,data1tem\n" + "!xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "\n" + " real*8 L1, L2, L3\n" + " real*8 d1,d2,d3 \n" + " real*8 k1,k2,k3,k,ks,k1s,k2s,k3s,k0,k0s,k0ksfak,k30,k30s\n" + "\n" + " real*8 z\n" + " real*8 ustar\n" + " real*8 E, En\n" + " \n" + " real F21re\n" + " real*8 L\n" + " real*8 fak\n" + " real*8 Cfakt\n" + " real fakhyp\n" + " real*8 beta\n" + " real*8 gam\n" + " real*8 sita1, sita2, Ce1, Ce2\n" + " real*8 atanfak, atanfak1\n" + " \n" + " real*8 xn1re, xn1im, xn2re, xn2im, xn3re, xn3im\n" + " real*8 uref, alfa, zref, ubasic, aquer,bquer\n" + " real*8 uz,umeanz,umzSBCi,umzECNA\n" + " real fscale\n" + " \n" + " real*8 dt,tsim\n" + " \n" + "! real xlength1, xlength2, xlenght3\n" + "\n" + "! gustbox\n" + " real*8 ugust, ugustm, ugustms\n" + " integer*4 n1b,n2b,n3b,n123b\n" + " integer*4 j1a,j1e,j1am,j1em,j1ams,iter,maxiter\n" + " integer*4 j1d\n" + " integer*4 j2a,j2e,j3a,j3e\n" + " real*8 B1,B2,B3,zgb\n" + " real*8 lgs, ugs\n" + " \n" + " integer iterende\n" + " integer checkl,usegust\n" + " real*8 gustarray(N1)\n" + " real*8 xlength,xinlet,yinlet,zinlet\n" + " real*8 checkvar, checkvarlimit,dustar\n" + "\n" + "! - complex \n" + " complex xn1, xn2, xn3\n" + " complex xn2check(N1)\n" + " complex dZiso1, dZiso2, dZiso3\n" + " complex S1,S2,S3\n" + " complex hypgeo\n" + " complex ah, bh, ch, zh\n" + " complex F21\n" + "\n" + "\n" + "! Wind speed profile according to EC\n" + "! Roughness length z0EC\n" + " real*8 z0EC \n" + "! Terrain factor krEC\n" + " real*8 krEC\n" + "! Roughness factor crzEC\n" + " real*8 crzEC\n" + "! Basic wind speed EC\n" + " real*8 vbasicEC\n" + "! Mean wind speed vmzEC\n" + " real*8 umzEC\n" + "! Standard deviation sdEC\n" + " real*8 sdEC\n" + "! Turbulence intensity IvEC\n" + " real*8 IvEC\n" + "! Peak velocity pressure\n" + " real*8 qpzEC\n" + "! Peak velocity\n" + " real*8 vpzEC\n" + " \n" + "! COMMON BLOCKS\n" + " common /dataar/ data1, data2, data3\n" + " common /statist/ umean, vmean, wmean, uvar, vvar, wvar,uw,uv,vw \n" + "\n" + "! OPEN FILES \n" + " open(unit=58,file='log.dat')\n" + " rewind(58)\n" + " \n" + " write(*,*)\n" + " write(*,*) 'Software to generate multicorrelated wind time' \n" + " write(*,*) 'histories of u,v,w wind components in x,y,z '\n" + " write(*,*) 'directions ' \n" + " write(*,*)\n" + " write(*,*) 'Open files'\n" + " write(*,*)\n" + " \n" + " write(58,*)\n" + " write(58,*) 'Software to generate multicorrelated wind time' \n" + " write(58,*) 'histories of u,v,w wind components in x,y,z '\n" + " write(58,*) 'directions ' \n" + " write(58,*)\n" + " write(58,*) 'Open files'\n" + " write(58,*)\n" + " \n" + " \n" + " \n" + "!xxxxxxxx used for debugging xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "! Temporre out files to check the direct access routines \n" + "! open(unit=8,file='u_out_temp.dat')\n" + "! open(unit=9,file='v_out_temp.dat')\n" + "! open(unit=10,file='w_out_temp.dat') \n" + "\n" + "! Temporary output files to check quality \n" + "! open(unit=14,file='checkdaccess.dat')\n" + "! open(unit=20,file='bug.dat')\n" + "! open(unit=21,file='input.dat')\n" + "! open(unit=22,file='ifft.dat') \n" + "! rewind(8)\n" + "! rewind(9)\n" + "! rewind(10)\n" + "! rewind(20)\n" + "! rewind(21)\n" + "! rewind(22)\n" + "! rewind(14)\n" + "!xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + " \n" + "! FOURIER NORM \n" + " nn(1) = N1\n" + " nn(2) = N2\n" + " nn(3) = N3\n" + "\n" + " write(*,*) 'Read input values...'\n" + " write(*,*)\n" + " write(58,*) 'Read input values...'\n" + " write(58,*)\n" + " \n" + "! INPUT VALUES\n" + "! - Length of domain\n" + "{2}\n" + " umeanz = {3}\n" + "! - grid size \n" + " d1 = L1/N1\n" + " d2 = L2/N2\n" + " d3 = L3/N3\n" + "! - gridpoints \n" + "! nth = N1 * N2 * N3\n" + " nth = N1I8 * N2I8 * N3I8\n" + "! - wavelenth interval\n" + " dk1 = 6.2831853/ L1\n" + " dk2 = 6.2831853/ L2\n" + " dk3 = 6.2831853/ L3 \n" + "! - spatial grid resolution \n" + " delta = d1*d2*d3 \n" + "! - Mean wind profile\n" + "! EC\n" + " alfa = {4}\n" + " uref = {5}d0*{6}\n" + " zref = {7}.d0\n" + "! SBC\n" + "! ubasic = 105.0\n" + "! aquer = 0.25\n" + "! bquer = 0.45\n" + "\n" + "! - Coupling routine \n" + "! ivalue = 0: read fluctuations, ivalue=1: read mean + fluctuation \n" + " ivalue = 1\n" + "! iflag = 0: linear interpolation in time, \n" + "! 1: bicubic spline interpolation in time \n" + " iflag = 0 \n" + "\n" + "! - OpenFOAM output files\n" + "! iout = 1: OpenFOAM output additionally \n" + " iout = 1 \n" + "! mean wind input file for OpenFOAM\n" + "! imeanwind = 1 --> write meanwind file\n" + " imeanwind = 0\n" + "{8}\n" + "\n" + "! MEANWIND inflow file \n" + " if (imeanwind.eq.1) then \n" + " write(*,*)\n" + " write(*,*) 'Write MEANWIND inflow for OpenFOAM'\n" + " write(*,*)\n" + " write(58,*)\n" + " write(58,*) 'Write MEANWIND inflow for OpenFOAM'\n" + " write(58,*) \n" + " open(unit=88,file='points',status='unknown')\n" + " open(unit=99,file='U',status='unknown')\n" + " call meanwind(N1,N2out,N3out,d1,d2,d3,nn,uref,zref,alfa, \n" + " & xinlet,yinlet,zinlet)\n" + " write(*,*) '...DONE'\n" + " write(*,*) \n" + " write(58,*) '...DONE'\n" + " write(58,*)\n" + " close(88)\n" + " close(99)\n" + " goto 122\n" + " endif\n" + " \n" + "! - Turbulence parameters \n" + " ustar = 1.57d0\n" + " \n" + "! - Spectral energy fit to KAIMAL Spectrum (J. Mann) \n" + " z = {9}\n" + " L = 0.59*z\n" + " fak = 3.2 * (ustar**2.d0)/(z**0.6666)*(L**1.6666)\n" + " fscale = 2.0\n" + "! (scale total isotropic variance of wind field with fscaleý)\n" + "! - Spectral tensor parameters (J.Mann 1998)\n" + "! - Non-dimensional shear distortion parameter\n" + "! gamma = 0 --> isotropic model \n" + " gam = 3.9\n\r"; #endregion string turbFile = string.Format(shellString, Nstring, NoutString, Lstring, uMean.ToString(), iAlpha.ToString(), ivRef.ToString(), iFactor.ToString(), izRef.ToString(), inletCoordsString, iZRefBeonspek.ToString()) + "\n" + StaticTextFiles.Get3c3dFile(); var o3c3dFile = new TextFile(turbFile, "3c3d_FOURN_structured.f"); string oInfo = "Wind field duration = " + (Math.Ceiling(N1 * iTimeSpacing / uMean / 60 * 100) / 100).ToString() + "min"; List <double> oUProfile = new List <double>(); oUProfile = uList; List <double> oTurbIntensity = new List <double>(); oTurbIntensity = turbIntensity; DA.SetData(0, oInfo); DA.SetData(1, oInlet); DA.SetDataList(2, zList); DA.SetDataList(3, oUProfile); DA.SetDataList(4, oTurbIntensity); DA.SetData(5, o3c3dFile); }
/// <summary> /// This one does many things, which essentially boil down to translating the geometry + performance measures into a spk instance. /// This instance subsequently gets json-ed out to a file /// </summary> public static System.Dynamic.ExpandoObject translateGeometry(List <System.Object> inputObjects, List <string> guids, String name, IGH_Component component) { dynamic myInstance = new System.Dynamic.ExpandoObject(); myInstance.metadata = new System.Dynamic.ExpandoObject(); myInstance.metadata.verion = "1.0"; myInstance.metadata.type = "Object"; myInstance.metadata.generator = "Instance Export"; // super important - name will link it to the correct group in three js myInstance.metadata.name = name; myInstance.metadata.properties = new List <String>(); foreach (IGH_Param param in component.Params.Input[1].Sources) { var myprop = getPanelNameAndVal(param); if (myprop != null) { myInstance.metadata.properties.Add(myprop); } } myInstance.geometries = new List <System.Object>(); int k = 0; foreach (System.Object myObj in inputObjects) { if (myObj != null) { string myguid = "000"; if (name != "staticGeo") { myguid = guids[k]; } k++; if (myObj is GH_Mesh) { GH_Mesh tempers = (GH_Mesh)myObj; SuperMesh mesh = new SuperMesh(tempers, myguid); myInstance.geometries.Add(mesh); } else if ((myObj is GH_Curve)) { GH_Curve tempers = (GH_Curve)myObj; Curve myCrv = tempers.Value; if (myCrv.Degree == 1) { Polyline tempP; myCrv.TryGetPolyline(out tempP); SuperPolyline polyline = new SuperPolyline(tempP, false, myguid); myInstance.geometries.Add(polyline); } else if ((myCrv.Degree == 2) || (myCrv.Degree == 3)) { bool isClosed = myCrv.IsClosed; int mainSegmentCount = 0, subSegmentCount = 1; double maxAngleRadians = 0, maxChordLengthRatio = 0, maxAspectRatio = 0, tolerance = 0.1, minEdgeLength = 0, maxEdgeLength = 0; bool keepStartPoint = true; PolylineCurve p = myCrv.ToPolyline(mainSegmentCount, subSegmentCount, maxAngleRadians, maxChordLengthRatio, maxAspectRatio, tolerance, minEdgeLength, maxEdgeLength, keepStartPoint); Polyline pp; p.TryGetPolyline(out pp); myInstance.geometries.Add(new SuperPolyline(pp, isClosed, myguid)); } } else if (myObj is Point3d) { GH_Point tempers = (GH_Point)myObj; SuperPoint point = new SuperPoint(tempers, myguid); myInstance.geometries.Add(point); } else if ((myObj is GH_Brep) || (myObj is GH_Surface)) { Mesh[] myMeshes; Brep myFutureBrep = null; GH_Convert.ToBrep(myObj, ref myFutureBrep, GH_Conversion.Primary); if (myFutureBrep != null) { myMeshes = Mesh.CreateFromBrep(myFutureBrep, MeshingParameters.Smooth); if (myMeshes == null || myMeshes.Length == 0) { // TODO throw an error } Mesh brep_mesh = new Mesh(); foreach (Mesh tempmesh in myMeshes) { brep_mesh.Append(tempmesh); } GH_Mesh temporal = new GH_Mesh(brep_mesh); SuperMesh mesh = new SuperMesh(temporal, myguid); myInstance.geometries.Add(mesh); } } else if (myObj is GH_Circle) { GH_Circle myCircle = myObj as GH_Circle; //NurbsCurve mycrv = myCircle.Value.ToNurbsCurve(); NurbsCurve mycrv = NurbsCurve.CreateFromCircle(myCircle.Value); int mainSegmentCount = 30, subSegmentCount = 1; double maxAngleRadians = 0, maxChordLengthRatio = 0, maxAspectRatio = 0, tolerance = 0.1, minEdgeLength = 0, maxEdgeLength = 0; bool keepStartPoint = true; if (mycrv != null) { PolylineCurve p = mycrv.ToPolyline(mainSegmentCount, subSegmentCount, maxAngleRadians, maxChordLengthRatio, maxAspectRatio, tolerance, minEdgeLength, maxEdgeLength, keepStartPoint); Polyline pp; p.TryGetPolyline(out pp); if (pp != null) { myInstance.geometries.Add(new SuperPolyline(pp, true, myguid)); } else { myInstance.geometries.Add("Circle error"); } } else { myInstance.geometries.Add("Circle error 2"); } } else if (myObj is GH_Line) { GH_Line myLine = myObj as GH_Line; myInstance.geometries.Add(new SuperPolyline(myLine, myguid)); } else { myInstance.geometries.Add("error - undefined type"); } } } return(myInstance); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaMember3d gsaMember3d = new GsaMember3d(); if (DA.GetData(0, ref gsaMember3d)) { if (gsaMember3d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Member3D input is null"); } GsaMember3d mem = gsaMember3d.Duplicate(); // #### inputs #### // 1 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(1, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { mem.ID = id; } } // 2 geometry GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(2, ref gh_typ)) { GsaMember3d tempMem = new GsaMember3d(); Brep brep = new Brep(); Mesh mesh = new Mesh(); if (GH_Convert.ToBrep(gh_typ.Value, ref brep, GH_Conversion.Both)) { tempMem = new GsaMember3d(brep); } else if (GH_Convert.ToMesh(gh_typ.Value, ref mesh, GH_Conversion.Both)) { tempMem = new GsaMember3d(mesh); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input to a 3D Member"); return; } mem.SolidMesh = tempMem.SolidMesh; } // 3 prop3d -- to be implemented GsaAPI gh_typ = new GH_ObjectWrapper(); if (DA.GetData(3, ref gh_typ)) { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { mem.Member.Property = idd; } //GsaProp3d prop3d = new GsaProp3d(); //if (gh_typ.Value is GsaProp3dGoo) // gh_typ.CastTo(ref prop3d); //else //{ // if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) // prop3d.ID = idd; // else // { // AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 3D Property of reference integer"); // return; // } //} //mem.Property = prop3d; } // 4 mesh size GH_Number ghmsz = new GH_Number(); if (DA.GetData(4, ref ghmsz)) { if (GH_Convert.ToDouble(ghmsz, out double msz, GH_Conversion.Both)) { mem.Member.MeshSize = msz; } } // 5 mesh with others GH_Boolean ghbool = new GH_Boolean(); if (DA.GetData(5, ref ghbool)) { if (GH_Convert.ToBoolean(ghbool, out bool mbool, GH_Conversion.Both)) { //mem.member.MeshWithOthers } } // 6 name GH_String ghnm = new GH_String(); if (DA.GetData(6, ref ghnm)) { if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both)) { mem.Member.Name = name; } } // 7 Group GH_Integer ghgrp = new GH_Integer(); if (DA.GetData(7, ref ghgrp)) { if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both)) { mem.Member.Group = grp; } } // 8 Colour GH_Colour ghcol = new GH_Colour(); if (DA.GetData(8, ref ghcol)) { if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both)) { mem.Member.Colour = col; } } // 9 Dummy GH_Boolean ghdum = new GH_Boolean(); if (DA.GetData(9, ref ghdum)) { if (GH_Convert.ToBoolean(ghdum, out bool dum, GH_Conversion.Both)) { mem.Member.IsDummy = dum; } } // #### outputs #### DA.SetData(0, new GsaMember3dGoo(mem)); DA.SetData(1, mem.ID); DA.SetData(2, mem.SolidMesh); //DA.SetData(3, mem.Property); DA.SetData(4, mem.Member.MeshSize); //DA.SetData(5, mem.Member.MeshWithOthers); DA.SetData(6, mem.Member.Name); DA.SetData(7, mem.Member.Group); DA.SetData(8, mem.Member.Colour); DA.SetData(9, mem.Member.IsDummy); } }
/// <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; var iStatStart = 0.0; var iGPeak = 0.0; DA.GetDataTree(0, out iDomain); DA.GetData(1, ref iStatStart); DA.GetData(2, ref iGPeak); if (iGPeak <= 0.0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "g peak can't be negative or equal to zero, please assign a different value."); return; } DataTree <Brep> convertedGeomTree = new DataTree <Brep>(); int iPath = 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(iPath)); convertedBrep = null; } iPath += 1; } string brepNames = ""; for (int i = 6; i < convertedGeomTree.Paths.Count; i++) { brepNames += " " + convertedGeomTree.Branch(convertedGeomTree.Path(i))[0].GetUserString("Name") + "\n"; } string statStartString = iStatStart.ToString(); string gPeakString = iGPeak.ToString(); string ESWLString = "/*--------------------------------*- 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" + "ESWL\n" + "{\n" + " type ESWL;\n" + " functionObjectLibs (\"libESWL.so\");\n" + "\n" + " statStartTime " + statStartString + "; //At what time should the statistics start?\n" + "\n" + " gPeak " + gPeakString + ";\n" + "\n" + " patches\n" + " (\n" + brepNames + " );\n" + "}"; var oESWLFile = new TextFile(ESWLString, "ESWL"); DA.SetData(0, oESWLFile); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Brep ghbrep = new GH_Brep(); if (DA.GetData(0, ref ghbrep)) { if (ghbrep == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Brep input is null"); } Brep brep = new Brep(); if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both)) { // 1 Points List <Point3d> pts = new List <Point3d>(); List <GH_Point> ghpts = new List <GH_Point>(); if (DA.GetDataList(1, ghpts)) { for (int i = 0; i < ghpts.Count; i++) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghpts[i], ref pt, GH_Conversion.Both)) { pts.Add(pt); } } } // 2 Curves List <Curve> crvs = new List <Curve>(); List <GH_Curve> ghcrvs = new List <GH_Curve>(); if (DA.GetDataList(2, ghcrvs)) { for (int i = 0; i < ghcrvs.Count; i++) { Curve crv = null; if (GH_Convert.ToCurve(ghcrvs[i], ref crv, GH_Conversion.Both)) { crvs.Add(crv); } } } // build new member with brep, crv and pts GsaMember2d mem = new GsaMember2d(brep, crvs, pts); // 3 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(3, ref gh_typ)) { if (gh_typ.Value is GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); mem.Property = prop2d; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { mem.Member.Property = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } } // 4 mesh size GH_Number ghmsz = new GH_Number(); if (DA.GetData(4, ref ghmsz)) { GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both); mem.Member.MeshSize = m_size; } DA.SetData(0, new GsaMember2dGoo(mem)); }
/// <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; //I don't need to write "= new GH_Structure<GH_Brep>();" since it is associated with an out keyword in DA.GetDataTree(...) var iConstantFolder = new List <TextFile>(); var iSystemFolder = new List <TextFile>(); var iZeroFolder = new List <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); DataTree <Brep> convertedGeomTree = new DataTree <Brep>(); int i = 0; foreach (GH_Path path in iGeometry.Paths) { foreach (var geom in iGeometry.get_Branch(path)) { Brep convertedBrep = null; GH_Convert.ToBrep(geom, ref convertedBrep, 0); convertedGeomTree.Add(convertedBrep, new GH_Path(i)); } i += 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 for folders. add some more stuff 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\\"); // Generate directories Directory.CreateDirectory(zeroPath); Directory.CreateDirectory(polyMeshPath); Directory.CreateDirectory(triSurfacePath); 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()); } // 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()); File.WriteAllText(System.IO.Path.Combine(openFoamFolder, "mesh.job"), StaticTextFiles.GetMesh()); //File.WriteAllText(System.IO.Path.Combine(constantPath, "LESProperties"), StaticTextFiles.GetLESProperties()); 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(systemPath, "forces"), StaticTextFiles.GetForcesFunction(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)); } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaGridAreaLoad gridareaload = new GsaGridAreaLoad(); // 0 Load case int lc = 1; GH_Integer gh_lc = new GH_Integer(); if (DA.GetData(0, ref gh_lc)) { GH_Convert.ToInt32(gh_lc, out lc, GH_Conversion.Both); } gridareaload.GridAreaLoad.Case = lc; // Do plane input first as to see if we need to project polyline onto grid plane // 2 Plane Plane pln = Plane.WorldXY; bool planeSet = false; GsaGridPlaneSurface grdplnsrf = new GsaGridPlaneSurface(); GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(2, ref gh_typ)) { if (gh_typ.Value is GsaGridPlaneSurfaceGoo) { GsaGridPlaneSurface temppln = new GsaGridPlaneSurface(); gh_typ.CastTo(ref temppln); grdplnsrf = temppln.Duplicate(); pln = grdplnsrf.Plane; planeSet = true; } else if (gh_typ.Value is Plane) { gh_typ.CastTo(ref pln); grdplnsrf = new GsaGridPlaneSurface(pln); planeSet = true; } else { int id = 0; if (GH_Convert.ToInt32(gh_typ.Value, out id, GH_Conversion.Both)) { gridareaload.GridAreaLoad.GridSurface = id; gridareaload.GridPlaneSurface = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in GPS input. Accepted inputs are Grid Plane Surface or Plane. " + System.Environment.NewLine + "If no input here then the brep's best-fit plane will be used"); return; } } } // we wait setting the gridplanesurface until we have run the polyline input // 1 Polyline Brep brep = new Brep(); GH_Brep gh_brep = new GH_Brep(); if (DA.GetData(1, ref gh_brep)) { GH_Convert.ToBrep(gh_brep, ref brep, GH_Conversion.Both); // get edge curves Curve[] edgeSegments = brep.DuplicateEdgeCurves(); Curve[] edges = Curve.JoinCurves(edgeSegments); Curve crv = edges[0]; //convert to polyline Polyline ln = new Polyline(); if (crv.TryGetPolyline(out ln)) { // get control points List <Point3d> ctrl_pts = ln.ToList(); // plane if (!planeSet) { // create nice plane from pts pln = Util.GH.Convert.CreateBestFitUnitisedPlaneFromPts(ctrl_pts); // create grid plane surface from best fit plane grdplnsrf = new GsaGridPlaneSurface(pln, true); } // project original curve onto grid plane crv = Curve.ProjectToPlane(crv, pln); // convert to polyline again crv.TryGetPolyline(out ln); //get control points again ctrl_pts = ln.ToList(); // string to write polyline description to string desc = ""; // loop through all points for (int i = 0; i < ctrl_pts.Count - 1; i++) { if (i > 0) { desc += " "; } // get control points in local plane coordinates Point3d temppt = new Point3d(); pln.RemapToPlaneSpace(ctrl_pts[i], out temppt); // write point to string // format accepted by GSA: (0,0) (0,1) (1,2) (3,4) (4,0)(m) desc += "(" + temppt.X + "," + temppt.Y + ")"; } // add units to the end desc += "(" + Units.LengthLarge + ")"; // set polyline in grid line load gridareaload.GridAreaLoad.Type = GridAreaPolyLineType.POLYGON; gridareaload.GridAreaLoad.PolyLineDefinition = desc; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not convert Brep edge to Polyline"); } } // now we can set the gridplanesurface: if (gridareaload.GridPlaneSurface != null) { if (gridareaload.GridPlaneSurface.GridSurfaceID == 0) { gridareaload.GridPlaneSurface = grdplnsrf; } } // 3 direction string dir = "Z"; Direction direc = Direction.Z; GH_String gh_dir = new GH_String(); if (DA.GetData(3, ref gh_dir)) { GH_Convert.ToString(gh_dir, out dir, GH_Conversion.Both); } dir = dir.ToUpper(); if (dir == "X") { direc = Direction.X; } if (dir == "Y") { direc = Direction.Y; } gridareaload.GridAreaLoad.Direction = direc; // 4 Axis int axis = 0; gridareaload.GridAreaLoad.AxisProperty = 0; GH_Integer gh_ax = new GH_Integer(); if (DA.GetData(4, ref gh_ax)) { GH_Convert.ToInt32(gh_ax, out axis, GH_Conversion.Both); if (axis == 0 || axis == -1) { gridareaload.GridAreaLoad.AxisProperty = axis; } } // 5 Projected bool proj = false; GH_Boolean gh_proj = new GH_Boolean(); if (DA.GetData(5, ref gh_proj)) { if (GH_Convert.ToBoolean(gh_proj, out proj, GH_Conversion.Both)) { gridareaload.GridAreaLoad.IsProjected = proj; } } // 6 Name string name = ""; GH_String gh_name = new GH_String(); if (DA.GetData(6, ref gh_name)) { if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both)) { gridareaload.GridAreaLoad.Name = name; } } // 7 load value double load1 = 0; if (DA.GetData(7, ref load1)) { load1 *= -1000; //convert to kN } gridareaload.GridAreaLoad.Value = load1; // convert to goo GsaLoad gsaLoad = new GsaLoad(gridareaload); DA.SetData(0, new GsaLoadGoo(gsaLoad)); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaMember2d gsaMember2d = new GsaMember2d(); if (DA.GetData(0, ref gsaMember2d)) { GsaMember2d mem = gsaMember2d.Duplicate(); // #### inputs #### // 1 brep Brep brep = mem.Brep; //existing brep GH_Brep ghbrep = new GH_Brep(); if (DA.GetData(1, ref ghbrep)) { if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both)) { mem.Brep = brep; } } // 2 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(2, ref gh_typ)) { GsaProp2d prop2d = new GsaProp2d(); if (gh_typ.Value is GsaProp2d) { gh_typ.CastTo(ref prop2d); } else if (gh_typ.Value is GH_Number) { if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both)) { prop2d.ID = idd; } } mem.Property = prop2d; } // 3 offset GsaOffset offset = new GsaOffset(); if (DA.GetData(3, ref offset)) { mem.Member.Offset.Z = offset.Z; } // 4 inclusion points List <Point3d> pts = mem.InclusionPoints; List <GH_Point> ghpts = new List <GH_Point>(); if (DA.GetDataList(4, ghpts)) { for (int i = 0; i < ghpts.Count; i++) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghpts[i], ref pt, GH_Conversion.Both)) { pts.Add(pt); } } } // 5 inclusion lines CurveList crvlist = new CurveList(mem.InclusionLines); List <Curve> crvs = crvlist.ToList(); List <GH_Curve> ghcrvs = new List <GH_Curve>(); if (DA.GetDataList(5, ghcrvs)) { for (int i = 0; i < ghcrvs.Count; i++) { Curve crv = null; if (GH_Convert.ToCurve(ghcrvs[i], ref crv, GH_Conversion.Both)) { crvs.Add(crv); } } } GsaMember2d tmpmem = new GsaMember2d(brep, crvs, pts) { ID = mem.ID, Member = mem.Member, Property = mem.Property }; mem = tmpmem; // 6 mesh size GH_Number ghmsz = new GH_Number(); if (DA.GetData(6, ref ghmsz)) { if (GH_Convert.ToDouble(ghmsz, out double msz, GH_Conversion.Both)) { mem.Member.MeshSize = msz; } } // 7 mesh with others GH_Boolean ghbool = new GH_Boolean(); if (DA.GetData(7, ref ghbool)) { if (GH_Convert.ToBoolean(ghbool, out bool mbool, GH_Conversion.Both)) { //mem.member.MeshWithOthers } } // 8 type GH_Integer ghint = new GH_Integer(); if (DA.GetData(8, ref ghint)) { if (GH_Convert.ToInt32(ghint, out int type, GH_Conversion.Both)) { mem.Member.Type = Util.Gsa.GsaToModel.Member2dType(type); } } // 9 element type / analysis order GH_Integer ghinteg = new GH_Integer(); if (DA.GetData(9, ref ghinteg)) { if (GH_Convert.ToInt32(ghinteg, out int type, GH_Conversion.Both)) { mem.Member.Type2D = Util.Gsa.GsaToModel.Element2dType(type); } } // 10 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(10, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { mem.ID = id; } } // 11 name GH_String ghnm = new GH_String(); if (DA.GetData(11, ref ghnm)) { if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both)) { mem.Member.Name = name; } } // 12 Group GH_Integer ghgrp = new GH_Integer(); if (DA.GetData(12, ref ghgrp)) { if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both)) { mem.Member.Group = grp; } } // 13 Colour GH_Colour ghcol = new GH_Colour(); if (DA.GetData(13, ref ghcol)) { if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both)) { mem.Member.Colour = col; } } // 14 Dummy GH_Boolean ghdum = new GH_Boolean(); if (DA.GetData(14, ref ghdum)) { if (GH_Convert.ToBoolean(ghdum, out bool dum, GH_Conversion.Both)) { mem.Member.IsDummy = dum; } } // #### outputs #### DA.SetData(0, new GsaMember2dGoo(mem)); DA.SetData(1, mem.Brep); DA.SetData(2, mem.Property); GsaOffset gsaOffset = new GsaOffset { Z = mem.Member.Offset.Z }; DA.SetData(3, gsaOffset); DA.SetDataList(4, mem.InclusionPoints); DA.SetDataList(5, mem.InclusionLines); DA.SetData(6, mem.Member.MeshSize); //DA.SetData(7, mem.member.MeshWithOthers); DA.SetData(8, mem.Member.Type); DA.SetData(9, mem.Member.Type2D); DA.SetData(10, mem.ID); DA.SetData(11, mem.Member.Name); DA.SetData(12, mem.Member.Group); DA.SetData(13, mem.Member.Colour); DA.SetData(14, mem.Member.IsDummy); } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaMember2d gsaMember2d = new GsaMember2d(); if (DA.GetData(0, ref gsaMember2d)) { if (gsaMember2d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Member2D input is null"); } GsaMember2d mem = gsaMember2d.Duplicate(); // #### inputs #### // 1 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(1, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { mem.ID = id; } } // 2/3/4 Brep, incl.pts and incl.lns Brep brep = mem.Brep; //existing brep GH_Brep ghbrep = new GH_Brep(); CurveList crvlist = new CurveList(mem.InclusionLines); List <Curve> crvs = crvlist.ToList(); List <GH_Curve> ghcrvs = new List <GH_Curve>(); List <GH_Point> ghpts = new List <GH_Point>(); List <Point3d> pts = mem.InclusionPoints; if ((DA.GetData(2, ref ghbrep)) || (DA.GetDataList(3, ghpts)) || (DA.GetDataList(4, ghcrvs))) { // 2 brep if (DA.GetData(2, ref ghbrep)) { if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both)) { mem.Brep = brep; } } // 3 inclusion points if (DA.GetDataList(3, ghpts)) { for (int i = 0; i < ghpts.Count; i++) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghpts[i], ref pt, GH_Conversion.Both)) { pts.Add(pt); } } } // 4 inclusion lines if (DA.GetDataList(4, ghcrvs)) { for (int i = 0; i < ghcrvs.Count; i++) { Curve crv = null; if (GH_Convert.ToCurve(ghcrvs[i], ref crv, GH_Conversion.Both)) { crvs.Add(crv); } } } GsaMember2d tmpmem = new GsaMember2d(brep, crvs, pts); mem.PolyCurve = tmpmem.PolyCurve; mem.Topology = tmpmem.Topology; mem.TopologyType = tmpmem.TopologyType; mem.VoidTopology = tmpmem.VoidTopology; mem.VoidTopologyType = tmpmem.VoidTopologyType; mem.InclusionLines = tmpmem.InclusionLines; mem.IncLinesTopology = tmpmem.IncLinesTopology; mem.IncLinesTopologyType = tmpmem.IncLinesTopologyType; mem.InclusionPoints = tmpmem.InclusionPoints; mem = tmpmem; } // 5 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(5, ref gh_typ)) { GsaProp2d prop2d = new GsaProp2d(); if (gh_typ.Value is GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); mem.Property = prop2d; mem.Member.Property = 0; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { mem.Member.Property = idd; mem.Property = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } }
/// <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; //GH_Structure<IGH_GeometricGoo> iGeometry = new GH_Structure<IGH_GeometricGoo>(); 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>(); * List<GH_Path> pathList = new List<GH_Path>(); * * foreach (var path in iGeometry.Paths) * for (int i = 0; i < iGeometry.get_Branch(path).Count; i++) * pathList.Add(path); * * var flattenedGeom = iGeometry.FlattenData(); * for (int i = 0; i < flattenedGeom.Count; i++) * { * flattenedGeom[i].CastTo(out Brep tempBrep); * convertedGeomTree.Add(tempBrep, pathList[i]); * }*/ 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 for folders. add some more stuff string openFoamFolder = System.IO.Path.Combine(folderLocation, convertedGeomTree.Branch(0)[0].GetUserString("RotAngle") + "deg"); string windFolder = System.IO.Path.Combine(folderLocation, "WIND"); 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\\"); // Generate directories Directory.CreateDirectory(zeroPath); Directory.CreateDirectory(polyMeshPath); Directory.CreateDirectory(triSurfacePath); Directory.CreateDirectory(boundaryDataPath); Directory.CreateDirectory(systemPath); Directory.CreateDirectory(windFolder); // 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()); } 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()); File.WriteAllText(System.IO.Path.Combine(openFoamFolder, "mesh.job"), StaticTextFiles.GetMesh()); //File.WriteAllText(System.IO.Path.Combine(constantPath, "LESProperties"), StaticTextFiles.GetLESProperties()); 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(systemPath, "forces"), StaticTextFiles.GetForcesFunction(convertedGeomTree)); 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)); } }
/// <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) { #region INPUTS // import silkwormSettings file List <string> silkwormSettings = new List <string>(); if (!DA.GetDataList(0, silkwormSettings)) { return; } // import raw Grasshopper Geometry to convert to Silkworm Movements List <GH_ObjectWrapper> MovementList = new List <GH_ObjectWrapper>(); if (!DA.GetDataList(1, MovementList)) { return; } int sorted = new int(); if (!DA.GetData(2, ref sorted)) { return; } #endregion #region Utilities //Utility to convert list of strings to Settings Dictionary SilkwormUtility sUtil = new SilkwormUtility(); Dictionary <string, string> Settings = sUtil.convertSettings(silkwormSettings); #endregion double layerHeight = double.Parse(Settings["layer_height"]); int layerHeightDP = CountDecimalPlaces(layerHeight); #region Output Holders //GCode Lines List <GH_String> sGCode = new List <GH_String>(); //Unsorted Movements List <SilkwormMovement> unMovements = new List <SilkwormMovement>(); //Movements sorted by Layer List <SilkwormMovement>[] sMovements = new List <SilkwormMovement> [0]; #endregion //Wrapper List for all types to Parse GH_ObjectWrapper[] Movement = MovementList.ToArray(); //Switch sorting routine by input switch (sorted) { case 1: #region Unsorted (Sort Order of Movements by z then x and y) if (sorted == 1) { //Parse #region Parse Input Type List <Brep> solids = new List <Brep>(); List <Mesh> meshes = new List <Mesh>(); //Incomplete Silkworm Movements List <SilkwormMovement> incmovements = new List <SilkwormMovement>(); List <Brep> shapes = new List <Brep>(); List <Curve> curves = new List <Curve>(); List <Polyline> plines = new List <Polyline>(); List <Line> lines = new List <Line>(); for (int i = 0; i < Movement.Length; i++) { //Sort Types into Container Lists #region IfNull if ((Movement[i].Value == null)) { continue; } #endregion #region SilkwormMovement else if ((Movement[i].Value is Silkworm.Type.SilkwormMovement)) { SilkwormMovement aMovement = (SilkwormMovement)Movement[i].Value; if (aMovement.complete) { aMovement.Configuration = Settings; //make sure it has a config field unMovements.Add(aMovement); continue; } else { incmovements.Add(aMovement); continue; } } #endregion #region Solids else if (Movement[i].Value is GH_Brep) { Brep solid = null; GH_Convert.ToBrep(Movement[i].Value, ref solid, GH_Conversion.Both); solids.Add(solid); continue; } else if (Movement[i].Value is GH_Mesh) { Mesh mesh = null; GH_Convert.ToMesh(Movement[i].Value, ref mesh, GH_Conversion.Both); meshes.Add(mesh); continue; } #endregion #region Regions //TODO #endregion #region Curves else if (Movement[i].Value is GH_Curve) { Curve curve = null; GH_Convert.ToCurve(Movement[i].Value, ref curve, GH_Conversion.Both); curves.Add(curve); continue; } #endregion #region SilkwormLine else if (Movement[i].Value is SilkwormLine) { List <SilkwormLine> slines = new List <SilkwormLine>(); slines.Add((SilkwormLine)Movement[i].Value); //Check if complete if (isCompleteLine((SilkwormLine)Movement[i].Value)) { unMovements.Add(new SilkwormMovement(slines, new Delimiter())); } else { incmovements.Add(new SilkwormMovement(slines, new Delimiter())); } continue; } #endregion #region Line else if (Movement[i].Value is GH_Line) { Line line = new Line(); GH_Convert.ToLine(Movement[i].Value, ref line, GH_Conversion.Both); lines.Add(line); continue; } #endregion #region Point else if (Movement[i].Value is GH_Point) { //TODO continue; } #endregion #region Not Supported else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Datatype Not Supported!"); continue; } #endregion #endregion } //Build Movements from Incomplete Parts #region Build Movement #region List<Brep>Add to unMovements if (solids.Count > 0) { List <SilkwormMovement> solidMovements = addsolidBrep(Settings, solids); unMovements.AddRange(solidMovements); } #endregion #region List<Mesh> Add to unMovements //TODO #endregion #region List<Shapes> Add to unMovements //TODO #endregion #region List<Curve> Add to unMovements foreach (Curve curve in curves) { SilkwormMovement movement = new SilkwormMovement(Settings, curve); unMovements.Add(movement); } #endregion #region List<Line> Add to unMovements foreach (Line line in lines) { List <Line> _lines = new List <Line>(); _lines.Add(line); unMovements.Add(new SilkwormMovement(Settings, _lines)); } #endregion #region List<IncompleteSilkwormMovement> Add to unMovements foreach (SilkwormMovement movement in incmovements) { unMovements.Add(completeMovement(Settings, movement));; continue; } #endregion #endregion } goto SortZ; #endregion break; case 2: #region Partially Sorted (Sort Movements by z only) if (sorted == 2) { for (int u = 0; u < Movement.Length; u++) { #region IfNull if ((Movement[u].Value == null)) { continue; } #endregion #region SilkwormMovement else if ((Movement[u].Value is Silkworm.Type.SilkwormMovement)) { SilkwormMovement aMovement = (SilkwormMovement)Movement[u].Value; if (aMovement.complete) { aMovement.Configuration = Settings; //make sure it has a config field unMovements.Add(aMovement); continue; } else { unMovements.Add(completeMovement(Settings, aMovement)); continue; } } #endregion #region Solids else if (Movement[u].Value is GH_Brep) { Brep solid = null; List <Brep> solids = new List <Brep>(); GH_Convert.ToBrep(Movement[u].Value, ref solid, GH_Conversion.Both); solids.Add(solid); List <SilkwormMovement> solidMovements = addsolidBrep(Settings, solids); unMovements.AddRange(solidMovements); continue; } else if (Movement[u].Value is GH_Mesh) { Mesh mesh = null; GH_Convert.ToMesh(Movement[u].Value, ref mesh, GH_Conversion.Both); continue; } #endregion #region Regions //TODO #endregion #region Curves else if (Movement[u].Value is GH_Curve) { Curve curve = null; GH_Convert.ToCurve(Movement[u].Value, ref curve, GH_Conversion.Both); SilkwormMovement movement = new SilkwormMovement(Settings, curve); unMovements.Add(movement); continue; } #endregion #region SilkwormLine else if (Movement[u].Value is SilkwormLine) { List <SilkwormLine> s_lines = new List <SilkwormLine>(); s_lines.Add((SilkwormLine)Movement[u].Value); //Check if complete if (isCompleteLine((SilkwormLine)Movement[u].Value)) { unMovements.Add(new SilkwormMovement(s_lines, new Delimiter())); } else { List <Line> lines = new List <Line>(); SilkwormLine[] s_Movement = new SilkwormLine[s_lines.Count]; foreach (SilkwormLine line in s_lines) { lines.Add(line.sLine); } List <SilkwormLine> sLines = new SilkwormMovement(Settings, lines).sMovement; List <SilkwormLine> Movements = new List <SilkwormLine>(); //Complete Movements for (int j = 0; j < sLines.Count; j++) { if (s_Movement[j].Flow == -1) { s_Movement[j].Flow = sLines[j].Flow; } if (s_Movement[j].Speed == -1) { s_Movement[j].Speed = sLines[j].Speed; } Movements.Add(s_Movement[j]); } SilkwormMovement newMovement = new SilkwormMovement(Movements, new Delimiter()); //Add Configuration newMovement.Configuration = Settings; unMovements.Add(newMovement); } continue; } #endregion #region Line else if (Movement[u].Value is GH_Line) { Line line = new Line(); GH_Convert.ToLine(Movement[u].Value, ref line, GH_Conversion.Both); List <Line> _lines = new List <Line>(); _lines.Add(line); unMovements.Add(new SilkwormMovement(Settings, _lines)); continue; } #endregion #region Point else if (Movement[u].Value is GH_Point) { //TODO continue; } #endregion #region Not Supported else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Datatype Not Supported!"); continue; } } #endregion } goto SortZ; #endregion break; case 3: #region Completely Sorted if (sorted == 3) { //Initialise sMovements sMovements = new List <SilkwormMovement> [1]; sMovements[0] = new List <SilkwormMovement>(); for (int u = 0; u < Movement.Length; u++) { #region IfNull if ((Movement[u].Value == null)) { continue; } #endregion #region SilkwormMovement else if ((Movement[u].Value is Silkworm.Type.SilkwormMovement)) { SilkwormMovement aMovement = (SilkwormMovement)Movement[u].Value; if (aMovement.complete) { aMovement.Configuration = Settings; //Make sure it has a config field sMovements[0].Add(aMovement); continue; } else { sMovements[0].Add(completeMovement(Settings, aMovement)); //sMovements[0].Add(new SilkwormMovement(Movements, new Delimiter())); continue; } } #endregion #region Solids else if (Movement[u].Value is GH_Brep) { Brep solid = null; List <Brep> solids = new List <Brep>(); GH_Convert.ToBrep(Movement[u].Value, ref solid, GH_Conversion.Both); solids.Add(solid); List <SilkwormMovement> solidMovements = addsolidBrep(Settings, solids); sMovements[0].AddRange(solidMovements); continue; } else if (Movement[u].Value is GH_Mesh) { Mesh mesh = null; GH_Convert.ToMesh(Movement[u].Value, ref mesh, GH_Conversion.Both); continue; } #endregion #region Regions //TODO #endregion #region Curves else if (Movement[u].Value is GH_Curve) { Curve curve = null; GH_Convert.ToCurve(Movement[u].Value, ref curve, GH_Conversion.Both); SilkwormMovement movement = new SilkwormMovement(Settings, curve); sMovements[0].Add(movement); continue; } #endregion #region SilkwormLine else if (Movement[u].Value is SilkwormLine) { List <SilkwormLine> s_lines = new List <SilkwormLine>(); s_lines.Add((SilkwormLine)Movement[u].Value); //Check if complete if (isCompleteLine((SilkwormLine)Movement[u].Value)) { sMovements[0].Add(new SilkwormMovement(s_lines, new Delimiter())); } else { List <Line> lines = new List <Line>(); SilkwormLine[] s_Movement = new SilkwormLine[s_lines.Count]; foreach (SilkwormLine line in s_lines) { lines.Add(line.sLine); } List <SilkwormLine> sLines = new SilkwormMovement(Settings, lines).sMovement; List <SilkwormLine> Movements = new List <SilkwormLine>(); //Complete Movements for (int j = 0; j < sLines.Count; j++) { if (s_Movement[j].Flow == -1) { s_Movement[j].Flow = sLines[j].Flow; } if (s_Movement[j].Speed == -1) { s_Movement[j].Speed = sLines[j].Speed; } Movements.Add(s_Movement[j]); } SilkwormMovement newMovement = new SilkwormMovement(Movements, new Delimiter()); //Add Configuration newMovement.Configuration = Settings; sMovements[0].Add(newMovement); } continue; } #endregion #region Line else if (Movement[u].Value is GH_Line) { Line line = new Line(); GH_Convert.ToLine(Movement[u].Value, ref line, GH_Conversion.Both); List <Line> _lines = new List <Line>(); _lines.Add(line); sMovements[0].Add(new SilkwormMovement(Settings, _lines)); continue; } #endregion #region Point else if (Movement[u].Value is GH_Point) { //TODO continue; } #endregion #region Not Supported else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Datatype Not Supported!"); continue; } } #endregion } goto Compiler; #endregion break; default: break; } #region ss ////Parse //#region Parse Input Type //List<Brep> solids = new List<Brep>(); //List<Mesh> meshes = new List<Mesh>(); ////Incomplete Silkworm Movements //List<SilkwormMovement> incmovements = new List<SilkwormMovement>(); //List<Brep> shapes = new List<Brep>(); //List<Curve> curves = new List<Curve>(); //List<Polyline> plines = new List<Polyline>(); //List<Line> lines = new List<Line>(); //for (int i = 0; i < Movement.Length; i++) //{ ////Sort Types into Container Lists // #region IfNull // if ((Movement[i].Value == null)) // { continue; } // #endregion //#region SilkwormMovement //if ((Movement[i].Value is Silkworm.Type.SilkwormMovement)) //{ // SilkwormMovement aMovement = (SilkwormMovement)Movement[i].Value; // if(aMovement.complete) // { // unMovements.Add(aMovement); // continue; // } // else // { // incmovements.Add(aMovement); // continue; // } //} //#endregion //#region Solids //if (Movement[i].Value is GH_Brep) //{ // Brep solid = null; // GH_Convert.ToBrep(Movement[i].Value, ref solid, GH_Conversion.Both); // solids.Add(solid); // continue; //} //if (Movement[i].Value is GH_Mesh) //{ // Mesh mesh = null; // GH_Convert.ToMesh(Movement[i].Value, ref mesh, GH_Conversion.Both); // meshes.Add(mesh); // continue; //} //#endregion //#region Regions ////TODO //#endregion //#region Curves //if (Movement[i].Value is GH_Curve) //{ // Curve curve = null; // GH_Convert.ToCurve(Movement[i].Value, ref curve, GH_Conversion.Both); // curves.Add(curve); // continue; //} //#endregion //#region SilkwormLine //if (Movement[i].Value is SilkwormLine) //{ // List<SilkwormLine> slines = new List<SilkwormLine>(); // slines.Add((SilkwormLine)Movement[i].Value); // //Check if complete // if (isCompleteLine((SilkwormLine)Movement[i].Value)) // { // unMovements.Add(new SilkwormMovement(slines, true)); // } // else // { // incmovements.Add(new SilkwormMovement(slines, true)); // } // continue; //} //#endregion //#region Line // if (Movement[i].Value is GH_Line) //{ // Line line = new Line(); // GH_Convert.ToLine(Movement[i].Value, ref line, GH_Conversion.Both); // lines.Add(line); //} //#endregion //#region Point // if (Movement[i].Value is GH_Point) //{ // //TODO // continue; //} //#endregion //else //{ // AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Datatype Not Supported!"); // continue; //} //#endregion //} ////Build Movements from Incomplete Parts //#region Build Movement //#region List<Brep>Add to unMovements // //List<Brep> solidS = new List<Brep>(); // //solidS.Add((Brep)solid); // List<Polyline>[] rPerimeter = new List<Polyline>[0]; // List<Polyline>[] rInfill = new List<Polyline>[0]; // //Slice, Skin and Fill Breps (TODO: Add Bridge Finder) // SilkwormSkein skein = new SilkwormSkein(Settings, solids); // if (skein.validPos) // { // rPerimeter = skein.plinePerimeter; // rInfill = skein.plineInfill; // } // List<SilkwormMovement> solidMovements = new List<SilkwormMovement>(); // //Add to ORGANISED List of Movements (i.e. Model) // for (int b = 0; b <= rPerimeter.GetUpperBound(0); b++) // { // foreach (Polyline pline in rPerimeter[b]) // { // //List<SilkwormMovement> sList = new List<SilkwormMovement>(); // //sList.Add(new SilkwormMovement(Settings, pline, true)); // solidMovements.Add(new SilkwormMovement(Settings, pline, true)); // } // foreach (Polyline pline in rInfill[b]) // { // //List<SilkwormMovement> sList = new List<SilkwormMovement>(); // //sList.Add(new SilkwormMovement(Settings, pline, true)); // solidMovements.Add(new SilkwormMovement(Settings, pline, true)); // } // } // unMovements.AddRange(solidMovements); //#endregion //#region List<Mesh> Add to unMovements ////TODO //#endregion //#region List<Shapes> Add to unMovements ////TODO //#endregion //#region List<Curve> Add to unMovements //foreach (Curve curve in curves) //{ // SilkwormMovement movement = new SilkwormMovement(Settings, curve, true); // unMovements.Add(movement); //} //#endregion //#region List<Line> Add to unMovements //foreach (Line line in lines) //{ // List<Line> _lines = new List<Line>(); // _lines.Add(line); // unMovements.Add(new SilkwormMovement(Settings, _lines, true)); //} //#endregion //#region List<IncompleteSilkwormMovement> Add to unMovements //foreach (SilkwormMovement movement in incmovements) // { // List<Line> lines = new List<Line>(); // SilkwormLine[] s_Movement = new SilkwormLine[movement.Count]; // foreach (SilkwormLine line in movement) // { // lines.Add(line.Curve); // } // List<SilkwormLine> sLines = new SilkwormMovement(Settings, lines,true).sMovement; // List<SilkwormLine> Movements = new List<SilkwormLine>(); // //Complete Movements // for (int j = 0; j < sLines.Count; j++) // { // if (s_Movement[j].Flow == -1) // { // s_Movement[j].Flow = sLines[j].Flow; // } // if (s_Movement[j].Speed == -1) // { // s_Movement[j].Speed = sLines[j].Speed; // } // Movements.Add(s_Movement[j]); // } // //Add Configuration // movement.Configuration = Settings; // unMovements.Add(new SilkwormMovement(Movements, true)); // continue; //} //#endregion //#endregion #endregion //Sort Unorganised Movements into Layered Model SortZ: #region Build Model List <double> uniqueZ = new List <double>(); //Find Unique ZValues uniqueZ.AddRange(FindUniqueZValues(unMovements, layerHeightDP)); //Sort List of Unique Z Levels uniqueZ.Sort(); //Make Dictionary from List of Unique Z Levels Dictionary <double, int> ZLevel = new Dictionary <double, int>(); for (int d = 0; d < uniqueZ.Count; d++) { ZLevel.Add(uniqueZ[d], d); } //Initialise Array of Lists sMovements = new List <SilkwormMovement> [uniqueZ.Count]; for (int a = 0; a < sMovements.Length; a++) { sMovements[a] = new List <SilkwormMovement>(); } //Sort Silkworm Movements into correct layers in Array of Lists foreach (SilkwormMovement movement in unMovements) { sMovements[ZLevel[Math.Round(movement.ZDomain.T0, layerHeightDP)]].Add(movement); } #endregion goto Compiler; //Compile Model to GCode Compiler: #region GCode Compiler #region HEADER //Add Custom Commands at Start string header = Settings["start_gcode"]; //Char[] splitChar = new Char[] {'\\','\n', 'n'}; string[] splitChar = new string[] { "\\n" }; string[] parts = header.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); if (parts != null) { for (int i = 0; i < parts.Length; i++) { sGCode.Add(new GH_String(parts[i])); } } else { sGCode.Add(new GH_String(header)); } if (int.Parse(Settings["absolute_extrudersteps"]) == 1) //if true use absolute distances for extrusion, otherwise use relative { sGCode.Add(new GH_String("M82 ; use absolute distances for extrusion")); } sGCode.Add(new GH_String("G90 ; use absolute coordinates")); sGCode.Add(new GH_String("G21 ; set units to millimeters")); sGCode.Add(new GH_String("G92 E0 ; reset extrusion distance")); //Set Temperature double temp = double.Parse(Settings["temperature"]); sGCode.Add(new GH_String("M104 S" + temp + " ; set temperature")); sGCode.Add(new GH_String("M109 S" + temp + " ; wait for temperature to be reached")); //Extrude a bit of plastic before start sGCode.Add(new GH_String("G1 Z0.0 F360 E1")); #endregion for (int z = 0; z <= sMovements.GetUpperBound(0); z++) { foreach (SilkwormMovement movement in sMovements[z]) { sGCode.AddRange(movement.ToGCode()); } } #region FOOTER sGCode.Add(new GH_String("G92 E0 ; reset extrusion distance")); //Add Custom Commands at End string footer = Settings["end_gcode"]; string[] fparts = footer.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); if (fparts != null) { for (int i = 0; i < fparts.Length; i++) { sGCode.Add(new GH_String(fparts[i])); } } else { sGCode.Add(new GH_String(footer)); } #endregion ////Convert Array of Movements to List //List<SilkwormMovement> outMovements = new List<SilkwormMovement>(); //for (int l = 0; l < sMovements.GetUpperBound(0); l++) //{ // outMovements.AddRange(sMovements[l]); //} #endregion #region Silkworm Model List <SilkwormMovement> s_Model = new List <SilkwormMovement>(); for (int p = 0; p <= sMovements.GetUpperBound(0); p++) { for (int s = 0; s < sMovements[p].Count; s++) { s_Model.Add(sMovements[p][s]); } } List <SilkwormModel> sModel = new List <SilkwormModel>(); sModel.Add(new SilkwormModel(Settings, s_Model)); #endregion //Output GCode and Model #region OUTPUTS DA.SetDataList(0, sGCode); DA.SetDataList(1, sModel); #endregion }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Brep ghbrep = new GH_Brep(); if (DA.GetData(0, ref ghbrep)) { if (ghbrep == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Brep input is null"); } Brep brep = new Brep(); if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both)) { // 1 Points List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); List <Point3d> pts = new List <Point3d>(); List <GsaNode> nodes = new List <GsaNode>(); if (DA.GetDataList(1, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { Point3d pt = new Point3d(); if (gh_types[i].Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_types[i].CastTo(ref gsanode); nodes.Add(gsanode); } else if (GH_Convert.ToPoint3d(gh_types[i].Value, ref pt, GH_Conversion.Both)) { pts.Add(pt); } else { string type = gh_types[i].Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Point/Node input parameter of type " + type + " to point or node"); } } } // 2 Curves gh_types = new List <GH_ObjectWrapper>(); List <Curve> crvs = new List <Curve>(); List <GsaMember1d> mem1ds = new List <GsaMember1d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { Curve crv = null; if (gh_types[i].Value is GsaMember1dGoo) { GsaMember1d gsamem1d = new GsaMember1d(); gh_types[i].CastTo(ref gsamem1d); mem1ds.Add(gsamem1d); } else if (GH_Convert.ToCurve(gh_types[i].Value, ref crv, GH_Conversion.Both)) { crvs.Add(crv); } else { string type = gh_types[i].Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Curve/Mem1D input parameter of type " + type + " to curve or 1D Member"); } } } // 4 mesh size GH_Number ghmsz = new GH_Number(); double meshSize = 0; if (DA.GetData(4, ref ghmsz)) { GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both); meshSize = m_size; } // build new element2d with brep, crv and pts GsaElement2d elem2d = new GsaElement2d(brep, crvs, pts, meshSize, mem1ds, nodes); // 3 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(3, ref gh_typ)) { if (gh_typ.Value is GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { prop2d.ID = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } } else { prop2d.ID = 1; } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int i = 0; i < elem2d.Elements.Count; i++) { prop2Ds.Add(prop2d); } elem2d.Properties = prop2Ds; DA.SetData(0, new GsaElement2dGoo(elem2d)); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaProfile profile = new GsaProfile(); #region catalogue if (_mode == FoldMode.Catalogue) { profile.profileType = GsaProfile.ProfileTypes.Catalogue; // need to implement the lists of cross sections profile.catalogueIndex = catalogueIndex; profile.catalogueProfileIndex = catalogueProfileIndex; profile.catalogueTypeIndex = catalogueTypeIndex; } #endregion #region geometric if (_mode == FoldMode.Geometric) { profile.profileType = GsaProfile.ProfileTypes.Geometric; GH_Brep gh_Brep = new GH_Brep(); if (DA.GetData(0, ref gh_Brep)) { Brep brep = new Brep(); if (GH_Convert.ToBrep(gh_Brep, ref brep, GH_Conversion.Both)) { // get edge curves from Brep Curve[] edgeSegments = brep.DuplicateEdgeCurves(); Curve[] edges = Curve.JoinCurves(edgeSegments); // find the best fit plane List <Point3d> ctrl_pts = new List <Point3d>(); if (edges[0].TryGetPolyline(out Polyline tempCrv)) { ctrl_pts = tempCrv.ToList(); } else { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Cannot convert edge to Polyline"); } Plane.FitPlaneToPoints(ctrl_pts, out Plane plane); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.ChangeBasis(Plane.WorldXY, plane); profile.geoType = GsaProfile.GeoTypes.Perim; List <Point2d> pts = new List <Point2d>(); foreach (Point3d pt3d in ctrl_pts) { pt3d.Transform(xform); Point2d pt2d = new Point2d(pt3d); pts.Add(pt2d); } profile.perimeterPoints = pts; if (edges.Length > 1) { List <List <Point2d> > voidPoints = new List <List <Point2d> >(); for (int i = 1; i < edges.Length; i++) { ctrl_pts.Clear(); if (!edges[i].IsPlanar()) { for (int j = 0; j < edges.Length; j++) { edges[j] = Curve.ProjectToPlane(edges[j], plane); } } if (edges[i].TryGetPolyline(out tempCrv)) { ctrl_pts = tempCrv.ToList(); pts = new List <Point2d>(); foreach (Point3d pt3d in ctrl_pts) { pt3d.Transform(xform); Point2d pt2d = new Point2d(pt3d); pts.Add(pt2d); } voidPoints.Add(pts); } else { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Cannot convert internal edge to Polyline"); } } profile.voidPoints = voidPoints; } } } } #endregion #region standard section if (_mode != FoldMode.Geometric & _mode != FoldMode.Catalogue) { profile.profileType = GsaProfile.ProfileTypes.Standard; GH_Number gh_d = new GH_Number(); GH_Number gh_b1 = new GH_Number(); GH_Number gh_b2 = new GH_Number(); GH_Number gh_tw1 = new GH_Number(); GH_Number gh_tw2 = new GH_Number(); GH_Number gh_tf1 = new GH_Number(); GH_Number gh_tf2 = new GH_Number(); switch (selections[1]) { case "Rectangle": profile.stdShape = GsaProfile.StdShapeOptions.Rectangle; // 0 d DA.GetData(0, ref gh_d); // 1 b1 DA.GetData(1, ref gh_b1); if (isTapered) { // 2 b2 DA.GetData(2, ref gh_b2); } else { if (isHollow) { // 2 tw DA.GetData(2, ref gh_tw1); // 3 tw DA.GetData(3, ref gh_tf1); } } break; case "Circle": profile.stdShape = GsaProfile.StdShapeOptions.Circle; // 0 d DA.GetData(0, ref gh_d); if (isHollow) { if (isElliptical) { // 1 b1 DA.GetData(1, ref gh_b1); // 2 tw DA.GetData(2, ref gh_tw1); } else { // 1 tw DA.GetData(1, ref gh_tw1); } } else { if (isElliptical) { // 1 b1 DA.GetData(1, ref gh_b1); } } break; case "I section": profile.stdShape = GsaProfile.StdShapeOptions.I_section; // 0 d DA.GetData(0, ref gh_d); // 1 b1 DA.GetData(1, ref gh_b1); // 2 tw1 DA.GetData(2, ref gh_tw1); // 3 tf1 DA.GetData(3, ref gh_tf1); if (isGeneral) { if (isTapered) { // 4 b2 DA.GetData(4, ref gh_b2); // 5 tw2 DA.GetData(5, ref gh_tw2); // 6 tf2 DA.GetData(6, ref gh_tf2); } else { // 4 b2 DA.GetData(4, ref gh_b2); // 5 tf2 DA.GetData(5, ref gh_tf2); } } break; case "Tee": profile.stdShape = GsaProfile.StdShapeOptions.Tee; // 0 d DA.GetData(0, ref gh_d); // 1 b1 DA.GetData(1, ref gh_b1); // 2 tf1 DA.GetData(2, ref gh_tf1); // 3 tw1 DA.GetData(3, ref gh_tw1); if (isTapered) { // 4 tw2 DA.GetData(4, ref gh_tw2); } break; case "Channel": profile.stdShape = GsaProfile.StdShapeOptions.Channel; // 0 d DA.GetData(0, ref gh_d); // 1 b1 DA.GetData(1, ref gh_b1); // 2 tf1 DA.GetData(2, ref gh_tf1); // 3 tw1 DA.GetData(3, ref gh_tw1); break; case "Angle": profile.stdShape = GsaProfile.StdShapeOptions.Angle; // 0 d DA.GetData(0, ref gh_d); // 1 b1 DA.GetData(1, ref gh_b1); // 2 tf1 DA.GetData(2, ref gh_tf1); // 3 tw1 DA.GetData(3, ref gh_tw1); break; } if (gh_d != null) { if (GH_Convert.ToDouble(gh_d, out double d, GH_Conversion.Both)) { profile.d = d; } } if (gh_b1 != null) { if (GH_Convert.ToDouble(gh_b1, out double b1, GH_Conversion.Both)) { profile.b1 = b1; } } if (gh_b2 != null) { if (GH_Convert.ToDouble(gh_b2, out double b2, GH_Conversion.Both)) { profile.b2 = b2; } } if (gh_tw1 != null) { if (GH_Convert.ToDouble(gh_tw1, out double tw1, GH_Conversion.Both)) { profile.tw1 = tw1; } } if (gh_tw2 != null) { if (GH_Convert.ToDouble(gh_tw2, out double tw2, GH_Conversion.Both)) { profile.tw2 = tw2; } } if (gh_tf1 != null) { if (GH_Convert.ToDouble(gh_tf1, out double tf1, GH_Conversion.Both)) { profile.tf1 = tf1; } } if (gh_tf2 != null) { if (GH_Convert.ToDouble(gh_tf2, out double tf2, GH_Conversion.Both)) { profile.tf2 = tf2; } } profile.isB2B = isB2B; profile.isElliptical = isElliptical; profile.isGeneral = isGeneral; profile.isHollow = isHollow; profile.isTapered = isTapered; } #endregion #region units switch (Util.Unit.LengthSection) { case "mm": profile.sectUnit = GsaProfile.SectUnitOptions.u_mm; break; case "cm": profile.sectUnit = GsaProfile.SectUnitOptions.u_cm; break; case "m": profile.sectUnit = GsaProfile.SectUnitOptions.u_m; break; case "in": profile.sectUnit = GsaProfile.SectUnitOptions.u_in; break; case "ft": profile.sectUnit = GsaProfile.SectUnitOptions.u_ft; break; } #endregion // build string and output DA.SetData(0, ConvertSection.ProfileConversion(profile)); }
/// <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> sBreps = new GH_Structure <GH_Brep>(); DA.GetDataTree <GH_Brep>(0, out sBreps); GH_Structure <GH_Brep> dBreps = new GH_Structure <GH_Brep>(); DA.GetDataTree <GH_Brep>(1, out dBreps); double tol = DocumentTolerance(); ///Reserve one processor for GUI int totalMaxConcurrancy = System.Environment.ProcessorCount - 1; ///Tells us how many threads were using Message = totalMaxConcurrancy + " threads"; ///Declare dictionaries that work in parallel to hold the successful boolean results and ///the unsuccessful boolean cutters var mainBrepsMT = new System.Collections.Concurrent.ConcurrentDictionary <GH_Path, GH_Brep>(); var badBrepsMT = new System.Collections.Concurrent.ConcurrentDictionary <GH_Path, List <GH_Brep> >(); ///Start of the parallel engine ///Cast to GH_Brep to Brep and back in parallel engine to avoid speed hit when casting all at once later System.Threading.Tasks.Parallel.ForEach(sBreps.Paths, new System.Threading.Tasks.ParallelOptions { MaxDegreeOfParallelism = totalMaxConcurrancy }, pth => { List <GH_Brep> badBrep = new List <GH_Brep>(); Brep mainBrep = new Brep(); GH_Convert.ToBrep(sBreps.get_Branch(pth)[0], ref mainBrep, 0); List <Brep> diffBreps = new List <Brep>(); foreach (var d_GH in dBreps.get_Branch(pth)) { Brep d_Rhino = new Brep(); GH_Convert.ToBrep(d_GH, ref d_Rhino, 0); diffBreps.Add(d_Rhino); } ///Difference one cutter brep at a time from the main brep in the branch. ///This allows the boolean operation to continue without failing ///and bad cutter breps can be discarded to a list that can be used for troubleshooting ///haven't noticed a hit big hit on performance foreach (Brep b in diffBreps) { Brep[] breps = new Brep[] { }; breps = Brep.CreateBooleanDifference(mainBrep, b, tol); if ((breps == null) || (breps.Length < 1)) { badBrep.Add(new GH_Brep(b)); } else { mainBrep = breps[0]; } } mainBrepsMT[pth] = new GH_Brep(mainBrep); badBrepsMT[pth] = badBrep; }); ///End of the parallel engine /// //convert dictionaries to regular old data trees GH_Structure <GH_Brep> mainBreps = new GH_Structure <GH_Brep>(); GH_Structure <GH_Brep> badBreps = new GH_Structure <GH_Brep>(); foreach (KeyValuePair <GH_Path, GH_Brep> p in mainBrepsMT) { mainBreps.Append(p.Value, p.Key); } foreach (KeyValuePair <GH_Path, List <GH_Brep> > b in badBrepsMT) { badBreps.AppendRange(b.Value, b.Key); } DA.SetDataTree(0, mainBreps); DA.SetDataTree(1, badBreps); }
/// <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; var iWriteControl = 0; var iWriteInterval = 0.0; DA.GetDataTree(0, out iDomain); DA.GetData(1, ref iWriteControl); DA.GetData(2, ref iWriteInterval); DataTree <Brep> convertedGeomTree = new DataTree <Brep>(); int iPath = 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(iPath)); convertedBrep = null; } iPath += 1; } if (iWriteControl < 1 || iWriteControl > 2) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Entry unknown! To set write control add a ValueList component."); return; } string writeInterval = iWriteInterval.ToString(); string writeControl = ""; switch (iWriteControl) { case 1: writeControl = "timeStep"; break; case 2: writeControl = "outputTime"; break; } string forcesString = ""; for (int i = 6; i < convertedGeomTree.Paths.Count; i++) { string brepName = convertedGeomTree.Branch(convertedGeomTree.Path(i))[0].GetUserString("Name").ToString(); string CofR_X = VolumeMassProperties.Compute(convertedGeomTree.Branch(convertedGeomTree.Path(i))).Centroid.X.ToString(); string CofR_Y = VolumeMassProperties.Compute(convertedGeomTree.Branch(convertedGeomTree.Path(i))).Centroid.Y.ToString(); string CofR_Z = VolumeMassProperties.Compute(convertedGeomTree.Branch(convertedGeomTree.Path(i))).Centroid.Z.ToString(); string CofR = CofR_X + " " + CofR_Y + " " + CofR_Z; forcesString += "forces_" + brepName + "\n" + "{\n" + " type forces;\n" + " functionObjectLibs (\"libforces.so\");\n" + " writeControl " + writeControl + "; //'timeStep' or 'outputTime'\n" + " writeInterval " + writeInterval + ";\n" + " name forces_" + brepName + " \n" + " log yes;\n" + " \n" + " patches (\"" + brepName + "\");\n" + " log true;\n" + " rho rhoInf;\n" + " rhoInf 1.18;\n" + " CofR (" + CofR + ");\n" + "}\n" + "\n"; } string brepNames = ""; for (int i = 6; i < convertedGeomTree.Paths.Count; i++) { brepNames += " " + convertedGeomTree.Branch(convertedGeomTree.Path(i))[0].GetUserString("Name") + "\n"; } convertedGeomTree.Flatten(); List <Brep> flattenedList = convertedGeomTree.Branch(convertedGeomTree.Path(0)); string geomXCoord = VolumeMassProperties.Compute(flattenedList.GetRange(6, flattenedList.Count - 6)).Centroid.X.ToString(); string geomYCoord = VolumeMassProperties.Compute(flattenedList.GetRange(6, flattenedList.Count - 6)).Centroid.Y.ToString(); string geomCentCoord = geomXCoord + " " + geomYCoord + " 0.0"; #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" + "{0}\n" + "\n" + "forces_All\n" + "{{\n" + " type forces;\n" + " functionObjectLibs (\"libforces.so\");\n" + " writeControl {1}; //'timeStep' or 'outputTime'\n" + " writeInterval {2};\n" + " name forces_SK_All\n" + "\n" + " log yes;\n" + "\n" + " patches\n" + " (\n" + "{3}" + " );\n" + " log true;\n" + " rho rhoInf;\n" + " rhoInf 1.20;\n" + " CofR ({4});\n" + "}}"; #endregion string forcesFile = string.Format(shellString, forcesString, writeControl, writeInterval, brepNames, geomCentCoord); var oForcesFile = new TextFile(forcesFile, "forces"); DA.SetData(0, oForcesFile); }
/// <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) { #region INPUTS // import silkwormSettings file List <string> silkwormSettings = new List <string>(); if (!DA.GetDataList(0, silkwormSettings)) { return; } List <GH_ObjectWrapper> things = new List <GH_ObjectWrapper>(); if (!DA.GetDataList(1, things)) { return; } // import Silkworm Movement #endregion SilkwormUtility sUtil = new SilkwormUtility(); Dictionary <string, string> Settings = sUtil.convertSettings(silkwormSettings); #region Optional Variables int shell = -999; if (!DA.GetData(4, ref shell)) { } double layerheight = -999; if (!DA.GetData(3, ref layerheight)) { } //bool detect = false; //if (!DA.GetData(5, ref detect)) { } List <Plane> sliceplanes = new List <Plane>(); if (!DA.GetDataList(2, sliceplanes)) { } if (shell == -999) { shell = int.Parse(Settings["perimeters"]); } if (layerheight == -999) { layerheight = double.Parse(Settings["layer_height"]); } if (sliceplanes.Count < 1) { sliceplanes.Add(Plane.WorldXY); } #endregion List <Brep> Breps = new List <Brep>(); List <Mesh> Meshes = new List <Mesh>(); SilkwormSkein skein = new SilkwormSkein(); #region Sort Types foreach (GH_ObjectWrapper obj in things) { if (obj.Value is GH_Brep) { Brep brep = null; GH_Convert.ToBrep(obj.Value, ref brep, GH_Conversion.Both); Breps.Add(brep); continue; } if (obj.Value is GH_Mesh) { Mesh mesh = null; GH_Convert.ToMesh(obj.Value, ref mesh, GH_Conversion.Both); Meshes.Add(mesh); continue; } } #endregion if (Breps.Count > 0) { skein = new SilkwormSkein(Settings, Breps, sliceplanes, shell, layerheight); skein.BrepSlice(false); } if (Meshes.Count > 0) { //TODO } //Reflect Errors and Warnings foreach (string message in skein.ErrorMessages) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message); } foreach (string message in skein.WarningMessages) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, message); } List <Curve>[] openregions = skein.openRegions; List <Brep>[] rRegions = skein.Regions; List <Brep>[] rPerimeterR = skein.regionPerimeter; List <Brep>[] rInfillR = skein.regionInfill; GH_Structure <GH_Brep> Regions = new GH_Structure <GH_Brep>(); GH_Structure <GH_Curve> openRegions = new GH_Structure <GH_Curve>(); #region Add Regions to GH_Structure if (rRegions.GetUpperBound(0) > 1) { for (int i = 0; i < rRegions.Length; i++) { if (rRegions[i] != null) { for (int j = 0; j < rRegions[i].Count; j++) { GH_Brep gShapes = new GH_Brep(rRegions[i][j]); Regions.Insert(gShapes, new GH_Path(i, 0), j); } } } } if (rPerimeterR.GetUpperBound(0) > 1) { for (int i = 0; i < rPerimeterR.Length; i++) { if (rPerimeterR[i] != null) { for (int j = 0; j < rPerimeterR[i].Count; j++) { GH_Brep gShapes = new GH_Brep(rPerimeterR[i][j]); Regions.Insert(gShapes, new GH_Path(i, 1), j); } } } } if (rInfillR.GetUpperBound(0) > 1) { for (int i = 0; i < rInfillR.Length; i++) { if (rInfillR[i] != null) { for (int j = 0; j < rInfillR[i].Count; j++) { GH_Brep gShapes = new GH_Brep(rInfillR[i][j]); Regions.Insert(gShapes, new GH_Path(i, 2), j); } } } } if (openregions.GetUpperBound(0) > 1) { for (int i = 0; i < openregions.Length; i++) { if (openregions[i] != null) { for (int j = 0; j < openregions[i].Count; j++) { GH_Curve gShapes = new GH_Curve(openregions[i][j]); openRegions.Insert(gShapes, new GH_Path(i), j); } } } } //TODO //Add Overhang and Bridges #endregion #region Add Open Regions to GH_Structure if (openregions.GetUpperBound(0) > 1) { for (int i = 0; i < openregions.Length; i++) { for (int j = 0; j < openregions[i].Count; j++) { if (openregions[i][j] != null) { SilkwormSegment segment = new SilkwormSegment(openregions[i][j]); Curve curve = segment.Pline.ToNurbsCurve(); GH_Curve gShapes = new GH_Curve(curve); openRegions.Insert(gShapes, new GH_Path(i), j); } } } } #endregion #region OUTPUT if (!DA.SetDataTree(0, Regions)) { return; } if (!DA.SetDataTree(1, openRegions)) { return; } #endregion }
/// <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); }