use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.
the class PDEDataViewer method createMultiTimePlotHelper.
// private static class MultiTimePointPropChangeListener implements PropertyChangeListener {
// @Override
// public void propertyChange(PropertyChangeEvent evt) {
// }
// }
private MultiTimePlotHelper createMultiTimePlotHelper(final ClientPDEDataContext copyThisPDEDatacontext, final User user, DataSymbolMetadataResolver argDataSymbolMetadataResolver) throws Exception {
final ClientPDEDataContext[] copyHolder = new ClientPDEDataContext[1];
if (PDEDataViewer.this.isPostProcess()) {
copyHolder[0] = PDEDataViewerPostProcess.createPostProcessPDEDataContext(copyThisPDEDatacontext);
} else {
copyHolder[0] = (ClientPDEDataContext) ((PDEDataManager) copyThisPDEDatacontext.getDataManager()).createNewPDEDataManager(copyThisPDEDatacontext.getVCDataIdentifier(), null).getPDEDataContext();
}
copyHolder[0].setVariableAndTime(copyThisPDEDatacontext.getDataIdentifier(), copyThisPDEDatacontext.getTimePoint());
return new PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper() {
private DataSymbolMetadataResolver dataSymbolMetadataResolver = argDataSymbolMetadataResolver;
private ArrayList<PropertyChangeListener> myPropertyChangeHolder = new ArrayList<>();
private ClientPDEDataContext myPdeDataContext = copyHolder[0];
private VariableType myVariableType = copyThisPDEDatacontext.getDataIdentifier().getVariableType();
// catch events from 'this' PDEDataViewer and pass with new source
private PropertyChangeListener myPropertyChangeListener;
private User myUser = user;
// List<AnnotatedFunction> myAnnots;
// access to anonymous outer class
private PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper multiTimePlotHelperThis = this;
private PDEPlotControlPanel.IdentifierListCellRenderer myListCellRenderer;
private AnnotatedFunction[] lastAnnotatedFunctions;
private PDEPlotControlPanel.FunctionListProvider functionListProvider = new PDEPlotControlPanel.FunctionListProvider() {
@Override
public List<AnnotatedFunction> getAnnotatedFunctions() {
if (myPdeDataContext.getDataManager().getOutputContext() != null && myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions() != null && myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions().length > 0) {
return new ArrayList<>(Arrays.asList(myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions()));
}
return new ArrayList<>();
}
};
private Comparator<AnnotatedFunction> nameComparator = new Comparator<AnnotatedFunction>() {
@Override
public int compare(AnnotatedFunction o1, AnnotatedFunction o2) {
return o2.getName().compareToIgnoreCase(o1.getName());
}
};
@Override
public void removeDataJobListener(DataJobListener dataJobListener) {
PDEDataViewer.this.removeDataJobListener(dataJobListener);
}
@Override
public void addDataJobListener(DataJobListener dataJobListener) {
PDEDataViewer.this.addDataJobListener(dataJobListener);
}
@Override
public User getUser() {
return myUser;
}
@Override
public PDEDataContext getPdeDatacontext() {
return myPdeDataContext;
}
@Override
public DataIdentifier[] getCopyOfDisplayedDataIdentifiers() {
DataIdentifier[] newData = PDEDataViewer.this.getPDEPlotControlPanel1().getDataIdentifierFilter().accept(DefaultDataIdentifierFilter.ALL, functionListProvider.getAnnotatedFunctions(), myPdeDataContext.getDataIdentifiers()).toArray(new DataIdentifier[0]);
return DataIdentifier.collectSortedSimilarDataTypes(this.getVariableType(), newData);
}
@Override
public PDEPlotControlPanel.IdentifierListCellRenderer getListCellRenderer() {
if (myListCellRenderer == null) {
myListCellRenderer = new PDEPlotControlPanel.IdentifierListCellRenderer(functionListProvider);
}
return myListCellRenderer;
}
@Override
public Simulation getsimulation() {
return PDEDataViewer.this.getSimulation();
}
private List<AnnotatedFunction> efficiencyFilter(List<AnnotatedFunction> funcs) {
ArrayList<AnnotatedFunction> outputfunctions = new ArrayList<>();
Iterator<AnnotatedFunction> iter = funcs.iterator();
while (iter.hasNext()) {
AnnotatedFunction theFunc = iter.next();
if ((isPostProcess() && theFunc.getFunctionType().equals(VariableType.POSTPROCESSING)) || (!isPostProcess() && !theFunc.getFunctionType().equals(VariableType.POSTPROCESSING))) {
outputfunctions.add(theFunc);
}
}
return outputfunctions;
}
@Override
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
myPropertyChangeHolder.add(propertyChangeListener);
if (myPropertyChangeListener == null) {
myPropertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource() == PDEDataViewer.this && evt.getPropertyName().equals(PDEDataContext.PROP_PDE_DATA_CONTEXT)) {
// List<AnnotatedFunction> currentOutputFunctions = functionListProvider.getAnnotatedFunctions();
// currentOutputFunctions = efficiencyFilter(currentOutputFunctions);
// currentOutputFunctions.sort(nameComparator);
List<AnnotatedFunction> newOutputFunctions0 = Arrays.asList(((ClientPDEDataContext) PDEDataViewer.this.getPdeDataContext()).getDataManager().getOutputContext().getOutputFunctions());
List<AnnotatedFunction> newOutputFunctions = efficiencyFilter(newOutputFunctions0);
newOutputFunctions.sort(nameComparator);
if (lastAnnotatedFunctions != null && Compare.isEqualOrNullStrict(lastAnnotatedFunctions, newOutputFunctions.toArray(new AnnotatedFunction[0]))) {
return;
}
lastAnnotatedFunctions = new AnnotatedFunction[newOutputFunctions.size()];
for (int i = 0; i < newOutputFunctions.size(); i++) {
lastAnnotatedFunctions[i] = new AnnotatedFunction(newOutputFunctions.get(i));
}
// lastAnnotatedFunctions = newOutputFunctions0.toArray(new AnnotatedFunction[0]);
myPdeDataContext.getDataManager().setOutputContext(new OutputContext(newOutputFunctions0.toArray(new AnnotatedFunction[0])));
myPdeDataContext.refreshIdentifiers();
for (int i = 0; i < myPropertyChangeHolder.size(); i++) {
myPropertyChangeHolder.get(i).propertyChange(new PropertyChangeEvent(multiTimePlotHelperThis, SimDataConstants.PROPERTY_NAME_DATAIDENTIFIERS, null, null));
}
}
}
};
PDEDataViewer.this.addPropertyChangeListener(myPropertyChangeListener);
}
}
@Override
public void removeallPropertyChangeListeners() {
myPropertyChangeHolder.clear();
if (myPropertyChangeListener != null) {
PDEDataViewer.this.removePropertyChangeListener(myPropertyChangeListener);
}
}
@Override
public VariableType getVariableType() {
return myVariableType;
}
// @Override
// public void addExtraTasks(AsynchClientTask[] moreTasks) {
// PDEDataViewer.this.addExtraTasks(moreTasks);
// }
@Override
public DataSymbolMetadataResolver getDataSymbolMetadataResolver() {
return dataSymbolMetadataResolver;
}
};
}
use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.
the class DefaultDataIdentifierFilter method accept.
public ArrayList<DataIdentifier> accept(String filterSetName, List<AnnotatedFunction> functionList, DataIdentifier[] filterTheseDataIdentifiers) {
//
if (dataSymbolMetadataResolver != null) {
ArrayList<String> allFilterNames = new ArrayList<String>();
if (this.dataSymbolMetadataResolver != null) {
ModelCategoryType[] uniqueCategories = dataSymbolMetadataResolver.getUniqueFilterCategories();
for (ModelCategoryType catType : uniqueCategories) {
allFilterNames.add(catType.getName());
}
}
if (allFilterNames.contains(filterSetName)) {
ArrayList<DataIdentifier> acceptedDataIdentifiers = new ArrayList<DataIdentifier>();
for (DataIdentifier dataID : filterTheseDataIdentifiers) {
DataSymbolMetadata metadata = dataSymbolMetadataResolver.getDataSymbolMetadata(dataID.getName());
if (metadata != null && metadata.filterCategory.getName().equals(filterSetName)) {
String varName = dataID.getName();
if (varName.startsWith(MathFunctionDefinitions.Function_regionVolume_current.getFunctionName())) {
continue;
}
if (varName.startsWith(MathFunctionDefinitions.Function_regionArea_current.getFunctionName())) {
continue;
}
acceptedDataIdentifiers.add(dataID);
}
}
return acceptedDataIdentifiers;
}
}
ArrayList<DataIdentifier> acceptedDataIdentifiers = new ArrayList<DataIdentifier>();
for (int i = 0; i < filterTheseDataIdentifiers.length; i++) {
if (bPostProcessingMode && filterTheseDataIdentifiers[i].getVariableType().equals(VariableType.POSTPROCESSING)) {
acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
continue;
}
if (bPostProcessingMode && !filterTheseDataIdentifiers[i].getVariableType().equals(VariableType.POSTPROCESSING)) {
continue;
}
if (!bPostProcessingMode && filterTheseDataIdentifiers[i].getVariableType().equals(VariableType.POSTPROCESSING)) {
continue;
}
String varName = filterTheseDataIdentifiers[i].getName();
if (varName.startsWith(MathFunctionDefinitions.Function_regionVolume_current.getFunctionName())) {
continue;
}
if (varName.startsWith(MathFunctionDefinitions.Function_regionArea_current.getFunctionName())) {
continue;
}
boolean bSizeVar = varName.startsWith(DiffEquMathMapping.PARAMETER_SIZE_FUNCTION_PREFIX);
if (filterSetName.equals(REGION_SIZE_FILTER_SET) && bSizeVar) {
acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
continue;
}
if (!filterSetName.equals(REGION_SIZE_FILTER_SET) && bSizeVar) {
continue;
}
if (filterSetName.equals(ALL)) {
acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
} else if (filterSetName.equals(VOLUME_FILTER_SET) && filterTheseDataIdentifiers[i].getVariableType().getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME)) {
acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
} else if (filterSetName.equals(MEMBRANE_FILTER_SET) && filterTheseDataIdentifiers[i].getVariableType().getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_MEMBRANE)) {
acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
} else if (filterSetName.equals(USER_DEFINED_FILTER_SET)) {
if (functionList != null) {
for (AnnotatedFunction f : functionList) {
if (!f.isPredefined() && f.getName().equals(varName)) {
acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
break;
}
}
}
}
}
if (acceptedDataIdentifiers.size() > 0) {
return acceptedDataIdentifiers;
}
return null;
}
use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.
the class VCellClientDataServiceImpl method displayPostProcessingDataInVCell.
@Override
public void displayPostProcessingDataInVCell(SimulationDataSetRef simulationDataSetRef) throws NumberFormatException, DataAccessException {
User vcUser = vcellClient.getRequestManager().getDocumentManager().getUser();
VCSimulationIdentifier vcSimId = new VCSimulationIdentifier(new KeyValue(simulationDataSetRef.getSimId()), vcUser);
ClientDocumentManager clientDocumentManager = (ClientDocumentManager) vcellClient.getClientServerManager().getDocumentManager();
SimulationOwner simulationOwner = null;
if (simulationDataSetRef.isMathModel) {
simulationOwner = clientDocumentManager.getMathModel(new KeyValue(simulationDataSetRef.getModelId()));
} else {
BioModel bioModel = clientDocumentManager.getBioModel(new KeyValue(simulationDataSetRef.getModelId()));
simulationOwner = bioModel.getSimulationContext(simulationDataSetRef.getSimulationContextName());
}
ArrayList<AnnotatedFunction> outputFunctionsList = simulationOwner.getOutputFunctionContext().getOutputFunctionsList();
OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
VCSimulationDataIdentifier vcSimDataId = new VCSimulationDataIdentifier(vcSimId, simulationDataSetRef.getJobIndex());
PDEDataManager pdeDataManager = (PDEDataManager) vcellClient.getRequestManager().getDataManager(outputContext, vcSimDataId, true);
final ClientPDEDataContext newClientPDEDataContext = pdeDataManager.getPDEDataContext();
// this was the code before the windows refactoring; appears to just always get the first window???
// Enumeration<TopLevelWindowManager> windowManagers = vcellClient.getMdiManager().getWindowManagers();
// final Window window = FindWindow.getWindow(windowManagers.nextElement().getComponent());
Optional<TopLevelWindowManager> first = vcellClient.getMdiManager().getWindowManagers().stream().findFirst();
VCAssert.assertTrue(first.isPresent(), "window manager not present?");
final Window window = getWindow(first.get().getComponent());
AsynchClientTask task = new AsynchClientTask("Display Post Processing Statistics", AsynchClientTask.TASKTYPE_SWING_NONBLOCKING, false, false) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
DataProcessingResultsPanel dataProcessingResultsPanel = new DataProcessingResultsPanel();
dataProcessingResultsPanel.update(newClientPDEDataContext);
DialogUtils.showComponentOKCancelDialog(window, dataProcessingResultsPanel, "Post Processing Statistics");
}
};
Hashtable<String, Object> hash = new Hashtable<String, Object>();
Vector<AsynchClientTask> tasksV = new Vector<AsynchClientTask>();
tasksV.add(task);
AsynchClientTask[] tasks = new AsynchClientTask[tasksV.size()];
tasksV.copyInto(tasks);
ClientTaskDispatcher.dispatch(window, hash, tasks, true);
}
use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.
the class FVSolverStandalone method initialize.
//
//
// /**
// * Insert the method's description here.
// * Creation date: (6/27/2001 2:33:03 PM)
// */
// public void propertyChange(java.beans.PropertyChangeEvent event) {
// super.propertyChange(event);
//
// if (event.getSource() == getMathExecutable() && event.getPropertyName().equals("applicationMessage")) {
// String messageString = (String)event.getNewValue();
// if (messageString==null || messageString.length()==0){
// return;
// }
// ApplicationMessage appMessage = getApplicationMessage(messageString);
// if (appMessage!=null && appMessage.getMessageType() == ApplicationMessage.DATA_MESSAGE) {
// fireSolverPrinted(appMessage.getTimepoint());
// }
// }
// }
/**
* This method was created by a SmartGuide.
*/
protected void initialize() throws SolverException {
try {
Simulation sim = simTask.getSimulation();
if (sim.isSerialParameterScan()) {
// write functions file for all the simulations in the scan
for (int scan = 0; scan < sim.getScanCount(); scan++) {
SimulationJob simJob = new SimulationJob(sim, scan, simTask.getSimulationJob().getFieldDataIdentifierSpecs());
// ** Dumping the functions of a simulation into a '.functions' file.
String basename = new File(getSaveDirectory(), simJob.getSimulationJobID()).getPath();
String functionFileName = basename + FUNCTIONFILE_EXTENSION;
Vector<AnnotatedFunction> funcList = simJob.getSimulationSymbolTable().createAnnotatedFunctionsList(simTask.getSimulation().getMathDescription());
// Try to save existing user defined functions
try {
File existingFunctionFile = new File(functionFileName);
if (existingFunctionFile.exists()) {
Vector<AnnotatedFunction> oldFuncList = FunctionFileGenerator.readFunctionsFile(existingFunctionFile, simTask.getSimulationJobID());
for (AnnotatedFunction func : oldFuncList) {
if (func.isOldUserDefined()) {
funcList.add(func);
}
}
}
} catch (Exception e) {
e.printStackTrace();
// ignore
}
// Try to save existing user defined functions
FunctionFileGenerator functionFileGenerator = new FunctionFileGenerator(functionFileName, funcList);
try {
functionFileGenerator.generateFunctionFile();
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error creating .function file for " + functionFileGenerator.getBasefileName() + e.getMessage());
}
}
} else {
writeFunctionsFile();
}
// not for Chombo solver
if (!isChombo) {
writeVCGAndResampleFieldData();
}
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INIT));
fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE));
File fvinputFile = new File(getInputFilename());
PrintWriter pw = null;
try {
pw = new PrintWriter(new FileWriter(fvinputFile));
new FiniteVolumeFileWriter(pw, simTask, getResampledGeometry(), getSaveDirectory(), destinationDirectory, bMessaging).write();
} finally {
if (pw != null) {
pw.close();
}
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
throw new SolverException(ex.getMessage());
}
}
use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.
the class FunctionFileGenerator method readFunctionsFile.
/**
* This method was created in VisualAge.
* @param logFile java.io.File
*/
public static synchronized Vector<AnnotatedFunction> readFunctionsFile(File functionsFile, String simJobID) throws java.io.FileNotFoundException, java.io.IOException {
// Check if file exists
if (!functionsFile.exists()) {
throw new java.io.FileNotFoundException("functions file " + functionsFile.getPath() + " not found");
}
//
// Read characters from functionFile into character array and transfer into string buffer.
//
Vector<AnnotatedFunction> annotatedFunctionsVector = new Vector<AnnotatedFunction>();
long fnFileLength = functionsFile.length();
StringBuffer stringBuffer = new StringBuffer();
FileInputStream is = null;
try {
is = new FileInputStream(functionsFile);
InputStreamReader reader = new InputStreamReader(is);
BufferedReader br = new BufferedReader(reader);
char[] charArray = new char[10000];
while (true) {
int numRead = br.read(charArray, 0, charArray.length);
if (numRead > 0) {
stringBuffer.append(charArray, 0, numRead);
} else if (numRead == -1) {
break;
}
}
} finally {
if (is != null) {
is.close();
}
}
if (stringBuffer.length() != fnFileLength) {
System.out.println("<<<SYSOUT ALERT>>>SimulationData.readFunctionFile(), read " + stringBuffer.length() + " of " + fnFileLength + " bytes of input file");
}
String newLineDelimiters = "\n\r";
StringTokenizer lineTokenizer = new StringTokenizer(stringBuffer.toString(), newLineDelimiters);
String token1 = new String("");
int j = 0;
//
// Each token is a line representing a function name and function expression,
// separated by a semicolon
//
HashSet<String> allSymbols = new HashSet<String>();
while (lineTokenizer.hasMoreTokens()) {
token1 = lineTokenizer.nextToken();
FunctionFileGenerator.FuncFileLineInfo funcFileLineInfo = readFunctionLine(token1);
if (funcFileLineInfo != null && funcFileLineInfo.functionName != null && funcFileLineInfo.functionExpr != null && funcFileLineInfo.funcVarType != null) {
Expression functionExpr = null;
try {
functionExpr = new Expression(funcFileLineInfo.functionExpr);
functionExpr = MathFunctionDefinitions.fixFunctionSyntax(functionExpr);
} catch (cbit.vcell.parser.ExpressionException e) {
throw new RuntimeException("Error in reading expression '" + funcFileLineInfo.functionExpr + "' for function \"" + funcFileLineInfo.functionName + "\"");
}
Domain domain = Variable.getDomainFromCombinedIdentifier(funcFileLineInfo.functionName);
String funcName = Variable.getNameFromCombinedIdentifier(funcFileLineInfo.functionName);
AnnotatedFunction annotatedFunc = new AnnotatedFunction(funcName, functionExpr, domain, funcFileLineInfo.errorString, funcFileLineInfo.funcVarType, funcFileLineInfo.funcIsUserDefined ? FunctionCategory.OLDUSERDEFINED : FunctionCategory.PREDEFINED);
allSymbols.add(annotatedFunc.getName());
String[] symbols = annotatedFunc.getExpression().getSymbols();
if (symbols != null) {
allSymbols.addAll(Arrays.asList(symbols));
}
annotatedFunctionsVector.addElement(annotatedFunc);
}
j++;
}
if (simJobID != null && simJobID.trim().length() > 0) {
SimpleSymbolTable simpleSymbolTable = new SimpleSymbolTable(allSymbols.toArray(new String[0]));
// bind
for (AnnotatedFunction func : annotatedFunctionsVector) {
if (func.isOldUserDefined()) {
try {
func.bind(simpleSymbolTable);
} catch (ExpressionBindingException e) {
e.printStackTrace();
}
}
}
// rename symbol table entries
for (int i = 0; i < annotatedFunctionsVector.size(); i++) {
AnnotatedFunction func = annotatedFunctionsVector.get(i);
if (func.isOldUserDefined()) {
SimpleSymbolTableEntry ste = (SimpleSymbolTableEntry) simpleSymbolTable.getEntry(func.getName());
ste.setName(simJobID + "_" + func.getName());
}
}
// rename in the expressions
for (int i = 0; i < annotatedFunctionsVector.size(); i++) {
AnnotatedFunction func = annotatedFunctionsVector.get(i);
if (func.isOldUserDefined()) {
try {
Expression exp = func.getExpression().renameBoundSymbols(simpleSymbolTable.getNameScope());
AnnotatedFunction newfunc = new AnnotatedFunction(simJobID + "_" + func.getName(), exp, func.getDomain(), func.getName(), func.getErrorString(), func.getFunctionType(), FunctionCategory.OLDUSERDEFINED);
annotatedFunctionsVector.set(i, newfunc);
} catch (ExpressionBindingException e) {
e.printStackTrace();
}
}
}
}
return annotatedFunctionsVector;
}
Aggregations