2.8.4.1: Cross section Optimization
The equivalent Python 3 code of the example in section 2.4.1 looks like this:
import Karamba.Models
import Karamba.CrossSections
import Karamba.Elements
import Karamba.Results
import KarambaCommon
from Karamba.Geometry import *
from System.Collections.Generic import List
from System import String
model = Model_in
if not isinstance(model, Karamba.Models.Model):
raise Exception("The input in 'Model_in' is not of type Karamba.Models.Model!")
for crosec in CroSecs_in:
if not isinstance(crosec, Karamba.CrossSections.CroSec_Beam):
raise Exception("The input in 'CroSecs_in' contains objects which are not of type Karamba.CrossSections.CroSec_Beam!")
# avoid side effects
model = model.Clone();
model.cloneElements();
k3d = KarambaCommon.Toolkit()
for i in range(niter):
loadCases = List[String]([lcName])
model, max_disp, outForce, outEnergy, Warning = k3d.Algorithms.Analyze(model, loadCases);
for elem_ind in range(model.elems.Count):
beam = model.elems[elem_ind]
if not isinstance(beam, Karamba.Elements.ModelBeam):
continue
# avoid side effects
beam = beam.Clone();
model.elems[elem_ind] = beam;
elemId = List[String](str(elem_ind))
N, V, M = Karamba.Results.BeamResultantForces.solve(model, elemId, lcName, 100, 1);
for crosec in CroSecs_in:
beam.crosec = crosec
maxSigma = abs(N[0][0]) / crosec.A + M[0][0] / crosec.Wely_z_pos;
ft = crosec.material.ft()
if (maxSigma < ft):
break
model.initMaterialCroSecLists();
model.buildFEModel();
model, max_disp, outForce, outEnergy, Warning = k3d.Algorithms.Analyze(model, loadCases);
Disp_out = max_disp[0];
Model_out = Karamba.GHopper.Models.GH_Model(model);
Last updated