Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.network.util.VoltageInitializer;
import com.powsybl.openloadflow.util.Reports;
import gnu.trove.list.array.TDoubleArrayList;
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -92,7 +92,7 @@ public static final class InitVmBusEquationTerm extends AbstractElementEquationT

private final List<Variable<InitVmVariableType>> variables;

private final TDoubleArrayList der;
private final DoubleArrayList der;

public InitVmBusEquationTerm(LfBus bus, VariableSet<InitVmVariableType> variableSet, double lowImpedanceThreshold) {
super(bus);
Expand All @@ -103,7 +103,7 @@ public InitVmBusEquationTerm(LfBus bus, VariableSet<InitVmVariableType> variable
}

variables = new ArrayList<>(neighbors.size());
der = new TDoubleArrayList(neighbors.size());
der = new DoubleArrayList(neighbors.size());
double bs = 0; // neighbor branches susceptance sum
for (Map.Entry<LfBus, List<LfBranch>> e : neighbors.entrySet()) {
LfBus neighborBus = e.getKey();
Expand Down Expand Up @@ -131,7 +131,7 @@ public InitVmBusEquationTerm(LfBus bus, VariableSet<InitVmVariableType> variable
throw new PowsyblException("Susceptance sum is zero");
}
for (int i = 0; i < der.size(); i++) {
der.setQuick(i, der.getQuick(i) / bs);
der.set(i, der.getDouble(i) / bs);
}
}

Expand All @@ -151,7 +151,7 @@ public double der(Variable<InitVmVariableType> variable) {
if (i == -1) {
throw new IllegalStateException("Unknown variable: " + variable);
}
return der.getQuick(i);
return der.getDouble(i);
}

@Override
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/powsybl/openloadflow/equations/EquationArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.openloadflow.network.LfElement;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.TIntIntMap;
import gnu.trove.map.hash.TIntIntHashMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;

import java.io.IOException;
import java.io.Writer;
Expand All @@ -36,7 +36,7 @@ public class EquationArray<V extends Enum<V> & Quantity, E extends Enum<E> & Qua

private int[] elementNumToColumn;

private TIntIntMap columnToElementNum;
private Int2IntMap columnToElementNum;

private int length;

Expand Down Expand Up @@ -73,17 +73,17 @@ void addSingleTerm(SingleEquationTerm<V, E> termImpl, Equation<V, E> equation) {
}

static class MatrixElementIndexes {
private final TIntArrayList indexes = new TIntArrayList();
private final IntArrayList indexes = new IntArrayList();

private int get(int i) {
if (i >= indexes.size()) {
indexes.add(-1);
}
return indexes.getQuick(i);
return indexes.getInt(i);
}

private void set(int i, int index) {
indexes.setQuick(i, index);
indexes.set(i, index);
}

void reset() {
Expand Down Expand Up @@ -141,7 +141,7 @@ public int getElementNumToColumn(int elementNum) {

public int getColumnToElementNum(int column) {
if (columnToElementNum == null) {
columnToElementNum = new TIntIntHashMap(elementCount);
columnToElementNum = new Int2IntOpenHashMap(elementCount);
for (int elementNum = 0; elementNum < elementCount; elementNum++) {
int c = getElementNumToColumn(elementNum);
if (c != -1) {
Expand Down Expand Up @@ -288,7 +288,7 @@ public <T extends EquationTerm<V, E>> List<T> getTerms() {
int iEnd = termNumsConcatenatedStartIndices[elementNum + 1];
var termNums = termArray.getTermNumsConcatenated();
for (int i = iStart; i < iEnd; i++) {
int termNum = termNums.getQuick(i);
int termNum = termNums.getInt(i);
int termElementNum = termArray.getTermElementNum(termNum);
terms.add((T) new EquationTermArray.EquationTermArrayElementImpl<>(termArray, termElementNum));
}
Expand Down Expand Up @@ -327,7 +327,7 @@ public double eval() {
int iEnd = termNumsConcatenatedStartIndices[elementNum + 1];
var termNums = termArray.getTermNumsConcatenated();
for (int i = iStart; i < iEnd; i++) {
int termNum = termNums.getQuick(i);
int termNum = termNums.getInt(i);
// skip inactive terms
if (termArray.isTermActive(termNum)) {
int termElementNum = termArray.getTermElementNum(termNum);
Expand Down Expand Up @@ -369,7 +369,7 @@ public void eval(double[] values) {
int iStart = termNumsConcatenatedStartIndices[elementNum];
int iEnd = termNumsConcatenatedStartIndices[elementNum + 1];
for (int i = iStart; i < iEnd; i++) {
int termNum = termNums.getQuick(i);
int termNum = termNums.getInt(i);
// skip inactive terms
if (termArray.isTermActive(termNum)) {
int termElementNum = termArray.getTermElementNum(termNum);
Expand Down Expand Up @@ -417,7 +417,7 @@ private void addEquationDerivativeVectorSortedTerms(int elementNum, List<Equatio
int iEnd = termNumsConcatenatedStartIndices[elementNum + 1];
var termNums = termArray.getTermNumsConcatenated();
for (int i = iStart; i < iEnd; i++) {
int termNum = termNums.getQuick(i);
int termNum = termNums.getInt(i);
// for each term of each, add an entry for each derivative operation we need
var termDerivatives = termArray.getTermDerivatives(termNum);
for (Derivative<V> derivative : termDerivatives) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public void onEquationArrayChange(EquationArray<V, E> equationArray, int element
switch (eventType) {
case EQUATION_DEACTIVATED:
for (var equationTermArray : equationArray.getTermArrays()) {
for (int termNum : equationTermArray.getTermNumsForEquationElementNum(elementNum).toArray()) {
for (int termNum : equationTermArray.getTermNumsForEquationElementNum(elementNum).toIntArray()) {
if (equationTermArray.isTermActive(termNum)) {
List<Variable<V>> variables = equationTermArray.getTermDerivatives(termNum).stream().map(Derivative::getVariable).toList();
removeVariables(variables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import com.powsybl.math.matrix.DenseMatrix;
import com.powsybl.openloadflow.network.ElementType;
import com.powsybl.openloadflow.network.LfElement;
import gnu.trove.impl.Constants;
import gnu.trove.list.array.TByteArrayList;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.TIntIntMap;
import gnu.trove.map.hash.TIntIntHashMap;
import it.unimi.dsi.fastutil.Hash;
import it.unimi.dsi.fastutil.bytes.ByteArrayList;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;

import java.io.IOException;
import java.io.Writer;
Expand Down Expand Up @@ -56,28 +55,31 @@ default double calculateSensi(int termElementNum, DenseMatrix dx, int column) {
private final Evaluator<V> evaluator;

// for each equation element number, term numbers
private TIntArrayList[] termNumsByEquationElementNum;
private TIntArrayList termNumsConcatenated;
private IntArrayList[] termNumsByEquationElementNum;
private IntArrayList termNumsConcatenated;
private int[] termNumsConcatenatedStartIndices;

// for each term element number, corresponding term number
private TIntIntMap termNumByTermElementNum = new TIntIntHashMap(3, Constants.DEFAULT_LOAD_FACTOR, -1, -1);
private Int2IntOpenHashMap termNumByTermElementNum = new Int2IntOpenHashMap(3, Hash.DEFAULT_LOAD_FACTOR);

// for each term number, corresponding equation element number
private final TIntArrayList equationElementNums = new TIntArrayList();
private final IntArrayList equationElementNums = new IntArrayList();

// for each term number, corresponding term element number
private final TIntArrayList termElementNums = new TIntArrayList();
private final IntArrayList termElementNums = new IntArrayList();

// for each term number, activity status
private final TByteArrayList termActive = new TByteArrayList();
private final ByteArrayList termActive = new ByteArrayList();

// for each term number, list of derivative variables
private final List<List<Derivative<V>>> termDerivatives = new ArrayList<>();

public EquationTermArray(ElementType elementType, Evaluator<V> evaluator) {
this.elementType = Objects.requireNonNull(elementType);
this.evaluator = Objects.requireNonNull(evaluator);

// Set the default return value for termNumByTermElementNum
termNumByTermElementNum.defaultReturnValue(-1);
}

public ElementType getElementType() {
Expand All @@ -94,34 +96,34 @@ void setEquationArray(EquationArray<V, E> equationArray) {
}
this.equationArray = Objects.requireNonNull(equationArray);
termNumsConcatenatedStartIndices = new int[equationArray.getElementCount() + 1];
termNumsByEquationElementNum = new TIntArrayList[equationArray.getElementCount()];
termNumsByEquationElementNum = new IntArrayList[equationArray.getElementCount()];
for (int elementNum = 0; elementNum < equationArray.getElementCount(); elementNum++) {
termNumsByEquationElementNum[elementNum] = new TIntArrayList(10);
termNumsByEquationElementNum[elementNum] = new IntArrayList(10);
}
}

public TIntArrayList getTermNumsForEquationElementNum(int equationElementNum) {
public IntArrayList getTermNumsForEquationElementNum(int equationElementNum) {
return termNumsByEquationElementNum[equationElementNum];
}

public int[] getTermNumsConcatenatedStartIndices() {
return termNumsConcatenatedStartIndices;
}

public TIntArrayList getTermNumsConcatenated() {
public IntArrayList getTermNumsConcatenated() {
return termNumsConcatenated;
}

public boolean isTermActive(int termNum) {
return termActive.getQuick(termNum) == 1;
return termActive.getByte(termNum) == 1;
}

public int getEquationElementNum(int termNum) {
return equationElementNums.getQuick(termNum);
return equationElementNums.getInt(termNum);
}

public int getTermElementNum(int termNum) {
return termElementNums.getQuick(termNum);
return termElementNums.getInt(termNum);
}

public List<Derivative<V>> getTermDerivatives(int termNum) {
Expand All @@ -148,15 +150,16 @@ public EquationTermArray<V, E> addTerm(int equationElementNum, int termElementNu
}

public void compress() {
termNumsConcatenated = new TIntArrayList(equationArray.getElementCount() * 2);
termNumsConcatenated = new IntArrayList(equationArray.getElementCount() * 2);
for (int i = 0; i < termNumsByEquationElementNum.length; i++) {
int iStart = termNumsConcatenated.size();
termNumsConcatenated.addAll(termNumsByEquationElementNum[i]);
termNumsConcatenatedStartIndices[i] = iStart;
}
termNumsConcatenatedStartIndices[termNumsByEquationElementNum.length] = termNumsConcatenated.size();

this.termNumByTermElementNum = new TIntIntHashMap(this.termNumByTermElementNum);
this.termNumByTermElementNum = new Int2IntOpenHashMap(this.termNumByTermElementNum);
termNumByTermElementNum.defaultReturnValue(-1);
}

public double[] eval() {
Expand All @@ -180,17 +183,17 @@ public boolean isTermElementActive(int termElementNum) {
if (termNum == -1) {
throw new PowsyblException("Array term element num not found");
}
return termActive.getQuick(termNum) == 1;
return termActive.getByte(termNum) == 1;
}

public void setTermElementActive(int termElementNum, boolean active) {
int termNum = termNumByTermElementNum.get(termElementNum);
if (termNum == -1) {
throw new PowsyblException("Array term element num not found");
}
boolean oldActive = termActive.getQuick(termNum) == 1;
boolean oldActive = termActive.getByte(termNum) == 1;
if (active != oldActive) {
termActive.setQuick(termNum, (byte) (active ? 1 : 0));
termActive.set(termNum, (byte) (active ? 1 : 0));
equationArray.getEquationSystem().notifyEquationTermArrayChange(this, termNum, active ? EquationTermEventType.EQUATION_TERM_ACTIVATED : EquationTermEventType.EQUATION_TERM_DEACTIVATED);
}
}
Expand Down Expand Up @@ -298,12 +301,12 @@ public boolean write(Writer writer, boolean writeInactiveTerms, int elementNum,
int iEnd = termNumsConcatenatedStartIndices[elementNum + 1];
boolean isFirst = first;
for (int i = iStart; i < iEnd; i++) {
int termNum = termNumsConcatenated.getQuick(i);
if (writeInactiveTerms || termActive.getQuick(termNum) == 1) {
int termNum = termNumsConcatenated.getInt(i);
if (writeInactiveTerms || termActive.getByte(termNum) == 1) {
if (!isFirst) {
writer.append(" + ");
}
if (termActive.getQuick(termNum) == 0) {
if (termActive.getByte(termNum) == 0) {
writer.write("[ ");
}
writer.append(evaluator.getName());
Expand All @@ -316,7 +319,7 @@ public boolean write(Writer writer, boolean writeInactiveTerms, int elementNum,
}
}
writer.write(")");
if (termActive.getQuick(termNum) == 0) {
if (termActive.getByte(termNum) == 0) {
writer.write(" ]");
}
isFirst = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package com.powsybl.openloadflow.graph;

import gnu.trove.list.array.TIntArrayList;
import it.unimi.dsi.fastutil.ints.IntArrayList;

import java.util.*;
import java.util.function.ToIntFunction;
Expand All @@ -21,7 +21,7 @@ public class JGraphTModelWithAdjacencyList<V, E> implements GraphModel<V, E> {

private final ToIntFunction<V> numGetter;

private final Map<V, TIntArrayList> adjacencyList = new LinkedHashMap<>();
private final Map<V, IntArrayList> adjacencyList = new LinkedHashMap<>();

public JGraphTModelWithAdjacencyList(ToIntFunction<V> numGetter) {
this.numGetter = Objects.requireNonNull(numGetter);
Expand All @@ -38,15 +38,15 @@ public void addEdge(V v1, V v2, E e) {
public void removeEdge(E e) {
V edgeSource = getEdgeSource(e);
V edgeTarget = getEdgeTarget(e);
adjacencyList.get(edgeSource).remove(numGetter.applyAsInt(edgeTarget));
adjacencyList.get(edgeTarget).remove(numGetter.applyAsInt(edgeSource));
adjacencyList.get(edgeSource).rem(numGetter.applyAsInt(edgeTarget));
adjacencyList.get(edgeTarget).rem(numGetter.applyAsInt(edgeSource));
delegate.removeEdge(e);
}

@Override
public void addVertex(V v) {
delegate.addVertex(v);
adjacencyList.put(v, new TIntArrayList(10));
adjacencyList.put(v, new IntArrayList(10));
}

@Override
Expand Down Expand Up @@ -105,7 +105,7 @@ public List<V> getNeighborVerticesOf(V v) {
return delegate.getNeighborVerticesOf(v);
}

public Map<V, TIntArrayList> getAdjacencyList() {
public Map<V, IntArrayList> getAdjacencyList() {
return adjacencyList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package com.powsybl.openloadflow.graph;

import com.powsybl.math.graph.GraphUtil;
import gnu.trove.list.array.TIntArrayList;
import it.unimi.dsi.fastutil.ints.IntArrayList;

import java.util.*;
import java.util.function.ToIntFunction;
Expand All @@ -33,11 +33,11 @@ public boolean supportTemporaryChangesNesting() {
}

private List<Set<V>> calculateConnectedSets() {
Map<V, TIntArrayList> adjacencyList = getGraph().getAdjacencyList();
TIntArrayList[] adjacencyListArray = new TIntArrayList[adjacencyList.size()];
for (Map.Entry<V, TIntArrayList> entry : adjacencyList.entrySet()) {
Map<V, IntArrayList> adjacencyList = getGraph().getAdjacencyList();
IntArrayList[] adjacencyListArray = new IntArrayList[adjacencyList.size()];
for (Map.Entry<V, IntArrayList> entry : adjacencyList.entrySet()) {
V vertex = entry.getKey();
TIntArrayList adj = entry.getValue();
IntArrayList adj = entry.getValue();
adjacencyListArray[numGetter.applyAsInt(vertex)] = adj;
}
GraphUtil.ConnectedComponentsComputationResult result = GraphUtil.computeConnectedComponents(adjacencyListArray);
Expand Down
Loading