use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.
the class PDEDataContextPanel method fetchSpatialSelections0.
/**
* Insert the method's description here.
* Creation date: (6/28/2003 4:57:18 PM)
* @return cbit.vcell.simdata.gui.SpatialSelection[]
*/
private SpatialSelection[] fetchSpatialSelections0(Curve curveOfInterest, boolean bFetchOnlyVisible, VariableType vt) {
//
java.util.Vector<SpatialSelection> spatialSelection = new java.util.Vector<SpatialSelection>();
//
if (getPdeDataContext() != null && getPdeDataContext().getCartesianMesh() != null && getImagePlaneManagerPanel() != null && getImagePlaneManagerPanel().getCurveRenderer() != null) {
//
CartesianMesh cm = getPdeDataContext().getCartesianMesh();
Curve[] curves = getImagePlaneManagerPanel().getCurveRenderer().getAllCurves();
//
if (curves != null && curves.length > 0) {
for (int i = 0; i < curves.length; i += 1) {
boolean bIsVisible = getImagePlaneManagerPanel().getCurveRenderer().getRenderPropertyVisible(curves[i]);
if ((bFetchOnlyVisible && !bIsVisible) || (curveOfInterest != null && curves[i] != curveOfInterest)) {
continue;
}
//
if ((vt.equals(VariableType.POSTPROCESSING) || vt.equals(VariableType.VOLUME) || vt.equals(VariableType.VOLUME_REGION)) && curves[i] instanceof ControlPointCurve && !(curves[i] instanceof CurveSelectionCurve) && (curves[i].getDescription() == null || curves[i].getDescription().startsWith(CurveValueProvider.DESCRIPTION_VOLUME)) && (membranesAndIndexes == null || !membranesAndIndexes.containsKey(curves[i]))) {
// Volume
//
Curve samplerCurve = null;
// if(isSpatial2D){
samplerCurve = projectCurveOntoSlice(curves[i].getSampledCurve());
// }
if (samplerCurve != null) {
samplerCurve.setDescription(curves[i].getDescription());
spatialSelection.add(new SpatialSelectionVolume(new CurveSelectionInfo(samplerCurve), vt, cm));
}
} else if ((vt.equals(VariableType.MEMBRANE) || vt.equals(VariableType.MEMBRANE_REGION)) && membranesAndIndexes != null) {
//
if (curves[i] instanceof CurveSelectionCurve) {
CurveSelectionCurve csCurve = (CurveSelectionCurve) curves[i];
if (csCurve.getSourceCurveSelectionInfo().getCurve() instanceof ControlPointCurve) {
int[] csisegsel = csCurve.getSourceCurveSelectionInfo().getSegmentsInSelectionOrder();
if (csisegsel != null) {
ControlPointCurve cscpcCurve = (ControlPointCurve) (csCurve.getSourceCurveSelectionInfo().getCurve());
Curve[] membraneCurves = (Curve[]) (membranesAndIndexes.keySet().toArray(new Curve[membranesAndIndexes.size()]));
// See if CurveSelectionCurve matches controlpoints in space of a membrane we have
for (int j = 0; j < membraneCurves.length; j += 1) {
if (membraneCurves[j] instanceof ControlPointCurve) {
// They should all be
ControlPointCurve cpc = (ControlPointCurve) membraneCurves[j];
boolean bSame = true;
for (int k = 0; k < csisegsel.length; k += 1) {
if (csisegsel[k] >= cpc.getControlPointCount() || csisegsel[k] >= cscpcCurve.getControlPointCount() || !Coordinate.get2DProjection(cpc.getControlPoint(csisegsel[k]), getNormalAxis()).equals(Coordinate.get2DProjection(cscpcCurve.getControlPoint(csisegsel[k]), getNormalAxis()))) {
//
bSame = false;
break;
}
}
if (bSame) {
int[] mi = (int[]) membranesAndIndexes.get(membraneCurves[j]);
spatialSelection.add(new SpatialSelectionMembrane(new CurveSelectionInfo(membraneCurves[j], csisegsel[0], csisegsel[csisegsel.length - 1], csCurve.getSourceCurveSelectionInfo().getDirectionNegative()), vt, cm, mi, csCurve));
}
}
}
}
}
} else if (curves[i] instanceof SinglePoint && (curves[i].getDescription() == null || curves[i].getDescription().startsWith(CurveValueProvider.DESCRIPTION_MEMBRANE))) {
CurveSelectionInfo[] csiArr = getImagePlaneManagerPanel().getCurveRenderer().getCloseCurveSelectionInfos(curves[i].getBeginningCoordinate());
if (csiArr != null && csiArr.length > 0) {
for (int j = 0; j < csiArr.length; j += 1) {
if (membranesAndIndexes.containsKey(csiArr[j].getCurve())) {
CurveSelectionInfo closestCSI = getImagePlaneManagerPanel().getCurveRenderer().getClosestSegmentSelectionInfo(curves[i].getBeginningCoordinate(), csiArr[j].getCurve());
int[] mi = (int[]) membranesAndIndexes.get(csiArr[j].getCurve());
spatialSelection.add(new SpatialSelectionMembrane(closestCSI, vt, cm, mi, (SinglePoint) curves[i]));
break;
}
}
}
}
}
}
}
}
//
if (spatialSelection.size() > 0) {
SpatialSelection[] ss = new SpatialSelection[spatialSelection.size()];
spatialSelection.copyInto(ss);
return ss;
}
return null;
}
use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.
the class PDEDataContextPanel method recodeDataForDomain0.
private void recodeDataForDomain0() {
Domain varDomain = getPdeDataContext().getDataIdentifier().getDomain();
double[] tempRecodedData = null;
Range dataRange = null;
VariableType vt = getPdeDataContext().getDataIdentifier().getVariableType();
boolean bRecoding = getDataInfoProvider() != null && varDomain != null;
Double notInDomainValue = null;
if (getPdeDataContext().getDataValues() != originalData || recodeDataForDomainInfo == null || ((getDataInfoProvider() == null) != bDataInfoProviderNull) || !Compare.isEqualOrNull(functionStatisticsRange, lastFunctionStatisticsRange)) {
lastFunctionStatisticsRange = functionStatisticsRange;
bDataInfoProviderNull = (getDataInfoProvider() == null);
originalData = getPdeDataContext().getDataValues();
tempRecodedData = originalData;
double illegalNumber = Double.POSITIVE_INFINITY;
if (bRecoding) {
tempRecodedData = new double[originalData.length];
System.arraycopy(originalData, 0, tempRecodedData, 0, tempRecodedData.length);
for (int i = 0; i < originalData.length; i++) {
if (!Double.isNaN(originalData[i])) {
illegalNumber = Math.min(illegalNumber, originalData[i]);
}
}
}
//
illegalNumber -= 1;
notInDomainValue = new Double(illegalNumber);
final CartesianMesh cartesianMesh = getPdeDataContext().getCartesianMesh();
double minCurrTime = Double.POSITIVE_INFINITY;
double maxCurrTime = Double.NEGATIVE_INFINITY;
for (int i = 0; i < tempRecodedData.length; i++) {
if (bRecoding) {
if (!isInDomain(cartesianMesh, varDomain, dataInfoProvider, i, vt)) {
tempRecodedData[i] = illegalNumber;
}
}
if (!Double.isNaN(tempRecodedData[i]) && tempRecodedData[i] != illegalNumber) {
minCurrTime = Math.min(minCurrTime, tempRecodedData[i]);
maxCurrTime = Math.max(maxCurrTime, tempRecodedData[i]);
}
}
if (!getdisplayAdapterService1().getAllTimes() || functionStatisticsRange == null) {
dataRange = new Range(minCurrTime, maxCurrTime);
} else if (functionStatisticsRange != null) {
dataRange = functionStatisticsRange;
} else {
throw new RuntimeException("Unexpected state for range calculation");
}
} else {
dataRange = recodeDataForDomainInfo.getRecodedDataRange();
tempRecodedData = recodeDataForDomainInfo.getRecodedDataForDomain();
}
if (bRecoding) {
recodeDataForDomainInfo = new RecodeDataForDomainInfo(true, tempRecodedData, dataRange, notInDomainValue);
} else {
recodeDataForDomainInfo = new RecodeDataForDomainInfo(false, tempRecodedData, dataRange, notInDomainValue);
}
}
use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.
the class RasterExporter method exportPDEData.
private NrrdInfo[] exportPDEData(OutputContext outputContext, long jobID, User user, DataServerImpl dataServerImpl, VCDataIdentifier vcdID, VariableSpecs variableSpecs, TimeSpecs timeSpecs2, GeometrySpecs geometrySpecs, RasterSpecs rasterSpecs, FileDataContainerManager fileDataContainerManager) throws RemoteException, DataAccessException, IOException {
CartesianMesh mesh = dataServerImpl.getMesh(user, vcdID);
DataProcessingOutputInfo dataProcessingOutputInfo = null;
// check if any of export variables are PostProcess and if so try to get PostProcessOutputInfo
exportServiceImpl.fireExportProgress(jobID, vcdID, "Check PostProcess", 0.0);
DataIdentifier[] dataIdentifiers = dataServerImpl.getDataIdentifiers(outputContext, user, vcdID);
for (int i = 0; i < dataIdentifiers.length; i++) {
for (int j = 0; j < variableSpecs.getVariableNames().length; j++) {
if (variableSpecs.getVariableNames()[j].equals(dataIdentifiers[i].getName()) && VariableType.POSTPROCESSING.equals(dataIdentifiers[i].getVariableType())) {
try {
// we need PostProcessOutputInfo
exportServiceImpl.fireExportProgress(jobID, vcdID, "Read PostProcess", 0.0);
dataProcessingOutputInfo = (DataProcessingOutputInfo) dataServerImpl.doDataOperation(user, new DataOperation.DataProcessingOutputInfoOP(vcdID, false, outputContext));
break;
} catch (Exception e) {
throw new DataAccessException("Export variable '" + variableSpecs.getVariableNames()[j] + "' is PostProcessing type. Error reading PostProcessing data: " + e.getClass().getName() + " " + e.getMessage());
}
}
}
}
long lastUpdateTime = 0;
switch(rasterSpecs.getFormat()) {
case NRRD_SINGLE:
{
switch(geometrySpecs.getModeID()) {
case GEOMETRY_FULL:
{
NrrdInfo nrrdInfo = NRRDHelper.getSizeCheckedNrrdHelper(variableSpecs, mesh.getISize(), mesh.getExtent(), dataProcessingOutputInfo).createSingleFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs, rasterSpecs, timeSpecs2);
int progressIndex = 1;
int progressEnd = variableSpecs.getVariableNames().length * (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-snglfull", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
NRRDHelper.appendDoubleData(nrrdInfo, fileDataContainerManager, data, variableSpecs.getVariableNames()[i]);
}
}
nrrdInfo = NrrdWriter.writeNRRD(nrrdInfo, fileDataContainerManager);
return new NrrdInfo[] { nrrdInfo };
}
case GEOMETRY_SLICE:
{
NrrdInfo sliceNrrdInfo = createSliceNrrdHelper(mesh, dataProcessingOutputInfo, vcdID, variableSpecs, timeSpecs2, geometrySpecs, rasterSpecs, fileDataContainerManager).createSingleFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs, rasterSpecs, timeSpecs2);
int progressIndex = 1;
int progressEnd = variableSpecs.getVariableNames().length * (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-snglslice", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
appendSlice(variableSpecs.getVariableNames()[i], data, sliceNrrdInfo, mesh, geometrySpecs, fileDataContainerManager);
}
}
sliceNrrdInfo = NrrdWriter.writeNRRD(sliceNrrdInfo, fileDataContainerManager);
return new NrrdInfo[] { sliceNrrdInfo };
}
default:
{
throw new DataAccessException("NRRD export from slice not yet supported");
}
}
}
case NRRD_BY_TIME:
{
switch(geometrySpecs.getModeID()) {
case GEOMETRY_FULL:
{
NRRDHelper nrrdHelper = NRRDHelper.getSizeCheckedNrrdHelper(variableSpecs, mesh.getISize(), mesh.getExtent(), dataProcessingOutputInfo);
Vector<NrrdInfo> nrrdinfoV = new Vector<NrrdInfo>();
int progressIndex = 1;
int progressEnd = (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-timefull", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
NrrdInfo nrrdInfo = nrrdHelper.createTimeFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs, timeSpecs2.getAllTimes()[j], rasterSpecs);
nrrdinfoV.add(nrrdInfo);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
NRRDHelper.appendDoubleData(nrrdInfo, fileDataContainerManager, data, variableSpecs.getVariableNames()[i]);
}
NrrdWriter.writeNRRD(nrrdInfo, fileDataContainerManager);
}
if (nrrdinfoV.size() > 0) {
NrrdInfo[] nrrdinfoArr = new NrrdInfo[nrrdinfoV.size()];
nrrdinfoV.copyInto(nrrdinfoArr);
return nrrdinfoArr;
}
return null;
}
case GEOMETRY_SLICE:
{
Vector<NrrdInfo> nrrdinfoV = new Vector<NrrdInfo>();
int progressIndex = 1;
int progressEnd = (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-timeslice", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
NrrdInfo sliceNrrdInfo = createSliceNrrdHelper(mesh, dataProcessingOutputInfo, vcdID, variableSpecs, timeSpecs2, geometrySpecs, rasterSpecs, fileDataContainerManager).createTimeFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs, timeSpecs2.getAllTimes()[j], rasterSpecs);
nrrdinfoV.add(sliceNrrdInfo);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
appendSlice(variableSpecs.getVariableNames()[i], data, sliceNrrdInfo, mesh, geometrySpecs, fileDataContainerManager);
}
NrrdWriter.writeNRRD(sliceNrrdInfo, fileDataContainerManager);
}
if (nrrdinfoV.size() > 0) {
NrrdInfo[] nrrdinfoArr = new NrrdInfo[nrrdinfoV.size()];
nrrdinfoV.copyInto(nrrdinfoArr);
return nrrdinfoArr;
}
return null;
}
default:
{
throw new DataAccessException("NRRD export from slice not yet supported");
}
}
}
case NRRD_BY_VARIABLE:
{
switch(geometrySpecs.getModeID()) {
case GEOMETRY_FULL:
{
Vector<NrrdInfo> nrrdinfoV = new Vector<NrrdInfo>();
int progressIndex = 1;
int progressEnd = variableSpecs.getVariableNames().length * (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
NRRDHelper nrrdhelHelper = new NRRDHelper(variableSpecs.getVariableNames()[i], mesh.getISize(), mesh.getExtent(), dataProcessingOutputInfo);
NrrdInfo nrrdInfo = nrrdhelHelper.createVariableFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2, rasterSpecs);
nrrdinfoV.add(nrrdInfo);
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-varsfull", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
NRRDHelper.appendDoubleData(nrrdInfo, fileDataContainerManager, data, variableSpecs.getVariableNames()[i]);
}
nrrdInfo = NrrdWriter.writeNRRD(nrrdInfo, fileDataContainerManager);
}
if (nrrdinfoV.size() > 0) {
NrrdInfo[] nrrdinfoArr = new NrrdInfo[nrrdinfoV.size()];
nrrdinfoV.copyInto(nrrdinfoArr);
return nrrdinfoArr;
}
return null;
}
case GEOMETRY_SLICE:
{
Vector<NrrdInfo> nrrdinfoV = new Vector<NrrdInfo>();
int progressIndex = 1;
int progressEnd = variableSpecs.getVariableNames().length * (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
NrrdInfo sliceNrrdInfo = createSliceNrrdHelper(mesh, dataProcessingOutputInfo, vcdID, variableSpecs, timeSpecs2, geometrySpecs, rasterSpecs, fileDataContainerManager).createVariableFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2, rasterSpecs);
nrrdinfoV.add(sliceNrrdInfo);
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-varsfull", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
appendSlice(variableSpecs.getVariableNames()[i], data, sliceNrrdInfo, mesh, geometrySpecs, fileDataContainerManager);
}
NrrdWriter.writeNRRD(sliceNrrdInfo, fileDataContainerManager);
}
if (nrrdinfoV.size() > 0) {
NrrdInfo[] nrrdinfoArr = new NrrdInfo[nrrdinfoV.size()];
nrrdinfoV.copyInto(nrrdinfoArr);
return nrrdinfoArr;
}
return null;
}
default:
{
throw new DataAccessException("NRRD export from slice not yet supported");
}
}
}
default:
{
throw new DataAccessException("Multiple NRRD file export not yet supported");
}
}
}
use of cbit.vcell.solvers.CartesianMesh 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 cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.
the class DataSetControllerImpl method getSimDataBlock.
/**
* This method was created by a SmartGuide.
* @return double[]
* @param varName java.lang.String
* @param time double
*/
public SimDataBlock getSimDataBlock(OutputContext outputContext, VCDataIdentifier vcdID, String varName, double time) throws DataAccessException {
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<ENTER>>");
try {
//
// check if already cached for non-function variables
//
VCData simData = getVCData(vcdID);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got VCData");
long dataBlockTimeStamp = simData.getDataBlockTimeStamp(PDE_DATA, time);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got dataBlockTimeStamp");
PDEDataInfo pdeDataInfo = new PDEDataInfo(vcdID.getOwner(), vcdID.getID(), varName, time, dataBlockTimeStamp);
SimDataBlock simDataBlock = null;
AnnotatedFunction function = getFunction(outputContext, vcdID, varName);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got function");
if (function == null) {
simDataBlock = (cacheTable0 != null ? cacheTable0.get(pdeDataInfo) : null);
if (simDataBlock == null) {
simDataBlock = simData.getSimDataBlock(outputContext, varName, time);
if (simDataBlock != null && dataCachingEnabled) {
// cacheTable.put(pdeDataInfo,simDataBlock);
if (cacheTable0 != null) {
try {
cacheTable0.put(pdeDataInfo, simDataBlock);
} catch (CacheException e) {
// if can't cache the data, it is ok
e.printStackTrace();
}
}
}
}
} else {
if (simData instanceof SimulationData) {
function = ((SimulationData) simData).simplifyFunction(function);
}
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") evaluating function");
simDataBlock = evaluateFunction(outputContext, vcdID, simData, function, time);
}
CartesianMesh mesh = getMesh(vcdID);
if (mesh != null && mesh.isChomboMesh()) {
for (int i = 0; i < simDataBlock.getData().length; i++) {
if (simDataBlock.getData()[i] == 1.23456789e300) {
simDataBlock.getData()[i] = Double.NaN;
}
}
}
if (simDataBlock != null) {
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<EXIT-simDataBlock not null>>");
return simDataBlock;
} else {
String msg = "failure reading " + varName + " at t=" + time + " for " + vcdID.getOwner().getName() + "'s " + vcdID.getID();
if (lg.isWarnEnabled())
lg.warn("DataSetControllerImpl.getDataBlockValues(): " + msg);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<EXIT-Exception>>");
throw new DataAccessException(msg);
}
} catch (MathException e) {
lg.error(e.getMessage(), e);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<EXIT-Exception>>");
throw new DataAccessException(e.getMessage());
} catch (IOException e) {
lg.error(e.getMessage(), e);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<EXIT-Exception>>");
throw new DataAccessException(e.getMessage());
} catch (ExpressionException e) {
lg.error(e.getMessage(), e);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<EXIT-Exception>>");
throw new DataAccessException(e.getMessage());
}
}
Aggregations