Search in sources :

Example 11 with Flow

use of org.openlca.core.model.Flow in project olca-modules by GreenDelta.

the class ProductSystemImport method sameExchange.

private boolean sameExchange(Exchange srcExchange, Exchange destExchange) {
    if (srcExchange.isInput != destExchange.isInput)
        return false;
    Unit srcUnit = srcExchange.unit;
    Unit destUnit = destExchange.unit;
    Flow srcFlow = srcExchange.flow;
    Flow destFlow = destExchange.flow;
    return srcUnit != null && destUnit != null && srcFlow != null && destFlow != null && Strings.nullOrEqual(srcUnit.refId, destUnit.refId) && Strings.nullOrEqual(srcFlow.refId, destFlow.refId);
}
Also used : Unit(org.openlca.core.model.Unit) Flow(org.openlca.core.model.Flow)

Example 12 with Flow

use of org.openlca.core.model.Flow in project olca-modules by GreenDelta.

the class FlowExport method doIt.

@Override
protected void doIt(CSVPrinter printer, IDatabase db) throws IOException {
    log.trace("write flows");
    FlowDao dao = new FlowDao(db);
    List<Flow> flows = dao.getAll();
    for (Flow flow : flows) {
        Object[] line = createLine(flow);
        printer.printRecord(line);
    }
    log.trace("{} flows written", flows.size());
}
Also used : FlowDao(org.openlca.core.database.FlowDao) Flow(org.openlca.core.model.Flow)

Example 13 with Flow

use of org.openlca.core.model.Flow in project olca-modules by GreenDelta.

the class ProcessWriter method writeDummies.

private void writeDummies() {
    for (Flow flow : inputProducts) {
        if (outputProducts.contains(flow))
            continue;
        var p = Process.of("Dummy: " + flow.name, flow);
        p.id = flow.id;
        p.category = new Category();
        p.category.name = "Dummy processes";
        writeProcess(p);
    }
}
Also used : Category(org.openlca.core.model.Category) Flow(org.openlca.core.model.Flow)

Example 14 with Flow

use of org.openlca.core.model.Flow in project olca-modules by GreenDelta.

the class ProcessWriter method writeReferenceFlows.

@SuppressWarnings("unchecked")
private void writeReferenceFlows() {
    // order flows by their type
    int n = ElementaryFlowType.values().length;
    List<Flow>[] buckets = new List[n];
    for (int i = 0; i < n; i++) {
        buckets[i] = new ArrayList<>();
    }
    for (Map.Entry<Flow, Compartment> e : flowCompartments.entrySet()) {
        ElementaryFlowType type = e.getValue().type();
        buckets[type.ordinal()].add(e.getKey());
    }
    // write the flow information
    for (var type : ElementaryFlowType.values()) {
        writeln(type.blockHeader());
        // duplicate names are not allowed here
        HashSet<String> handledNames = new HashSet<>();
        for (Flow flow : buckets[type.ordinal()]) {
            String name;
            String unit = null;
            FlowMapEntry mapEntry = mappedFlow(flow);
            if (mapEntry != null) {
                // handle mapped flows
                name = mapEntry.targetFlow().flow.name;
                if (mapEntry.targetFlow().unit != null) {
                    unit = unit(mapEntry.targetFlow().unit.name);
                }
            } else {
                // handle unmapped flows
                name = flow.name;
                Unit refUnit = null;
                if (flow.referenceFlowProperty != null) {
                    if (flow.referenceFlowProperty.unitGroup != null) {
                        refUnit = flow.referenceFlowProperty.unitGroup.referenceUnit;
                    }
                }
                unit = unit(refUnit);
            }
            if (name == null || unit == null)
                continue;
            String id = name.trim().toLowerCase();
            if (handledNames.contains(id))
                continue;
            handledNames.add(id);
            writeln(name, unit, flow.casNumber, "");
        }
        writeln();
        writeln("End");
        writeln();
        writeln();
    }
}
Also used : SubCompartment(org.openlca.simapro.csv.enums.SubCompartment) FlowMapEntry(org.openlca.io.maps.FlowMapEntry) Unit(org.openlca.core.model.Unit) Flow(org.openlca.core.model.Flow) ElementaryFlowType(org.openlca.simapro.csv.enums.ElementaryFlowType) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) FlowMap(org.openlca.io.maps.FlowMap) HashSet(java.util.HashSet)

Example 15 with Flow

use of org.openlca.core.model.Flow in project olca-modules by GreenDelta.

the class AllocationSheet method getFactorExchange.

private Exchange getFactorExchange(int row) {
    String name = config.getString(sheet, row, 0);
    if (name == null)
        return null;
    String category = config.getString(sheet, row, 1);
    Flow flow = config.refData.getFlow(name, category);
    String direction = config.getString(sheet, row, 2);
    if (flow == null || direction == null)
        return null;
    boolean input = direction.equalsIgnoreCase("Input");
    for (Exchange exchange : process.exchanges) {
        if (exchange.isInput == input && Objects.equals(exchange.flow, flow))
            return exchange;
    }
    return null;
}
Also used : Exchange(org.openlca.core.model.Exchange) Flow(org.openlca.core.model.Flow)

Aggregations

Flow (org.openlca.core.model.Flow)102 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)23 FlowDao (org.openlca.core.database.FlowDao)22 FlowProperty (org.openlca.core.model.FlowProperty)17 Exchange (org.openlca.core.model.Exchange)14 Unit (org.openlca.core.model.Unit)14 Process (org.openlca.core.model.Process)13 UnitGroup (org.openlca.core.model.UnitGroup)9 ArrayList (java.util.ArrayList)8 Before (org.junit.Before)7 Test (org.junit.Test)7 TechFlow (org.openlca.core.matrix.index.TechFlow)6 Category (org.openlca.core.model.Category)6 ProcessDao (org.openlca.core.database.ProcessDao)5 EnviFlow (org.openlca.core.matrix.index.EnviFlow)5 Location (org.openlca.core.model.Location)5 FlowMapEntry (org.openlca.io.maps.FlowMapEntry)5 FlowRef (org.openlca.io.maps.FlowRef)5 HashSet (java.util.HashSet)4 List (java.util.List)4