Exemplo n.º 1
0
    /// <summary>
    /// This procedure contains the user code. Input parameters are provided as regular arguments,
    /// Output parameters as ref arguments. You don't have to assign output parameters,
    /// they will have a default value.
    /// </summary>
    private void RunScript(DataTree <Point3d> P, ref object A, ref object B, ref object C, ref object D, ref object E)
    {
        // simplify
        P.SimplifyPaths();
        // making a copy since DataTree is reference type
        A = new DataTree <Point3d>(P);

        // graft
        P.Graft(false);
        B = new DataTree <Point3d>(P);

        // flatten (extract alla data to a list)
        List <Point3d> pts = P.AllData(); // data tree to List

        C = pts;

        // extract paths list (like Param Viewer)
        IList <GH_Path> paths = P.Paths;

        D = paths;

        // rebuild a tree from the list
        DataTree <Point3d> pTree = new DataTree <Point3d>();
        GH_Path            p;

        for (int i = 0; i < paths.Count; i++)
        {
            p = new GH_Path(paths[i][0]);
            pTree.Add(pts[i], p);
        }
        E = pTree;
    }
Exemplo n.º 2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh m = new Mesh();

            DA.GetData(0, ref m);

            double d = 1;

            DA.GetData(1, ref d);

            Polyline[] polylinesOriginal = m.GetPolylines();
            Polyline[] polylines         = m.PlanarOffset(d);
            //Polyline[] polylines = m.PlanarBisectorOffset(d);

            DataTree <Polyline> dt = new DataTree <Polyline>();

            for (int i = 0; i < polylines.Length; i++)
            {
                dt.AddRange(new[] { polylinesOriginal[i], polylines[i] }, new Grasshopper.Kernel.Data.GH_Path(i));
            }

            this.PreparePreview(m, DA.Iteration, dt.AllData(), false);

            DA.SetDataTree(0, dt);
        }
Exemplo n.º 3
0
        //http://www.pointclouds.org/documentation/tutorials/normal_estimation.php
        //https://www.cloudcompare.org/doc/wiki/index.php?title=Normals%5CCompute



        public static List <Vector3d> LineCloudNormals(DataTree <Line> lines, DataTree <int> adj)
        {
            List <Vector3d> _Normals = new List <Vector3d>();

            //Compute bounding box of cloud
            BoundingBox bbox = new BoundingBox();

            foreach (Line l in lines.AllData())
            {
                bbox.Union(l.From);
                bbox.Union(l.To);
            }

            bbox.Inflate(100);
            Point3d p = bbox.PointAt(0.5, 0.5, 1);



            //Iterate through joints



            //Fit to Plane

            //Add all lines point to a base datatree
            DataTree <Point3d> pts = new DataTree <Point3d>();

            for (int i = 0; i < lines.BranchCount; i++)
            {
                pts.Add(lines.Branch(i)[0].From, new GH_Path(i));
                pts.Add(lines.Branch(i)[0].To, new GH_Path(i));
            }

            //Add only second object point to first object path
            for (int i = 0; i < adj.BranchCount; i++)
            {
                int id0 = adj.Branch(i)[0];
                int id1 = adj.Branch(i)[1];

                pts.Add(lines.Branch(id1)[0].From, new GH_Path(id0));
                pts.Add(lines.Branch(id1)[0].To, new GH_Path(id0));
            }

            //Orient Plane
            for (int i = 0; i < pts.BranchCount; i++)
            {
                Plane.FitPlaneToPoints(pts.Branch(i), out Plane plane);
                plane.Origin = (pts.Branch(i)[0] + pts.Branch(i)[1]) * 0.5;
                if ((plane.Origin + plane.Normal).DistanceToSquared(p) > (plane.Origin - plane.Normal).DistanceToSquared(p))
                {
                    plane.Flip();
                }
                _Normals.Add(plane.Normal);
            }



            return(_Normals);
        }
Exemplo n.º 4
0
	}//eof




	/// <summary>
    /// This is the method that actually does the work.
	/// </summary>
	protected override void SolveInstance(IGH_DataAccess DA)
	{
		List<Curve> crv = new List<Curve>();
		if (!DA.GetDataList(0, crv)) return;

		DataTree<Curve> r = new DataTree<Curve>();

		for (int i = 0; i < crv.Count; ++i)
		{
			if (!isChildOfCrv(crv[i], crv))
			{
				GH_Path p = new GH_Path(0);
				r.Add(crv[i], p);
			}
		}

		bool isAnyCrvAligned = true;

		while (isAnyCrvAligned)
		{
			isAnyCrvAligned = false;
			int BC = r.BranchCount;
			for (int i = 0; i < BC; ++i)
			{
				for (int j = 0; j < crv.Count; ++j)
				{
					if (r.AllData().IndexOf(crv[j]) == -1)
					{
						GH_Path p = new GH_Path(i + 1);
						if (isChildOfCrv(crv[j], r.Branch(i)))
						{
							r.Add(crv[j], p);
							isAnyCrvAligned = true;
						}
					}
				}
			}
		}

		DA.SetDataTree(0, r);
	}//eof
Exemplo n.º 5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <IGH_GeometricGoo> iGeometry = new GH_Structure <IGH_GeometricGoo>();
            double        iAngle       = 0.0;
            List <string> iPatchNames  = new List <string>();
            List <int>    iRefLvlGeom  = new List <int>();
            List <int>    ieMeshRefLvl = new List <int>();
            List <double> iX           = new List <double>();
            double        iY           = 0.0;
            double        iZ           = 0.0;
            Plane         iZeroPlane   = new Plane();

            DA.GetDataTree(0, out iGeometry);
            DA.GetData(1, ref iAngle);
            DA.GetDataList(2, iPatchNames);
            DA.GetDataList(3, iRefLvlGeom);
            DA.GetDataList(4, ieMeshRefLvl);
            DA.GetDataList(5, iX);
            DA.GetData(6, ref iY);
            DA.GetData(7, ref iZ);
            DA.GetData(8, ref iZeroPlane);


            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> rotatedGeomTree = convertedGeomTree;
            Point3d         centerPt        = GetCenterPt(rotatedGeomTree.AllData());

            foreach (GH_Path path in rotatedGeomTree.Paths)
            {
                foreach (var brep in rotatedGeomTree.Branch(path))
                {
                    brep.Rotate(iAngle * Math.PI / 180, Vector3d.ZAxis, centerPt);
                }
            }

            if (DA.GetData(8, ref iZeroPlane))
            {
                centerPt.Z = iZeroPlane.OriginZ;
            }

            double height = GetHeight(convertedGeomTree.AllData());
            double width  = GetWidth(convertedGeomTree.AllData());
            double depth  = GetDepth(convertedGeomTree.AllData());

            if (!DA.GetDataList(2, iPatchNames))
            {
                for (int i = 0; i < rotatedGeomTree.BranchCount; i++)
                {
                    iPatchNames.Add("PATCH_" + i);
                }
            }

            if (!DA.GetDataList(3, iRefLvlGeom))
            {
                for (int i = 0; i < rotatedGeomTree.BranchCount; i++)
                {
                    iRefLvlGeom.Add(2);
                }
            }

            if (!DA.GetDataList(4, ieMeshRefLvl))
            {
                for (int i = 0; i < rotatedGeomTree.BranchCount; i++)
                {
                    ieMeshRefLvl.Add(2);
                }
            }

            if (!DA.GetDataList(5, iX))
            {
                iX.Add(4 * height);
                iX.Add(12 * height);
            }

            if (!DA.GetData(6, ref iY))
            {
                iY = 6 * height;
            }

            if (!DA.GetData(7, ref iZ))
            {
                iZ = 6 * height;
            }

            if (iX[0] <= 0.5 * depth || iX[1] <= 0.5 * depth)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The depth of the wind tunnel is too small!");
            }
            else if (iX[0] < 2.5 * height || iX[1] < 7.5 * height)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The depth of the wind tunnel is small, be aware.");
            }

            if (iY < 4 * height)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The width of the wind tunnel is small, be aware.");
            }
            else if (iY <= width)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The width of the wind tunnel is too small!");
            }

            if (iZ < 6 * height)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The height of the wind tunnel is small, be aware.");
            }
            else if (iZ <= height)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The height of the wind tunnel is too small!");
            }

            List <Point3d> cornerPoints = new List <Point3d>
            {
                new Point3d(centerPt.X - iX[0], centerPt.Y - iY / 2, centerPt.Z),
                new Point3d(centerPt.X + iX[1], centerPt.Y - iY / 2, centerPt.Z),
                new Point3d(centerPt.X + iX[1], centerPt.Y + iY / 2, centerPt.Z),
                new Point3d(centerPt.X - iX[0], centerPt.Y + iY / 2, centerPt.Z),
                new Point3d(centerPt.X - iX[0], centerPt.Y - iY / 2, centerPt.Z + iZ),
                new Point3d(centerPt.X + iX[1], centerPt.Y - iY / 2, centerPt.Z + iZ),
                new Point3d(centerPt.X + iX[1], centerPt.Y + iY / 2, centerPt.Z + iZ),
                new Point3d(centerPt.X - iX[0], centerPt.Y + iY / 2, centerPt.Z + iZ)
            };


            List <Brep> surfaceList = new List <Brep> {
                Brep.CreateFromCornerPoints(cornerPoints[0], cornerPoints[4], cornerPoints[7], cornerPoints[3], 0.01),
                Brep.CreateFromCornerPoints(cornerPoints[1], cornerPoints[2], cornerPoints[6], cornerPoints[5], 0.01),
                Brep.CreateFromCornerPoints(cornerPoints[3], cornerPoints[7], cornerPoints[6], cornerPoints[2], 0.01),
                Brep.CreateFromCornerPoints(cornerPoints[0], cornerPoints[1], cornerPoints[5], cornerPoints[4], 0.01),
                Brep.CreateFromCornerPoints(cornerPoints[0], cornerPoints[3], cornerPoints[2], cornerPoints[1], 0.01),
                Brep.CreateFromCornerPoints(cornerPoints[4], cornerPoints[5], cornerPoints[6], cornerPoints[7], 0.01)
            };


            List <string> nameList = new List <string>
            {
                "INLET",
                "OUTLET",
                "LEFTSIDE",
                "RIGHTSIDE",
                "BOTTOM",
                "TOP"
            };

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

            int j = 0;
            int k = 0;

            foreach (var surface in surfaceList)
            {
                surface.SetUserString("Name", nameList[j]);
                surface.SetUserString("RefLvl", "0");
                surface.SetUserString("eMeshLvl", "0");
                surface.SetUserString("RotAngle", iAngle.ToString());
                oGeometryList.Add(surface, new GH_Path(k));
                j++;
                k++;
            }
            ;

            j = 0;
            foreach (GH_Path path in rotatedGeomTree.Paths)
            {
                foreach (var brep in rotatedGeomTree.Branch(path))
                {
                    brep.SetUserString("Name", iPatchNames[j]);
                    brep.SetUserString("RefLvl", iRefLvlGeom[j].ToString());
                    brep.SetUserString("eMeshLvl", ieMeshRefLvl[j].ToString());
                    brep.SetUserString("RotAngle", iAngle.ToString());
                    oGeometryList.Add(brep, new GH_Path(k));
                }
                j++;
                k++;
            }

            DA.SetDataTree(0, oGeometryList);
        }
Exemplo n.º 6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <GH_Brep> 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" +
                "!       Tempor„re 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);
        }
        public void calculate(
            ref DataTree <Rectangle3d> core_list,
            ref List <Rectangle3d> skin_list,
            ref DataTree <Point3d> g_pts,
            ref DataTree <int> g_val,
            int max_skin_width,
            int max_skin_height,
            int core_min_width,
            int core_min_height,
            double efficiency,
            double deviation
            )
        {
            List <Rectangle3d>     s = new List <Rectangle3d>();
            DataTree <Rectangle3d> c = new DataTree <Rectangle3d>();

            double core_area = core_min_width * core_min_height;
            double gfa       = ((1.0 / efficiency) * core_area) - core_area;

            for (int skin_w = 1; skin_w <= max_skin_width; skin_w++)
            {
                for (int skin_h = 1; skin_h <= max_skin_height; skin_h++)
                {
                    if (skin_w * skin_h - core_area >= gfa * (1.0 - deviation) && skin_w * skin_h - core_area <= gfa * (1.0 + deviation))
                    {
                        s.Add(new Rectangle3d(Plane.WorldXY, new Point3d(0, 0, 0), new Point3d(skin_w, skin_h, 0)));

                        double possible_x_pos = skin_w - core_min_width;
                        double possible_y_pos = skin_h - core_min_height;

                        c.EnsurePath(s.Count - 1);
                        for (int k = 0; k <= possible_x_pos; k++)
                        {
                            for (int l = 0; l <= possible_y_pos; l++)
                            {
                                c.Add(new Rectangle3d(Plane.WorldXY, new Point3d(k, l, 0), new Point3d(k + core_min_width, l + core_min_height, 0)));

                                g_val.EnsurePath(c.AllData().Count - 1);

                                g_pts.EnsurePath(c.AllData().Count - 1);

                                for (int m = 0; m < skin_w; m++)
                                {
                                    for (int n = 0; n < skin_h; n++)
                                    {
                                        g_pts.Add(new Point3d(m + 0.5, n + 0.5, 0));

                                        if ((m + 0.5 > k && m + 0.5 < k + core_min_width) && (n + 0.5 > l && n + 0.5 < l + core_min_height))
                                        {
                                            g_val.Add(0);
                                        }
                                        else
                                        {
                                            g_val.Add(1);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            skin_list = s;
            core_list = c;
        }
Exemplo n.º 8
0
 public List <Point3d> ToList()
 {
     return(tree.AllData());
 }
Exemplo n.º 9
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            try {
                Mesh   M   = DA.Fetch <Mesh>("Mesh");
                double D   = DA.Fetch <double>("Offset");
                int    T   = DA.Fetch <int>("Type");
                double W   = DA.Fetch <double>("Dist2");
                double Tol = DA.Fetch <double>("Tol");
                var    mid = DA.FetchList <int>("Custom");


                bool                P = true;
                Polyline[]          p0;
                Polyline[]          p1;
                DataTree <Polyline> dt          = new DataTree <Polyline>();
                DataTree <Polyline> dtThickness = new DataTree <Polyline>();
                if (D == 0)
                {
                    switch (T)
                    {
                    case (1):

                        base.Message = "No Offset \n Projection";
                        //output
                        dt = new DataTree <Polyline>();
                        var polygons = M.ProjectedPolylinesToAveragePlane(P);
                        for (int i = 0; i < M.Ngons.Count; i++)
                        {
                            dt.Add(polygons[i], new GH_Path(DA.Iteration, i));
                        }

                        break;

                    default:

                        base.Message = "No Offset \n FaceEdgeBisector";

                        //Get edge planes and corner bisectors *----*----*
                        Plane[][] bisePlanes;
                        Plane[][] edgePlanes;
                        M.GetEdgeAndBisectorPlanes(out bisePlanes, out edgePlanes);
                        dt = new DataTree <Polyline>();


                        //Get Outlines
                        p0 = M.GetPolylines();
                        for (int i = 0; i < M.Ngons.Count; i++)
                        {
                            Plane plane = p0[i].GetPlane(P);
                            dt.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i));

                            if (W > 0)
                            {
                                plane = plane.MovePlanebyAxis(-W * 0.5);
                                dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i));
                                plane = plane.MovePlanebyAxis(W);
                                dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i));
                                plane = plane.MovePlanebyAxis(-W * 0.5);
                            }
                        }

                        break;
                    }
                    DA.SetDataList(0, new Mesh[] { M });
                }
                else
                {
                    //Offset two meshes in both sides
                    Mesh m0 = M.DuplicateMesh();
                    Mesh m1 = M.DuplicateMesh();

                    m0 = m0.Offset(D * 0.5);
                    m1 = m1.Offset(-D * 0.5);


                    switch (T)
                    {
                    case (1):
                        //case (2):

                        base.Message = "Offset \n Projection";



                        //output
                        Mesh mA  = M.DuplicateMesh();
                        Mesh mB  = M.DuplicateMesh();
                        Mesh mC  = M.DuplicateMesh();
                        Mesh mD  = M.DuplicateMesh();
                        Mesh mA_ = M.DuplicateMesh();
                        Mesh mB_ = M.DuplicateMesh();

                        Mesh mE = M.DuplicateMesh();
                        Mesh mF = M.DuplicateMesh();

                        mA  = mA.Offset(-D * 0.5 + W * 0.5);
                        mB  = mB.Offset(-D * 0.5 - W * 0.5);
                        mC  = mC.Offset(D * 0.5 + W * 0.5);
                        mD  = mD.Offset(D * 0.5 - W * 0.5);
                        mA_ = mA_.Offset(-D * 0.5);
                        mB_ = mB_.Offset(D * 0.5);
                        mE  = mE.Offset(W * 0.5);
                        mF  = mF.Offset(-W * 0.5);


                        dtThickness = new DataTree <Polyline>();
                        dt          = new DataTree <Polyline>();

                        //Rhino.RhinoApp.WriteLine("Hi");

                        var a  = mA.ProjectedPolylinesToAveragePlane(P);
                        var b  = mB.ProjectedPolylinesToAveragePlane(P);
                        var c  = mC.ProjectedPolylinesToAveragePlane(P);
                        var d  = mD.ProjectedPolylinesToAveragePlane(P);
                        var a_ = mA_.ProjectedPolylinesToAveragePlane(P);
                        var b_ = mB_.ProjectedPolylinesToAveragePlane(P);
                        var e  = mE.ProjectedPolylinesToAveragePlane(P);
                        var f  = mF.ProjectedPolylinesToAveragePlane(P);

                        for (int i = 0; i < a.Length; i++)
                        {
                            dtThickness.Add(a[i], new GH_Path(DA.Iteration, i));
                            dtThickness.Add(b[i], new GH_Path(DA.Iteration, i));

                            if (mid.Contains(i))
                            {
                                dtThickness.Add(e[i], new GH_Path(DA.Iteration, i));
                                dtThickness.Add(f[i], new GH_Path(DA.Iteration, i));
                            }
                            dtThickness.Add(c[i], new GH_Path(DA.Iteration, i));
                            dtThickness.Add(d[i], new GH_Path(DA.Iteration, i));


                            dt.Add(a_[i], new GH_Path(DA.Iteration, i));
                            dt.Add(b_[i], new GH_Path(DA.Iteration, i));
                        }

                        break;

                    default:

                        base.Message = "Offset \n FaceEdgeBisector";

                        //Get edge planes and corner bisectors *----*----*
                        Plane[][] bisePlanes;
                        Plane[][] edgePlanes;
                        M.GetEdgeAndBisectorPlanes(out bisePlanes, out edgePlanes);

                        DataTree <Plane> pls = new DataTree <Plane>();

                        for (int i = 0; i < bisePlanes.Length; i++)
                        {
                            pls.AddRange(bisePlanes[i], new GH_Path(DA.Iteration, 0, i));
                            pls.AddRange(edgePlanes[i], new GH_Path(DA.Iteration, 1, i));
                        }
                        //EdgePlanes = pls;
                        DA.SetDataTree(3, pls);

                        dt          = new DataTree <Polyline>();
                        dtThickness = new DataTree <Polyline>();

                        //Get Outlines
                        p0 = M.GetPolylines();
                        p1 = M.GetPolylines();
                        for (int i = 0; i < M.Ngons.Count; i++)
                        {
                            Plane plane = p0[i].GetPlane(P);

                            plane = plane.MovePlanebyAxis(D * 0.5);
                            dt.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i));

                            if (W > 0)
                            {
                                plane = plane.MovePlanebyAxis(-W * 0.5);
                                dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i));
                                plane = plane.MovePlanebyAxis(W);
                                dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i));
                                plane = plane.MovePlanebyAxis(-W * 0.5);
                            }



                            plane = plane.MovePlanebyAxis(-D);
                            dt.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i));

                            if (W > 0)
                            {
                                plane = plane.MovePlanebyAxis(-W * 0.5);
                                dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i));
                                plane = plane.MovePlanebyAxis(W);
                                dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i));
                                plane = plane.MovePlanebyAxis(-W * 0.5);
                            }
                        }

                        break;
                    }

                    //Output
                    //OffsetMesh = new Mesh[] { m0, m1 };
                    this.PreparePreview(m0, DA.Iteration, dt.AllData(), false);
                    DA.SetDataList(0, new Mesh[] { m0, m1 });
                }

                DA.SetDataTree(1, dt);
                DA.SetDataTree(2, dtThickness);
                //ProjectedPolylines = dt;
                //Thickness = dtThickness;
            }catch (Exception e) {
                Rhino.RhinoApp.WriteLine(e.ToString());
            }
        }