SO-Optimization Sun Hours on Roof
-
Intro
-
Design
-
Setting up the geometry
-
Sun Hour analysis
-
Galapagos optimization
-
Conclusion
-
Useful Links
Information
Primary software used | Grasshopper |
Course | BKB2WV3 – Digitale Ontwerpomgeving |
Primary subject | AI & ML |
Secondary subject | Optimization |
Level | Intermediate |
Last updated | November 11, 2024 |
Keywords |
Responsible
Teachers | |
Faculty |
SO-Optimization Sun Hours on Roof 0/6
SO-Optimization Sun Hours on Roof link copied
In this tutorial you learn to set up a script for optimizing roof openings to minimize the total sun hours using Galapagos.
Welcome to the tutorial on Single Criterion Optimization using Galapagos. For the design problem, we are imagining the following scenario: you are tasked to design the roof of a sunken courtyard in which you will need to place openings. These openings should be placed to minimize the direct light shining on the terrace below during summer. In the following chapters we will discuss a method to optimize the location of the openings, based on sun exposure. After this tutorial you will be able to set up a script for optimization using Ladybug and Galapagos.
SO-Optimization Sun Hours on Roof 1/6
Design link copied
A roof design is created for a partially covered terrace. The terrace is located in a sunken courtyard and is split into two separate terraces. The roof consists of a curved surface with three openings. The three openings can be placed freely within the roof surface. The goal is to optimize the total amount of sunlight on the terraces so it is minimized in the summer. The geometry for the 3 opening is able to overlap to form a larger opening, so there will be between 1 and 3 openings in the roof. To work with the same settings as the tutorial create the surfaces with the following design criteria:
- Courtyard (in Rhino): 18×38 meters
- Roof (in Grasshopper or in Rhino): 2 times wider than deep (18 meters wide, 9 meter deep)
- Opening (in Grasshopper or in Rhino): 2 times longer than wide (4 meters long, 3 meter wide)
- Terrace (in Rhino): 3 times as long than wide & 2 separate terraces (small and big) (10.5×3,5 meters & 7×21 meters)
Exercise file
In this starting example file the courtyard, roof, openings, and terraces are located as a starting point. You can follow this tutorial with the exact same geometries or replace the roof and terrace design with your own design within the courtyard. If wanted, you could also follow the optimization steps with a completely different design, as the optimization steps work the same.
Download SO-OptimizationSunHoursOnRoof_GHscript_00
application/zip (ZIP, 34 KB)
SO-Optimization Sun Hours on Roof 2/6
Setting up the geometry link copied
Connect Rhino Geometry
First create a model in Rhino with the design of the roof and terrace. You can use the example of this tutorial which is internalised (saved) in the exercise script or create your own design. If you’re using the created design of this tutorial you can skip this step.
Design the surfaces for: roof (blue), terrace(s) (orange), opening (white) and context walls (grey) and assign each of the three to a separate surface node. The design surface from Rhino can be imported into grasshopper by:
- Creating the geometries in Rhino
- Input created surface by setting one surface from Rhino
Note: It is recommended to use a surface, not a 3D geometry.
If you want to understand how the roofs and openings can be created fully parametrically, follow this tutorial. Be aware that this is not needed for this current tutorial and can bring extra complexity to your model.
Create multiple openings
Now that we have our geometry linked, we will want to duplicate the geometry of the openings so that we can have multiple openings in our roof. Decide which transformations are allowed. In the case of this example, we will assume that three openings can be moved along the X and Y axis. You can also incorporate scaling the openings or manipulating them in other ways. Use the Stack Data component to duplicate the geometry. The input data will be connected to the surfaces and the number of duplications (three times to get three openings). Additionally, the openings should be movable across the X and Y axis. A Move Component needs to be created for the X and Y axes.
- Create multiple openings
- Move the surface
- Select the X and Y axes
Create movable openings
The distance that an opening can be moved should be defined. The available values will be defined by a Gene Pool. By double-clicking on the Gene Pool, you can setup the sliders. This process works similar to a standard Number Slider. As the model is in mm the input should also be given in milimeters. However, as this will result in too many steps if each step is a change of 1 mm, set the Gene Pool input in meters and multiply with 1000 to convert to millimetres.
Two Gene Pool components will be created, one for the X-axis and one for the Y-axis. Set the Gene Count to 3 and the decimals to 1. For the X-axis, the maximum is the width (longer edge) of the roof minus the width (longer edge) of the opening (18-4=14m in the example case), since that is the maximum distance that the opening can move across the roof. For the Y-axis, the maximum is the depth (shorter edge) of the roof minus the depth (shorter edge) of the opening (9-2=7m in the example case).
- Add a Gene Pool
- Change the settings of the Gene Pool
- Maximum X-axis Gene Pool = 14
- Maximum Y-axis Gene Pool = 7
Connect the Gene Pool components to an Expression component that converts the meters input to millimetres. Write the equation ‘x*1000’ and ‘-y*1000’ inside the expression box by double-clicking LMB on the expression component. Note that the y-axis is multiplied by -1, so the openings move in the right direction on the axis. Connect the outputs to the different Move components. Connect the expression from Gene Pool for X to the Unit X component and expression from Gene Pool for Y to the Unit Y component.
- Convert to mm with the expression component
- Multiplicate x-axis with 1000
- Multiplicate y-axis
- Connect output Expression to Unit X OR Unit Y
Roof openings
Now that we have the location of our openings, what we’re going to need to do is cut our roof with these openings so that we can get our final roof geometry Finish the script by creating a roof with openings by projecting the opening onto the roof surface. Deconstruct the openings to get the edges, project the edges onto the surface, and split the surface with these curves. Because the edges come in with the edges in separate branches, we also want to make sure to flatten the curves that come out of this projection.
- Deconstruct Brep to get the opening edges
- project the edges onto the surface
- split the surface with these curve
To select the roof surface with the holes, sort the surfaces by area, and select the -1 index which selects the last item (largest area) in the list. Note that the output of projecting the curves and the output of the calculating the area need to be flattened.
- Calculate surface area
- Sort the surfaces by area
- Select the -1 index
SO-Optimization Sun Hours on Roof 3/6
Sun Hour analysis link copied
Now we need to analyse the hours of sun on the terrace below. For the optimization, we need to measure the fitness of our design options and show where the best location for the openings in the roof are. We will be using Ladybug to understand the amount of sunlight that comes through the openings to the deck below. This tutorial goes briefly through the Ladybug sun analysis set-up. To learn more about incorporating a shading analysis from Ladybug with Galapagos please see this tutorial.
Creating Sun Path
First we need to import the weather files, determine the analysis period, and create the sun path. For this example, we are analysing during the summer period at 4 in the afternoon. Note that for this example the True North was shifted with 60 degrees. You will need to confirm where True North is for your project.
- Import weather file
- Set analysis period
- Construct sun path
Sun Hour Analysis
Secondly, the sun hours analysis should be created. The roof surface and context wall surfaces should be entwined as those surfaces combined are creating the context that blocks the sunlight from the terrace surfaces. Use the Entwine component to combine the roof surface and the context surfaces. For the set-up of the sun hour analysis a grid size of 1m and an offset height of 0.7m is used. A false start toggle is created to run the analysis. This component ensures that the toggle is set to False when the file is opened, this prevents crashing. Lastly, add a mass addition component to the results of the sun analysis to find the total sun hours on the terrace.
- Create sun hour component
- Entwine context surfaces
- Connect the Entwine component to the context input of the LB Direct Sun Hours component
- Connect the terraces surface component to the geometry input of the LB Direct Sun Hours component
- Ensure both geometry and context inputs are flattened
- Create false toggle to run analysis
- Find total sun hours
Note: if you only see the original surface, try to hide the terrace in Rhino
To check if the simulation is running, you can connect a panel to the result of mass addition. If the analysis results in a total of zero sun hours the terrace surface may need to be flipped. To solve, flip the terrace surface before inputting the geometry in LB Direct Sun Hours component. Then re-run the sun hours analysis.
- Flip terrace surface
- OR select the surface in Rhino and use the command Flip
SO-Optimization Sun Hours on Roof 4/6
Galapagos optimization link copied
Now that the geometry and simulation are set-up we can run our optimization analysis with Galapagos, a plug in for Grasshopper which is written by David Rutten. Galapagos is an evolutionary solver that can optimize one Fitness value, based on multiple parameters. This tutorial quickly goes through the set-up of Galapagos, for a more detailed explanation, please check the “Initiating Galapagos” section of the Galapagos Optimization page to learn how to initiate Galapagos.
Adding Galapagos
To run a single-objective optimization, place the Galapagos component. The fitness is the value you want to optimize for and the Genome are design parameters that influence the fitness. Connecting the wires to Galapagos works a bit different than normal components because the wires will be connected backwards. You always have to connect the wire from the Galapagos input to the parameters. Connect fitness to the total sun hours of the Ladybug analysis, the result of our mass addition.
- Create a Galapagos component
- Connect the Fitness to the Mass Addition
Connect Genome to the Gene Pool components, which controls the position of the openings. Note that to connect both the Gene Pool components you must hold shift when adding the second Gene Pool to the Genome.
- Connect the Genome to the Gene Pools
Galapagos Settings
The next step is to run the optimization. During this tutorial the optimization is run with the standard settings.
Info: Before starting the algorithm, make sure you turned off all previews of nodes that are not relevant. In our case, only preview the Geometry parameter node showing the roof and showing the shadow on the terraces. Additionally, save your file before going to the next steps.
Double click LMB on the Galapagos component to open the optimization analysis. Go to the options tab in the Galapagos Editor. As we are minimizing the sun hours on the terrace in summer, change the Fitness to Minimize. Besides that, we don’t make any changes in the Galapagos settings. We are using the Evolutionary Solver during this optimization.
- Set the Fitness to minimize
- DO NOT enable the Runtime Limit
To run the optimization, go to the tab Solvers and click Start Solver. Run the optimization solver until the results start to converge or when you are satisfied with the results. Then click on Stop Solver and reinstate the result. You can reinstate a result by clicking one of the design options in the right bottom corner and then clicking on ‘Reinstate’. Note that the value shown next to the design option refers to the total sun hours, which was the fitness input. Now the sliders in the Grasshopper script are adjusted and the optimal solution is shown.
- Start optimization by Starting Solver
- Run optimization until satisfied
- Stop optimization by Stopping Solver
- Select the design option
- Reinstate the optimal design solution
Note: Please note that if you close the Galapagos solver window, the results are not saved and you will not be able to open them again.
SO-Optimization Sun Hours on Roof 5/6
Conclusion link copied
After finishing this tutorial, you are now able to set-up a single-objective optimization problem which uses a LB simulation. You can select and connect the correct optimization objective and the influencing design parameters.
Final Script
Download SO-Optimization Sun Hours on Roof Final Grasshopper Script
application/zip (ZIP, 94 KB)
SO-Optimization Sun Hours on Roof 6/6
Useful Links link copied
If you want to know the basics of running a Galapagos optimization, please look at this tutorial:
Follow up tutorials
If you want to bring your optimization even further you can look at this tutorial where the same example is used for muli-objective optimization.
External links
On this website below you can find detailed explanation about the used optimization algorithm in Galapagos, to understand the theory behind it.