/// <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_Point> iProbes; DA.GetDataTree(0, out iProbes); DataTree <Point3d> convertedProbesTree = new DataTree <Point3d>(); int x = 0; Point3d convertedPoint = new Point3d(); foreach (GH_Path path in iProbes.Paths) { foreach (var pt in iProbes.get_Branch(path)) { GH_Convert.ToPoint3d(pt, ref convertedPoint, 0); convertedProbesTree.Add(convertedPoint, new GH_Path(x)); convertedPoint = new Point3d(); } x += 1; } List <TextFile> windProbesFiles = new List <TextFile>(); foreach (var path in convertedProbesTree.Paths) { #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" + " // Where to load it from\n" + " functionObjectLibs (\"libsampling.so\");\n" + " type probes;\n" + " // Name of the directory for probe data\n" + " name {1};\n" + " // Write at same frequency as fields\n" + " writeControl timeStep;\n" + " writeInterval 1;\n" + " // Fields to be probed\n" + " fields\n" + " (\n" + " p U\n" + " );\n" + " //For Spectral analysis and velo profile\n" + " probeLocations\n" + " (\n" + " {2}\n" + " );\n" + " }}"; #endregion string ptCoord = ""; foreach (var pt in convertedProbesTree.Branch(path)) { ptCoord += "(" + pt.X.ToString() + " " + pt.Y.ToString() + " " + pt.Z.ToString() + ")\n "; } string name = "windProbes_" + path.ToString().Replace("{", "").Replace("}", ""); string tempWindFile = string.Format(shellString, name, name, ptCoord); var oWindFile = new TextFile(tempWindFile, name); windProbesFiles.Add(oWindFile); } DA.SetDataList(0, windProbesFiles); }
protected override void SolveInstance(IGH_DataAccess DA) { ///input parameters GH_Structure <GH_Vector> Tree = new GH_Structure <GH_Vector>(); bool s = false; /// initialise parameters List <int> X_i = new List <int>(); List <int> Y_i = new List <int>(); List <int> Z_i = new List <int>(); GH_Path pth = null; Vector3d vector3D = new Vector3d(); DataTree <int> indices = new DataTree <int>(); ///import if (!DA.GetDataTree("Vectors", out Tree)) { return; } if (!DA.GetData("Strict", ref s)) { return; } /// 0. error catching /// 1. decompose datatree /// 2. convert GH_GOO structure to rhinocommon Vector3D /// 3. querry list /// 4. create new datatree /// 5. output data List <Point3d> P1 = new List <Point3d>(); List <Point3d> P2 = new List <Point3d>(); List <Point3d> result = new List <Point3d>(); /// 1. decompose datatree for (int i = 0; i < Tree.PathCount; i++) { /// 2. convert GH_GOO structure to rhinocommon Vector3D pth = Tree.get_Path(i); var branch = Tree.Branches[i]; List <Vector3d> V = new List <Vector3d>(); foreach (GH_Vector thisGHVector in branch) { GH_Convert.ToVector3d(thisGHVector, ref vector3D, 0); V.Add(vector3D); } /// 3. querry list if (s == false) { X_i = V .Select((v, index) => index) .Where(index => Math.Abs(V[index].X) >= Math.Abs(V[index].Y) && Math.Abs(V[index].X) >= Math.Abs(V[index].Z)) .ToList(); Y_i = V .Select((v, index) => index) .Where(index => Math.Abs(V[index].Y) >= Math.Abs(V[index].X) && Math.Abs(V[index].Y) >= Math.Abs(V[index].Z)) .ToList(); Z_i = V .Select((v, index) => index) .Where(index => Math.Abs(V[index].Z) >= Math.Abs(V[index].X) && Math.Abs(V[index].Z) >= Math.Abs(V[index].Y)) .ToList(); } else { var a = 1 / Math.Sqrt(3); X_i = V .Select((v, index) => index) .Where(index => Math.Abs(V[index].X) >= a) .ToList(); Y_i = V .Select((v, index) => index) .Where(index => Math.Abs(V[index].Y) >= a) .ToList(); Z_i = V .Select((v, index) => index) .Where(index => Math.Abs(V[index].Z) >= a) .ToList(); } /// 4. create new datatree var path = pth.Indices.ToList(); path.Add(0); var p = new GH_Path(path.ToArray()); indices.AddRange(X_i, p); path = pth.Indices.ToList(); path.Add(1); p = new GH_Path(path.ToArray()); indices.AddRange(Y_i, p); path = pth.Indices.ToList(); path.Add(2); p = new GH_Path(path.ToArray()); indices.AddRange(Z_i, p); } /// Output DA.SetDataTree(0, indices); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaProp2d prop = new GsaProp2d(); // element type (picked in dropdown) prop.Prop2d.Type = Property2D_Type.UNDEF; if (_mode == FoldMode.PlaneStress) { prop.Prop2d.Type = Property2D_Type.PL_STRESS; } if (_mode == FoldMode.Fabric) { prop.Prop2d.Type = Property2D_Type.FABRIC; } if (_mode == FoldMode.FlatPlate) { prop.Prop2d.Type = Property2D_Type.PLATE; } if (_mode == FoldMode.Shell) { prop.Prop2d.Type = Property2D_Type.SHELL; } if (_mode == FoldMode.CurvedShell) { prop.Prop2d.Type = Property2D_Type.CURVED_SHELL; } if (_mode == FoldMode.LoadPanel) { prop.Prop2d.Type = Property2D_Type.LOAD; } //id GH_Integer gh_ID = new GH_Integer(); DA.GetData(0, ref gh_ID); int idd = 0; GH_Convert.ToInt32_Primary(gh_ID, ref idd); prop.ID = idd; //name GH_String gh_Name = new GH_String(); DA.GetData(1, ref gh_Name); string name = ""; GH_Convert.ToString_Primary(gh_Name, ref name); prop.Prop2d.Name = name; //colour GH_Colour gh_Colour = new GH_Colour(); DA.GetData(2, ref gh_Colour); System.Drawing.Color colour = new System.Drawing.Color(); GH_Convert.ToColor_Primary(gh_Colour, ref colour); prop.Prop2d.Colour = (ValueType)colour; if (_mode != FoldMode.LoadPanel) { //axis GH_Integer gh_Axis = new GH_Integer(); DA.GetData(3, ref gh_Axis); int axis = 0; GH_Convert.ToInt32_Primary(gh_Axis, ref axis); prop.Prop2d.AxisProperty = axis; if (_mode != FoldMode.Fabric) { //Material type GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); MaterialType matType = MaterialType.CONCRETE; if (DA.GetData(4, ref gh_typ)) { if (gh_typ.Value is MaterialType) { gh_typ.CastTo(ref matType); } if (gh_typ.Value is GH_String) { string typ = "CONCRETE"; GH_Convert.ToString_Primary(gh_typ, ref typ); if (typ.ToUpper() == "STEEL") { matType = MaterialType.STEEL; } if (typ.ToUpper() == "CONCRETE") { matType = MaterialType.CONCRETE; } if (typ.ToUpper() == "FRP") { matType = MaterialType.FRP; } if (typ.ToUpper() == "ALUMINIUM") { matType = MaterialType.ALUMINIUM; } if (typ.ToUpper() == "TIMBER") { matType = MaterialType.TIMBER; } if (typ.ToUpper() == "GLASS") { matType = MaterialType.GLASS; } if (typ.ToUpper() == "FABRIC") { matType = MaterialType.FABRIC; } if (typ.ToUpper() == "GENERIC") { matType = MaterialType.GENERIC; } } } prop.Prop2d.MaterialType = matType; //thickness GH_Number gh_THK = new GH_Number(); double thickness = 0.2; if (DA.GetData(7, ref gh_THK)) { GH_Convert.ToDouble_Primary(gh_THK, ref thickness); } //prop.Prop2d.Thickness = thickness; } else { prop.Prop2d.MaterialType = MaterialType.FABRIC; } //handle that the last two inputs are at different -1 index for fabric mode int fab = 0; if (_mode == FoldMode.Fabric) { fab = 1; } //grade GH_Integer gh_grd = new GH_Integer(); DA.GetData(5 - fab, ref gh_grd); int grade = 1; GH_Convert.ToInt32_Primary(gh_grd, ref grade); prop.Prop2d.MaterialGradeProperty = grade; //analysis GH_Integer gh_anal = new GH_Integer(); DA.GetData(6 - fab, ref gh_anal); int analysis = 1; GH_Convert.ToInt32_Primary(gh_anal, ref analysis); prop.Prop2d.MaterialAnalysisProperty = analysis; } DA.SetData(0, new GsaProp2dGoo(prop)); }
/// <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); }
public override bool CastTo <Q>(out Q target) { // This function is called when Grasshopper needs to convert this // instance of GsaElement into some other type Q. if (typeof(Q).IsAssignableFrom(typeof(GsaElement1d))) { if (Value == null) { target = default; } else { target = (Q)(object)Value.Duplicate(); } return(true); } if (typeof(Q).IsAssignableFrom(typeof(Element))) { if (Value == null) { target = default; } else { target = (Q)(object)Value.Element; } return(true); } //Cast to Curve if (typeof(Q).IsAssignableFrom(typeof(Line))) { if (Value == null) { target = default; } else { target = (Q)(object)Value.Line; } return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Line))) { if (Value == null) { target = default; } else { GH_Line ghLine = new GH_Line(); GH_Convert.ToGHLine(Value.Line, GH_Conversion.Both, ref ghLine); target = (Q)(object)ghLine; } return(true); } if (typeof(Q).IsAssignableFrom(typeof(Curve))) { if (Value == null) { target = default; } else { target = (Q)(object)Value.Line; } return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Curve))) { if (Value == null) { target = default; } else { target = (Q)(object)new GH_Curve(Value.Line); } return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Integer))) { if (Value == null) { target = default; } else { GH_Integer ghint = new GH_Integer(); if (GH_Convert.ToGHInteger(Value.ID, GH_Conversion.Both, ref ghint)) { target = (Q)(object)ghint; } else { target = default; } } return(true); } target = default; return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { string filePath = null; if (!DA.GetData(0, ref filePath)) { return; } if (!filePath.EndsWith(@"\")) { filePath = filePath + @"\"; } var heating = new List <double>(); var cooling = new List <double>(); var dhw = new List <double>(); var electricity = new List <double>(); if (!DA.GetDataList(1, heating)) { return; } if (!DA.GetDataList(2, cooling)) { return; } if (!DA.GetDataList(3, dhw)) { return; } if (!DA.GetDataList(4, electricity)) { return; } var solarAreas = new List <double>(); if (!DA.GetDataList(5, solarAreas)) { return; } GH_Structure <GH_Number> solarPotentials; if (!DA.GetDataTree(6, out solarPotentials)) { return; } List <List <double> > solarPotList = new List <List <double> >(); for (int i = 0; i < solarPotentials.Branches.Count; i++) { solarPotList.Add(new List <double>()); foreach (GH_Number gooNumber in solarPotentials.get_Branch(i)) { double numb; GH_Convert.ToDouble(gooNumber, out numb, GH_Conversion.Both); solarPotList[i].Add(numb); } } var irradiance = new double[solarPotList.Count][]; for (int i = 0; i < solarPotList.Count; i++) { irradiance[i] = solarPotList[i].ToArray(); } var ghi = new List <double>(); var dryBulb = new List <double>(); if (!DA.GetDataList(7, ghi)) { return; } if (!DA.GetDataList(8, dryBulb)) { return; } bool run = false; DA.GetData(9, ref run); int epsilonCuts = 3; DA.GetData(10, ref epsilonCuts); if (run) { try { LoadTechParameters(filePath + "technologies.csv", out var technologyParameters); technologyParameters.Add("NumberOfBuildingsInEHub", Convert.ToDouble(1)); technologyParameters.Add("Peak_Htg_" + Convert.ToString(0), heating.Max()); technologyParameters.Add("Peak_Clg_" + Convert.ToString(0), cooling.Max()); Rhino.RhinoApp.WriteLine("_____LOADING INPUTS COMPLETE_____"); Rhino.RhinoApp.WriteLine("_________________________________"); Rhino.RhinoApp.WriteLine("_____CLUSTERING TYPICAL DAYS_____"); int numberOfSolarAreas = solarAreas.Count; int numBaseLoads = 5; // heating, cooling, electricity, ghi, tamb int numLoads = numBaseLoads + numberOfSolarAreas; // heating, cooling, electricity, ghi, tamb, solar. however, solar will include several profiles. const int hoursPerYear = 8760; double[][] fullProfiles = new double[numLoads][]; string[] loadTypes = new string[numLoads]; bool[] peakDays = new bool[numLoads]; bool[] correctionLoad = new bool[numLoads]; for (int u = 0; u < numLoads; u++) { fullProfiles[u] = new double[hoursPerYear]; } loadTypes[0] = "heating"; loadTypes[1] = "cooling"; loadTypes[2] = "electricity"; loadTypes[3] = "ghi"; loadTypes[4] = "Tamb"; peakDays[0] = true; peakDays[1] = true; peakDays[2] = true; peakDays[3] = false; peakDays[4] = false; correctionLoad[0] = true; correctionLoad[1] = true; correctionLoad[2] = true; correctionLoad[3] = false; correctionLoad[4] = false; bool[] useForClustering = new bool[fullProfiles .Length]; // specificy here, which load is used for clustering. the others are just reshaped for (int t = 0; t < hoursPerYear; t++) { fullProfiles[0][t] = heating[t] + dhw[t]; fullProfiles[1][t] = cooling[t]; fullProfiles[2][t] = electricity[t]; fullProfiles[3][t] = ghi[t]; fullProfiles[4][t] = dryBulb[t]; useForClustering[0] = true; useForClustering[1] = true; useForClustering[2] = true; useForClustering[3] = true; useForClustering[4] = false; } for (int u = 0; u < numberOfSolarAreas; u++) { useForClustering[u + numBaseLoads] = false; peakDays[u + numBaseLoads] = false; correctionLoad[u + numBaseLoads] = true; loadTypes[u + numBaseLoads] = "solar"; for (int t = 0; t < hoursPerYear; t++) { fullProfiles[u + numBaseLoads][t] = irradiance[u][t]; } } // TO DO: load in GHI time series, add it to full profiles (right after heating, cooling, elec), and use it for clustering. exclude other solar profiles from clustering, but they need to be reshaped too EhubMisc.HorizonReduction.TypicalDays typicalDays = EhubMisc.HorizonReduction.GenerateTypicalDays( fullProfiles, loadTypes, 12, peakDays, useForClustering, correctionLoad, true); /// Running Energy Hub Rhino.RhinoApp.WriteLine("Solving MILP optimization model..."); double[][] typicalSolarLoads = new double[numberOfSolarAreas][]; // solar profiles negative or very small numbers. rounding floating numbers thing? for (int u = 0; u < numberOfSolarAreas; u++) { typicalSolarLoads[u] = typicalDays.DayProfiles[numBaseLoads + u]; for (int t = 0; t < typicalSolarLoads[u].Length; t++) { if (typicalSolarLoads[u][t] < 0.1) { typicalSolarLoads[u][t] = 0.0; } } } // same for heating, cooling, elec demand... round very small numbers for (int t = 0; t < typicalDays.DayProfiles[0].Length; t++) { for (int i = 0; i < 3; i++) { if (typicalDays.DayProfiles[i][t] < 0.001) { typicalDays.DayProfiles[i][t] = 0.0; } } } int[] clustersizePerTimestep = typicalDays.NumberOfDaysPerTimestep; Ehub ehub = new Ehub(typicalDays.DayProfiles[0], typicalDays.DayProfiles[1], typicalDays.DayProfiles[2], typicalSolarLoads, solarAreas.ToArray(), typicalDays.DayProfiles[4], technologyParameters, clustersizePerTimestep); ehub.Solve(epsilonCuts, true); Rhino.RhinoApp.WriteLine("___________________________"); Rhino.RhinoApp.WriteLine("ENERGY HUB SOLVER COMPLETED"); var capex = new List <double>(); var opex = new List <double>(); var emissions = new List <double>(); for (int i = 0; i < ehub.Outputs.Length; i++) { capex.Add(ehub.Outputs[i].CAPEX); opex.Add(ehub.Outputs[i].OPEX); emissions.Add(ehub.Outputs[i].carbon); } DA.SetDataList(0, capex); DA.SetDataList(1, opex); DA.SetDataList(2, emissions); WriteOutput("EaCS3_HS21_Results_Ehub", filePath, numberOfSolarAreas, ehub, typicalDays, numBaseLoads); Rhino.RhinoApp.WriteLine("___________________________"); Rhino.RhinoApp.WriteLine("RESULTS WRITTEN TO" + filePath.ToString()); } catch (Exception e) { Rhino.RhinoApp.WriteLine(e.Message); throw; } } // return results to outputs IN GH component }
protected override void Layout() { base.Layout(); Rectangle global_rec = GH_Convert.ToRectangle(Bounds); int height = 19; int width = 90; int radi1 = 7; int radi2 = 4; int pitchx = 8; int pitchy = 11; int textheight = 20; radio_rec0 = global_rec; radio_rec0.Y = radio_rec0.Bottom; radio_rec0.Height = height; radio_rec_1 = radio_rec0; radio_rec_1.X += 5; radio_rec_1.Y += 5; radio_rec_1.Height = radi1; radio_rec_1.Width = radi1; text_rec_1 = radio_rec_1; text_rec_1.X += pitchx; text_rec_1.Y -= radi2; text_rec_1.Height = textheight; text_rec_1.Width = width; title_rec1 = radio_rec0; title_rec1.Y = radio_rec0.Bottom; title_rec1.Width = global_rec.Width; title_rec1.Height = 22; radio_rec1 = title_rec1; radio_rec1.Y = title_rec1.Bottom; radio_rec1.Height = height; radio_rec_11 = radio_rec1; radio_rec_11.X += 5; radio_rec_11.Y += 5; radio_rec_11.Height = radi1; radio_rec_11.Width = radi1; text_rec_11 = radio_rec_11; text_rec_11.X += pitchx; text_rec_11.Y -= radi2; text_rec_11.Height = textheight; text_rec_11.Width = width; radio_rec_12 = radio_rec_11; radio_rec_12.X = text_rec_11.X + 45; text_rec_12 = radio_rec_12; text_rec_12.X += pitchx; text_rec_12.Y -= radi2; text_rec_12.Height = textheight; text_rec_12.Width = width; title_rec2 = radio_rec1; title_rec2.Y = radio_rec1.Bottom; title_rec2.Width = global_rec.Width; title_rec2.Height = 22; radio_rec2 = title_rec2; radio_rec2.Y = title_rec2.Bottom; radio_rec2.Height = height * 2; radio_rec_21 = radio_rec2; radio_rec_21.X += 5; radio_rec_21.Y += 5; radio_rec_21.Height = radi1; radio_rec_21.Width = radi1; text_rec_21 = radio_rec_21; text_rec_21.X += pitchx; text_rec_21.Y -= radi2; text_rec_21.Height = textheight; text_rec_21.Width = width; radio_rec_22 = radio_rec_21; radio_rec_22.Y += pitchy; text_rec_22 = radio_rec_22; text_rec_22.X += pitchx; text_rec_22.Y -= radi2; text_rec_22.Height = textheight; text_rec_22.Width = width; radio_rec_23 = radio_rec_22; radio_rec_23.Y += pitchy; text_rec_23 = radio_rec_23; text_rec_23.X += pitchx; text_rec_23.Y -= radi2; text_rec_23.Height = textheight; text_rec_23.Width = width; global_rec.Height += radio_rec2.Bottom - radio_rec0.Y; Bounds = global_rec; }