Search in sources :

Example 1 with Technology

use of org.openlca.ilcd.models.Technology 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());
}
Also used : Group(org.openlca.ilcd.models.Group) Category(org.openlca.ilcd.commons.Category) Connection(org.openlca.ilcd.models.Connection) DownstreamLink(org.openlca.ilcd.models.DownstreamLink) StringWriter(java.io.StringWriter) Technology(org.openlca.ilcd.models.Technology) Classification(org.openlca.ilcd.commons.Classification) Model(org.openlca.ilcd.models.Model) StringReader(java.io.StringReader) Parameter(org.openlca.ilcd.models.Parameter) ProcessInstance(org.openlca.ilcd.models.ProcessInstance) GroupRef(org.openlca.ilcd.models.GroupRef) Test(org.junit.Test)

Example 2 with Technology

use of org.openlca.ilcd.models.Technology 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);
        }
    }
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) Technology(org.openlca.ilcd.models.Technology) HashMap(java.util.HashMap) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ProcessInstance(org.openlca.ilcd.models.ProcessInstance)

Example 3 with Technology

use of org.openlca.ilcd.models.Technology 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;
}
Also used : GroupRef(org.openlca.ilcd.models.GroupRef) Technology(org.openlca.ilcd.models.Technology) DownstreamLink(org.openlca.ilcd.models.DownstreamLink) Logger(org.slf4j.Logger) QuantitativeReference(org.openlca.ilcd.models.QuantitativeReference) Process(org.openlca.core.model.Process) ProcessDao(org.openlca.core.database.ProcessDao) LoggerFactory(org.slf4j.LoggerFactory) Connection(org.openlca.ilcd.models.Connection) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) Model(org.openlca.ilcd.models.Model) IDatabase(org.openlca.core.database.IDatabase) ProcessInstance(org.openlca.ilcd.models.ProcessInstance) Map(java.util.Map) Exchange(org.openlca.core.model.Exchange) Group(org.openlca.ilcd.models.Group) Collections(java.util.Collections) Group(org.openlca.ilcd.models.Group) Process(org.openlca.core.model.Process) Logger(org.slf4j.Logger) Technology(org.openlca.ilcd.models.Technology) ProcessDao(org.openlca.core.database.ProcessDao) ProcessInstance(org.openlca.ilcd.models.ProcessInstance) GroupRef(org.openlca.ilcd.models.GroupRef) QuantitativeReference(org.openlca.ilcd.models.QuantitativeReference)

Example 4 with Technology

use of org.openlca.ilcd.models.Technology in project olca-modules by GreenDelta.

the class ModelImport method mapModel.

private void mapModel(Model m) {
    Technology tech = Models.getTechnology(m);
    if (tech == null)
        return;
    Map<Integer, Process> processes = insertProcesses(m, tech);
    Map<String, Flow> flows = collectFlows(tech);
    for (ProcessInstance pi : tech.processes) {
        Process out = processes.get(pi.id);
        if (out == null)
            continue;
        for (Connection con : pi.connections) {
            Flow outFlow = flows.get(con.outputFlow);
            if (outFlow == null)
                continue;
            for (DownstreamLink link : con.downstreamLinks) {
                Flow inFlow = flows.get(link.inputFlow);
                Process in = processes.get(link.process);
                if (inFlow == null || in == null)
                    continue;
                if (Objects.equals(inFlow, outFlow)) {
                    addLink(out, in, inFlow, link.linkedExchange);
                } else {
                    Process connector = connector(inFlow, outFlow);
                    addLink(out, connector, outFlow, null);
                    addLink(connector, in, inFlow, null);
                }
            }
        }
    }
}
Also used : Technology(org.openlca.ilcd.models.Technology) Connection(org.openlca.ilcd.models.Connection) Process(org.openlca.core.model.Process) ProcessInstance(org.openlca.ilcd.models.ProcessInstance) DownstreamLink(org.openlca.ilcd.models.DownstreamLink) Flow(org.openlca.core.model.Flow)

Aggregations

ProcessInstance (org.openlca.ilcd.models.ProcessInstance)4 Technology (org.openlca.ilcd.models.Technology)4 Connection (org.openlca.ilcd.models.Connection)3 DownstreamLink (org.openlca.ilcd.models.DownstreamLink)3 HashMap (java.util.HashMap)2 Process (org.openlca.core.model.Process)2 Group (org.openlca.ilcd.models.Group)2 GroupRef (org.openlca.ilcd.models.GroupRef)2 Model (org.openlca.ilcd.models.Model)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.Test)1 IDatabase (org.openlca.core.database.IDatabase)1 ProcessDao (org.openlca.core.database.ProcessDao)1