Search in sources :

Example 1 with FullResult

use of org.openlca.core.results.FullResult in project olca-modules by GreenDelta.

the class RegionalizedCalculationTest method testRegionalizedCalculation.

@Test
public void testRegionalizedCalculation() {
    Flow nox = flow("NOx", "mg", FlowType.ELEMENTARY_FLOW);
    // create the process
    Process p = new Process();
    p.name = "transport, bus";
    p.quantitativeReference = p.output(flow("transport, bus", "p*km", FlowType.PRODUCT_FLOW), 1);
    Exchange e1 = p.output(nox, 5);
    e1.location = loc1;
    Exchange e2 = p.output(nox, 10);
    e2.location = loc2;
    p = new ProcessDao(db).insert(p);
    // create the LCIA category & method
    var impact = new ImpactCategory();
    impact.name = "human tox";
    impact.factor(nox, 0.5);
    impact.factor(nox, 0.1).location = loc1;
    impact.factor(nox, 0.9).location = loc2;
    impact = new ImpactCategoryDao(db).insert(impact);
    var method = new ImpactMethod();
    method.impactCategories.add(impact);
    method = new ImpactMethodDao(db).insert(method);
    // create the product system and calculation setup
    var setup = CalculationSetup.fullAnalysis(ProductSystem.of(p)).withImpactMethod(method).withRegionalization(true);
    var calculator = new SystemCalculator(db);
    FullResult r = calculator.calculateFull(setup);
    Assert.assertTrue(r.enviIndex().isRegionalized());
    checkRegTotalFlowResults(r, new Object[][] { { nox, loc1, 5.0 }, { nox, loc2, 10.0 } });
}
Also used : Exchange(org.openlca.core.model.Exchange) FullResult(org.openlca.core.results.FullResult) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) ProcessDao(org.openlca.core.database.ProcessDao) Process(org.openlca.core.model.Process) ImpactCategory(org.openlca.core.model.ImpactCategory) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao) ImpactMethod(org.openlca.core.model.ImpactMethod) Flow(org.openlca.core.model.Flow) EnviFlow(org.openlca.core.matrix.index.EnviFlow) TechFlow(org.openlca.core.matrix.index.TechFlow) Test(org.junit.Test)

Example 2 with FullResult

use of org.openlca.core.results.FullResult in project olca-modules by GreenDelta.

the class RegionalizedCalculationTest method checkNoLocations.

@Test
public void checkNoLocations() {
    CalculationSetup setup = calcSetup();
    SystemCalculator calc = new SystemCalculator(db);
    FullResult r = calc.calculateFull(setup);
    // total results
    checkTotalFlowResults(r, new Object[][] { { e1, 2.0 }, { e2, 4.0 } });
    checkTotalImpactResult(r, 14.0);
    // direct contributions
    checkDirectFlowResults(r, new Object[][] { { p1, e1, 2.0 }, { p1, e2, 0.0 }, { p2, e1, 0.0 }, { p2, e2, 4.0 } });
    checkDirectImpactResults(r, new Object[][] { { p1, 2 * 3.0 }, { p2, 4 * 2.0 } });
    // upstream contributions
    checkUpstreamFlowResults(r, new Object[][] { { p1, e1, 2.0 }, { p1, e2, 4.0 }, { p2, e1, 0.0 }, { p2, e2, 4.0 } });
    checkUpstreamImpactResults(r, new Object[][] { { p1, 14.0 }, { p2, 8.0 } });
}
Also used : CalculationSetup(org.openlca.core.model.CalculationSetup) FullResult(org.openlca.core.results.FullResult) Test(org.junit.Test)

Example 3 with FullResult

use of org.openlca.core.results.FullResult in project olca-modules by GreenDelta.

the class AvoidedFlowsTest method check.

private void check(Process refProc, Process linkedProc) {
    ProductSystem system = TestSystem.of(refProc).link(linkedProc).get();
    FullResult r = TestSystem.calculate(system);
    assertEquals(1, r.enviIndex().size());
    EnviFlow co2 = r.enviIndex().at(0);
    assertEquals(1.0, r.getTotalFlowResult(co2), 1e-16);
}
Also used : FullResult(org.openlca.core.results.FullResult) ProductSystem(org.openlca.core.model.ProductSystem) EnviFlow(org.openlca.core.matrix.index.EnviFlow)

Example 4 with FullResult

use of org.openlca.core.results.FullResult in project olca-modules by GreenDelta.

the class CostTests method testSimpleChain.

@Test
public void testSimpleChain() {
    Process p1 = TestProcess.refProduct("p1", 1, "kg").addCosts("p1", 2, "EUR").elemIn("water", 1, "m3").addCosts("water", 5, "EUR").get();
    Process p2 = TestProcess.refProduct("p2", 1, "kg").addCosts("p2", 5, "EUR").prodIn("p1", 2, "kg").addCosts("p1", 4, "EUR").get();
    ProductSystem system = TestSystem.of(p2).link(p1).get();
    FullResult r = TestSystem.calculate(system);
    ProcessDescriptor d1 = Descriptor.of(p1);
    ProcessDescriptor d2 = Descriptor.of(p2);
    Assert.assertEquals(5, r.totalCosts(), 1e-10);
    Assert.assertEquals(6, r.getDirectCostResult(d1), 1e-10);
    Assert.assertEquals(-1, r.getDirectCostResult(d2), 1e-10);
    Assert.assertEquals(6, r.getUpstreamCostResult(d1), 1e-10);
    Assert.assertEquals(5, r.getUpstreamCostResult(d2), 1e-10);
}
Also used : FullResult(org.openlca.core.results.FullResult) ProductSystem(org.openlca.core.model.ProductSystem) Process(org.openlca.core.model.Process) TestProcess(org.openlca.core.TestProcess) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Test(org.junit.Test)

Example 5 with FullResult

use of org.openlca.core.results.FullResult in project olca-modules by GreenDelta.

the class CostTests method test.

@Test
public void test() {
    Process electricity = TestProcess.refProduct("Electricity", 1, "MJ").addCosts("Electricity", 5, "EUR").elemOut("CO2", 3, "kg").get();
    Process wood = TestProcess.refProduct("Wood", 1, "kg").addCosts("Wood", 1, "EUR").get();
    Process chair = TestProcess.refProduct("Chair", 1, "piece").addCosts("Chair", 25, "EUR").prodIn("Electricity", 2, "MJ").addCosts("Electricity", 10, "EUR").prodIn("Wood", 5, "kg").addCosts("Wood", 5, "EUR").get();
    Process disposal = TestProcess.refProduct("Disposal of chair", 1, "piece").addCosts("Disposal of chair", 2, "EUR").get();
    Process usage = TestProcess.refProduct("Sitting", 10, "years").addCosts("Sitting", 135, "EUR").prodIn("Chair", 5, "piece").addCosts("Chair", 125, "EUR").prodIn("Disposal of chair", 5, "piece").addCosts("Disposal of chair", 10, "EUR").get();
    ProductSystem system = TestSystem.of(usage).link(disposal).link(chair).link(wood).link(electricity).get();
    // TODO: test something here
    FullResult result = TestSystem.calculate(system);
    System.out.println(result.totalCosts());
}
Also used : FullResult(org.openlca.core.results.FullResult) ProductSystem(org.openlca.core.model.ProductSystem) Process(org.openlca.core.model.Process) TestProcess(org.openlca.core.TestProcess) Test(org.junit.Test)

Aggregations

FullResult (org.openlca.core.results.FullResult)13 Test (org.junit.Test)7 Process (org.openlca.core.model.Process)6 ProductSystem (org.openlca.core.model.ProductSystem)5 JsonObject (com.google.gson.JsonObject)4 TestProcess (org.openlca.core.TestProcess)4 EntityCache (org.openlca.core.database.EntityCache)4 EnviFlow (org.openlca.core.matrix.index.EnviFlow)3 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)3 TechFlow (org.openlca.core.matrix.index.TechFlow)2 CalculationSetup (org.openlca.core.model.CalculationSetup)2 Exchange (org.openlca.core.model.Exchange)2 Flow (org.openlca.core.model.Flow)2 List (java.util.List)1 Stream (java.util.stream.Stream)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Tests (org.openlca.core.Tests)1 IDatabase (org.openlca.core.database.IDatabase)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1 ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)1