use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class ClientPDEDataContext method initialize.
/**
* Insert the method's description here.
* Creation date: (10/3/00 5:16:19 PM)
*/
private void initialize() {
try {
setVCDataIdentifier(getDataManager().getVCDataIdentifier());
setParticleData(getDataManager().getParticleDataExists());
setCartesianMesh(getDataManager().getMesh());
setTimePoints(getDataManager().getDataSetTimes());
setDataIdentifiers(getDataManager().getDataIdentifiers());
double tp = getTimePoint();
double[] timePoints = getTimePoints();
if (timePoints != null && timePoints.length > 0) {
tp = timePoints[0];
}
DataIdentifier variable = getDataIdentifier();
DataIdentifier[] dataIdentifiers = getDataIdentifiers();
if (dataIdentifiers != null && dataIdentifiers.length > 0) {
variable = dataIdentifiers[0];
}
setVariableAndTime(variable, tp);
} catch (DataAccessException exc) {
exc.printStackTrace(System.out);
throw new RuntimeException(exc.getMessage(), exc);
}
}
use of org.vcell.util.DataAccessException 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());
}
}
use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class DataSetControllerImpl method getVtuVarInfos.
public VtuVarInfo[] getVtuVarInfos(ComsolSimFiles comsolFiles, OutputContext outputContext, VCDataIdentifier vcdataID) throws DataAccessException {
try {
DataIdentifier[] dataIdentifiers = getDataIdentifiers(outputContext, vcdataID);
if (dataIdentifiers == null) {
return null;
}
ArrayList<VtuVarInfo> vtuVarInfos = new ArrayList<VtuVarInfo>();
for (DataIdentifier di : dataIdentifiers) {
String name = di.getName();
String displayName = di.getDisplayName();
if (di.getDomain() != null) {
System.err.println("DataSetControllerImpl.getVtuVarInfos(comsol): need to support proper domain names now");
}
String domainName = "domain";
VariableDomain variableDomain = null;
VariableType variableType = di.getVariableType();
if (variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.VOLUME_REGION)) {
variableDomain = VariableDomain.VARIABLEDOMAIN_VOLUME;
} else if (variableType.equals(VariableType.MEMBRANE) || variableType.equals(VariableType.MEMBRANE_REGION)) {
variableDomain = VariableDomain.VARIABLEDOMAIN_MEMBRANE;
} else if (variableType.equals(VariableType.POINT_VARIABLE)) {
variableDomain = VariableDomain.VARIABLEDOMAIN_POINT;
} else if (variableType.equals(VariableType.CONTOUR) || variableType.equals(VariableType.CONTOUR_REGION)) {
variableDomain = VariableDomain.VARIABLEDOMAIN_CONTOUR;
} else if (variableType.equals(VariableType.NONSPATIAL)) {
variableDomain = VariableDomain.VARIABLEDOMAIN_UNKNOWN;
} else if (variableType.equals(VariableType.POSTPROCESSING)) {
variableDomain = VariableDomain.VARIABLEDOMAIN_POSTPROCESSING;
} else {
System.err.print("skipping var " + di + ", unsupported data type");
}
String functionExpression = null;
boolean bMeshVariable = false;
if (name.toUpperCase().contains("SIZE")) {
System.err.println("Skipping Moving Boundary variable '" + name + "' because it is a size ... change later");
continue;
}
vtuVarInfos.add(new VtuVarInfo(name, displayName, domainName, variableDomain, functionExpression, DataType.PointData, bMeshVariable));
}
return vtuVarInfos.toArray(new VtuVarInfo[0]);
} catch (Exception e) {
lg.error(e.getMessage(), e);
throw new DataAccessException("failed to retrieve VTK variable list: " + e.getMessage(), e);
}
}
use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class DataSetControllerImpl method getVtuVarInfos.
public VtuVarInfo[] getVtuVarInfos(VCellSimFiles vcellFiles, OutputContext outputContext, VCDataIdentifier vcdataID) throws DataAccessException {
try {
CartesianMeshVtkFileWriter cartesianMeshVTKFileWriter = new CartesianMeshVtkFileWriter();
VtuVarInfo[] vtuVarInfos = cartesianMeshVTKFileWriter.getVtuVarInfos(vcellFiles, outputContext, getVCData(vcdataID));
return vtuVarInfos;
} catch (Exception e) {
lg.error(e.getMessage(), e);
throw new DataAccessException("failed to retrieve VTK variable list: " + e.getMessage(), e);
}
}
use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class DataSetControllerImpl method fieldFunctionSubstitution.
private Expression fieldFunctionSubstitution(OutputContext outputContext, final VCDataIdentifier vcdID, Expression functionExpression) throws ExpressionException, DataAccessException, IOException, MathException {
SimResampleInfoProvider simResampleInfoProvider = null;
Expression origExpression = new Expression(functionExpression);
if (vcdID instanceof VCSimulationDataIdentifier) {
simResampleInfoProvider = ((VCSimulationDataIdentifier) vcdID);
} else if (vcdID instanceof VCSimulationDataIdentifierOldStyle) {
simResampleInfoProvider = ((VCSimulationDataIdentifierOldStyle) vcdID);
} else if (vcdID instanceof ExternalDataIdentifier) {
simResampleInfoProvider = ((ExternalDataIdentifier) vcdID);
} else {
return origExpression;
}
FieldFunctionArguments[] fieldfuncArgumentsArr = FieldUtilities.getFieldFunctionArguments(origExpression);
if (fieldfuncArgumentsArr == null || fieldfuncArgumentsArr.length == 0) {
return origExpression;
}
String[] origSymbols = origExpression.getSymbols();
Vector<SymbolTableEntry> originalSymbolTablEntrryV = new Vector<SymbolTableEntry>();
for (int i = 0; origSymbols != null && i < origSymbols.length; i++) {
if (!originalSymbolTablEntrryV.contains(origExpression.getSymbolBinding(origSymbols[i]))) {
originalSymbolTablEntrryV.add(origExpression.getSymbolBinding(origSymbols[i]));
}
}
Expression exp = new Expression(origExpression);
//
// Handle Field Data Function field(...)
//
double[][] resampledFieldDatas = null;
HashMap<String, Integer> substSymbolIndexH = new HashMap<String, Integer>();
// if(fieldfuncArgumentsArr != null && fieldfuncArgumentsArr.length > 0){
FieldDataIdentifierSpec[] fieldDataIdentifierSpecArr = getFieldDataIdentifierSpecs(fieldfuncArgumentsArr, simResampleInfoProvider.getOwner());
// Substitute Field Data Functions for simple symbols for lookup-------
for (int i = 0; i < fieldfuncArgumentsArr.length; i += 1) {
for (int j = 0; j < fieldDataIdentifierSpecArr.length; j++) {
if (fieldfuncArgumentsArr[i].equals(fieldDataIdentifierSpecArr[j].getFieldFuncArgs())) {
String substFieldName = fieldfuncArgumentsArr[i].getFieldName() + "_" + fieldfuncArgumentsArr[i].getVariableName() + "_" + fieldfuncArgumentsArr[i].getTime().evaluateConstant();
substFieldName = TokenMangler.fixTokenStrict(substFieldName);
if (exp.hasSymbol(substFieldName)) {
throw new DataAccessException("Substitute Field data name is not unique");
}
String fieldFuncString = SimulationData.createCanonicalFieldFunctionSyntax(fieldDataIdentifierSpecArr[j].getExternalDataIdentifier().getName(), fieldfuncArgumentsArr[i].getVariableName(), fieldfuncArgumentsArr[i].getTime().evaluateConstant(), fieldfuncArgumentsArr[i].getVariableType().getTypeName());
exp.substituteInPlace(new Expression(fieldFuncString), new Expression(substFieldName));
substSymbolIndexH.put(substFieldName, i);
break;
}
}
}
// ----------------------------------------------------------------------
boolean[] bResample = new boolean[fieldDataIdentifierSpecArr.length];
Arrays.fill(bResample, true);
writeFieldFunctionData(outputContext, fieldDataIdentifierSpecArr, bResample, getMesh(simResampleInfoProvider), simResampleInfoProvider, getMesh(simResampleInfoProvider).getNumMembraneElements(), FVSolverStandalone.HESM_KEEP_AND_CONTINUE);
resampledFieldDatas = new double[fieldfuncArgumentsArr.length][];
for (int i = 0; i < fieldfuncArgumentsArr.length; i += 1) {
// File resampledFile =
// new File(getUserDir(vcsdID.getOwner()),
// vcsdID.getID()+
// FieldDataIdentifierSpec.getDefaultFieldDataFileNameForSimulation(fieldfuncArgumentsArr[i])
// );
// File resampledFile = new File(getPrimaryUserDir(simResampleInfoProvider.getOwner(), true),
// SimulationData.createCanonicalResampleFileName(
// simResampleInfoProvider, fieldfuncArgumentsArr[i]));
File resampledFile = ((SimulationData) getVCData(simResampleInfoProvider)).getFieldDataFile(simResampleInfoProvider, fieldfuncArgumentsArr[i]);
resampledFieldDatas[i] = DataSet.fetchSimData(fieldfuncArgumentsArr[i].getVariableName(), resampledFile);
}
// }
// Rebind all the symbols
String[] dependentIDs = exp.getSymbols();
VariableSymbolTable varSymbolTable = new VariableSymbolTable();
for (int i = 0; dependentIDs != null && i < dependentIDs.length; i++) {
SymbolTableEntry newSymbolTableEntry = null;
for (int j = 0; j < originalSymbolTablEntrryV.size(); j++) {
if (originalSymbolTablEntrryV.elementAt(j).getName().equals(dependentIDs[i])) {
newSymbolTableEntry = originalSymbolTablEntrryV.elementAt(j);
break;
}
}
if (newSymbolTableEntry == null) {
if (substSymbolIndexH.containsKey(dependentIDs[i])) {
int resampledDataIndex = substSymbolIndexH.get(dependentIDs[i]).intValue();
FieldDataParameterVariable fieldDataParameterVariable = new FieldDataParameterVariable(dependentIDs[i], resampledFieldDatas[resampledDataIndex]);
newSymbolTableEntry = fieldDataParameterVariable;
}
}
if (newSymbolTableEntry == null) {
throw new DataAccessException("Field Data Couldn't find substituted expression while evaluating function");
}
varSymbolTable.addVar(newSymbolTableEntry);
}
exp.bindExpression(varSymbolTable);
return exp;
}
Aggregations