Search in sources :

Example 26 with Parameter

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

the class ParameterUsageTreeTest method setup.

@Before
public void setup() {
    db.clear();
    // a dependent global parameter
    var globalDep = new Parameter();
    globalDep.name = "global_dep_param";
    globalDep.isInputParameter = false;
    globalDep.scope = ParameterScope.GLOBAL;
    globalDep.formula = "param / pi";
    db.insert(globalDep);
    var flow = new Flow();
    flow.name = "flow";
    db.insert(flow);
    // local process parameter
    process = new Process();
    process.name = "process";
    var processParam = new Parameter();
    processParam.name = "param";
    processParam.isInputParameter = true;
    processParam.scope = ParameterScope.PROCESS;
    process.parameters.add(processParam);
    var processDepParam = new Parameter();
    processDepParam.name = "process_dep_param";
    processDepParam.formula = "21 * param";
    processDepParam.scope = ParameterScope.PROCESS;
    process.parameters.add(processDepParam);
    var exchange = process.output(flow, 1.0);
    exchange.formula = "sin(param)";
    db.insert(process);
}
Also used : Parameter(org.openlca.core.model.Parameter) Process(org.openlca.core.model.Process) TestProcess(org.openlca.core.TestProcess) Flow(org.openlca.core.model.Flow) Before(org.junit.Before)

Example 27 with Parameter

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

the class DataUtil method toDataSet.

static ProtoDataSet.Builder toDataSet(IDatabase db, RefEntity e) {
    var ds = ProtoDataSet.newBuilder();
    var conf = WriterConfig.of(db);
    if (e instanceof Actor)
        return ds.setActor(new ActorWriter(conf).write((Actor) e));
    if (e instanceof Category)
        return ds.setCategory(new CategoryWriter(conf).write((Category) e));
    if (e instanceof Currency)
        return ds.setCurrency(new CurrencyWriter(conf).write((Currency) e));
    if (e instanceof DQSystem)
        return ds.setDqSystem(new DQSystemWriter(conf).write((DQSystem) e));
    if (e instanceof Flow)
        return ds.setFlow(new FlowWriter(conf).write((Flow) e));
    if (e instanceof FlowProperty)
        return ds.setFlowProperty(new FlowPropertyWriter(conf).write((FlowProperty) e));
    if (e instanceof ImpactCategory)
        return ds.setImpactCategory(new ImpactCategoryWriter(conf).write((ImpactCategory) e));
    if (e instanceof ImpactMethod)
        return ds.setImpactMethod(new ImpactMethodWriter(conf).write((ImpactMethod) e));
    if (e instanceof Location)
        return ds.setLocation(new LocationWriter(conf).write((Location) e));
    if (e instanceof Parameter)
        return ds.setParameter(new ParameterWriter(conf).write((Parameter) e));
    if (e instanceof Process)
        return ds.setProcess(new ProcessWriter(conf).write((Process) e));
    if (e instanceof ProductSystem)
        return ds.setProductSystem(new ProductSystemWriter(conf).write((ProductSystem) e));
    if (e instanceof Project)
        return ds.setProject(new ProjectWriter(conf).write((Project) e));
    if (e instanceof SocialIndicator)
        return ds.setSocialIndicator(new SocialIndicatorWriter(conf).write((SocialIndicator) e));
    if (e instanceof Source)
        return ds.setSource(new SourceWriter(conf).write((Source) e));
    if (e instanceof UnitGroup)
        return ds.setUnitGroup(new UnitGroupWriter(conf).write((UnitGroup) e));
    return ds;
}
Also used : ImpactCategory(org.openlca.core.model.ImpactCategory) Category(org.openlca.core.model.Category) UnitGroup(org.openlca.core.model.UnitGroup) ImpactCategoryWriter(org.openlca.proto.io.output.ImpactCategoryWriter) ProductSystem(org.openlca.core.model.ProductSystem) Process(org.openlca.core.model.Process) UnitGroupWriter(org.openlca.proto.io.output.UnitGroupWriter) ImpactMethod(org.openlca.core.model.ImpactMethod) ProductSystemWriter(org.openlca.proto.io.output.ProductSystemWriter) Source(org.openlca.core.model.Source) CurrencyWriter(org.openlca.proto.io.output.CurrencyWriter) FlowPropertyWriter(org.openlca.proto.io.output.FlowPropertyWriter) Actor(org.openlca.core.model.Actor) Currency(org.openlca.core.model.Currency) CategoryWriter(org.openlca.proto.io.output.CategoryWriter) ImpactCategoryWriter(org.openlca.proto.io.output.ImpactCategoryWriter) FlowProperty(org.openlca.core.model.FlowProperty) FlowWriter(org.openlca.proto.io.output.FlowWriter) ImpactCategory(org.openlca.core.model.ImpactCategory) SourceWriter(org.openlca.proto.io.output.SourceWriter) Flow(org.openlca.core.model.Flow) LocationWriter(org.openlca.proto.io.output.LocationWriter) Project(org.openlca.core.model.Project) DQSystemWriter(org.openlca.proto.io.output.DQSystemWriter) ParameterWriter(org.openlca.proto.io.output.ParameterWriter) DQSystem(org.openlca.core.model.DQSystem) ActorWriter(org.openlca.proto.io.output.ActorWriter) ImpactMethodWriter(org.openlca.proto.io.output.ImpactMethodWriter) ProjectWriter(org.openlca.proto.io.output.ProjectWriter) Parameter(org.openlca.core.model.Parameter) SocialIndicator(org.openlca.core.model.SocialIndicator) ProcessWriter(org.openlca.proto.io.output.ProcessWriter) Location(org.openlca.core.model.Location) SocialIndicatorWriter(org.openlca.proto.io.output.SocialIndicatorWriter)

Example 28 with Parameter

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

the class ParameterReferencesTest method testImpactFactorUncertainty.

@Test
public void testImpactFactorUncertainty() {
    Parameter p1 = createParameter("p1", null, null, null);
    Parameter p1Intern = createParameter("p1", null, ParameterScope.PROCESS, null);
    Parameter p2 = createParameter("p2", null, null, null);
    Uncertainty u1 = createUncertainty("1", "2", "3*p2");
    Uncertainty u2 = createUncertainty("p1", "2*p1", "3*p2");
    ImpactFactor f1 = createImpactFactor("2", u1);
    ImpactFactor f2 = createImpactFactor("2", u2);
    ImpactCategory impact = createImpactCategory(new ImpactFactor[] { f1, f2 }, new Parameter[] { p1Intern });
    with((store) -> {
        JsonExport export = new JsonExport(db, store);
        export.write(impact);
        assertNotNull(store.get(ModelType.IMPACT_CATEGORY, impact.refId));
        assertNull(store.get(ModelType.PARAMETER, p1.refId));
        assertNull(store.get(ModelType.PARAMETER, p1Intern.refId));
        assertNotNull(store.get(ModelType.PARAMETER, p2.refId));
    });
}
Also used : Uncertainty(org.openlca.core.model.Uncertainty) ImpactFactor(org.openlca.core.model.ImpactFactor) Parameter(org.openlca.core.model.Parameter) ImpactCategory(org.openlca.core.model.ImpactCategory) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 29 with Parameter

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

the class ParameterReferencesTest method testParameterUncertainty.

@Test
public void testParameterUncertainty() {
    Uncertainty u2 = createUncertainty("1", "2", "3*p4");
    Uncertainty u4 = createUncertainty("p1", "2*p1", "3*p2");
    Parameter p1 = createParameter("p1", null, null, null);
    Parameter p2 = createParameter("p2", "2*2", null, u2);
    Parameter p3 = createParameter("p3", null, null, null);
    Parameter p4 = createParameter("p4", "2*2", null, u4);
    with((store) -> {
        JsonExport export = new JsonExport(db, store);
        export.write(p4);
        assertNotNull(store.get(ModelType.PARAMETER, p1.refId));
        assertNotNull(store.get(ModelType.PARAMETER, p2.refId));
        assertNull(store.get(ModelType.PARAMETER, p3.refId));
        assertNotNull(store.get(ModelType.PARAMETER, p4.refId));
    });
}
Also used : Uncertainty(org.openlca.core.model.Uncertainty) Parameter(org.openlca.core.model.Parameter) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 30 with Parameter

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

the class ParameterRedefTest method testInProductSystem.

@Test
public void testInProductSystem() {
    // create the model
    var sys = new ProductSystem();
    sys.refId = UUID.randomUUID().toString();
    sys.parameterSets.add(ParameterRedefSet.of("baseline", redef));
    db.insert(sys);
    // write and clear DB
    with(zip -> new JsonExport(db, zip).write(sys));
    db.clear();
    Assert.assertNull(db.get(ProductSystem.class, sys.refId));
    Assert.assertNull(paramDao.getForRefId(globalParam.refId));
    // import and check
    with(zip -> new JsonImport(zip, db).run());
    var copy = db.get(ProductSystem.class, sys.refId);
    Assert.assertEquals("R", copy.parameterSets.get(0).parameters.get(0).name);
    Parameter p = paramDao.getForRefId(globalParam.refId);
    Assert.assertEquals("R", p.name);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) ProductSystem(org.openlca.core.model.ProductSystem) Parameter(org.openlca.core.model.Parameter) JsonExport(org.openlca.jsonld.output.JsonExport) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Aggregations

Parameter (org.openlca.core.model.Parameter)74 Test (org.junit.Test)17 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)14 Process (org.openlca.core.model.Process)12 ParameterDao (org.openlca.core.database.ParameterDao)11 Uncertainty (org.openlca.core.model.Uncertainty)8 ArrayList (java.util.ArrayList)7 Category (org.openlca.core.model.Category)6 ImpactCategory (org.openlca.core.model.ImpactCategory)6 ParameterRedef (org.openlca.core.model.ParameterRedef)6 Exchange (org.openlca.core.model.Exchange)5 ImpactFactor (org.openlca.core.model.ImpactFactor)5 ProductSystem (org.openlca.core.model.ProductSystem)5 Before (org.junit.Before)4 JsonArray (com.google.gson.JsonArray)3 JsonObject (com.google.gson.JsonObject)3 ImpactMethod (org.openlca.core.model.ImpactMethod)3 ProcessDao (org.openlca.core.database.ProcessDao)2 DQSystem (org.openlca.core.model.DQSystem)2 Flow (org.openlca.core.model.Flow)2