Search in sources :

Example 1 with MatrixCache

use of org.openlca.core.matrix.cache.MatrixCache 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();
}
Also used : IDatabase(org.openlca.core.database.IDatabase) Derby(org.openlca.core.database.Derby) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) Process(org.openlca.core.model.Process) SimpleResult(org.openlca.core.results.SimpleResult) MatrixCache(org.openlca.core.matrix.cache.MatrixCache) ProcessDao(org.openlca.core.database.ProcessDao) LinkingConfig(org.openlca.core.matrix.linking.LinkingConfig) ProductSystemBuilder(org.openlca.core.matrix.ProductSystemBuilder) File(java.io.File) SystemCalculator(org.openlca.core.math.SystemCalculator)

Aggregations

File (java.io.File)1 Derby (org.openlca.core.database.Derby)1 IDatabase (org.openlca.core.database.IDatabase)1 ProcessDao (org.openlca.core.database.ProcessDao)1 SystemCalculator (org.openlca.core.math.SystemCalculator)1 ProductSystemBuilder (org.openlca.core.matrix.ProductSystemBuilder)1 MatrixCache (org.openlca.core.matrix.cache.MatrixCache)1 LinkingConfig (org.openlca.core.matrix.linking.LinkingConfig)1 Process (org.openlca.core.model.Process)1 ImpactDescriptor (org.openlca.core.model.descriptors.ImpactDescriptor)1 SimpleResult (org.openlca.core.results.SimpleResult)1