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);
}
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);
}
}
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);
}
}
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);
}
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;
}
});
}
}
}
Aggregations