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