+1 vote
18 views

I have created a product systems that contains other product systems as providers for the main process. They contain processes that depend on a global parameter. When I run them in openLCA and change the global parameter and run again, the results change. If I do the same from a python script (inside openLCA), the results stay the same. For everything else (e.g. the same use case where I uses processes as providers and not product systems), the python script works fine.

The script looks something like this:

for prod_system in prod_systems:
  for param_val in param1_vals:
    system = dao.getForName(prod_system)[0]
    solver = JuliaSolver()
    m_cache = MatrixCache.createLazy(db)
    calculator = SystemCalculator(m_cachesolver)
    setup = CalculationSetup(CalculationType.UPSTREAM_ANALYSIS, system)
 
    ### Parameter für Berechnung festlegen
    p1 = model.ParameterRedef()
    p1.value = param_val
    p1.name = 'param1'
    setup.parameterRedefs.add(p1)
 
    ### Die Wirkungsabschätzungsmethode auswählen
    method_dao = ImpactMethodDao(db)
    impactMethod = method_dao.getForName('My_Method')[0]
    setup.impactMethod = Descriptors.toDescriptor(impactMethod)
 
    result = calculator.calculateFull(setup)
in openLCA by (420 points)

1 Answer

+1 vote
by (420 points)
 
Best answer

And I found a solution that makes sense. If I update the parameter in the database, it works fine. So ParameterRedef only seems to update the foreground system. Here ist the working code:

for prod_system in prod_systems:
  for param_val in param1_vals:
    system = dao.getForName(prod_system)[0]
    solver = JuliaSolver()
    m_cache = MatrixCache.createLazy(db)
    calculator = SystemCalculator(m_cachesolver)
    setup = CalculationSetup(CalculationType.UPSTREAM_ANALYSIS, system)
 
    ### Parameter für Berechnung festlegen
    param_dao = ParameterDao(db)
    param = param_dao.getForName('param1')[0]
    param.value = param_val
    param_dao.update(param)
 
    ### Die Wirkungsabschätzungsmethode auswählen
    method_dao = ImpactMethodDao(db)
    impactMethod = method_dao.getForName('My_Method')[0]
    setup.impactMethod = Descriptors.toDescriptor(impactMethod)
 
    result = calculator.calculateFull(setup)
...