2.8.2: Data Retrieval from Models
The following constitutes the Python 3 version of the example discussed in section 2.8.2. This is the source code of the Python component:
import Karamba
model = Model_in;
if not isinstance(model, Karamba.Models.Model):
raise Exception("The input is not of type 'Model'")
matWeights = {}
for elem in model.elems:
mat = elem.crosec.material
if not(mat in matWeights):
matWeights[mat] = 0.0
matWeights[mat] += elem.weight(model.nodes)
ucf = Karamba.Utilities.UnitsConversionFactory.Conv();
mass = ucf.force2mass();
kg = ucf.kg();
for key, value in matWeights.items():
print(f"Material: {key.name}: {kg.toUnit(mass.toBase(value))}" + kg.unitB)
Last updated