use of org.vcell.util.Coordinate in project vcell by virtualcell.
the class CurveRenderer method setWorldDelta.
/**
* Sets the worldDelta property (cbit.vcell.geometry.Coordinate) value.
* @param worldDelta The new value for the property.
* @see #getWorldDelta
*/
public void setWorldDelta(org.vcell.util.Coordinate wd) {
if (wd == null && fieldWorldDelta == null) {
return;
}
Coordinate oldValue = fieldWorldDelta;
fieldWorldDelta = wd;
// Calc smallest 1 Pixel distance of the 3 axes
// unitDistance[Coordinate.X_AXIS] = Math.sqrt((wd.getZ() * wd.getZ()) + (wd.getY() * wd.getY()));
// unitDistance[Coordinate.Y_AXIS] = Math.sqrt((wd.getX() * wd.getX()) + (wd.getZ() * wd.getZ()));
// unitDistance[Coordinate.Z_AXIS] = Math.sqrt((wd.getX() * wd.getX()) + (wd.getY() * wd.getY()));
//
updateOriginAndScaling2D();
firePropertyChange("worldDelta", oldValue, wd);
}
use of org.vcell.util.Coordinate in project vcell by virtualcell.
the class MathTestingUtilities method comparePDEResultsWithExact.
/**
* Insert the method's description here.
* Creation date: (8/20/2003 12:58:10 PM)
*/
public static SimulationComparisonSummary comparePDEResultsWithExact(SimulationSymbolTable simSymbolTable, PDEDataManager dataManager, String type, double absErrorThreshold, double relErrorThreshold) throws DataAccessException, ExpressionException {
java.util.Hashtable<String, DataErrorSummary> tempVarHash = new java.util.Hashtable<String, DataErrorSummary>();
double[] timeArray = dataManager.getDataSetTimes();
Variable[] vars = simSymbolTable.getVariables();
CartesianMesh mesh = dataManager.getMesh();
MathDescription mathDesc = simSymbolTable.getSimulation().getMathDescription();
// Get volumeSubdomains from mathDesc/mesh and store in lookupTable
int numVol = mesh.getSizeX() * mesh.getSizeY() * mesh.getSizeZ();
CompartmentSubDomain[] volSubDomainLookup = new CompartmentSubDomain[numVol];
for (int i = 0; i < numVol; i++) {
int subVolumeIndex = mesh.getSubVolumeFromVolumeIndex(i);
SubVolume subVolume = mathDesc.getGeometry().getGeometrySpec().getSubVolume(subVolumeIndex);
CompartmentSubDomain compSubDomain = mathDesc.getCompartmentSubDomain(subVolume.getName());
volSubDomainLookup[i] = compSubDomain;
}
// Get membraneSubdomains from mathDesc/mesh and store in lookupTable
int numMem = mesh.getMembraneElements().length;
MembraneSubDomain[] memSubDomainLookup = new MembraneSubDomain[numMem];
for (int i = 0; i < numMem; i++) {
int insideVolIndex = mesh.getMembraneElements()[i].getInsideVolumeIndex();
int outsideVolIndex = mesh.getMembraneElements()[i].getOutsideVolumeIndex();
MembraneSubDomain memSubDomain = mathDesc.getMembraneSubDomain(volSubDomainLookup[insideVolIndex], volSubDomainLookup[outsideVolIndex]);
memSubDomainLookup[i] = memSubDomain;
}
double[] valueArray = new double[4];
SimpleSymbolTable symbolTable = new SimpleSymbolTable(new String[] { "t", "x", "y", "z" });
int tIndex = symbolTable.getEntry("t").getIndex();
int xIndex = symbolTable.getEntry("x").getIndex();
int yIndex = symbolTable.getEntry("y").getIndex();
int zIndex = symbolTable.getEntry("z").getIndex();
SimulationComparisonSummary simComparisonSummary = new SimulationComparisonSummary();
String hashKey = new String("");
long dataLength = 0;
// for each var, do the following :
for (int i = 0; i < vars.length; i++) {
if (vars[i] instanceof VolVariable || vars[i] instanceof MemVariable || vars[i] instanceof FilamentVariable || vars[i] instanceof VolumeRegionVariable || vars[i] instanceof MembraneRegionVariable || vars[i] instanceof FilamentRegionVariable) {
// for each time in timeArray,
for (int j = 0; j < timeArray.length; j++) {
if (type.equals(TestCaseNew.EXACT_STEADY)) {
if (j != (timeArray.length - 1)) {
continue;
}
}
// get data block from varName, data from datablock
SimDataBlock simDataBlock = dataManager.getSimDataBlock(vars[i].getName(), timeArray[j]);
double[] data = simDataBlock.getData();
dataLength = data.length;
SubDomain subDomain = null;
Coordinate subDomainCoord = null;
// for each point in data block ...
for (int k = 0; k < dataLength; k++) {
// Get subdomain from mesh (from the lookupTable), get coordinates (x,y,z) from mesh, evaluate EXACT SOLN at that coord
if (vars[i] instanceof VolVariable) {
subDomain = volSubDomainLookup[k];
subDomainCoord = mesh.getCoordinateFromVolumeIndex(k);
} else if (vars[i] instanceof MemVariable) {
subDomain = memSubDomainLookup[k];
subDomainCoord = mesh.getCoordinateFromMembraneIndex(k);
} else {
throw new RuntimeException("Var " + vars[i].getName() + " not supported yet!");
}
hashKey = vars[i].getName() + ":" + subDomain.getName();
DataErrorSummary tempVar = (DataErrorSummary) tempVarHash.get(hashKey);
if (tempVar == null) {
Expression exp = new Expression(subDomain.getEquation(vars[i]).getExactSolution());
exp.bindExpression(simSymbolTable);
exp = MathUtilities.substituteFunctions(exp, simSymbolTable);
exp = exp.flatten();
exp.bindExpression(symbolTable);
tempVar = new DataErrorSummary(exp);
tempVarHash.put(hashKey, tempVar);
}
// time
valueArray[tIndex] = timeArray[j];
// x
valueArray[xIndex] = subDomainCoord.getX();
// y
valueArray[yIndex] = subDomainCoord.getY();
// z
valueArray[zIndex] = subDomainCoord.getZ();
// EXACT soln at coord subDomainCoord
double value = tempVar.getExactExp().evaluateVector(valueArray);
tempVar.addDataValues(value, data[k], timeArray[j], k, absErrorThreshold, relErrorThreshold);
}
// end for (k)
}
// end for (j)
}
// end - if (var)
}
// end for (i)
Enumeration<String> enumKeys = tempVarHash.keys();
while (enumKeys.hasMoreElements()) {
String key = enumKeys.nextElement();
DataErrorSummary tempVarSummary = tempVarHash.get(key);
simComparisonSummary.addVariableComparisonSummary(new VariableComparisonSummary(key, tempVarSummary.getMinRef(), tempVarSummary.getMaxRef(), tempVarSummary.getMaxAbsoluteError(), tempVarSummary.getMaxRelativeError(), tempVarSummary.getL2Norm(), tempVarSummary.getTimeAtMaxAbsoluteError(), tempVarSummary.getIndexAtMaxAbsoluteError(), tempVarSummary.getTimeAtMaxRelativeError(), tempVarSummary.getIndexAtMaxRelativeError()));
}
return simComparisonSummary;
}
use of org.vcell.util.Coordinate in project vcell by virtualcell.
the class MathTestingUtilities method resample3DSpatialSimple.
/**
* Insert the method's description here.
* Creation date: (10/27/2003 5:07:42 PM)
* @return double[]
* @param data double[]
* @param sourceMesh cbit.vcell.solvers.CartesianMesh
* @param targetMesh cbit.vcell.solvers.CartesianMesh
*/
public static double[] resample3DSpatialSimple(double[] sourceData, CartesianMesh sourceMesh, CartesianMesh refMesh) {
if (sourceData.length != sourceMesh.getNumVolumeElements()) {
throw new RuntimeException("must be volume data, data length doesn't match number of volume elements");
}
// for volume samples:
//
// loop through volumeIndexes from refMesh
// Coordinate refCoordinate = refMesh.getCoordinate(volumeIndex);
// Coordinate fractionalIndex = sourceMesh.getFractionCoordinateIndex(Coordinate refCoordinate);
// ....interpolate in z
// start with integer portion of fractionIndex
double[] resampledData = new double[refMesh.getSizeX() * refMesh.getSizeY() * refMesh.getSizeZ()];
for (int i = 0; i < resampledData.length; i++) {
Coordinate refCoordinate = refMesh.getCoordinateFromVolumeIndex(i);
Coordinate fractionalIndex = sourceMesh.getFractionalCoordinateIndex(refCoordinate);
int ceil_x;
int floor_x;
int ceil_y;
int floor_y;
int ceil_z;
int floor_z;
if (fractionalIndex.getX() < 0) {
floor_x = 0;
ceil_x = 1;
} else if (fractionalIndex.getX() > sourceMesh.getSizeX() - 1) {
floor_x = sourceMesh.getSizeX() - 2;
ceil_x = sourceMesh.getSizeX() - 1;
} else {
ceil_x = (int) Math.ceil(fractionalIndex.getX());
floor_x = (int) Math.floor(fractionalIndex.getX());
}
if (fractionalIndex.getY() < 0) {
floor_y = 0;
ceil_y = 1;
} else if (fractionalIndex.getY() > sourceMesh.getSizeY() - 1) {
floor_y = sourceMesh.getSizeY() - 2;
ceil_y = sourceMesh.getSizeY() - 1;
} else {
ceil_y = (int) Math.ceil(fractionalIndex.getY());
floor_y = (int) Math.floor(fractionalIndex.getY());
}
if (fractionalIndex.getZ() < 0) {
floor_z = 0;
ceil_z = 1;
} else if (fractionalIndex.getZ() > sourceMesh.getSizeZ() - 1) {
floor_z = sourceMesh.getSizeZ() - 2;
ceil_z = sourceMesh.getSizeZ() - 1;
} else {
ceil_z = (int) Math.ceil(fractionalIndex.getZ());
floor_z = (int) Math.floor(fractionalIndex.getZ());
}
double fract_x = fractionalIndex.getX() - floor_x;
double fract_y = fractionalIndex.getY() - floor_y;
double fract_z = fractionalIndex.getZ() - floor_z;
CoordinateIndex coord_1 = new CoordinateIndex(floor_x, floor_y, floor_z);
CoordinateIndex coord_2 = new CoordinateIndex(ceil_x, floor_y, floor_z);
CoordinateIndex coord_3 = new CoordinateIndex(floor_x, floor_y, ceil_z);
CoordinateIndex coord_4 = new CoordinateIndex(ceil_x, floor_y, ceil_z);
CoordinateIndex coord_5 = new CoordinateIndex(floor_x, ceil_y, ceil_z);
CoordinateIndex coord_6 = new CoordinateIndex(ceil_x, ceil_y, ceil_z);
CoordinateIndex coord_7 = new CoordinateIndex(floor_x, ceil_y, floor_z);
CoordinateIndex coord_8 = new CoordinateIndex(ceil_x, ceil_y, floor_z);
int volIndx1 = sourceMesh.getVolumeIndex(coord_1);
int volIndx2 = sourceMesh.getVolumeIndex(coord_2);
int volIndx3 = sourceMesh.getVolumeIndex(coord_3);
int volIndx4 = sourceMesh.getVolumeIndex(coord_4);
int volIndx5 = sourceMesh.getVolumeIndex(coord_5);
int volIndx6 = sourceMesh.getVolumeIndex(coord_6);
int volIndx7 = sourceMesh.getVolumeIndex(coord_7);
int volIndx8 = sourceMesh.getVolumeIndex(coord_8);
double val_a = sourceData[volIndx1] + fract_x * (sourceData[volIndx2] - sourceData[volIndx1]);
double val_b = sourceData[volIndx3] + fract_x * (sourceData[volIndx4] - sourceData[volIndx3]);
double val_c = sourceData[volIndx5] + fract_x * (sourceData[volIndx6] - sourceData[volIndx5]);
double val_d = sourceData[volIndx7] + fract_x * (sourceData[volIndx8] - sourceData[volIndx7]);
// Interpolate in Y
double val_e = val_a + fract_y * (val_d - val_a);
double val_f = val_b + fract_y * (val_c - val_b);
// Interpolate in Z - final resampledSourceData value
resampledData[i] = val_e + fract_z * (val_f - val_e);
}
return resampledData;
}
use of org.vcell.util.Coordinate in project vcell by virtualcell.
the class MathTestingUtilities method resample1DSpatialSimple.
/**
* Insert the method's description here.
* Creation date: (10/27/2003 5:07:42 PM)
* @return double[]
* @param data double[]
* @param sourceMesh cbit.vcell.solvers.CartesianMesh
* @param targetMesh cbit.vcell.solvers.CartesianMesh
*/
public static double[] resample1DSpatialSimple(double[] sourceData, CartesianMesh sourceMesh, CartesianMesh refMesh) {
if (sourceData.length != sourceMesh.getNumVolumeElements()) {
throw new RuntimeException("must be volume data, data length doesn't match number of volume elements");
}
// for volume samples:
//
// loop through volumeIndexes from refMesh
// Coordinate refCoordinate = refMesh.getCoordinate(volumeIndex);
// Coordinate fractionalIndex = sourceMesh.getFractionCoordinateIndex(Coordinate refCoordinate);
// ....interpolate in z
// start with integer portion of fractionIndex
double[] resampledData = new double[refMesh.getSizeX()];
for (int i = 0; i < resampledData.length; i++) {
Coordinate refCoordinate = refMesh.getCoordinateFromVolumeIndex(i);
Coordinate fractionalIndex = sourceMesh.getFractionalCoordinateIndex(refCoordinate);
int ceil_x;
int floor_x;
if (fractionalIndex.getX() < 0) {
floor_x = 0;
ceil_x = 1;
} else if (fractionalIndex.getX() > sourceMesh.getSizeX() - 1) {
floor_x = sourceMesh.getSizeX() - 2;
ceil_x = sourceMesh.getSizeX() - 1;
} else {
ceil_x = (int) Math.ceil(fractionalIndex.getX());
floor_x = (int) Math.floor(fractionalIndex.getX());
}
double fract_x = fractionalIndex.getX() - floor_x;
// ***** SHOULD Y,Z BE 0 OR 1 ???? *****
CoordinateIndex coord_1 = new CoordinateIndex(floor_x, 0, 0);
CoordinateIndex coord_2 = new CoordinateIndex(ceil_x, 0, 0);
int volIndx1 = sourceMesh.getVolumeIndex(coord_1);
int volIndx2 = sourceMesh.getVolumeIndex(coord_2);
// Interpolate in X - final resampledSourceData value
resampledData[i] = sourceData[volIndx1] + fract_x * (sourceData[volIndx2] - sourceData[volIndx1]);
}
return resampledData;
}
use of org.vcell.util.Coordinate in project vcell by virtualcell.
the class CartesianMesh method getCoordinateFromMembraneIndex.
/**
* This method was created in VisualAge.
* @return cbit.vcell.geometry.Coordinate
* @param coordIndex cbit.vcell.math.CoordinateIndex
*/
public Coordinate getCoordinateFromMembraneIndex(int membraneIndex) {
MembraneElement me = getMembraneElements()[membraneIndex];
Coordinate inCoord = getCoordinateFromVolumeIndex(me.getInsideVolumeIndex());
Coordinate outCoord = getCoordinateFromVolumeIndex(me.getOutsideVolumeIndex());
return (new Coordinate(0.5 * (inCoord.getX() + outCoord.getX()), 0.5 * (inCoord.getY() + outCoord.getY()), 0.5 * (inCoord.getZ() + outCoord.getZ())));
}
Aggregations