Search in sources :

Example 26 with Process

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

the class ProcessImport method map.

@Override
Process map(JsonObject json, long id) {
    if (json == null)
        return null;
    Process p = new Process();
    In.mapAtts(json, p, id, conf);
    p.processType = getType(json);
    p.infrastructureProcess = Json.getBool(json, "isInfrastructureProcess", false);
    p.defaultAllocationMethod = Json.getEnum(json, "defaultAllocationMethod", AllocationMethod.class);
    p.documentation = ProcessDocReader.read(json, conf);
    String locId = Json.getRefId(json, "location");
    if (locId != null)
        p.location = LocationImport.run(locId, conf);
    // DQ systems
    String dqSystemId = Json.getRefId(json, "dqSystem");
    if (dqSystemId != null)
        p.dqSystem = DQSystemImport.run(dqSystemId, conf);
    p.dqEntry = Json.getString(json, "dqEntry");
    String exchangeDqSystemId = Json.getRefId(json, "exchangeDqSystem");
    if (exchangeDqSystemId != null)
        p.exchangeDqSystem = DQSystemImport.run(exchangeDqSystemId, conf);
    String socialDqSystemId = Json.getRefId(json, "socialDqSystem");
    if (socialDqSystemId != null)
        p.socialDqSystem = DQSystemImport.run(socialDqSystemId, conf);
    addParameters(json, p);
    addExchanges(json, p);
    addSocialAspects(json, p);
    addAllocationFactors(json, p);
    p = conf.db.put(p);
    conf.providers().pop(p);
    return p;
}
Also used : AllocationMethod(org.openlca.core.model.AllocationMethod) Process(org.openlca.core.model.Process)

Example 27 with Process

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

the class ProcessReferenceSearchTest method createModel.

@Override
protected Process createModel() {
    Process process = new Process();
    process.category = insertAndAddExpected("category", new Category());
    process.location = insertAndAddExpected("location", new Location());
    process.dqSystem = insertAndAddExpected("dqSystem", new DQSystem());
    process.exchangeDqSystem = insertAndAddExpected("exchangeDqSystem", new DQSystem());
    process.socialDqSystem = insertAndAddExpected("socialDqSystem", new DQSystem());
    String n1 = generateName();
    String n2 = generateName();
    String n3 = generateName();
    String n4 = generateName();
    String n5 = generateName();
    createExchange(process, 3d, true);
    createExchange(process, "2*" + n4, false);
    process.parameters.add(createParameter(n1, 3d, false));
    process.parameters.add(createParameter(n2, n1 + "*2*" + n3, false));
    process.socialAspects.add(createSocialAspect());
    process.socialAspects.add(createSocialAspect());
    process.documentation = createDocumentation();
    insertAndAddExpected(n3, createParameter(n3, "5*5", true));
    // formula with parameter to see if added as reference (unexpected)
    insertAndAddExpected(n4, createParameter(n4, "3*" + n5, true));
    Parameter globalUnreferenced = createParameter(n1, "3*3", true);
    Parameter globalUnreferenced2 = createParameter(n5, "3*3", true);
    // must be inserted manually
    globalUnreferenced = db.insert(globalUnreferenced);
    globalUnreferenced2 = db.insert(globalUnreferenced2);
    process = db.insert(process);
    for (Exchange e : process.exchanges) {
        addExpected("flow", e.flow, "exchanges", Exchange.class, e.id);
        addExpected("flowPropertyFactor", e.flowPropertyFactor, "exchanges", Exchange.class, e.id);
        addExpected("flowProperty", e.flowPropertyFactor.flowProperty, "flowPropertyFactor", FlowPropertyFactor.class, e.flowPropertyFactor.id);
        addExpected("unit", e.unit, "exchanges", Exchange.class, e.id);
        Process provider = processes.get(e.defaultProviderId);
        if (provider != null)
            addExpected("defaultProviderId", provider, "exchanges", Exchange.class, e.id);
    }
    for (SocialAspect a : process.socialAspects) {
        addExpected("indicator", a.indicator, "socialAspects", SocialAspect.class, a.id);
        addExpected("source", a.source, "socialAspects", SocialAspect.class, a.id);
    }
    ProcessDocumentation doc = process.documentation;
    addExpected("dataDocumentor", doc.dataDocumentor, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("dataGenerator", doc.dataGenerator, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("dataSetOwner", doc.dataSetOwner, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("reviewer", doc.reviewer, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("publication", doc.publication, "documentation", ProcessDocumentation.class, doc.id);
    for (Source s : process.documentation.sources) addExpected("sources", s, "documentation", ProcessDocumentation.class, doc.id);
    return process;
}
Also used : Exchange(org.openlca.core.model.Exchange) Category(org.openlca.core.model.Category) SocialAspect(org.openlca.core.model.SocialAspect) DQSystem(org.openlca.core.model.DQSystem) Parameter(org.openlca.core.model.Parameter) Process(org.openlca.core.model.Process) ProcessDocumentation(org.openlca.core.model.ProcessDocumentation) Source(org.openlca.core.model.Source) Location(org.openlca.core.model.Location)

Example 28 with Process

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

the class ProductSystemReferenceSearchTest method createModel.

@Override
protected ProductSystem createModel() {
    ProductSystem system = new ProductSystem();
    system.category = insertAndAddExpected("category", new Category());
    system.referenceProcess = createProcess();
    system.referenceExchange = system.referenceProcess.exchanges.get(0);
    system.targetFlowPropertyFactor = system.referenceExchange.flowPropertyFactor;
    system.targetUnit = system.targetFlowPropertyFactor.flowProperty.unitGroup.units.get(0);
    system.processes.add(system.referenceProcess.id);
    Process p1 = insertAndAddExpected("processes", new Process());
    Process p2 = insertAndAddExpected("processes", new Process());
    Process p3 = insertAndAddExpected("processes", new Process());
    system.processes.add(p1.id);
    system.processes.add(p2.id);
    system.processes.add(p3.id);
    system.processLinks.add(createLink(p1, p2));
    system.processLinks.add(createLink(p2, p3));
    String n1 = generateName();
    String n2 = generateName();
    String n3 = generateName();
    // TODO: find parameter references
    // system.parameterRedefs.add(createParameterRedef(n1, p1.id));
    // formula with parameter to see if added as reference (unexpected)
    // system.parameterRedefs.add(createParameterRedef(n2, n3 + "*5"));
    Parameter globalUnreferenced = createParameter(n1, "3*3", true);
    Parameter globalUnreferenced2 = createParameter(n3, "3*3", true);
    // must be inserted manually
    globalUnreferenced = db.insert(globalUnreferenced);
    globalUnreferenced2 = db.insert(globalUnreferenced2);
    return db.insert(system);
}
Also used : Category(org.openlca.core.model.Category) ProductSystem(org.openlca.core.model.ProductSystem) Parameter(org.openlca.core.model.Parameter) Process(org.openlca.core.model.Process)

Example 29 with Process

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

use of org.openlca.core.model.Process 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

Process (org.openlca.core.model.Process)103 Test (org.junit.Test)35 ProcessDao (org.openlca.core.database.ProcessDao)27 Exchange (org.openlca.core.model.Exchange)20 TestProcess (org.openlca.core.TestProcess)15 ProductSystem (org.openlca.core.model.ProductSystem)14 Flow (org.openlca.core.model.Flow)13 Parameter (org.openlca.core.model.Parameter)13 Before (org.junit.Before)9 IDatabase (org.openlca.core.database.IDatabase)9 ProcessDocumentation (org.openlca.core.model.ProcessDocumentation)9 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)9 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)8 AllocationMethod (org.openlca.core.model.AllocationMethod)6 FlowProperty (org.openlca.core.model.FlowProperty)6 ImpactMethod (org.openlca.core.model.ImpactMethod)6 Location (org.openlca.core.model.Location)6 File (java.io.File)5 UnitGroup (org.openlca.core.model.UnitGroup)5 FullResult (org.openlca.core.results.FullResult)5