use of cbit.vcell.model.ModelUnitSystem in project vcell by virtualcell.
the class XmlReader method getModelParameter.
public ModelParameter getModelParameter(Element paramElement, Model model) {
// get its attributes : name, role and unit definition
String glParamName = unMangle(paramElement.getAttributeValue(XMLTags.NameAttrTag));
String role = paramElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
ModelUnitSystem modelUnitSystem = model.getUnitSystem();
int glParamRole = -1;
if (role.equals(XMLTags.ParamRoleUserDefinedTag)) {
glParamRole = Model.ROLE_UserDefined;
} else {
throw new RuntimeException("unknown type of model parameter (not user-defined)");
}
//
// int glParamRole = -1;
// if (role.equals(XMLTags.ParamRoleUserDefinedTag)) {
// glParamRole = Model.ROLE_UserDefined;
// } else if (role.equals(XMLTags.RoleVariableRateTag)) {
// glParamRole = Model.ROLE_VariableRate;
// } else {
// throw new RuntimeException("unknown type of model parameter (not user-defined or variable rate)");
// }
String unitSymbol = paramElement.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
VCUnitDefinition glParamUnit = null;
if (unitSymbol != null) {
glParamUnit = modelUnitSystem.getInstance(unitSymbol);
}
// get parameter contents : expression; annotation, if any.
String glParamExpStr = paramElement.getText();
Expression glParamExp = unMangleExpression(glParamExpStr);
String glParamAnnotation = null;
String annotationText = paramElement.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotationText != null && annotationText.length() > 0) {
glParamAnnotation = unMangle(annotationText);
}
// create new global parameter
ModelParameter newGlParam = model.new ModelParameter(glParamName, glParamExp, glParamRole, glParamUnit);
newGlParam.setModelParameterAnnotation(glParamAnnotation);
return newGlParam;
}
use of cbit.vcell.model.ModelUnitSystem in project vcell by virtualcell.
the class VFrapXmlHelper method CreateSaveVFrapDataSymbols.
public static void CreateSaveVFrapDataSymbols(Hashtable<String, Object> hashTable, BioModel bioModel, ExternalDataIdentifier vfrapMisc) {
String[] channelNames = (String[]) hashTable.get("channelNames");
DataSymbolType[] channelVFrapImageType = (DataSymbolType[]) hashTable.get("channelVFrapImageType");
String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
SimulationContext simContext = bioModel.getSimulationContexts()[0];
ModelUnitSystem modelUnitSystem = bioModel.getModel().getUnitSystem();
for (int i = 0; i < channelNames.length; i++) {
// TODO: construct dataSymbolName from vFrapConstants::nameFromToken()
// item name postfixed with field data name
String dataSymbolName = channelNames[i] + "_" + initialFieldDataName;
DataSymbol dataSymbol = new FieldDataSymbol(dataSymbolName, channelVFrapImageType[i], simContext.getDataContext(), modelUnitSystem.getInstance_TBD(), vfrapMisc, channelNames[i], VariableType.VOLUME.getTypeName(), 0D);
simContext.getDataContext().addDataSymbol(dataSymbol);
}
}
use of cbit.vcell.model.ModelUnitSystem in project vcell by virtualcell.
the class ITextWriter method writeStructureMapping.
// boundary types ignored.
protected void writeStructureMapping(Section simContextSection, SimulationContext sc) throws DocumentException {
GeometryContext gc = sc.getGeometryContext();
if (gc == null) {
return;
}
Section structMappSection = null;
/*try {
ByteArrayOutputStream bos = generateStructureMappingImage(sc);
com.lowagie.text.Image structMapImage = com.lowagie.text.Image.getInstance(Toolkit.getDefaultToolkit().createImage(bos.toByteArray()), null);
structMappSection = simContextSection.addSection("Structure Mapping For " + sc.getName(), simContextSection.numberDepth() + 1);
structMappSection.add(structMapImage);
} catch (Exception e) {
System.err.println("Unable to add structure mapping image to report.");
e.printStackTrace();
}*/
StructureMapping[] structMap = gc.getStructureMappings();
Table structMapTable = null;
ModelUnitSystem modelUnitSystem = sc.getModel().getUnitSystem();
for (int i = 0; i < structMap.length; i++) {
if (!(structMap[i] instanceof FeatureMapping)) {
continue;
}
if (i == 0) {
structMapTable = getTable(5, 100, 1, 3, 3);
structMapTable.addCell(createCell("Structure Mapping", getBold(DEF_HEADER_FONT_SIZE), 5, 1, Element.ALIGN_CENTER, true));
structMapTable.addCell(createHeaderCell("Structure", getBold(), 1));
structMapTable.addCell(createHeaderCell("Subdomain", getBold(), 1));
structMapTable.addCell(createHeaderCell("Resolved (T/F)", getBold(), 1));
structMapTable.addCell(createHeaderCell("Surf/Vol", getBold(), 1));
structMapTable.addCell(createHeaderCell("VolFract", getBold(), 1));
structMapTable.endHeaders();
}
String structName = structMap[i].getStructure().getName();
SubVolume subVol = (SubVolume) ((FeatureMapping) structMap[i]).getGeometryClass();
String subDomain = "";
if (subVol != null) {
subDomain = subVol.getName();
}
// ((FeatureMapping)structMap[i]).getResolved();
boolean isResolved = false;
String surfVolStr = "", volFractStr = "";
MembraneMapping mm = (MembraneMapping) gc.getStructureMapping(sc.getModel().getStructureTopology().getParentStructure(structMap[i].getStructure()));
if (mm != null) {
StructureMapping.StructureMappingParameter smp = mm.getSurfaceToVolumeParameter();
if (smp != null) {
Expression tempExp = smp.getExpression();
VCUnitDefinition tempUnit = smp.getUnitDefinition();
if (tempExp != null) {
surfVolStr = tempExp.infix();
if (tempUnit != null && !modelUnitSystem.getInstance_DIMENSIONLESS().compareEqual(tempUnit)) {
// no need to add '1' for dimensionless unit
surfVolStr += " " + tempUnit.getSymbolUnicode();
}
}
}
smp = mm.getVolumeFractionParameter();
if (smp != null) {
Expression tempExp = smp.getExpression();
VCUnitDefinition tempUnit = smp.getUnitDefinition();
if (tempExp != null) {
volFractStr = tempExp.infix();
if (tempUnit != null && !modelUnitSystem.getInstance_DIMENSIONLESS().compareEqual(tempUnit)) {
volFractStr += " " + tempUnit.getSymbolUnicode();
}
}
}
}
structMapTable.addCell(createCell(structName, getFont()));
structMapTable.addCell(createCell(subDomain, getFont()));
structMapTable.addCell(createCell((isResolved ? " T " : " F "), getFont()));
structMapTable.addCell(createCell(surfVolStr, getFont()));
structMapTable.addCell(createCell(volFractStr, getFont()));
}
if (structMapTable != null) {
if (structMappSection == null) {
structMappSection = simContextSection.addSection("Structure Mapping For " + sc.getName(), simContextSection.numberDepth() + 1);
}
structMappSection.add(structMapTable);
}
}
Aggregations