Search in sources :

Example 86 with Exchange

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

the class ProcessWriter method createExchangeRef.

private JsonObject createExchangeRef(Exchange exchange) {
    if (exchange == null)
        return null;
    JsonObject obj = new JsonObject();
    Json.put(obj, "@type", Exchange.class.getSimpleName());
    Json.put(obj, "internalId", exchange.internalId);
    Json.put(obj, "flow", exp.handleRef(exchange.flow));
    return obj;
}
Also used : Exchange(org.openlca.core.model.Exchange) JsonObject(com.google.gson.JsonObject)

Example 87 with Exchange

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

the class AllocationCleanup method run.

private void run() {
    var products = getProducts();
    if (products.size() < 2) {
        process.allocationFactors.clear();
        return;
    }
    removeInvalid();
    if (process.allocationFactors.isEmpty()) {
        checkFactors(process.quantitativeReference);
    }
    for (Exchange product : products) {
        checkFactors(product);
    }
}
Also used : Exchange(org.openlca.core.model.Exchange)

Example 88 with Exchange

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

the class AllocationCleanup method checkFactors.

private void checkFactors(Exchange product) {
    if (product == null)
        return;
    double defaultValue = 0;
    if (process.allocationFactors.isEmpty() && isQuantitativeReference(product)) {
        // initialize quant. ref. with 1
        defaultValue = 1;
    }
    checkFactor(product, AllocationMethod.PHYSICAL, defaultValue);
    checkFactor(product, AllocationMethod.ECONOMIC, defaultValue);
    for (Exchange exchange : process.exchanges) {
        if (isProduct(exchange))
            continue;
        checkFactor(product, exchange, defaultValue);
    }
}
Also used : Exchange(org.openlca.core.model.Exchange)

Example 89 with Exchange

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

the class ModelImport method exchange.

private Exchange exchange(Flow flow, Process p, boolean isInput) {
    Exchange e = new Exchange();
    e.isInput = isInput;
    e.amount = 1.0;
    e.flow = flow;
    e.flowPropertyFactor = flow.getReferenceFactor();
    e.unit = getRefUnit(flow);
    p.exchanges.add(e);
    return e;
}
Also used : Exchange(org.openlca.core.model.Exchange)

Example 90 with Exchange

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

the class Node method findExchange.

private Exchange findExchange(String flowID, boolean isInput) {
    if (process == null || flowID == null)
        return null;
    ArrayList<Exchange> matches = new ArrayList<>(1);
    for (Exchange e : process.exchanges) {
        if (e.isInput != isInput || e.flow == null)
            continue;
        if (Objects.equals(flowID, e.flow.refId)) {
            matches.add(e);
        }
    }
    if (matches.size() == 1)
        return matches.get(0);
    Logger log = LoggerFactory.getLogger(getClass());
    if (matches.size() > 1) {
        log.warn("There are multiple exchanges with flowID={} isInput={} " + "in process={}; -> we take the first for linking", flowID, isInput, process.refId);
        return matches.get(0);
    }
    log.warn("Could not find exchange with flowID={} isInput={} " + "in process={}", flowID, isInput, process.refId);
    return null;
}
Also used : Exchange(org.openlca.core.model.Exchange) ArrayList(java.util.ArrayList) Logger(org.slf4j.Logger)

Aggregations

Exchange (org.openlca.core.model.Exchange)90 Process (org.openlca.core.model.Process)20 ArrayList (java.util.ArrayList)15 Flow (org.openlca.core.model.Flow)15 Test (org.junit.Test)7 AllocationFactor (org.openlca.core.model.AllocationFactor)6 ProcessDao (org.openlca.core.database.ProcessDao)5 Parameter (org.openlca.core.model.Parameter)5 ProcessLink (org.openlca.core.model.ProcessLink)5 HashSet (java.util.HashSet)3 Uncertainty (org.openlca.core.model.Uncertainty)3 JsonObject (com.google.gson.JsonObject)2 HashMap (java.util.HashMap)2 List (java.util.List)2 M (org.openlca.app.M)2 Labels (org.openlca.app.util.Labels)2 MsgBox (org.openlca.app.util.MsgBox)2 FlowProperty (org.openlca.core.model.FlowProperty)2 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)2 IExchange (org.openlca.ecospold.IExchange)2