use of org.openlca.core.math.SystemCalculator in project olca-modules by GreenDelta.
the class WasteScenarioUnrollingTest method testUnrolling.
@Test
public void testUnrolling() throws Exception {
var dataSet = new CsvDataSet();
// unit: kg
dataSet.units().add(new UnitRow().name("kg").conversionFactor(1.0).referenceUnit("kg").quantity("Mass"));
// quantity: mass
dataSet.quantities().add(new QuantityRow().name("Mass").hasDimension(true));
// CO2
dataSet.airborneEmissions().add(new ElementaryFlowRow().name("Carbon dioxide").unit("kg").cas("000124-38-9").comment("Formula: CO2").platformId("DBE27C73-9DF4-4F21-B2EB-A0CE1FE87A4B"));
// material
var material = new ProcessBlock().category(ProcessCategory.MATERIAL).name("material 1").identifier("Dev99229000009369600012");
material.products().add(new ProductOutputRow().name("material 1").amount(Numeric.of(1.0)).unit("kg").wasteType("Some waste"));
dataSet.processes().add(material);
// waste treatment
var wasteTreatment = new ProcessBlock().category(ProcessCategory.WASTE_TREATMENT).name("waste treatment 1").identifier("Dev99229000009369600013");
wasteTreatment.wasteTreatment(new WasteTreatmentRow().name("waste treatment 1").amount(Numeric.of(1)).unit("kg"));
wasteTreatment.emissionsToAir().add(new ElementaryExchangeRow().name("Carbon dioxide").amount(Numeric.of(1.0)).unit("kg"));
dataSet.processes().add(wasteTreatment);
// waste scenario
var wasteScenario = new ProcessBlock().category(ProcessCategory.WASTE_SCENARIO).name("waste scenario 1").identifier("Dev99229000009369600014");
wasteScenario.wasteScenario(new WasteTreatmentRow().name("waste scenario 1").wasteType("All waste types").amount(Numeric.of(1)).unit("kg"));
wasteScenario.separatedWaste().add(new WasteFractionRow().wasteType("All waste types").fraction(100).wasteTreatment("waste treatment 1"));
wasteScenario.remainingWaste().add(new WasteFractionRow().wasteType("All waste types").fraction(100).wasteTreatment("waste treatment 1"));
dataSet.processes().add(wasteScenario);
// assembly
var assembly = new ProductStageBlock().category(ProductStageCategory.ASSEMBLY);
assembly.products().add(new ProductStageOutputRow().name("assembly 1").amount(Numeric.of(1)).unit("kg"));
assembly.materialsAndAssemblies().add(new TechExchangeRow().name("material 1").amount(Numeric.of(2)).unit("kg"));
dataSet.productStages().add(assembly);
// life cycle
var lifeCycle = new ProductStageBlock().category(ProductStageCategory.LIFE_CYCLE);
lifeCycle.products().add(new ProductStageOutputRow().name("life cycle 1").amount(Numeric.of(1)).unit("kg"));
lifeCycle.assembly(new TechExchangeRow().name("assembly 1").amount(Numeric.of(2)).unit("kg"));
lifeCycle.wasteOrDisposalScenario(new TechExchangeRow().name("waste scenario 1"));
dataSet.productStages().add(lifeCycle);
// write the file
var file = Files.createTempFile("_olca_", ".csv").toFile();
dataSet.write(file);
new SimaProCsvImport(db, file).generateLifeCycleSystems(true).unrollWasteScenarios(true).run();
var systems = db.getAll(ProductSystem.class);
assertEquals(1, systems.size());
var system = systems.get(0);
assertEquals(1, system.parameterSets.size());
var setup = CalculationSetup.simple(systems.get(0)).withParameters(system.parameterSets.get(0).parameters);
var result = new SystemCalculator(db).calculateSimple(setup);
var inventory = result.getTotalFlowResults();
assertEquals(1, inventory.size());
var co2Result = inventory.get(0);
assertEquals("Carbon dioxide", co2Result.flow().name);
assertEquals(4.0, co2Result.value(), 1e-10);
assertTrue(file.delete());
}
use of org.openlca.core.math.SystemCalculator in project olca-modules by GreenDelta.
the class ResultExportTest method testSimpleResult.
@Test
public void testSimpleResult() throws Exception {
// create a simple process
var units = db.insert(UnitGroup.of("Mass units", Unit.of("kg")));
var mass = db.insert(FlowProperty.of("Mass", units));
var steel = db.insert(Flow.product("Steel", mass));
var co2 = db.insert(Flow.elementary("C02", mass));
var process = Process.of("Steel production", steel);
process.output(co2, 2);
process = db.insert(process);
// create a system and calculate it
var sys = ProductSystem.of(process);
var setup = CalculationSetup.fullAnalysis(sys);
var calculator = new SystemCalculator(db);
var result = calculator.calculateFull(setup);
// run the export
var file = Files.createTempFile("_olca_test_", ".xlsx").toFile();
new ResultExport(setup, result, file, EntityCache.create(db)).run();
Assert.assertTrue(file.length() > 0);
// clean up
Files.delete(file.toPath());
db.clear();
}
use of org.openlca.core.math.SystemCalculator in project olca-modules by GreenDelta.
the class LibraryCalculatorExample method main.
public static void main(String[] args) throws Exception {
var workspace = "C:/Users/Win10/openLCA-data-1.4";
var db = new Derby(new File(workspace + "/databases/libre2"));
var libDir = new LibraryDir(new File(workspace + "/libraries"));
var system = db.get(ProductSystem.class, "6b32cda2-5aa4-44b9-b32a-c654da48436d");
var setup = CalculationSetup.simple(system);
var result = new SystemCalculator(db).calculateSimple(setup);
var flow = result.enviIndex().at(0);
System.out.println(flow.flow().name + " => " + result.getTotalFlowResult(flow));
db.close();
}
use of org.openlca.core.math.SystemCalculator in project olca-modules by GreenDelta.
the class ProductSystemInMemoryCalculationExample method main.
public static void main(String[] args) throws Exception {
// load the database and matrix cache
String workspace = "C:/Users/Besitzer/openLCA-data-1.4";
String dbPath = workspace + "/databases/ecoinvent_2_2_unit";
IDatabase db = new Derby(new File(dbPath));
MatrixCache mcache = MatrixCache.createLazy(db);
// load the reference process and create
// the product system with auto-completion
// the system is not saved in the database
Process p = new ProcessDao(db).getForRefId("7ff672e3-a296-30e8-b1bb-a3173711a28b");
var config = new LinkingConfig().providerLinking(ProviderLinking.PREFER_DEFAULTS).preferredType(ProcessType.UNIT_PROCESS);
var builder = new ProductSystemBuilder(mcache, config);
var system = builder.build(p);
var method = db.get(ImpactMethod.class, "207ffac9-aaa8-401d-ac90-874defd3751a");
// create the calculation setup
var setup = CalculationSetup.simple(system).withImpactMethod(method);
// load the native library and calculate the result
// TODO: load Julia libraries first here
SystemCalculator calc = new SystemCalculator(db);
SimpleResult r = calc.calculateSimple(setup);
// print the LCIA results
for (ImpactDescriptor impact : r.getImpacts()) {
System.out.println(impact.name + "\t" + r.getTotalImpactResult(impact) + "\t" + impact.referenceUnit);
}
// finally, close the database
db.close();
}
use of org.openlca.core.math.SystemCalculator in project olca-modules by GreenDelta.
the class TestSystem method contributions.
public static ContributionResult contributions(ProductSystem system) {
var setup = CalculationSetup.contributions(system).withCosts(true);
SystemCalculator calc = new SystemCalculator(Tests.getDb());
return calc.calculateContributions(setup);
}
Aggregations