use of cbit.vcell.util.FunctionRangeGenerator.VarStatistics 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);
}
}
use of cbit.vcell.util.FunctionRangeGenerator.VarStatistics in project vcell by virtualcell.
the class PDEDataViewer method calcVarStat.
private static ArrayList<VarStatistics> calcVarStat(PDEDataContext pdeDataContext, String[] stateVarNames) throws Exception {
ArrayList<VarStatistics> varStatsArr = new ArrayList<>();
DataProcessingOutputInfo dataProcessingOutputInfo = DataProcessingResultsPanel.getDataProcessingOutputInfo(pdeDataContext);
if (dataProcessingOutputInfo == null) {
return null;
}
String[] statisticVarNames = dataProcessingOutputInfo.getVariableNames();
for (String stateVarName : stateVarNames) {
double[] minValuesOvertime = null;
double[] maxValuesOverTime = null;
for (String statisticVarName : statisticVarNames) {
if (statisticVarName.startsWith(stateVarName + "_min")) {
minValuesOvertime = dataProcessingOutputInfo.getVariableStatValues().get(statisticVarName);
}
if (statisticVarName.startsWith(stateVarName + "_max")) {
maxValuesOverTime = dataProcessingOutputInfo.getVariableStatValues().get(statisticVarName);
}
}
if (minValuesOvertime != null && maxValuesOverTime != null) {
FunctionRangeGenerator.VarStatistics varstatistics = new VarStatistics(stateVarName, minValuesOvertime, maxValuesOverTime);
varStatsArr.add(varstatistics);
}
}
return varStatsArr;
}
Aggregations