Commit 1b9dc54f authored by Piotr Wendykier's avatar Piotr Wendykier

Merge branch 'bugfix/issue_87' into 'develop'

Fix for issue #87.

See merge request !99
parents d175f6d2 0d4c4f14
Pipeline #30660924 passed with stage
in 0 seconds
......@@ -40,6 +40,9 @@ package pl.edu.icm.visnow.lib.basic.filters.DifferentialOperations;
import pl.edu.icm.visnow.engine.core.ParameterName;
import pl.edu.icm.visnow.gui.widgets.RunButton.RunState;
import pl.edu.icm.visnow.lib.utils.field.DifferentialOperations.ScalarOperation;
import pl.edu.icm.visnow.lib.utils.field.DifferentialOperations.TimeOperation;
import pl.edu.icm.visnow.lib.utils.field.DifferentialOperations.VectorOperation;
/**
*
......@@ -47,22 +50,6 @@ import pl.edu.icm.visnow.gui.widgets.RunButton.RunState;
*/
public class DifferentialOperationsShared
{
public enum ScalarOperation
{
GRADIENT, GRADIENT_NORM, GRADIENT_COMPONENTS, NORMALIZED_GRADIENT,
LAPLACIAN, HESSIAN, HESSIAN_EIGEN
};
public enum VectorOperation
{
DERIV, DERIV_COMPONENTS, DIV, ROT
};
public enum TimeOperation
{
D_DT, D2_DT2
};
//Parameter names + specification. SPECIFICATION CONSTRAINTS ARE NOT TESTED IN LOGIC!
//Specification:
......
......@@ -55,9 +55,9 @@ import pl.edu.icm.visnow.engine.core.ParameterProxy;
import pl.edu.icm.visnow.engine.core.Parameters;
import pl.edu.icm.visnow.gui.widgets.RunButton.RunState;
import static pl.edu.icm.visnow.lib.basic.filters.DifferentialOperations.DifferentialOperationsShared.*;
import static pl.edu.icm.visnow.lib.basic.filters.DifferentialOperations.DifferentialOperationsShared.ScalarOperation.*;
import static pl.edu.icm.visnow.lib.basic.filters.DifferentialOperations.DifferentialOperationsShared.VectorOperation.*;
import static pl.edu.icm.visnow.lib.basic.filters.DifferentialOperations.DifferentialOperationsShared.TimeOperation.*;
import pl.edu.icm.visnow.lib.utils.field.DifferentialOperations.ScalarOperation;
import pl.edu.icm.visnow.lib.utils.field.DifferentialOperations.TimeOperation;
import pl.edu.icm.visnow.lib.utils.field.DifferentialOperations.VectorOperation;
import pl.edu.icm.visnow.system.swing.FixedGridBagLayoutPanel;
/**
......@@ -71,8 +71,8 @@ public final class GUI extends FixedGridBagLayoutPanel
protected final static ScalarOperation[] SCALAR_TABLE_COLUMN_ORDER =
{null, GRADIENT, GRADIENT_COMPONENTS, GRADIENT_NORM, NORMALIZED_GRADIENT,
LAPLACIAN, HESSIAN, HESSIAN_EIGEN};
{null, ScalarOperation.GRADIENT, ScalarOperation.GRADIENT_COMPONENTS, ScalarOperation.GRADIENT_NORM, ScalarOperation.NORMALIZED_GRADIENT,
ScalarOperation.LAPLACIAN, ScalarOperation.HESSIAN, ScalarOperation.HESSIAN_EIGEN};
protected final static String[] SCALAR_TABLE_TOOLTIPS = {
null, "gradient", "partial derivatives as scalars", "gradient norm", "normalized gradient",
"Laplacian","Hessian matrix (upper triangle)","Hessian eigenvalues and eigenvectors"
......@@ -132,7 +132,7 @@ public final class GUI extends FixedGridBagLayoutPanel
}
};
private final static VectorOperation[] VECTOR_TABLE_COLUMN_ORDER = {null, DERIV, ROT, DIV};
private final static VectorOperation[] VECTOR_TABLE_COLUMN_ORDER = {null, VectorOperation.DERIV, VectorOperation.ROT, VectorOperation.DIV};
protected final static String[] VECTOR_TABLE_TOOLTIPS = {null, "partial derivatives", "rotation", "divergence"};
protected final static int[] VECTOR_TABLE_COLUMN_WIDTHS = new int[]{100, 20, 20, 20};
protected final DefaultTableModel vectorTableModel =
......@@ -187,7 +187,7 @@ public final class GUI extends FixedGridBagLayoutPanel
}
};
private final static TimeOperation[] TIME_TABLE_COLUMN_ORDER = {null, D_DT, D2_DT2};
private final static TimeOperation[] TIME_TABLE_COLUMN_ORDER = {null, TimeOperation.D_DT, TimeOperation.D2_DT2};
protected final static String[] TIME_TABLE_TOOLTIPS = {null, "time derivative (change velocity)", "time change acceleration"};
protected final static int[] TIME_TABLE_COLUMN_WIDTHS = new int[]{120, 30, 30};
protected DefaultTableModel timeTableModel
......
......@@ -36,7 +36,6 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
//</editor-fold>
package pl.edu.icm.visnow.lib.utils.field;
import java.util.Arrays;
......@@ -51,10 +50,6 @@ import pl.edu.icm.jscic.TimeData;
import pl.edu.icm.jscic.dataarrays.DataArray;
import static pl.edu.icm.jscic.dataarrays.DataArrayType.*;
import pl.edu.icm.visnow.engine.core.ProgressAgent;
import pl.edu.icm.visnow.lib.basic.filters.DifferentialOperations.DifferentialOperationsShared.*;
import static pl.edu.icm.visnow.lib.basic.filters.DifferentialOperations.DifferentialOperationsShared.ScalarOperation.*;
import static pl.edu.icm.visnow.lib.basic.filters.DifferentialOperations.DifferentialOperationsShared.VectorOperation.*;
import static pl.edu.icm.visnow.lib.basic.filters.DifferentialOperations.DifferentialOperationsShared.TimeOperation.*;
import static pl.edu.icm.visnow.lib.utils.numeric.FiniteDifferences.Derivatives.*;
import pl.edu.icm.visnow.lib.utils.numeric.FiniteDifferences.InvertedJacobian;
import pl.edu.icm.visnow.lib.utils.numeric.PointwiseLinearAlgebra2D;
......@@ -70,6 +65,22 @@ import pl.edu.icm.visnow.system.main.VisNow;
public class DifferentialOperations
{
public enum ScalarOperation
{
GRADIENT, GRADIENT_NORM, GRADIENT_COMPONENTS, NORMALIZED_GRADIENT,
LAPLACIAN, HESSIAN, HESSIAN_EIGEN
};
public enum VectorOperation
{
DERIV, DERIV_COMPONENTS, DIV, ROT
};
public enum TimeOperation
{
D_DT, D2_DT2
};
private static final String[] COORD_NAMES = {"x", "y", "z"};
private static void computeD_Dt(float[] times, float[][] dIn, float[][] dOut)
......@@ -77,7 +88,7 @@ public class DifferentialOperations
int nTimesteps = dIn.length;
for (int timestep = 0; timestep < nTimesteps; timestep++) {
int tstep0 = timestep;
int tstep1 = timestep > 0 ? timestep - 1: timestep + 2;
int tstep1 = timestep > 0 ? timestep - 1 : timestep + 2;
int tstep2 = timestep < nTimesteps - 1 ? timestep + 1 : timestep - 2;
float t0 = times[tstep0];
float t1 = times[tstep1];
......@@ -101,69 +112,69 @@ public class DifferentialOperations
}
public static Field computeDifferentialOperators(Field inField,
HashMap<String, ScalarOperation[]> scalarOps,
HashMap<String, VectorOperation[]> vectorOps,
HashMap<String, TimeOperation[]> timeOps,
boolean computeFully, ProgressAgent progressAgent, int nThreads)
HashMap<String, ScalarOperation[]> scalarOps,
HashMap<String, VectorOperation[]> vectorOps,
HashMap<String, TimeOperation[]> timeOps,
boolean computeFully, ProgressAgent progressAgent, int nThreads)
{
Field outField = inField.cloneShallow();
int nData = (int)inField.getNNodes();
int nData = (int) inField.getNNodes();
if (inField instanceof RegularField) {
RegularField regInField = (RegularField)inField;
int[]dims = regInField.getDims();
RegularField regInField = (RegularField) inField;
int[] dims = regInField.getDims();
int dim = dims.length;
float[] invJacobian = InvertedJacobian.computeInvertedJacobian(VisNow.availableProcessors(), regInField);
if (scalarOps != null) {
for (Map.Entry<String, ScalarOperation[]> entry : scalarOps.entrySet()) {
DataArray outGrad = null, outGradNorm = null, outNormalizedGradient = null,
outHessian = null, outLaplacian = null;
DataArray[] outGradCmp = new DataArray[dim];
outHessian = null, outLaplacian = null;
DataArray[] outGradCmp = new DataArray[dim];
DataArray[] outHessianEigval = new DataArray[dim];
DataArray[] outHessianEigvec = new DataArray[dim];
List<ScalarOperation> scalarOperations = Arrays.asList((ScalarOperation[]) entry.getValue());
if (scalarOperations.size() > 0) {
DataArray da = regInField.getComponent(entry.getKey());
if (scalarOperations.contains(GRADIENT))
if (scalarOperations.contains(ScalarOperation.GRADIENT))
outGrad = DataArray.create(FIELD_DATA_FLOAT, nData, dim,
da.getName() + "_grad", da.getUnit() + "/m",
da.getUserData());
if (scalarOperations.contains(GRADIENT_NORM))
da.getName() + "_grad", da.getUnit() + "/m",
da.getUserData());
if (scalarOperations.contains(ScalarOperation.GRADIENT_NORM))
outGradNorm = DataArray.create(FIELD_DATA_FLOAT, nData, 1,
da.getName() + "_gradNorm", da.getUnit() + "/m",
da.getUserData());
if (scalarOperations.contains(NORMALIZED_GRADIENT))
da.getName() + "_gradNorm", da.getUnit() + "/m",
da.getUserData());
if (scalarOperations.contains(ScalarOperation.NORMALIZED_GRADIENT))
outNormalizedGradient = DataArray.create(FIELD_DATA_FLOAT, nData, dim,
da.getName() + "_normGrad", da.getUnit() + "/m",
da.getUserData());
if (scalarOperations.contains(GRADIENT_COMPONENTS))
da.getName() + "_normGrad", da.getUnit() + "/m",
da.getUserData());
if (scalarOperations.contains(ScalarOperation.GRADIENT_COMPONENTS))
for (int coord = 0; coord < dim; coord++)
outGradCmp[coord] = DataArray.create(FIELD_DATA_FLOAT, nData, 1,
da.getName() + "_d/d" + COORD_NAMES[coord], da.getUnit() + "/m",
da.getUserData());
if (scalarOperations.contains(LAPLACIAN))
da.getName() + "_d/d" + COORD_NAMES[coord], da.getUnit() + "/m",
da.getUserData());
if (scalarOperations.contains(ScalarOperation.LAPLACIAN))
outLaplacian = DataArray.create(FIELD_DATA_FLOAT, nData, 1,
da.getName() + "_lap", da.getUnit() + "/m^2",
da.getUserData());
if (scalarOperations.contains(HESSIAN))
da.getName() + "_lap", da.getUnit() + "/m^2",
da.getUserData());
if (scalarOperations.contains(ScalarOperation.HESSIAN))
outHessian = DataArray.create(FIELD_DATA_FLOAT, nData,
(dim * (dim + 1)) / 2, da.getName() + "_hessian",
da.getUnit() + "/m^2", da.getUserData());
if (scalarOperations.contains(HESSIAN_EIGEN))
(dim * (dim + 1)) / 2, da.getName() + "_hessian",
da.getUnit() + "/m^2", da.getUserData());
if (scalarOperations.contains(ScalarOperation.HESSIAN_EIGEN))
for (int coord = 0; coord < dim; coord++) {
outHessianEigval[coord] = DataArray.create(FIELD_DATA_FLOAT, nData, 1,
da.getName() + "_eigval" + COORD_NAMES[coord], "",
da.getUserData());
da.getName() + "_eigval" + COORD_NAMES[coord], "",
da.getUserData());
outHessianEigvec[coord] = DataArray.create(FIELD_DATA_FLOAT, nData, dim,
da.getName() + "_eigvec" + COORD_NAMES[coord], "",
da.getUserData());
da.getName() + "_eigvec" + COORD_NAMES[coord], "",
da.getUserData());
}
int nTimesteps = computeFully ? da.getNFrames() : 1;
for (int timestep = 0; timestep < nTimesteps; timestep++) {
float time = da.getTime(timestep);
float[] fda = computeFully
? da.getRawArray(time).getFloatData()
: da.getRawArray().getFloatData();
? da.getRawArray(time).getFloatData()
: da.getRawArray().getFloatData();
//first derivative must be computed and stored
float[] grad = computeDerivatives(nThreads, regInField.getDims(), fda, invJacobian);
......@@ -205,7 +216,7 @@ public class DifferentialOperations
progressAgent.increase();
}
if (scalarOperations.contains(GRADIENT_COMPONENTS))
if (scalarOperations.contains(ScalarOperation.GRADIENT_COMPONENTS))
for (int coord = 0; coord < dim; coord++) {
float[] cmp = new float[nData];
for (int k = 0, l = coord; k < nData; k++, l += dim)
......@@ -217,9 +228,9 @@ public class DifferentialOperations
}
//second derivatives
if (scalarOperations.contains(LAPLACIAN)
|| scalarOperations.contains(HESSIAN)
|| scalarOperations.contains(HESSIAN_EIGEN)) {
if (scalarOperations.contains(ScalarOperation.LAPLACIAN) ||
scalarOperations.contains(ScalarOperation.HESSIAN) ||
scalarOperations.contains(ScalarOperation.HESSIAN_EIGEN)) {
float[] d2 = computeDerivatives(nThreads, regInField.getDims(), grad, invJacobian);
float[] h = symmetrize(dim, d2);
......@@ -242,7 +253,7 @@ public class DifferentialOperations
progressAgent.increase();
}
if (scalarOperations.contains(HESSIAN_EIGEN)) {
if (scalarOperations.contains(ScalarOperation.HESSIAN_EIGEN)) {
float[][] hEigV = new float[dim][nData];
float[][] hEigR = new float[dim][nData * dim];
if (dim == 3)
......@@ -264,16 +275,16 @@ public class DifferentialOperations
outField.addComponent(outGrad);
if (outGradNorm != null)
outField.addComponent(outGradNorm);
if (outNormalizedGradient != null)
if (outNormalizedGradient != null)
outField.addComponent(outNormalizedGradient);
if (scalarOperations.contains(GRADIENT_COMPONENTS))
if (scalarOperations.contains(ScalarOperation.GRADIENT_COMPONENTS))
for (int coord = 0; coord < dim; coord++)
outField.addComponent(outGradCmp[coord]);
if (outLaplacian != null)
outField.addComponent(outLaplacian);
if (outHessian != null)
outField.addComponent(outHessian);
if (scalarOperations.contains(HESSIAN_EIGEN))
if (scalarOperations.contains(ScalarOperation.HESSIAN_EIGEN))
for (int coord = 0; coord < dim; coord++) {
outField.addComponent(outHessianEigval[coord]);
outField.addComponent(outHessianEigvec[coord]);
......@@ -292,32 +303,32 @@ public class DifferentialOperations
int vLen = da.getVectorLength();
if (vLen != dim)
continue;
if (vectorOperations.contains(DERIV))
if (vectorOperations.contains(VectorOperation.DERIV))
for (int coord = 0; coord < dim; coord++)
outDerivCmp[coord] = DataArray.create(FIELD_DATA_FLOAT, nData, dim,
da.getName() + "_d" + coord, da.getUnit() + "/m",
da.getUserData());
if (vectorOperations.contains(DIV))
da.getName() + "_d" + coord, da.getUnit() + "/m",
da.getUserData());
if (vectorOperations.contains(VectorOperation.DIV))
outDiv = DataArray.create(FIELD_DATA_FLOAT, nData, 1,
da.getName() + "_div", da.getUnit() + "/m",
da.getUserData());
if (vectorOperations.contains(ROT))
da.getName() + "_div", da.getUnit() + "/m",
da.getUserData());
if (vectorOperations.contains(VectorOperation.ROT))
if (dim == 3)
outRot = DataArray.create(FIELD_DATA_FLOAT, nData, dim,
da.getName() + "_rot", da.getUnit() + "/m",
da.getUserData());
da.getName() + "_rot", da.getUnit() + "/m",
da.getUserData());
else if (dim == 2)
outRot = DataArray.create(FIELD_DATA_FLOAT, nData, 1,
da.getName() + "_rot", da.getUnit() + "/m",
da.getUserData());
da.getName() + "_rot", da.getUnit() + "/m",
da.getUserData());
int nTimesteps = computeFully ? da.getNFrames() : 1;
for (int timestep = 0; timestep < nTimesteps; timestep++) {
float time = da.getTime(timestep);
float[] fda = computeFully
? da.getRawArray(time).getFloatData()
: da.getRawArray().getFloatData();
? da.getRawArray(time).getFloatData()
: da.getRawArray().getFloatData();
float[] h = computeDerivatives(nThreads, regInField.getDims(), fda, invJacobian);
if (vectorOperations.contains(DERIV)) {
if (vectorOperations.contains(VectorOperation.DERIV)) {
for (int k = 0; k < dim; k++) {
float[] dta = new float[dim * nData];
for (int l = 0, m = 0; l < nData; l++)
......@@ -362,17 +373,17 @@ public class DifferentialOperations
progressAgent.increase();
}
}
if (vectorOperations.contains(DERIV))
if (vectorOperations.contains(VectorOperation.DERIV))
for (int coord = 0; coord < dim; coord++)
outField.addComponent(outDerivCmp[coord]);
if (vectorOperations.contains(DIV))
if (vectorOperations.contains(VectorOperation.DIV))
outField.addComponent(outDiv);
if (vectorOperations.contains(ROT))
if (vectorOperations.contains(VectorOperation.ROT))
outField.addComponent(outRot);
}
}
}
if (timeOps != null) {
for (Map.Entry<String, TimeOperation[]> entry : timeOps.entrySet()) {
List<TimeOperation> timeOperations = Arrays.asList((TimeOperation[]) entry.getValue());
......@@ -384,19 +395,18 @@ public class DifferentialOperations
td = inField.getCoords();
vLen = 3;
nTimesteps = td.getNSteps();
}
else {
} else {
DataArray da = inField.getComponent(entry.getKey());
td = da.getTimeData();
vLen = da.getVectorLength();
nTimesteps = da.getNFrames();
}
if (nTimesteps < 2)
continue;
//first derivative must be computed and stored
float[][] dIn = new float[nTimesteps][];
float[] times = td.getTimesAsArray();
float[][] dIn = new float[nTimesteps][];
float[] times = td.getTimesAsArray();
for (int i = 0; i < nTimesteps; i++) {
float time = times[i];
dIn[i] = td.getValue(time).getFloatData();
......@@ -406,28 +416,28 @@ public class DifferentialOperations
computeD_Dt(times, dIn, dOut);
else {
float dt = times[1] - times[0];
for (int i = 0; i < dOut[0].length; i++)
for (int i = 0; i < dOut[0].length; i++)
dOut[0][i] = dOut[1][i] = (dIn[1][i] - dIn[0][i]) / dt;
}
if (timeOperations.contains(D_DT)) {
if (timeOperations.contains(TimeOperation.D_DT)) {
DataArray d_dt = DataArray.create(FIELD_DATA_FLOAT, nData, vLen,
"d_" + name + "_dt", "", new String[] {});
for (int i = 0; i < dOut.length; i++)
"d_" + name + "_dt", "", new String[]{});
for (int i = 0; i < dOut.length; i++)
d_dt.addRawArray(new FloatLargeArray(dOut[i]), times[i]);
outField.addComponent(d_dt);
}
if (timeOperations.contains(D2_DT2)) {
if (timeOperations.contains(TimeOperation.D2_DT2)) {
DataArray d2_dt2 = DataArray.create(FIELD_DATA_FLOAT, nData, vLen,
"d2_" + name + "_dt2", "", new String[] {});
float[][] dOut2 = new float[nTimesteps][nData * vLen];
"d2_" + name + "_dt2", "", new String[]{});
float[][] dOut2 = new float[nTimesteps][nData * vLen];
if (times.length > 2)
computeD_Dt(times, dOut, dOut2);
computeD_Dt(times, dOut, dOut2);
else {
float dt = times[1] - times[0];
for (int i = 0; i < dOut[0].length; i++)
for (int i = 0; i < dOut[0].length; i++)
dOut2[0][i] = dOut2[1][i] = (dOut[1][i] - dOut[0][i]) / dt;
}
for (int i = 0; i < dOut2.length; i++)
for (int i = 0; i < dOut2.length; i++)
d2_dt2.addRawArray(new FloatLargeArray(dOut2[i]), times[i]);
outField.addComponent(d2_dt2);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment