Search in sources :

Example 21 with Exchange

use of org.openlca.core.model.Exchange in project olca-modules by GreenDelta.

the class EcoSpold2Export method mapExchanges.

private void mapExchanges(Process process, DataSet ds) {
    if (ds.flowData == null)
        ds.flowData = new FlowData();
    for (Exchange exchange : process.exchanges) {
        if (!isValid(exchange))
            continue;
        Flow flow = exchange.flow;
        UserMasterData masterData = ds.masterData;
        if (flow.flowType == FlowType.ELEMENTARY_FLOW) {
            ElementaryExchange e = createElemExchange(exchange, masterData);
            ds.flowData.elementaryExchanges.add(e);
        } else {
            IntermediateExchange e = createIntermediateExchange(exchange, process, masterData);
            ds.flowData.intermediateExchanges.add(e);
        }
    }
}
Also used : Exchange(org.openlca.core.model.Exchange) ElementaryExchange(spold2.ElementaryExchange) IntermediateExchange(spold2.IntermediateExchange) FlowData(spold2.FlowData) ElementaryExchange(spold2.ElementaryExchange) IntermediateExchange(spold2.IntermediateExchange) UserMasterData(spold2.UserMasterData) Flow(org.openlca.core.model.Flow)

Example 22 with Exchange

use of org.openlca.core.model.Exchange 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 23 with Exchange

use of org.openlca.core.model.Exchange in project olca-modules by GreenDelta.

the class UncertaintyTableTest method testForExchange.

@Test
public void testForExchange() throws Exception {
    Exchange exchange = new Exchange();
    Uncertainty uncertainty = createUncertainty();
    exchange.uncertainty = uncertainty;
    Process process = new Process();
    process.exchanges.add(exchange);
    ProcessDao dao = new ProcessDao(database);
    dao.insert(process);
    Set<Long> set = new HashSet<>();
    set.add(process.id);
    List<CalcExchange> exchanges = cache.getExchangeCache().get(process.id);
    checkExchange(exchanges.get(0));
    dao.delete(process);
}
Also used : Exchange(org.openlca.core.model.Exchange) CalcExchange(org.openlca.core.matrix.CalcExchange) Uncertainty(org.openlca.core.model.Uncertainty) CalcExchange(org.openlca.core.matrix.CalcExchange) ProcessDao(org.openlca.core.database.ProcessDao) Process(org.openlca.core.model.Process) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with Exchange

use of org.openlca.core.model.Exchange in project olca-modules by GreenDelta.

the class ParameterReferencesTest method createExchange.

private Exchange createExchange(String formula, Uncertainty u) {
    Exchange e = new Exchange();
    e.formula = formula;
    e.uncertainty = u;
    return e;
}
Also used : Exchange(org.openlca.core.model.Exchange)

Example 25 with Exchange

use of org.openlca.core.model.Exchange in project olca-modules by GreenDelta.

the class ProcessTest method addProvider.

private Process addProvider(Process p, Process provider, ProcessDao dao) {
    Exchange in = createExchange(p, provider.quantitativeReference.flow, provider);
    in.isInput = true;
    p.exchanges.add(in);
    return dao.update(p);
}
Also used : Exchange(org.openlca.core.model.Exchange)

Aggregations

Exchange (org.openlca.core.model.Exchange)90 Process (org.openlca.core.model.Process)21 ArrayList (java.util.ArrayList)15 Flow (org.openlca.core.model.Flow)14 Test (org.junit.Test)7 AllocationFactor (org.openlca.core.model.AllocationFactor)6 ProcessDao (org.openlca.core.database.ProcessDao)5 Parameter (org.openlca.core.model.Parameter)5 ProcessLink (org.openlca.core.model.ProcessLink)5 HashSet (java.util.HashSet)3 Uncertainty (org.openlca.core.model.Uncertainty)3 JsonObject (com.google.gson.JsonObject)2 HashMap (java.util.HashMap)2 List (java.util.List)2 M (org.openlca.app.M)2 Labels (org.openlca.app.util.Labels)2 MsgBox (org.openlca.app.util.MsgBox)2 FlowProperty (org.openlca.core.model.FlowProperty)2 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)2 IExchange (org.openlca.ecospold.IExchange)2