use of cbit.vcell.math.VariableType in project vcell by virtualcell.
the class OutputFunctionsPanel method getSubdomainComboBox.
private JComboBox getSubdomainComboBox() {
if (subdomainComboBox == null) {
try {
subdomainComboBox = new JComboBox();
subdomainComboBox.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof GeometryClass) {
setText(((GeometryClass) value).getName());
} else if (value instanceof VariableType) {
setText(((VariableType) value).getTypeName());
}
return this;
}
});
} catch (java.lang.Throwable e) {
e.printStackTrace(System.out);
}
}
return subdomainComboBox;
}
use of cbit.vcell.math.VariableType in project vcell by virtualcell.
the class ROIDataGenerator method getROIDataGeneratorDescription.
public String getROIDataGeneratorDescription(File userDirectory, SimulationJob simulationJob) throws Exception {
// DataAccessException, FileNotFoundException, MathException, IOException, DivideByZeroException, ExpressionException
Simulation simulation = simulationJob.getSimulation();
StringBuffer sb = new StringBuffer();
sb.append(ROI_GENERATOR_BEGIN + " " + name + "\n");
sb.append("VolumePoints " + volumePoints.length + "\n");
for (int i = 0; i < volumePoints.length; i++) {
sb.append(volumePoints[i] + " ");
if ((i + 1) % 20 == 0) {
sb.append("\n");
}
}
sb.append("\n");
if (membranePoints != null && membranePoints.length > 0) {
sb.append("MembranePoints " + membranePoints.length + "\n");
for (int i = 0; i < membranePoints.length; i++) {
sb.append(membranePoints[i] + " ");
if ((i + 1) % 20 == 0) {
sb.append("\n");
}
}
sb.append("\n");
}
sb.append("SampleImage " + numImgRegions + " " + zSlice + " " + fieldDataKey + " " + fieldFuncArguments.infix() + "\n");
sb.append("StoreEnabled " + bStoreEnabled + "\n");
// sample image field data file
FieldDataIdentifierSpec fdis = getSampleImageFieldData(simulation.getVersion().getOwner());
if (fdis == null) {
throw new DataAccessException("Can't find sample image in ROI data generator.");
}
String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
DataSetControllerImpl dsci = new DataSetControllerImpl(null, userDirectory.getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
CartesianMesh origMesh = dsci.getMesh(fdis.getExternalDataIdentifier());
SimDataBlock simDataBlock = dsci.getSimDataBlock(null, fdis.getExternalDataIdentifier(), fdis.getFieldFuncArgs().getVariableName(), fdis.getFieldFuncArgs().getTime().evaluateConstant());
VariableType varType = fdis.getFieldFuncArgs().getVariableType();
VariableType dataVarType = simDataBlock.getVariableType();
if (!varType.equals(VariableType.UNKNOWN) && !varType.equals(dataVarType)) {
throw new IllegalArgumentException("field function variable type (" + varType.getTypeName() + ") doesn't match real variable type (" + dataVarType.getTypeName() + ")");
}
double[] origData = simDataBlock.getData();
String filename = SimulationJob.createSimulationJobID(Simulation.createSimulationID(simulation.getKey()), simulationJob.getJobIndex()) + SimulationData.getDefaultFieldDataFileNameForSimulation(fdis.getFieldFuncArgs());
File fdatFile = new File(userDirectory, filename);
DataSet.writeNew(fdatFile, new String[] { fdis.getFieldFuncArgs().getVariableName() }, new VariableType[] { simDataBlock.getVariableType() }, new ISize(origMesh.getSizeX(), origMesh.getSizeY(), origMesh.getSizeZ()), new double[][] { origData });
sb.append("SampleImageFile " + fdis.getFieldFuncArgs().getVariableName() + " " + fdis.getFieldFuncArgs().getTime().infix() + " " + fdatFile + "\n");
sb.append(ROI_GENERATOR_END);
return sb.toString();
}
use of cbit.vcell.math.VariableType in project vcell by virtualcell.
the class DataSet method readMBSDataMetadata.
private void readMBSDataMetadata() throws Exception {
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
FileFormat solFile = null;
try {
solFile = fileFormat.createInstance(fileName, FileFormat.READ);
solFile.open();
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) solFile.getRootNode();
Group rootGroup = (Group) rootNode.getUserObject();
Group solutionGroup = null;
for (Object member : rootGroup.getMemberList()) {
String memberName = ((HObject) member).getName();
if (member instanceof Group) {
MBSDataGroup group = MBSDataGroup.valueOf(memberName);
if (group == MBSDataGroup.Solution) {
solutionGroup = (Group) member;
break;
}
}
}
if (solutionGroup == null) {
throw new Exception("Group " + MBSDataGroup.Solution + " not found");
}
// find any timeGroup
Group timeGroup = null;
for (Object member : solutionGroup.getMemberList()) {
String memberName = ((HObject) member).getName();
if (member instanceof Group && memberName.startsWith("time")) {
timeGroup = (Group) member;
break;
}
}
if (timeGroup == null) {
throw new Exception("No time group found");
}
// find all the datasets in that time group
for (Object member : timeGroup.getMemberList()) {
if (member instanceof Dataset) {
List<Attribute> solAttrList = ((Dataset) member).getMetadata();
int size = 0;
String varName = null;
VariableType varType = null;
for (Attribute attr : solAttrList) {
String attrName = attr.getName();
Object attrValue = attr.getValue();
if (attrName.equals(MSBDataAttribute.name.name())) {
varName = ((String[]) attrValue)[0];
} else if (attrName.equals(MSBDataAttribute.size.name())) {
size = ((int[]) attrValue)[0];
} else if (attrName.equals(MSBDataAttribute.type.name())) {
String vt = ((String[]) attrValue)[0];
if (vt.equals(MSBDataAttributeValue.Point.name())) {
varType = VariableType.POINT_VARIABLE;
} else if (vt.equals(MSBDataAttributeValue.Volume.name())) {
varType = VariableType.VOLUME;
} else if (vt.equals(MSBDataAttributeValue.PointSubDomain.name())) {
// Position for PointSubdomain
}
}
}
if (varType == VariableType.VOLUME) {
// only display volume
dataBlockList.addElement(DataBlock.createDataBlock(varName, varType.getType(), size, 0));
}
if (varType == VariableType.POINT_VARIABLE) {
// only display volume
dataBlockList.addElement(DataBlock.createDataBlock(varName, varType.getType(), size, 0));
}
}
}
} finally {
if (solFile != null) {
try {
solFile.close();
} catch (Exception e) {
// ignore
}
}
}
}
use of cbit.vcell.math.VariableType in project vcell by virtualcell.
the class DataSetControllerImpl method findFunctionIndexes.
/**
* Insert the method's description here.
* Creation date: (10/13/00 9:13:52 AM)
* @return cbit.vcell.simdata.SimDataBlock
* @param user cbit.vcell.server.User
* @param simResults cbit.vcell.simdata.SimResults
* @param function cbit.vcell.math.Function
* @param time double
*/
private FunctionIndexes[] findFunctionIndexes(VCDataIdentifier vcdID, AnnotatedFunction function, int[] dataIndexes, OutputContext outputContext) throws ExpressionException, DataAccessException, IOException, MathException {
if (function.getFunctionType().equals(VariableType.POSTPROCESSING)) {
FunctionIndexes[] fiArr = new FunctionIndexes[dataIndexes.length];
Vector<DataSetIdentifier> dependencyList = identifyDataDependencies(function);
SimulationData simData = (SimulationData) getVCData(vcdID);
String[] varNames = new String[dependencyList.size()];
String[] simFileVarNames = new String[dependencyList.size()];
for (int i = 0; i < varNames.length; i++) {
varNames[i] = dependencyList.get(i).getName();
simFileVarNames[i] = dependencyList.get(i).getName();
}
CartesianMesh mesh = simData.getPostProcessingMesh(function.getName(), outputContext);
int[][] varIndexes = new int[dataIndexes.length][varNames.length];
for (int i = 0; i < dataIndexes.length; i += 1) {
for (int j = 0; j < varNames.length; j++) {
varIndexes[i][j] = dataIndexes[i];
}
}
// VolumeIndexNearFar[][] outside_near_far_indexes = null;//new VolumeIndexNearFar[dataIndexes.length][/*varNames.length*/];
for (int i = 0; i < dataIndexes.length; i += 1) {
fiArr[i] = new FunctionIndexes(function, mesh.getCoordinateFromVolumeIndex(dataIndexes[i]), varNames, simFileVarNames, varIndexes[i], null, null);
}
return fiArr;
}
VariableType variableType = function.getFunctionType();
Vector<DataSetIdentifier> dependencyList = identifyDataDependencies(function);
int varIndex = TXYZ_OFFSET + dependencyList.size();
//
// get Indexes and simFileNames
//
Coordinate initCoord = new Coordinate(0, 0, 0);
Coordinate[] coords = new Coordinate[dataIndexes.length];
for (int i = 0; i < coords.length; i += 1) {
coords[i] = initCoord;
}
String[] varNames = new String[varIndex - TXYZ_OFFSET];
String[] simFileVarNames = new String[varNames.length];
int[][] varIndexes = new int[dataIndexes.length][varNames.length];
// New data needed for INSIDE-OUTSIDE interpolation
VolumeIndexNearFar[][] inside_near_far_indexes = new VolumeIndexNearFar[dataIndexes.length][varNames.length];
VolumeIndexNearFar[][] outside_near_far_indexes = new VolumeIndexNearFar[dataIndexes.length][varNames.length];
CartesianMesh mesh = getMesh(vcdID);
//
for (int i = 0; i < dataIndexes.length; i += 1) {
coords[i] = mesh.getCoordinateFromVolumeIndex(dataIndexes[i]);
if (variableType.equals(VariableType.VOLUME)) {
// coord = mesh.getCoordinateFromVolumeIndex(dataIndex);
coords[i] = mesh.getCoordinateFromVolumeIndex(dataIndexes[i]);
for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
if (dsi.getVariableType().equals(VariableType.VOLUME)) {
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName();
varIndexes[i][j] = dataIndexes[i];
} else if (dsi.getVariableType().equals(VariableType.VOLUME_REGION)) {
int volumeIndex = mesh.getVolumeRegionIndex(dataIndexes[i]);
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName();
varIndexes[i][j] = volumeIndex;
}
}
} else if (variableType.equals(VariableType.VOLUME_REGION)) {
for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
if (dsi.getVariableType().equals(VariableType.VOLUME_REGION)) {
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName();
varIndexes[i][j] = dataIndexes[i];
}
}
} else if (variableType.equals(VariableType.MEMBRANE)) {
// coord = mesh.getCoordinateFromMembraneIndex(dataIndex);
coords[i] = mesh.getCoordinateFromMembraneIndex(dataIndexes[i]);
for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
if (dsi.getVariableType().equals(VariableType.VOLUME)) {
if (mesh.isChomboMesh()) {
// don't do any varname modifications here,
// because chombo needs this info to decide
// which data set to read, extrapolate values or solution.
// if varname doesn't have _INSIDE or _OUTSIDE
// add _INSIDE to varname to indicate it needs to read extrapolated values
String varName = dsi.getName();
if (!varName.endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX) && !varName.endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
varName += InsideVariable.INSIDE_VARIABLE_SUFFIX;
// add this new varname to the list if it's not already there
getVCData(vcdID).getEntry(varName);
}
simFileVarNames[j] = varName;
varIndexes[i][j] = dataIndexes[i];
} else {
if (dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
int volInsideIndex = mesh.getMembraneElements()[dataIndexes[i]].getInsideVolumeIndex();
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
varIndexes[i][j] = volInsideIndex;
inside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], true, false);
} else if (dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
int volOutsideIndex = mesh.getMembraneElements()[dataIndexes[i]].getOutsideVolumeIndex();
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
varIndexes[i][j] = volOutsideIndex;
outside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], false, false);
} else {
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName();
if (isDomainInside(mesh, dsi.getDomain(), dataIndexes[i])) {
inside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dsi.getDomain(), dataIndexes[i], false);
varIndexes[i][j] = inside_near_far_indexes[i][j].volIndexNear;
} else {
outside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dsi.getDomain(), dataIndexes[i], false);
varIndexes[i][j] = outside_near_far_indexes[i][j].volIndexNear;
}
}
}
} else if (dsi.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
int insideVolumeIndex = mesh.getMembraneElements()[dataIndexes[i]].getInsideVolumeIndex();
int volRegionIndex = mesh.getVolumeRegionIndex(insideVolumeIndex);
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
varIndexes[i][j] = volRegionIndex;
inside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], true, true);
} else if (dsi.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
int outsideVolumeIndex = mesh.getMembraneElements()[dataIndexes[i]].getOutsideVolumeIndex();
int volRegionIndex = mesh.getVolumeRegionIndex(outsideVolumeIndex);
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
varIndexes[i][j] = volRegionIndex;
outside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], false, true);
} else if (dsi.getVariableType().equals(VariableType.MEMBRANE)) {
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName();
varIndexes[i][j] = dataIndexes[i];
} else if (dsi.getVariableType().equals(VariableType.MEMBRANE_REGION)) {
int memRegionIndex = mesh.getMembraneRegionIndex(dataIndexes[i]);
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName();
varIndexes[i][j] = memRegionIndex;
}
}
} else if (variableType.equals(VariableType.MEMBRANE_REGION)) {
for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
if (dsi.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
//
// find "inside" volume element index for first membrane element in MembraneRegion 'i'.
//
int insideVolumeIndex = -1;
for (int k = 0; k < mesh.getMembraneElements().length; k++) {
if (mesh.getMembraneRegionIndex(k) == dataIndexes[i]) {
insideVolumeIndex = mesh.getMembraneElements()[k].getInsideVolumeIndex();
break;
}
}
int volRegionIndex = mesh.getVolumeRegionIndex(insideVolumeIndex);
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
varIndexes[i][j] = volRegionIndex;
inside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], true, true);
;
} else if (dsi.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
//
// find "outside" volume element index for first membrane element in MembraneRegion 'i'.
//
int outsideVolumeIndex = -1;
for (int k = 0; k < mesh.getMembraneElements().length; k++) {
if (mesh.getMembraneRegionIndex(k) == dataIndexes[i]) {
outsideVolumeIndex = mesh.getMembraneElements()[k].getOutsideVolumeIndex();
break;
}
}
int volRegionIndex = mesh.getVolumeRegionIndex(outsideVolumeIndex);
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
varIndexes[i][j] = volRegionIndex;
outside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], false, true);
} else if (dsi.getVariableType().equals(VariableType.MEMBRANE)) {
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName();
varIndexes[i][j] = dataIndexes[i];
} else if (dsi.getVariableType().equals(VariableType.MEMBRANE_REGION)) {
int memRegionIndex = mesh.getMembraneRegionIndex(dataIndexes[i]);
varNames[j] = dsi.getName();
simFileVarNames[j] = dsi.getName();
varIndexes[i][j] = memRegionIndex;
}
}
}
}
FunctionIndexes[] fiArr = new FunctionIndexes[dataIndexes.length];
for (int i = 0; i < dataIndexes.length; i += 1) {
fiArr[i] = new FunctionIndexes(function, coords[i], varNames, simFileVarNames, varIndexes[i], inside_near_far_indexes[i], outside_near_far_indexes[i]);
}
return fiArr;
//
}
use of cbit.vcell.math.VariableType in project vcell by virtualcell.
the class DataSetControllerImpl method getVariableTypeForFieldFunction.
private VariableType getVariableTypeForFieldFunction(OutputContext outputContext, VCDataIdentifier vcdID, AnnotatedFunction function) throws DataAccessException {
VariableType funcType = function.getFunctionType();
if (funcType == null || funcType.equals(VariableType.UNKNOWN)) {
FieldFunctionArguments[] ffas = FieldUtilities.getFieldFunctionArguments(function.getExpression());
if (ffas == null || ffas.length == 0) {
throw new DataAccessException("Unknown function type for function " + function.getName());
}
// use the type from the first field function
FieldDataIdentifierSpec[] fdiss = getFieldDataIdentifierSpecs(ffas, vcdID.getOwner());
SimDataBlock dataBlock = getSimDataBlock(outputContext, fdiss[0].getExternalDataIdentifier(), ffas[0].getVariableName(), 0.0);
funcType = dataBlock.getVariableType();
}
return funcType;
}
Aggregations