use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.
the class CellQuanVCTranslator method addRateFunction.
private Function addRateFunction(Element varRef, String compName, String mangledName) {
Element role;
String stoich = null, roleAtt = null;
// can only imply the delta function if the stoichiometry attribute is present also
// not sure if there can be more than one, if not, could just pass in the 'role' element itself.
@SuppressWarnings("unchecked") Iterator<Element> i = varRef.getChildren(CELLMLTags.ROLE, sNamespace).iterator();
while (i.hasNext()) {
role = i.next();
stoich = role.getAttributeValue(CELLMLTags.stoichiometry, sAttNamespace);
roleAtt = role.getAttributeValue(CELLMLTags.role, sAttNamespace);
if (stoich != null)
break;
}
if (stoich != null) {
// Can only imply the function if a variable_ref with a role of "rate" exists
JDOMTreeWalker reactionWalker = new JDOMTreeWalker((Element) varRef.getParent(), new ElementFilter(CELLMLTags.ROLE));
Element rateRole = reactionWalker.getMatchingElement(CELLMLTags.role, sAttNamespace, CELLMLTags.rateRole);
if (rateRole != null) {
String rateVarName = ((Element) rateRole.getParent()).getAttributeValue(CELLMLTags.variable, sAttNamespace);
StringBuffer formula = new StringBuffer("(");
if (roleAtt.equals(CELLMLTags.productRole))
formula.append("-(");
formula.append(stoich + "*" + nm.getMangledName(compName, rateVarName));
if (roleAtt.equals(CELLMLTags.productRole))
formula.append(")");
formula.append(")");
try {
Domain domain = null;
return new Function(mangledName, new Expression(formula.toString()), domain);
// fnsVector.add(function);
// mathDescription.addVariable(function);
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error adding function (" + mangledName + ") to mathDexcription : " + e.getMessage());
}
}
}
return null;
}
use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.
the class OutputFunctionsPanel method addFunction.
private void addFunction() throws Exception {
String funcName = getFunctionNameTextField().getText();
Expression funcExp = null;
funcExp = new Expression(getFunctionExpressionTextField().getText());
Domain domain = null;
VariableType newFunctionVariableType = null;
boolean bSpatial = simulationWorkspace.getSimulationOwner().getGeometry().getDimension() > 0;
if (bSpatial) {
Object selectedItem = getSubdomainComboBox().getSelectedItem();
if (selectedItem instanceof GeometryClass) {
GeometryClass geoClass = (GeometryClass) selectedItem;
domain = new Domain(geoClass);
if (selectedItem instanceof SubVolume) {
newFunctionVariableType = VariableType.VOLUME;
} else if (selectedItem instanceof SurfaceClass) {
newFunctionVariableType = VariableType.MEMBRANE;
}
} else if (selectedItem instanceof VariableType) {
newFunctionVariableType = (VariableType) selectedItem;
} else {
newFunctionVariableType = VariableType.UNKNOWN;
}
} else {
newFunctionVariableType = VariableType.NONSPATIAL;
}
AnnotatedFunction tempFunction = new AnnotatedFunction(funcName, funcExp, domain, null, newFunctionVariableType, FunctionCategory.OUTPUTFUNCTION);
VariableType vt = outputFunctionContext.computeFunctionTypeWRTExpression(tempFunction, funcExp);
FunctionCategory category = FunctionCategory.OUTPUTFUNCTION;
if (vt.equals(VariableType.POSTPROCESSING)) {
category = FunctionCategory.POSTPROCESSFUNCTION;
}
AnnotatedFunction newFunction = new AnnotatedFunction(funcName, funcExp, domain, null, vt, category);
outputFunctionContext.addOutputFunction(newFunction);
setSelectedObjects(new Object[] { newFunction });
enableDeleteFnButton();
}
use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.
the class SimulationDataSpatialHdf5 method retriveVariableNames.
private void retriveVariableNames() throws Exception {
// read variables only when I have never read the file since variables don't change
if (dataSetIdentifierList.size() > 0) {
return;
}
File tempFile = getTempSimHdf5File(0.0);
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
FileFormat meshFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
meshFile.open();
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) meshFile.getRootNode();
Group rootGroup = (Group) rootNode.getUserObject();
Group solGroup = (Group) rootGroup.getMemberList().get(0);
List<Attribute> solAttrList = solGroup.getMetadata();
String[] varNames = null;
int[] varTypes = null;
for (Attribute attr : solAttrList) {
String attrName = attr.getName();
Object value = attr.getValue();
if (attrName.equals(SOLUTION_ATTR_VARIABLES)) {
varNames = (String[]) value;
} else if (attrName.equals(SOLUTION_ATTR_VARIABLE_TYPES)) {
varTypes = (int[]) value;
}
}
for (int i = 0; i < varNames.length; i++) {
VariableType varType = VariableType.getVariableTypeFromInteger(varTypes[i]);
Domain domain = Variable.getDomainFromCombinedIdentifier(varNames[i]);
String varName = Variable.getNameFromCombinedIdentifier(varNames[i]);
dataSetIdentifierList.add(new DataSetIdentifier(varName, varType, domain));
}
}
use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.
the class DisplayTimeSeries method displayImageTimeSeries.
public static void displayImageTimeSeries(final ImageTimeSeries<Image> imageTimeSeries, String title, WindowListener windowListener) throws ImageException, IOException {
ISize size = imageTimeSeries.getISize();
int dimension = (size.getZ() > 0) ? (3) : (2);
Extent extent = imageTimeSeries.getExtent();
Origin origin = imageTimeSeries.getAllImages()[0].getOrigin();
// don't care ... no surfaces
double filterCutoffFrequency = 0.5;
VCImage vcImage = new VCImageUncompressed(null, new byte[size.getXYZ()], extent, size.getX(), size.getY(), size.getZ());
RegionImage regionImage = new RegionImage(vcImage, dimension, extent, origin, filterCutoffFrequency);
final CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, size, regionImage);
final DataIdentifier dataIdentifier = new DataIdentifier("var", VariableType.VOLUME, new Domain("domain"), false, "var");
final DataSetController dataSetController = new DataSetController() {
@Override
public ExportEvent makeRemoteFile(OutputContext outputContext, ExportSpecs exportSpecs) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public TimeSeriesJobResults getTimeSeriesValues(OutputContext outputContext, VCDataIdentifier vcdataID, TimeSeriesJobSpec timeSeriesJobSpec) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public SimDataBlock getSimDataBlock(OutputContext outputContext, VCDataIdentifier vcdataID, String varName, double time) throws RemoteProxyException, DataAccessException {
double timePoint = time;
double[] timePoints = getDataSetTimes(vcdataID);
int index = -1;
for (int i = 0; i < timePoints.length; i++) {
if (timePoint == timePoints[i]) {
index = i;
break;
}
}
double[] data = imageTimeSeries.getAllImages()[index].getDoublePixels();
PDEDataInfo pdeDataInfo = new PDEDataInfo(null, null, varName, time, 0);
VariableType varType = VariableType.VOLUME;
return new SimDataBlock(pdeDataInfo, data, varType);
}
@Override
public boolean getParticleDataExists(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
return false;
}
@Override
public ParticleDataBlock getParticleDataBlock(VCDataIdentifier vcdataID, double time) throws DataAccessException, RemoteProxyException {
return null;
}
@Override
public ODESimData getODEData(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
return null;
}
@Override
public CartesianMesh getMesh(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
return mesh;
}
@Override
public PlotData getLineScan(OutputContext outputContext, VCDataIdentifier vcdataID, String variable, double time, SpatialSelection spatialSelection) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public AnnotatedFunction[] getFunctions(OutputContext outputContext, VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
return new AnnotatedFunction[0];
}
@Override
public double[] getDataSetTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
return imageTimeSeries.getImageTimeStamps();
}
@Override
public DataSetTimeSeries getDataSetTimeSeries(VCDataIdentifier vcdataID, String[] variableNames) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public DataSetMetadata getDataSetMetadata(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public DataIdentifier[] getDataIdentifiers(OutputContext outputContext, VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
return new DataIdentifier[] { dataIdentifier };
}
@Override
public FieldDataFileOperationResults fieldDataFileOperation(FieldDataFileOperationSpec fieldDataFileOperationSpec) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public DataOperationResults doDataOperation(DataOperation dataOperation) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public VtuFileContainer getEmptyVtuMeshFiles(VCDataIdentifier vcdataID, int timeIndex) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public double[] getVtuTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public double[] getVtuMeshData(OutputContext outputContext, VCDataIdentifier vcdataID, VtuVarInfo var, double time) throws RemoteProxyException, DataAccessException {
// TODO Auto-generated method stub
return null;
}
@Override
public VtuVarInfo[] getVtuVarInfos(OutputContext outputContext, VCDataIdentifier vcDataIdentifier) throws DataAccessException, RemoteProxyException {
// TODO Auto-generated method stub
return null;
}
@Override
public NFSimMolecularConfigurations getNFSimMolecularConfigurations(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
// TODO Auto-generated method stub
return null;
}
};
DataSetControllerProvider dataSetControllerProvider = new DataSetControllerProvider() {
@Override
public DataSetController getDataSetController() throws DataAccessException {
return dataSetController;
}
};
VCDataManager vcDataManager = new VCDataManager(dataSetControllerProvider);
OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {
public User getOwner() {
return new User("nouser", null);
}
public KeyValue getDataKey() {
return null;
}
public String getID() {
return "mydata";
}
};
PDEDataManager pdeDataManager = new PDEDataManager(outputContext, vcDataManager, vcDataIdentifier);
ClientPDEDataContext myPdeDataContext = new ClientPDEDataContext(pdeDataManager);
PDEDataViewer pdeDataViewer = new PDEDataViewer();
JFrame jframe = new JFrame();
jframe.setTitle(title);
jframe.getContentPane().add(pdeDataViewer);
jframe.setSize(1000, 600);
jframe.setVisible(true);
if (windowListener != null) {
jframe.addWindowListener(windowListener);
}
pdeDataViewer.setPdeDataContext(myPdeDataContext);
}
Aggregations