2.4.1: Cross section Optimization
When it comes to modifying an existing Karamba3D model keep to these general rules:
In order to avoid side-effects, clone objects before modifying them. This applies recursively to the objects which contain objects to be modified.
The Karamba3D API for modifications allows for changes which can make the C++-model crash. So make it a habit to regularly save your work.
The example “CrossSectionOptimization.gh” (see fig. 2.4.1.1) shows how to optimize beam cross sections under arbitrary loads. The C#-component takes a model and an ordered list of cross sections as the main input, chooses the optimum cross sections according to the given cross section forces and outputs the optimized model as well as its maximum displacement. The input-plug “niter” lets one chose the number of iteration steps. Each consists of model evaluation and cross section selection. With “lcind” the index of a load-case to be considered for cross section optimization can be selected. The algorithm inside the component neglects buckling and calculates the maximum stress in the cross section based on the assumption that there are only normal forces and bending moments about the local Y-axis.
In the first two paragraphs of source-code the type of the “Model_in” and “CroSecs_in” input gets checked. The third block consists of instantiations of objects which are used later when looping over the model’s elements.
When C# assigns an object to a variable it actually assigns a reference. Changes made on the object are thus visible in all variables that also reference that object. In Grasshopper this breaks the data flow logic that an object is only influenced by upstream operations. Whenever an object gets plugged into two different components a change in one object would magically transfer to the other object. In order to avoid this, the actual data and not only references need to be assigned and copied. This is done in line 33 for the model and in line 36 for its list of elements.
The loop in line 39 cycles over the optimization iterations and starts with calculating the system response. Starting in line 41 all elements get checked whether they epitomize beam-elements. If yes the beam gets cloned (see line 44) to avoid side-effects and re-enlisted in the model.
For cross section-optimization the beam’s resultant cross section forces are determine in line 47. One could have used “Karamba.Results.BeamForces.solve()” here instead for considering e.g. bi-axial bending. The loop which follows goes through the list of user-provided cross sections and chooses an appropriate one by comparing the maximum stress in a cross section against the cross section’s material strength.
After completing cross section selection, the iteration step ends with initializing the model’s lists of cross sections and materials (line 58) and recreation of the C++ model on which the C# model depends for result evaluation (line 59).
Before handing over the model to the output-plug an analysis step updates the structural response and determines the model’s maximum displacement.
The above C# script could be improved in many ways i.e. by providing a stop criteria for the optimization iterations or more elaborate design procedures for determining the load-bearing capacity of the elements. Yet this was omitted for the the sake of simplicity.
Last updated