-
Notifications
You must be signed in to change notification settings - Fork 3
Angiogenesis #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Angiogenesis #190
Changes from 39 commits
0cf2719
9915650
fb498be
1748fca
363d67f
74c0da2
86ba444
3e15f8b
e146543
e9d09f9
17f8d9c
a9fd46f
9a2bc91
946889c
253aad3
0ba65bf
2c832e6
5dda2c9
bd7ee7f
fdd8d07
943281d
5197158
eb06923
4d2fe52
a7572c1
98ad1bf
bf1ca4c
a19778e
28dfc5c
cab2f02
9f169a0
6037755
6006b41
3cce139
e48151f
2086199
8bb6ef6
2399cb4
79bc465
5cf3045
cfad7eb
5e74cb3
db39c38
b1d605e
317484a
d931ac1
df34e85
f94e0da
7cec022
45ad5b3
7656e5c
36d6e6a
7ab6c1a
b3da84a
9632e82
06db7cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package arcade.core.util; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import arcade.core.util.Matrix.Value; | ||
|
|
||
| /** | ||
| * Container class for array-based sparse matrix representation. | ||
| * | ||
| * <p>Class provides a subset of matrix operations needed for solving a system of linear equations | ||
| * using the successive over-relaxation method in {@link arcade.core.util.Solver}. | ||
| */ | ||
| public class MatrixArray { | ||
| public MatrixArray(double[][] a) { | ||
|
Check failure on line 14 in src/arcade/core/util/MatrixArray.java
|
||
| nRows = a.length; | ||
| if (nRows == 0) { | ||
| throw new IllegalArgumentException("MatrixArray ctor: input is empty"); | ||
| } | ||
| nColumns = a[0].length; | ||
|
|
||
| if (nColumns == 0) { | ||
| throw new IllegalArgumentException("Matrix array ctor: empty columns"); | ||
| } | ||
|
|
||
| ArrayList<Value> alValues = new ArrayList<>(); | ||
| int nNonZero = 0; | ||
| for (int row = 0; row < nRows; row++) { | ||
| if (a[row].length != nColumns) { | ||
| throw new IllegalArgumentException( | ||
| "Matrix array ctor: not all columns are the same length"); | ||
| } | ||
|
|
||
| for (int column = 0; column < nColumns; column++) { | ||
| if (a[row][column] != 0.) { | ||
| alValues.add(new Value(row, column, a[row][column])); | ||
| nNonZero++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // | ||
| // No need to sort, since we built them in order. | ||
| // | ||
|
|
||
| values = new Value[nNonZero]; | ||
| int i = 0; | ||
| for (Value v : alValues) { | ||
| values[i] = v; | ||
| i++; | ||
| } | ||
| } // ctor | ||
|
|
||
| public MatrixArray(ArrayList<Value> alValues, int i_nRows, int i_Columns) { | ||
|
Check failure on line 53 in src/arcade/core/util/MatrixArray.java
|
||
| nRows = i_nRows; | ||
| nColumns = i_Columns; | ||
| values = new Value[alValues.size()]; | ||
|
|
||
| Collections.sort( | ||
| alValues, | ||
| (v1, v2) -> (v1.i == v2.i ? Integer.compare(v1.j, v2.j) : (v1.i > v2.i ? 1 : -1))); | ||
|
|
||
| int i = 0; | ||
| for (Value v : alValues) { | ||
| values[i] = v; | ||
| i++; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Solves the equation {@code Lx = b} using forward substitution for an array-based sparse | ||
| * matrix. | ||
| * | ||
| * @param b the right-hand side vector | ||
| * @return the left-hand side vector | ||
| */ | ||
| public double[] forwardSubstitution(double[] b) { | ||
|
|
||
| int n = b.length; | ||
| double[] subbed = new double[n]; | ||
| double[] diag = new double[n]; | ||
|
|
||
| // Group lower diagonal by row. | ||
| ArrayList<ArrayList<Value>> rowsL = new ArrayList<ArrayList<Value>>(); | ||
| for (int r = 0; r < n; r++) { | ||
| rowsL.add(new ArrayList<>()); | ||
| } | ||
| for (Value v : values) { | ||
| rowsL.get(v.i).add(v); | ||
| } | ||
|
|
||
| // Get values along diagonal. | ||
| for (Value v : values) { | ||
| if (v.i == v.j) { | ||
| diag[v.i] = v.v; | ||
| } | ||
| } | ||
|
|
||
| // Iterate only through non-zero entries in the lower diagonal matrix. | ||
| for (int i = 0; i < n; i++) { | ||
| ArrayList<Value> rowL = rowsL.get(i); | ||
| double val = 0; | ||
| for (Value v : rowL) { | ||
| val += subbed[v.j] * v.v; | ||
| } | ||
| val = b[i] - val; | ||
| subbed[i] = val / diag[i]; | ||
| } | ||
|
|
||
| return subbed; | ||
| } | ||
|
|
||
| public double[] multiply(double[] b) { | ||
|
Check failure on line 112 in src/arcade/core/util/MatrixArray.java
|
||
| if (b.length != nRows) { | ||
| throw new IllegalArgumentException("MatrixArray.multiply (by a vector): conformation"); | ||
| } | ||
| double[] multiplied = new double[nRows]; | ||
|
|
||
| // Iterate through all entries and multiply. | ||
| for (Value a : values) { | ||
| multiplied[a.i] += a.v * b[a.j]; | ||
| } | ||
|
|
||
| return multiplied; | ||
| } | ||
|
|
||
| int nRows; | ||
|
Check failure on line 126 in src/arcade/core/util/MatrixArray.java
|
||
| int nColumns; | ||
|
Check failure on line 127 in src/arcade/core/util/MatrixArray.java
|
||
| Value[] values; | ||
|
Check failure on line 128 in src/arcade/core/util/MatrixArray.java
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.