use of org.openlca.core.matrix.CalcExchange in project olca-modules by GreenDelta.
the class TechIndexBuilder method build.
@Override
public TechIndex build(TechFlow refFlow) {
log.trace("build product index for {}", refFlow);
TechIndex index = new TechIndex(refFlow);
index.setDemand(1.0);
addSystemLinks(index);
List<TechFlow> block = new ArrayList<>();
block.add(refFlow);
HashSet<TechFlow> handled = new HashSet<>();
while (!block.isEmpty()) {
var nextBlock = new ArrayList<TechFlow>();
log.trace("fetch next block with {} entries", block.size());
Map<Long, List<CalcExchange>> exchanges = fetchExchanges(block);
for (TechFlow recipient : block) {
handled.add(recipient);
List<CalcExchange> all = exchanges.get(recipient.providerId());
List<CalcExchange> candidates = providers.getLinkCandidates(all);
for (CalcExchange linkExchange : candidates) {
TechFlow provider = providers.find(linkExchange);
if (provider == null)
continue;
LongPair exchange = new LongPair(recipient.providerId(), linkExchange.exchangeId);
index.putLink(exchange, provider);
if (!handled.contains(provider) && !nextBlock.contains(provider))
nextBlock.add(provider);
}
}
block = nextBlock;
}
return index;
}
use of org.openlca.core.matrix.CalcExchange in project olca-modules by GreenDelta.
the class UMatrixTest method testSimpleExchange.
@Test
public void testSimpleExchange() {
CalcExchange e = baseExchange();
UMatrix u = new UMatrix();
u.add(42, 42, e);
HashPointMatrix m = new HashPointMatrix(100, 100);
u.generate(m, new FormulaInterpreter());
Assert.assertEquals(42.0, m.get(42, 42), 1e-16);
}
use of org.openlca.core.matrix.CalcExchange in project olca-modules by GreenDelta.
the class UMatrixTest method testUniformExchange.
@Test
public void testUniformExchange() {
CalcExchange e = baseExchange();
e.parameter1 = 10;
e.parameter2 = 20;
e.uncertaintyType = UncertaintyType.UNIFORM;
UMatrix u = new UMatrix();
u.add(42, 42, e);
HashPointMatrix m = new HashPointMatrix(100, 100);
for (int i = 0; i < 10; i++) {
u.generate(m, new FormulaInterpreter());
double val = m.get(42, 42);
Assert.assertTrue(val >= 10 && val <= 20);
}
}
use of org.openlca.core.matrix.CalcExchange in project olca-modules by GreenDelta.
the class UMatrixTest method baseExchange.
private CalcExchange baseExchange() {
CalcExchange e = new CalcExchange();
e.amount = 42.0;
e.conversionFactor = 1.0;
e.flowType = FlowType.ELEMENTARY_FLOW;
e.exchangeId = e.flowId = e.processId = 42L;
return e;
}
use of org.openlca.core.matrix.CalcExchange in project olca-modules by GreenDelta.
the class UMatrixTest method testAddExchanges.
@Test
public void testAddExchanges() {
CalcExchange e1 = baseExchange();
e1.parameter1 = 10;
e1.parameter2 = 20;
e1.uncertaintyType = UncertaintyType.UNIFORM;
CalcExchange e2 = baseExchange();
e2.parameter1 = 10;
e2.parameter2 = 20;
e2.uncertaintyType = UncertaintyType.UNIFORM;
UMatrix u = new UMatrix();
u.add(42, 42, e1);
u.add(42, 42, e2);
HashPointMatrix m = new HashPointMatrix(100, 100);
for (int i = 0; i < 10; i++) {
u.generate(m, new FormulaInterpreter());
double val = m.get(42, 42);
Assert.assertTrue(val >= 20 && val <= 40);
}
}
Aggregations