use of org.openlca.ilcd.models.ProcessInstance in project olca-modules by GreenDelta.
the class Graph method buildLinks.
private static void buildLinks(Graph g, Model model) {
// also support such things here...
for (ProcessInstance pi : model.info.technology.processes) {
Node refNode = g.getNode(pi.id);
if (refNode == null)
continue;
for (Connection con : pi.connections) {
Exchange output = refNode.findOutput(con.outputFlow);
Exchange input = null;
if (output == null) {
input = refNode.findInput(con.outputFlow);
if (input == null)
continue;
}
for (DownstreamLink dlink : con.downstreamLinks) {
Node provider = null;
Node recipient = null;
if (output != null) {
provider = refNode;
recipient = g.getNode(dlink.process);
if (recipient == null)
continue;
input = recipient.findInput(dlink.inputFlow);
} else if (input != null) {
recipient = refNode;
provider = g.getNode(dlink.process);
if (provider == null)
continue;
output = provider.findOutput(dlink.inputFlow);
}
if (input == null || output == null)
continue;
Link link = new Link();
link.provider = provider;
link.output = output;
link.recipient = recipient;
link.input = input;
g.putLink(link);
}
}
}
}
use of org.openlca.ilcd.models.ProcessInstance in project olca-modules by GreenDelta.
the class ModelImport method collectFlows.
/**
* Collect the flows that are used in the process links. This function must
* be called after all processes are imported.
*/
private Map<String, Flow> collectFlows(Technology tech) {
Set<String> usedFlows = new HashSet<>();
for (ProcessInstance pi : tech.processes) {
for (Connection con : pi.connections) {
usedFlows.add(con.outputFlow);
for (DownstreamLink link : con.downstreamLinks) {
usedFlows.add(link.inputFlow);
}
}
}
FlowDao dao = new FlowDao(config.db());
Map<String, Flow> m = new HashMap<>();
for (Flow f : dao.getForRefIds(usedFlows)) {
m.put(f.refId, f);
}
return m;
}
use of org.openlca.ilcd.models.ProcessInstance in project olca-modules by GreenDelta.
the class ModelIOTest method testSimpleModel.
@Test
public void testSimpleModel() throws Exception {
Model model = new Model();
Models.forceDataSetInfo(model).uuid = UUID.randomUUID().toString();
Models.forceModelName(model).name.add(LangString.of("Example model", "en"));
Models.forcePublication(model).version = "01.00.000";
Classification classification = new Classification();
Category category = new Category();
category.level = 0;
category.value = "Life cycle models";
classification.categories.add(category);
Models.forceClassifications(model).add(classification);
Models.forceQuantitativeReference(model).refProcess = 42;
Technology tech = Models.forceTechnology(model);
Group group = new Group();
group.id = 42;
group.name.add(LangString.of("Use phase", "en"));
tech.groups.add(group);
ProcessInstance pi = new ProcessInstance();
tech.processes.add(pi);
GroupRef groupRef = new GroupRef();
groupRef.groupID = 42;
pi.groupRefs.add(groupRef);
Parameter param = new Parameter();
param.name = "distance";
param.value = 42.42;
pi.parameters.add(param);
Connection con = new Connection();
con.outputFlow = UUID.randomUUID().toString();
DownstreamLink link = new DownstreamLink();
link.inputFlow = UUID.randomUUID().toString();
link.process = 42;
con.downstreamLinks.add(link);
pi.connections.add(con);
StringWriter writer = new StringWriter();
XmlBinder binder = new XmlBinder();
binder.toWriter(model, writer);
StringReader reader = new StringReader(writer.toString());
model = JAXB.unmarshal(reader, Model.class);
assertEquals(1, model.info.technology.processes.size());
}
use of org.openlca.ilcd.models.ProcessInstance 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.ilcd.models.ProcessInstance in project olca-modules by GreenDelta.
the class Graph method build.
/**
* Creates a graph that synchronizes the given eILCD model with the given
* database.
*/
static Graph build(Model model, IDatabase db) {
Graph g = new Graph();
Logger log = LoggerFactory.getLogger(Graph.class);
if (model == null || model.info == null || db == null) {
log.warn("Invalid constraints; return empty index");
return g;
}
Technology tech = model.info.technology;
if (tech == null) {
log.warn("No processes in model; return empty index");
return g;
}
Map<Integer, Group> groups = tech.groups.stream().collect(Collectors.toMap(group -> group.id, group -> group));
ProcessDao dao = new ProcessDao(db);
for (ProcessInstance pi : tech.processes) {
if (pi.process == null || pi.process.uuid == null) {
log.warn("Invalid process reference node={}", pi.id);
continue;
}
String refID = pi.process.uuid;
Process process = dao.getForRefId(refID);
if (process == null) {
log.warn("Could not find process {}; skip node {}", refID, pi.id);
continue;
}
Node n = Node.init(pi, process);
if (!pi.groupRefs.isEmpty()) {
GroupRef gr = pi.groupRefs.get(0);
n.group = groups.get(gr.groupID);
}
g.putNode(n);
}
buildLinks(g, model);
QuantitativeReference qRef = model.info.quantitativeReference;
if (qRef != null && qRef.refProcess != null) {
g.root = g.getNode(qRef.refProcess);
}
return g;
}
Aggregations