use of org.openlca.core.model.ProcessLink in project olca-app by GreenDelta.
the class RemoveAllConnectionsAction method run.
@Override
public void run() {
if (processNodes.size() == 0)
return;
ProductSystemNode systemNode = editor.getModel();
List<Link> links = new ArrayList<>();
// create new link search to avoid problems with missing entries before
// ConnectionLink.unlink is called
List<ProcessLink> pLinks = systemNode.getProductSystem().processLinks;
MutableProcessLinkSearchMap linkSearch = new MutableProcessLinkSearchMap(pLinks);
for (ProcessNode processNode : processNodes) {
List<ProcessLink> processLinks = linkSearch.getLinks(processNode.process.id);
for (ProcessLink link : processLinks) linkSearch.remove(link);
for (Link link : processNode.links) if (!links.contains(link))
links.add(link);
}
Command command = new DeleteLinkCommand(links);
editor.getCommandStack().execute(command);
}
use of org.openlca.core.model.ProcessLink in project olca-app by GreenDelta.
the class RemoveSupplyChainAction method collectSupplyChain.
private void collectSupplyChain(long processId) {
ProductSystemNode systemNode = editor.getModel();
ProcessNode node = systemNode.getProcessNode(processId);
List<ProcessLink> incomingLinks = linkSearch.getConnectionLinks(processId);
for (ProcessLink link : incomingLinks) {
if (node != null) {
Link l = node.getLink(link);
if (l != null)
connections.add(l);
else
links.add(link);
} else {
links.add(link);
}
linkSearch.remove(link);
if (linkSearch.getProviderLinks(link.providerId).size() == 0) {
collectSupplyChain(link.providerId);
ProcessNode providerNode = editor.getModel().getProcessNode(link.providerId);
if (providerNode != null)
nodes.add(providerNode);
else
processIds.add(link.providerId);
}
}
}
use of org.openlca.core.model.ProcessLink in project olca-modules by GreenDelta.
the class SystemExport method mapLinks.
private void mapLinks(Model model) {
Technology tech = Models.forceTechnology(model);
Map<Long, ProcessInstance> instances = new HashMap<>();
for (Long id : system.processes) {
if (id == null)
continue;
ProcessInstance pi = initProcessInstance(id);
instances.put(id, pi);
tech.processes.add(pi);
}
for (ProcessLink link : system.processLinks) {
FlowDescriptor flow = flows.get(link.flowId);
if (flow == null)
continue;
if (flow.flowType == FlowType.PRODUCT_FLOW) {
ProcessInstance pi = instances.get(link.providerId);
addLink(pi, link, flow);
} else if (flow.flowType == FlowType.WASTE_FLOW) {
ProcessInstance pi = instances.get(link.processId);
addLink(pi, link, flow);
}
}
}
use of org.openlca.core.model.ProcessLink in project olca-modules by GreenDelta.
the class DQResultTest method createProductSystem.
private void createProductSystem() {
system = ProductSystem.of(process1);
system.targetAmount = 1;
system.processes.add(process1.id);
system.processes.add(process2.id);
ProcessLink link = new ProcessLink();
link.flowId = pFlow2.id;
link.providerId = process2.id;
for (Exchange e : process1.exchanges) {
if (e.flow.id == pFlow2.id)
link.exchangeId = e.id;
}
link.processId = process1.id;
system.processLinks.add(link);
system = db.insert(system);
}
use of org.openlca.core.model.ProcessLink in project olca-modules by GreenDelta.
the class CostTests method testAddCostsForSameProduct.
@Test
public void testAddCostsForSameProduct() {
Process p1 = TestProcess.refProduct("p1", 1, "kg").addCosts("p1", 1, "EUR").prodIn("p1", 0.5, "kg").elemIn("water", 1, "m3").get();
long exchangeId = -1;
for (Exchange e : p1.exchanges) {
if (e.flow.name.equals("p1") && e.isInput) {
e.costs = 0.4d;
e.currency = p1.quantitativeReference.currency;
exchangeId = e.id;
break;
}
}
p1 = db.update(p1);
ProductSystem system = TestSystem.of(p1).get();
// add a link to the process itself
ProcessLink selfLink = new ProcessLink();
selfLink.flowId = p1.quantitativeReference.flow.id;
selfLink.providerId = p1.id;
selfLink.processId = p1.id;
selfLink.exchangeId = exchangeId;
system.processLinks.add(selfLink);
system = db.update(system);
FullResult r = TestSystem.calculate(system);
Assert.assertEquals(-1.2, r.totalCosts(), 1e-10);
}
Aggregations