use of cbit.vcell.math.VolVariable in project vcell by virtualcell.
the class MathOverridesPanel method jMenuItemPaste_ActionPerformed.
/**
* Comment
*/
private void jMenuItemPaste_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
java.util.Vector<String> pasteDescriptionsV = new java.util.Vector<String>();
java.util.Vector<Expression> newConstantsV = new java.util.Vector<Expression>();
java.util.Vector<String> changedParameterNamesV = new java.util.Vector<String>();
try {
if (actionEvent.getSource().equals(getJMenuItemPaste()) || actionEvent.getSource().equals(getJMenuItemPasteAll())) {
int[] rows = null;
if (actionEvent.getSource() == getJMenuItemPasteAll()) {
rows = new int[getJTableFixed().getRowCount()];
for (int i = 0; i < rows.length; i += 1) {
rows[i] = i;
}
} else {
rows = getJTableFixed().getSelectedRows();
}
Object pasteThis = VCellTransferable.getFromClipboard(VCellTransferable.OBJECT_FLAVOR);
for (int i = 0; i < rows.length; i += 1) {
if (pasteThis instanceof VCellTransferable.ResolvedValuesSelection) {
VCellTransferable.ResolvedValuesSelection rvs = (VCellTransferable.ResolvedValuesSelection) pasteThis;
for (int j = 0; j < rvs.getPrimarySymbolTableEntries().length; j += 1) {
Constant pastedConstant = null;
if (rvs.getPrimarySymbolTableEntries()[j] instanceof Constant) {
pastedConstant = (Constant) rvs.getPrimarySymbolTableEntries()[j];
} else if (rvs.getAlternateSymbolTableEntries() != null && rvs.getAlternateSymbolTableEntries()[j] instanceof Constant) {
pastedConstant = (Constant) rvs.getAlternateSymbolTableEntries()[j];
}
//
if (pastedConstant == null && (rvs.getPrimarySymbolTableEntries()[j] instanceof Function) || (rvs.getPrimarySymbolTableEntries()[j] instanceof VolVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof VolumeRegionVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof MemVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof MembraneRegionVariable)) {
MathDescription mathDescription = getMathOverrides().getSimulation().getMathDescription();
Enumeration<Constant> constants = mathDescription.getConstants();
while (constants.hasMoreElements()) {
Constant constant = constants.nextElement();
if (constant.getName().startsWith(rvs.getPrimarySymbolTableEntries()[j].getName() + DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONC_UNIT_PREFIX)) {
pastedConstant = new Constant(constant.getName(), rvs.getExpressionValues()[j]);
}
}
}
//
// find row of math overrides table with the same name as the pastedConstant and propose to change that override to the pasted value
//
String rowName = (String) getJTableFixed().getValueAt(rows[i], MathOverridesTableModel.COLUMN_PARAMETER);
if (pastedConstant != null && pastedConstant.getName().equals(rowName)) {
changedParameterNamesV.add(rowName);
newConstantsV.add(rvs.getExpressionValues()[j]);
String originalValueDescription = null;
if (getMathOverrides().getConstantArraySpec(rowName) != null) {
originalValueDescription = getMathOverrides().getConstantArraySpec(rowName).toString();
} else if (getMathOverrides().getActualExpression(rowName, 0) != null) {
originalValueDescription = getMathOverrides().getActualExpression(rowName, 0).infix();
} else {
throw new Exception("MathOverridesPanel can't find value for '" + rowName + "'");
}
pasteDescriptionsV.add(VCellCopyPasteHelper.formatPasteList(rowName, pastedConstant.getName(), originalValueDescription, rvs.getExpressionValues()[j].infix() + ""));
}
}
}
}
}
} catch (Throwable e) {
PopupGenerator.showErrorDialog(this, "Paste failed during pre-check (no changes made).\n" + e.getClass().getName() + " " + e.getMessage(), e);
return;
}
// Do paste
try {
if (pasteDescriptionsV.size() > 0) {
String[] pasteDescriptionArr = new String[pasteDescriptionsV.size()];
pasteDescriptionsV.copyInto(pasteDescriptionArr);
String[] changedParameterNamesArr = new String[changedParameterNamesV.size()];
changedParameterNamesV.copyInto(changedParameterNamesArr);
VCellCopyPasteHelper.chooseApplyPaste(this, pasteDescriptionArr, getMathOverrides(), changedParameterNamesArr, newConstantsV);
} else {
PopupGenerator.showInfoDialog(this, "No paste items match the destination (no changes made).");
}
} catch (Throwable e) {
PopupGenerator.showErrorDialog(this, "Paste Error\n" + e.getClass().getName() + " " + e.getMessage(), e);
}
}
use of cbit.vcell.math.VolVariable in project vcell by virtualcell.
the class FastSystemAnalyzer method refreshFastVarList.
/**
* @return java.util.Vector
*/
private void refreshFastVarList() throws MathException, ExpressionException {
fastVarList.clear();
//
// get list of unique (VolVariables and MemVariables) in fastRate expressions
//
Enumeration<FastRate> fastRatesEnum = fastSystem.getFastRates();
while (fastRatesEnum.hasMoreElements()) {
FastRate fr = fastRatesEnum.nextElement();
Expression exp = fr.getFunction();
Enumeration<Variable> enum1 = MathUtilities.getRequiredVariables(exp, this);
while (enum1.hasMoreElements()) {
Variable var = enum1.nextElement();
if (var instanceof VolVariable || var instanceof MemVariable) {
if (!fastVarList.contains(var)) {
fastVarList.addElement(var);
// System.out.println("FastSystemImplicit.refreshFastVarList(), FAST RATE VARIABLE: "+var.getName());
}
}
}
}
//
// get list of all variables used in invariant expressions that are not used in fast rates
//
Enumeration<FastInvariant> fastInvariantsEnum = fastSystem.getFastInvariants();
while (fastInvariantsEnum.hasMoreElements()) {
FastInvariant fi = (FastInvariant) fastInvariantsEnum.nextElement();
Expression exp = fi.getFunction();
// System.out.println("FastSystemImplicit.refreshFastVarList(), ORIGINAL FAST INVARIANT: "+exp);
Enumeration<Variable> enum1 = MathUtilities.getRequiredVariables(exp, this);
while (enum1.hasMoreElements()) {
Variable var = enum1.nextElement();
if (var instanceof VolVariable || var instanceof MemVariable) {
if (!fastVarList.contains(var)) {
fastVarList.addElement(var);
}
}
}
}
//
// verify that there are N equations (rates+invariants) and N unknowns (fastVariables)
//
int numBoundFunctions = fastSystem.getNumFastInvariants() + fastSystem.getNumFastRates();
if (fastVarList.size() != numBoundFunctions) {
throw new MathException("FastSystem.checkDimension(), there are " + fastVarList.size() + " variables and " + numBoundFunctions + " FastInvariant's & FastRates");
}
}
use of cbit.vcell.math.VolVariable in project vcell by virtualcell.
the class MathMapping_4_8 method getResolvedVolVariable.
/**
* Find the defined variable (VolVariable) for the resolved compartments.
* This method is used to assure only one variable is created.
* @return cbit.vcell.math.VolVariable
* @param species cbit.vcell.model.Species
*/
private VolVariable getResolvedVolVariable(Species species) {
Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = enum1.nextElement();
if (scm.getSpeciesContext().getSpecies() == species) {
Variable var = scm.getVariable();
if (var instanceof VolVariable) {
Structure structure = scm.getSpeciesContext().getStructure();
StructureMapping sm = simContext.getGeometryContext().getStructureMapping(structure);
if (structure instanceof Feature && getResolved(sm)) {
return (VolVariable) var;
}
}
}
}
return new VolVariable(TokenMangler.fixTokenStrict(species.getCommonName()), nullDomain);
}
use of cbit.vcell.math.VolVariable in project vcell by virtualcell.
the class MathMapping_4_8 method refreshVariables.
/**
* This method was created in VisualAge.
*/
private void refreshVariables() throws MappingException {
// System.out.println("MathMapping.refreshVariables()");
//
// non-constant dependent variables require a function
//
Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = enum1.nextElement();
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (scm.getDependencyExpression() != null && !scs.isConstant()) {
// scm.setVariable(new Function(scm.getSpeciesContext().getName(),scm.getDependencyExpression()));
scm.setVariable(null);
}
}
enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = enum1.nextElement();
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (getSimulationContext().hasEventAssignment(scs.getSpeciesContext())) {
scm.setDependencyExpression(null);
}
}
//
// non-constant independent variables require either a membrane or volume variable
//
enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (scm.getDependencyExpression() == null && (!scs.isConstant() || getSimulationContext().hasEventAssignment(scs.getSpeciesContext()))) {
StructureMapping sm = simContext.getGeometryContext().getStructureMapping(scm.getSpeciesContext().getStructure());
Structure struct = scm.getSpeciesContext().getStructure();
if (struct instanceof Feature) {
if (getResolved(sm)) {
scm.setVariable(getResolvedVolVariable(scm.getSpeciesContext().getSpecies()));
} else {
scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), nullDomain));
}
} else if (struct instanceof Membrane) {
if (getResolved(sm)) {
scm.setVariable(new MemVariable(scm.getSpeciesContext().getName(), nullDomain));
} else {
scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), nullDomain));
}
} else {
throw new MappingException("class " + scm.getSpeciesContext().getStructure().getClass() + " not supported");
}
mathSymbolMapping.put(scm.getSpeciesContext(), scm.getVariable().getName());
}
}
}
use of cbit.vcell.math.VolVariable in project vcell by virtualcell.
the class PDEDataViewer method calcAutoAllTimes.
private void calcAutoAllTimes() throws Exception {
HashSet<String> stateVarNames = null;
Variable theVariable = null;
boolean bStateVar = true;
boolean isFieldData = getPdeDataContext().getVCDataIdentifier() instanceof ExternalDataIdentifier || getPdeDataContext().getVCDataIdentifier() instanceof MergedDataInfo;
if (isFieldData) {
// fielddata
DataIdentifier[] dataids = getPdeDataContext().getDataIdentifiers();
stateVarNames = new HashSet<>();
for (int i = 0; i < dataids.length; i++) {
if (!dataids[i].isFunction()) {
stateVarNames.add(dataids[i].getName());
}
// System.out.println("name:'"+dataids[i].getName()+"' type:"+dataids[i].getVariableType()+" func:"+dataids[i].isFunction());
}
bStateVar = !getPdeDataContext().getDataIdentifier().isFunction();
if (bStateVar) {
theVariable = new VolVariable(getPdeDataContext().getDataIdentifier().getName(), getPdeDataContext().getDataIdentifier().getDomain());
} else {
AnnotatedFunction[] funcs = getPdeDataContext().getFunctions();
for (int i = 0; i < funcs.length; i++) {
if (funcs[i].getName().equals(getPdeDataContext().getDataIdentifier().getName())) {
theVariable = funcs[i];
break;
}
}
}
} else {
stateVarNames = getSimulation().getMathDescription().getStateVariableNames();
theVariable = getSimulation().getMathDescription().getVariable(getPdeDataContext().getVariableName());
if (theVariable == null) {
theVariable = ((ClientPDEDataContext) getPdeDataContext()).getDataManager().getOutputContext().getOutputFunction(getPdeDataContext().getVariableName());
}
if (theVariable == null) {
DataProcessingOutputInfo dataProcessingOutputInfo = DataProcessingResultsPanel.getDataProcessingOutputInfo(getPdeDataContext());
if (dataProcessingOutputInfo != null && Arrays.asList(dataProcessingOutputInfo.getVariableNames()).contains(getPdeDataContext().getVariableName())) {
// PostProcess Variable
return;
}
}
bStateVar = stateVarNames.contains(getPdeDataContext().getVariableName());
}
if (theVariable == null) {
throw new Exception("Unexpected Alltimes... selected variable '" + getPdeDataContext().getVariableName() + "' is not stateVariable or OutputFunction");
}
if (getPDEDataContextPanel1().getdisplayAdapterService1().getAllTimes()) {
// min-max over all timepoints (allTimes)
if (theVariable.isConstant()) {
getPDEDataContextPanel1().getdisplayAdapterServicePanel1().changeAllTimesButtonText(DisplayAdapterServicePanel.ALL_TIMES__STATE_TEXT);
double constVal = theVariable.getExpression().evaluateConstant();
getPDEDataContextPanel1().setFunctionStatisticsRange(new Range(constVal, constVal));
} else if (bStateVar) {
getPDEDataContextPanel1().getdisplayAdapterServicePanel1().changeAllTimesButtonText(DisplayAdapterServicePanel.ALL_TIMES__STATE_TEXT);
ArrayList<VarStatistics> varStatsArr = calcVarStat(getPdeDataContext(), new String[] { theVariable.getName() });
if (errorAutoAllTimes(varStatsArr != null, (varStatsArr == null ? null : varStatsArr.size() > 0), isFieldData)) {
// no postprocessinfo
return;
}
FunctionStatistics functionStatistics = new FunctionStatistics(varStatsArr.get(0).minValuesOverTime, varStatsArr.get(0).maxValuesOverTime);
getPDEDataContextPanel1().setFunctionStatisticsRange(new Range(functionStatistics.getMinOverTime(), functionStatistics.getMaxOverTime()));
} else if (theVariable instanceof Function) {
getPDEDataContextPanel1().getdisplayAdapterServicePanel1().changeAllTimesButtonText(DisplayAdapterServicePanel.ALL_TIMES__APPROX_TEXT);
Function flattened = MathDescription.getFlattenedFunctions(SimulationSymbolTable.createMathSymbolTableFactory(), getSimulation().getMathDescription(), new String[] { theVariable.getName() })[0];
if (flattened == null) {
flattened = (Function) theVariable;
}
ArrayList<VarStatistics> varStatsArr = calcVarStat(getPdeDataContext(), stateVarNames.toArray(new String[0]));
if (errorAutoAllTimes(varStatsArr != null, (varStatsArr == null ? null : varStatsArr.size() > 0), isFieldData)) {
// check for no postprocessinfo
return;
}
if (varStatsArr.size() == stateVarNames.size()) {
if (getSimulation().getMeshSpecification().getGeometry().getGeometrySurfaceDescription().getRegionImage() == null) {
getSimulation().getMeshSpecification().getGeometry().getGeometrySurfaceDescription().updateAll();
}
FunctionStatistics functionStatistics = FunctionRangeGenerator.getFunctionStatistics(flattened.getExpression(), varStatsArr.toArray(new VarStatistics[0]), getPdeDataContext().getTimePoints(), getPdeDataContext().getCartesianMesh(), calcInDomainBitSet(), getPdeDataContext().getDataIdentifier().getVariableType());
getPDEDataContextPanel1().setFunctionStatisticsRange(new Range(functionStatistics.getMinOverTime(), functionStatistics.getMaxOverTime()));
} else {
throw new Exception("Unexpectede AllTimes... calculated state var stats size != mathdescr state var size");
}
} else {
throw new Exception("Unexpected AllTimes... not constant, stateVar or function");
}
} else {
// min-max at each timepoint (currTime)
if (!(theVariable instanceof Function)) {
getPDEDataContextPanel1().getdisplayAdapterServicePanel1().changeAllTimesButtonText(DisplayAdapterServicePanel.ALL_TIMES__STATE_TEXT);
} else {
getPDEDataContextPanel1().getdisplayAdapterServicePanel1().changeAllTimesButtonText(DisplayAdapterServicePanel.ALL_TIMES__APPROX_TEXT);
}
getPDEDataContextPanel1().setFunctionStatisticsRange(null);
}
}
Aggregations