Search in sources :

Example 1 with FormulaInterpreter

use of org.openlca.expressions.FormulaInterpreter in project olca-modules by GreenDelta.

the class ParameterTableTest method testProcessParams.

@Test
public void testProcessParams() throws Exception {
    FormulaInterpreter fi = ParameterTable.interpreter(Tests.getDb(), Collections.singleton(process.id), emptySet());
    // global
    assertEquals(42.0, fi.eval("inp_param"), 1e-6);
    assertEquals(2 * 42.0, fi.eval("dep_param"), 1e-6);
    // local
    var scope = fi.getScope(process.id);
    assertTrue(scope.isPresent());
    assertEquals(84.0, scope.get().eval("inp_param"), 1e-6);
    assertEquals(3 * 84.0, scope.get().eval("dep_param"), 1e-6);
}
Also used : FormulaInterpreter(org.openlca.expressions.FormulaInterpreter) Test(org.junit.Test)

Example 2 with FormulaInterpreter

use of org.openlca.expressions.FormulaInterpreter in project olca-modules by GreenDelta.

the class UMatrixTest method testAddExchanges.

@Test
public void testAddExchanges() {
    CalcExchange e1 = baseExchange();
    e1.parameter1 = 10;
    e1.parameter2 = 20;
    e1.uncertaintyType = UncertaintyType.UNIFORM;
    CalcExchange e2 = baseExchange();
    e2.parameter1 = 10;
    e2.parameter2 = 20;
    e2.uncertaintyType = UncertaintyType.UNIFORM;
    UMatrix u = new UMatrix();
    u.add(42, 42, e1);
    u.add(42, 42, e2);
    HashPointMatrix m = new HashPointMatrix(100, 100);
    for (int i = 0; i < 10; i++) {
        u.generate(m, new FormulaInterpreter());
        double val = m.get(42, 42);
        Assert.assertTrue(val >= 20 && val <= 40);
    }
}
Also used : CalcExchange(org.openlca.core.matrix.CalcExchange) HashPointMatrix(org.openlca.core.matrix.format.HashPointMatrix) FormulaInterpreter(org.openlca.expressions.FormulaInterpreter) Test(org.junit.Test)

Example 3 with FormulaInterpreter

use of org.openlca.expressions.FormulaInterpreter in project olca-modules by GreenDelta.

the class UMatrixTest method testUniformExchange.

@Test
public void testUniformExchange() {
    CalcExchange e = baseExchange();
    e.parameter1 = 10;
    e.parameter2 = 20;
    e.uncertaintyType = UncertaintyType.UNIFORM;
    UMatrix u = new UMatrix();
    u.add(42, 42, e);
    HashPointMatrix m = new HashPointMatrix(100, 100);
    for (int i = 0; i < 10; i++) {
        u.generate(m, new FormulaInterpreter());
        double val = m.get(42, 42);
        Assert.assertTrue(val >= 10 && val <= 20);
    }
}
Also used : CalcExchange(org.openlca.core.matrix.CalcExchange) HashPointMatrix(org.openlca.core.matrix.format.HashPointMatrix) FormulaInterpreter(org.openlca.expressions.FormulaInterpreter) Test(org.junit.Test)

Example 4 with FormulaInterpreter

use of org.openlca.expressions.FormulaInterpreter in project olca-modules by GreenDelta.

the class UMatrixTest method testSimpleExchange.

@Test
public void testSimpleExchange() {
    CalcExchange e = baseExchange();
    UMatrix u = new UMatrix();
    u.add(42, 42, e);
    HashPointMatrix m = new HashPointMatrix(100, 100);
    u.generate(m, new FormulaInterpreter());
    Assert.assertEquals(42.0, m.get(42, 42), 1e-16);
}
Also used : CalcExchange(org.openlca.core.matrix.CalcExchange) HashPointMatrix(org.openlca.core.matrix.format.HashPointMatrix) FormulaInterpreter(org.openlca.expressions.FormulaInterpreter) Test(org.junit.Test)

Example 5 with FormulaInterpreter

use of org.openlca.expressions.FormulaInterpreter in project olca-modules by GreenDelta.

the class Simulator method generateData.

private void generateData(Node node) {
    FormulaInterpreter fi = node.parameters.simulate();
    node.data.simulate(fi);
    if (node.subSystems != null) {
        for (TechFlow subLink : node.subSystems) {
            // add the LCI result of the sub-system
            Node sub = nodeIndex.get(subLink.providerId());
            if (sub == null)
                continue;
            if (sub.lastResult == null || sub.lastResult.totalFlowResults() == null)
                // should not happen
                continue;
            int col = node.data.techIndex.of(subLink);
            if (col < 0)
                continue;
            sub.lastResult.enviIndex().each((i, f) -> {
                double val = sub.lastResult.totalFlowResults()[i];
                int row = node.data.enviIndex.of(f);
                if (row >= 0) {
                    var fm = node.data.enviMatrix.asMutable();
                    fm.set(row, col, val);
                    node.data.enviMatrix = fm;
                }
            });
        }
    }
}
Also used : TechFlow(org.openlca.core.matrix.index.TechFlow) FormulaInterpreter(org.openlca.expressions.FormulaInterpreter)

Aggregations

FormulaInterpreter (org.openlca.expressions.FormulaInterpreter)11 Test (org.junit.Test)7 CalcExchange (org.openlca.core.matrix.CalcExchange)4 HashPointMatrix (org.openlca.core.matrix.format.HashPointMatrix)4 TLongByteHashMap (gnu.trove.map.hash.TLongByteHashMap)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 ArrayList (java.util.ArrayList)1 ParameterDao (org.openlca.core.database.ParameterDao)1 TechFlow (org.openlca.core.matrix.index.TechFlow)1 ImpactFactor (org.openlca.core.model.ImpactFactor)1 Location (org.openlca.core.model.Location)1 Parameter (org.openlca.core.model.Parameter)1 Scope (org.openlca.expressions.Scope)1 Pair (org.openlca.util.Pair)1