Search in sources :

Example 1 with LinkingConfig

use of org.openlca.core.matrix.linking.LinkingConfig in project olca-app by GreenDelta.

the class ProductSystemWizard method performFinish.

@Override
public boolean performFinish() {
    var page = (ProductSystemWizardPage) getPage();
    var system = page.createModel();
    if (system == null || system.referenceProcess == null)
        return false;
    system.category = getCategory();
    // product system with new and empty ref. process
    if (system.referenceProcess.id == 0L) {
        var db = Database.get();
        var refProcess = db.insert(system.referenceProcess);
        system.referenceProcess = refProcess;
        system.processes.add(refProcess.id);
        db.insert(system);
        App.open(system);
        return true;
    }
    LinkingConfig config = page.getLinkingConfig();
    system.cutoff = config.cutoff().isPresent() ? config.cutoff().getAsDouble() : null;
    addCreationInfo(system, page);
    try {
        createDao().insert(system);
        boolean autoComplete = page.addSupplyChain();
        if (!autoComplete) {
            App.open(system);
            return true;
        }
        Runner runner = new Runner(system, config);
        getContainer().run(true, true, runner);
        system = runner.system;
        Cache.registerNew(Descriptor.of(system));
        App.open(system);
        return true;
    } catch (Exception e) {
        log.error("Failed to create model", e);
        return false;
    }
}
Also used : LinkingConfig(org.openlca.core.matrix.linking.LinkingConfig)

Example 2 with LinkingConfig

use of org.openlca.core.matrix.linking.LinkingConfig in project olca-modules by GreenDelta.

the class ModelHandler method createProductSystem.

@Rpc("create/product_system")
public RpcResponse createProductSystem(RpcRequest req) {
    if (req.params == null || !req.params.isJsonObject())
        return Responses.invalidParams("params must be an object with valid processId", req);
    var obj = req.params.getAsJsonObject();
    if (!obj.has("processId") || !obj.get("processId").isJsonPrimitive())
        return Responses.invalidParams("params must be an object with valid processId", req);
    var processId = obj.get("processId").getAsString();
    if (Strings.nullOrEmpty(processId))
        return Responses.invalidParams("params must be an object with valid processId", req);
    var refProcess = new ProcessDao(db).getForRefId(processId);
    if (refProcess == null)
        return Responses.invalidParams("No process found for ref id " + processId, req);
    var system = ProductSystem.of(refProcess);
    system = new ProductSystemDao(db).insert(system);
    var config = new LinkingConfig().preferredType(ProcessType.UNIT_PROCESS);
    if (obj.has("preferredType") && obj.get("preferredType").getAsString().equalsIgnoreCase("lci_result")) {
        config.preferredType(ProcessType.LCI_RESULT);
    }
    config.providerLinking(ProviderLinking.PREFER_DEFAULTS);
    if (obj.has("providerLinking")) {
        if (obj.get("providerLinking").getAsString().equalsIgnoreCase("ignore")) {
            config.providerLinking(ProviderLinking.IGNORE_DEFAULTS);
        } else if (obj.get("providerLinking").getAsString().equalsIgnoreCase("only")) {
            config.providerLinking(ProviderLinking.ONLY_DEFAULTS);
        }
    }
    var builder = new ProductSystemBuilder(MatrixCache.createLazy(db), config);
    builder.autoComplete(system);
    system = ProductSystemBuilder.update(db, system);
    var res = new JsonObject();
    res.addProperty("@id", system.refId);
    return Responses.ok(res, req);
}
Also used : ProcessDao(org.openlca.core.database.ProcessDao) LinkingConfig(org.openlca.core.matrix.linking.LinkingConfig) ProductSystemBuilder(org.openlca.core.matrix.ProductSystemBuilder) JsonObject(com.google.gson.JsonObject) ProductSystemDao(org.openlca.core.database.ProductSystemDao) Rpc(org.openlca.ipc.Rpc)

Example 3 with LinkingConfig

use of org.openlca.core.matrix.linking.LinkingConfig in project olca-modules by GreenDelta.

the class ProductSystemBuilderExample method main.

public static void main(String[] args) {
    String dbPath = "C:/Users/Besitzer/openLCA-data-1.4/databases/ecoinvent_2_2_unit";
    IDatabase db = new Derby(new File(dbPath));
    // load the reference process of the new product system
    Process p = new ProcessDao(db).getForRefId("81261285-cc4a-3588-8cce-3aabb786d7aa");
    // create and auto-complete the product system
    var config = new LinkingConfig().providerLinking(ProviderLinking.PREFER_DEFAULTS).preferredType(ProcessType.UNIT_PROCESS);
    var system = new ProductSystemBuilder(MatrixCache.createLazy(db), config).build(p);
    // save the product system
    new ProductSystemDao(db).insert(system);
}
Also used : IDatabase(org.openlca.core.database.IDatabase) Derby(org.openlca.core.database.Derby) ProcessDao(org.openlca.core.database.ProcessDao) LinkingConfig(org.openlca.core.matrix.linking.LinkingConfig) ProductSystemBuilder(org.openlca.core.matrix.ProductSystemBuilder) Process(org.openlca.core.model.Process) File(java.io.File) ProductSystemDao(org.openlca.core.database.ProductSystemDao)

Example 4 with LinkingConfig

use of org.openlca.core.matrix.linking.LinkingConfig 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)

Example 5 with LinkingConfig

use of org.openlca.core.matrix.linking.LinkingConfig in project olca-app by GreenDelta.

the class LinkingConfigPanel method getLinkingConfig.

public LinkingConfig getLinkingConfig() {
    LinkingConfig config = new LinkingConfig();
    if (preferUnitRadio.getSelection()) {
        config.preferredType(ProcessType.UNIT_PROCESS);
    } else {
        config.preferredType(ProcessType.LCI_RESULT);
    }
    if (ignoreProvidersRadio.getSelection()) {
        config.providerLinking(ProviderLinking.IGNORE_DEFAULTS);
    } else if (onlyLinkProvidersRadio.getSelection()) {
        config.providerLinking(ProviderLinking.ONLY_DEFAULTS);
    } else {
        config.providerLinking(ProviderLinking.PREFER_DEFAULTS);
    }
    config.cutoff(getCutoff());
    return config;
}
Also used : LinkingConfig(org.openlca.core.matrix.linking.LinkingConfig)

Aggregations

LinkingConfig (org.openlca.core.matrix.linking.LinkingConfig)6 ProcessDao (org.openlca.core.database.ProcessDao)3 ProductSystemBuilder (org.openlca.core.matrix.ProductSystemBuilder)3 File (java.io.File)2 Derby (org.openlca.core.database.Derby)2 IDatabase (org.openlca.core.database.IDatabase)2 ProductSystemDao (org.openlca.core.database.ProductSystemDao)2 Process (org.openlca.core.model.Process)2 JsonObject (com.google.gson.JsonObject)1 SystemCalculator (org.openlca.core.math.SystemCalculator)1 MatrixCache (org.openlca.core.matrix.cache.MatrixCache)1 ImpactDescriptor (org.openlca.core.model.descriptors.ImpactDescriptor)1 SimpleResult (org.openlca.core.results.SimpleResult)1 Rpc (org.openlca.ipc.Rpc)1