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