Search in sources :

Example 11 with VariableType

use of cbit.vcell.math.VariableType in project vcell by virtualcell.

the class PDEDataContextPanel method setDescription.

public void setDescription(Curve curve) {
    VariableType variableType = getPdeDataContext().getDataIdentifier().getVariableType();
    boolean isVolume = variableType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME) || variableType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_POSTPROCESSING);
    curve.setDescription((isVolume ? CurveValueProvider.DESCRIPTION_VOLUME : CurveValueProvider.DESCRIPTION_MEMBRANE) + (curve instanceof SinglePoint ? "p" : (curve instanceof PolyLine ? "l" : (curve instanceof Spline ? "s" : (curve instanceof CurveSelectionCurve ? "l" : "?")))) + uniquCurveID++);
}
Also used : CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) SinglePoint(cbit.vcell.geometry.SinglePoint) VariableType(cbit.vcell.math.VariableType) PolyLine(cbit.vcell.geometry.PolyLine) Spline(cbit.vcell.geometry.Spline)

Example 12 with VariableType

use of cbit.vcell.math.VariableType in project vcell by virtualcell.

the class FiniteVolumeFileWriter method writeFieldData.

/**
 * # Field Data
 * FIELD_DATA_BEGIN
 * #id, name, varname, time filename
 * 0 _VCell_FieldData_0 FRAP_binding_ALPHA rfB 0.1 \\users\\fgao\\SimID_22489731_0_FRAP_binding_ALPHA_rfB_0_1.fdat
 * FIELD_DATA_END
 * @throws FileNotFoundException
 * @throws ExpressionException
 * @throws DataAccessException
 */
private void writeFieldData() throws FileNotFoundException, ExpressionException, DataAccessException {
    FieldDataIdentifierSpec[] fieldDataIDSpecs = simTask.getSimulationJob().getFieldDataIdentifierSpecs();
    if (fieldDataIDSpecs == null || fieldDataIDSpecs.length == 0) {
        return;
    }
    String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
    DataSetControllerImpl dsci = new DataSetControllerImpl(null, workingDirectory.getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
    printWriter.println("# Field Data");
    printWriter.println("FIELD_DATA_BEGIN");
    printWriter.println("#id, type, new name, name, varname, time, filename");
    FieldFunctionArguments psfFieldFunc = null;
    Variable var = simTask.getSimulationJob().getSimulationSymbolTable().getVariable(Simulation.PSF_FUNCTION_NAME);
    if (var != null) {
        FieldFunctionArguments[] ffas = FieldUtilities.getFieldFunctionArguments(var.getExpression());
        if (ffas == null || ffas.length == 0) {
            throw new DataAccessException("Point Spread Function " + Simulation.PSF_FUNCTION_NAME + " can only be a single field function.");
        } else {
            Expression newexp = new Expression(ffas[0].infix());
            if (!var.getExpression().compareEqual(newexp)) {
                throw new DataAccessException("Point Spread Function " + Simulation.PSF_FUNCTION_NAME + " can only be a single field function.");
            }
            psfFieldFunc = ffas[0];
        }
    }
    int index = 0;
    HashSet<FieldDataIdentifierSpec> uniqueFieldDataIDSpecs = new HashSet<FieldDataIdentifierSpec>();
    uniqueFieldDataNSet = new HashSet<FieldDataNumerics>();
    for (int i = 0; i < fieldDataIDSpecs.length; i++) {
        if (!uniqueFieldDataIDSpecs.contains(fieldDataIDSpecs[i])) {
            FieldFunctionArguments ffa = fieldDataIDSpecs[i].getFieldFuncArgs();
            File newResampledFieldDataFile = new File(workingDirectory, SimulationData.createCanonicalResampleFileName((VCSimulationDataIdentifier) simTask.getSimulationJob().getVCDataIdentifier(), fieldDataIDSpecs[i].getFieldFuncArgs()));
            uniqueFieldDataIDSpecs.add(fieldDataIDSpecs[i]);
            VariableType varType = fieldDataIDSpecs[i].getFieldFuncArgs().getVariableType();
            SimDataBlock simDataBlock = dsci.getSimDataBlock(null, fieldDataIDSpecs[i].getExternalDataIdentifier(), fieldDataIDSpecs[i].getFieldFuncArgs().getVariableName(), fieldDataIDSpecs[i].getFieldFuncArgs().getTime().evaluateConstant());
            VariableType dataVarType = simDataBlock.getVariableType();
            if (varType.equals(VariableType.UNKNOWN)) {
                varType = dataVarType;
            } else if (!varType.equals(dataVarType)) {
                throw new IllegalArgumentException("field function variable type (" + varType.getTypeName() + ") doesn't match real variable type (" + dataVarType.getTypeName() + ")");
            }
            if (psfFieldFunc != null && psfFieldFunc.equals(ffa)) {
                psfFieldIndex = index;
            }
            String fieldDataID = "_VCell_FieldData_" + index;
            printWriter.println(index + " " + varType.getTypeName() + " " + fieldDataID + " " + ffa.getFieldName() + " " + ffa.getVariableName() + " " + ffa.getTime().infix() + " " + newResampledFieldDataFile);
            uniqueFieldDataNSet.add(new FieldDataNumerics(SimulationData.createCanonicalFieldFunctionSyntax(ffa.getFieldName(), ffa.getVariableName(), ffa.getTime().evaluateConstant(), ffa.getVariableType().getTypeName()), fieldDataID));
            index++;
        }
    }
    if (psfFieldIndex >= 0) {
        printWriter.println("PSF_FIELD_DATA_INDEX " + psfFieldIndex);
    }
    printWriter.println("FIELD_DATA_END");
    printWriter.println();
}
Also used : FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) ParameterVariable(cbit.vcell.math.ParameterVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) MemVariable(cbit.vcell.math.MemVariable) Variable(cbit.vcell.math.Variable) VariableType(cbit.vcell.math.VariableType) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) SimDataBlock(cbit.vcell.simdata.SimDataBlock) Expression(cbit.vcell.parser.Expression) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) File(java.io.File) DataAccessException(org.vcell.util.DataAccessException) HashSet(java.util.HashSet)

Example 13 with VariableType

use of cbit.vcell.math.VariableType in project vcell by virtualcell.

the class DataInfoProvider method isDefined.

public boolean isDefined(DataIdentifier dataIdentifier, int dataIndex) {
    try {
        Domain varDomain = dataIdentifier.getDomain();
        if (varDomain == null || dataIdentifier.getVariableType().equals(VariableType.POSTPROCESSING)) {
            return true;
        }
        VariableType varType = dataIdentifier.getVariableType();
        if (pdeDataContext.getCartesianMesh().isChomboMesh() && !Double.isNaN(pdeDataContext.getDataValues()[dataIndex])) {
            return true;
        }
        if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION)) {
            int subvol = pdeDataContext.getCartesianMesh().getSubVolumeFromVolumeIndex(dataIndex);
            if (simulationModelInfo.getVolumeNameGeometry(subvol) == null || simulationModelInfo.getVolumeNameGeometry(subvol).equals(varDomain.getName())) {
                return true;
            }
        } else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
            String memSubdomainName = pdeDataContext.getCartesianMesh().getMembraneSubdomainNamefromMemIndex(dataIndex);
            if (varDomain.getName().equals(memSubdomainName)) {
                return true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
Also used : VariableType(cbit.vcell.math.VariableType) Domain(cbit.vcell.math.Variable.Domain)

Example 14 with VariableType

use of cbit.vcell.math.VariableType in project vcell by virtualcell.

the class DataSetControllerImpl method getVtuVarInfos.

public VtuVarInfo[] getVtuVarInfos(ComsolSimFiles comsolFiles, OutputContext outputContext, VCDataIdentifier vcdataID) throws DataAccessException {
    try {
        DataIdentifier[] dataIdentifiers = getDataIdentifiers(outputContext, vcdataID);
        if (dataIdentifiers == null) {
            return null;
        }
        ArrayList<VtuVarInfo> vtuVarInfos = new ArrayList<VtuVarInfo>();
        for (DataIdentifier di : dataIdentifiers) {
            String name = di.getName();
            String displayName = di.getDisplayName();
            if (di.getDomain() != null) {
                System.err.println("DataSetControllerImpl.getVtuVarInfos(comsol): need to support proper domain names now");
            }
            String domainName = "domain";
            VariableDomain variableDomain = null;
            VariableType variableType = di.getVariableType();
            if (variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.VOLUME_REGION)) {
                variableDomain = VariableDomain.VARIABLEDOMAIN_VOLUME;
            } else if (variableType.equals(VariableType.MEMBRANE) || variableType.equals(VariableType.MEMBRANE_REGION)) {
                variableDomain = VariableDomain.VARIABLEDOMAIN_MEMBRANE;
            } else if (variableType.equals(VariableType.POINT_VARIABLE)) {
                variableDomain = VariableDomain.VARIABLEDOMAIN_POINT;
            } else if (variableType.equals(VariableType.CONTOUR) || variableType.equals(VariableType.CONTOUR_REGION)) {
                variableDomain = VariableDomain.VARIABLEDOMAIN_CONTOUR;
            } else if (variableType.equals(VariableType.NONSPATIAL)) {
                variableDomain = VariableDomain.VARIABLEDOMAIN_UNKNOWN;
            } else if (variableType.equals(VariableType.POSTPROCESSING)) {
                variableDomain = VariableDomain.VARIABLEDOMAIN_POSTPROCESSING;
            } else {
                System.err.print("skipping var " + di + ", unsupported data type");
            }
            String functionExpression = null;
            boolean bMeshVariable = false;
            if (name.toUpperCase().contains("SIZE")) {
                System.err.println("Skipping Moving Boundary variable '" + name + "' because it is a size ... change later");
                continue;
            }
            vtuVarInfos.add(new VtuVarInfo(name, displayName, domainName, variableDomain, functionExpression, DataType.PointData, bMeshVariable));
        }
        return vtuVarInfos.toArray(new VtuVarInfo[0]);
    } catch (Exception e) {
        lg.error(e.getMessage(), e);
        throw new DataAccessException("failed to retrieve VTK variable list: " + e.getMessage(), e);
    }
}
Also used : VtuVarInfo(org.vcell.vis.io.VtuVarInfo) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) VariableType(cbit.vcell.math.VariableType) ArrayList(java.util.ArrayList) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) CacheException(org.vcell.util.CacheException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) FileNotFoundException(java.io.FileNotFoundException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) DataAccessException(org.vcell.util.DataAccessException)

Example 15 with VariableType

use of cbit.vcell.math.VariableType in project vcell by virtualcell.

the class SimulationSymbolTable method getFunctionVariableType.

/**
 * Insert the method's description here.
 * Creation date: (2/19/2004 11:17:15 AM)
 * @return cbit.vcell.simdata.VariableType
 * @param function cbit.vcell.math.Function
 * @param variableNames java.lang.String[]
 * @param variableTypes cbit.vcell.simdata.VariableType[]
 */
public static VariableType getFunctionVariableType(Function function, MathDescription mathDescription, String[] variableNames, VariableType[] variableTypes, boolean isSpatial) throws InconsistentDomainException {
    if (!isSpatial) {
        return VariableType.NONSPATIAL;
    }
    VariableType domainFuncType = null;
    // initial guess, restrict variable type to be consistent with domain.
    if (function.getDomain() != null) {
        String domainName = function.getDomain().getName();
        if (mathDescription != null) {
            SubDomain subdomain = mathDescription.getSubDomain(domainName);
            if (subdomain instanceof MembraneSubDomain) {
                domainFuncType = VariableType.MEMBRANE_REGION;
            } else {
                domainFuncType = VariableType.VOLUME_REGION;
            }
        }
    }
    Expression exp = function.getExpression();
    String[] symbols = exp.getSymbols();
    ArrayList<VariableType> varTypeList = new ArrayList<VariableType>();
    boolean bExplicitFunctionOfSpace = false;
    if (symbols != null) {
        for (int j = 0; j < symbols.length; j++) {
            if (symbols[j].equals(ReservedVariable.X.getName()) || symbols[j].equals(ReservedVariable.Y.getName()) || symbols[j].equals(ReservedVariable.Z.getName())) {
                bExplicitFunctionOfSpace = true;
                continue;
            }
            for (int k = 0; k < variableNames.length; k++) {
                if (symbols[j].equals(variableNames[k])) {
                    varTypeList.add(variableTypes[k]);
                    break;
                } else if (symbols[j].equals(variableNames[k] + InsideVariable.INSIDE_VARIABLE_SUFFIX) || symbols[j].equals(variableNames[k] + OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                    if (variableTypes[k].equals(VariableType.VOLUME)) {
                        varTypeList.add(VariableType.MEMBRANE);
                    } else if (variableTypes[k].equals(VariableType.VOLUME_REGION)) {
                        varTypeList.add(VariableType.MEMBRANE_REGION);
                    }
                    break;
                }
            }
        }
    }
    // Size Functions
    Set<FunctionInvocation> sizeFunctionInvocationSet = SolverUtilities.getSizeFunctionInvocations(function.getExpression());
    for (FunctionInvocation fi : sizeFunctionInvocationSet) {
        String functionName = fi.getFunctionName();
        if (functionName.equals(MathFunctionDefinitions.Function_regionArea_current.getFunctionName())) {
            varTypeList.add(VariableType.MEMBRANE_REGION);
        } else if (functionName.equals(MathFunctionDefinitions.Function_regionVolume_current.getFunctionName())) {
            varTypeList.add(VariableType.VOLUME_REGION);
        }
    }
    // Membrane Normal Functions
    FunctionInvocation[] functionInvocations = function.getExpression().getFunctionInvocations(null);
    for (FunctionInvocation fi : functionInvocations) {
        String functionName = fi.getFunctionName();
        if (functionName.equals(MathFunctionDefinitions.Function_normalX.getFunctionName()) || functionName.equals(MathFunctionDefinitions.Function_normalY.getFunctionName())) {
            varTypeList.add(VariableType.MEMBRANE);
        }
    }
    FieldFunctionArguments[] fieldFuncArgs = FieldUtilities.getFieldFunctionArguments(function.getExpression());
    if (fieldFuncArgs != null && fieldFuncArgs.length > 0) {
        varTypeList.add(fieldFuncArgs[0].getVariableType());
    }
    VariableType funcType = domainFuncType;
    for (VariableType vt : varTypeList) {
        if (funcType == null) {
            funcType = vt;
        } else {
            // 
            if (vt.isExpansionOf(funcType)) {
                funcType = vt;
            } else if (vt.equals(VariableType.VOLUME)) {
                if (funcType.equals(VariableType.MEMBRANE_REGION)) {
                    funcType = VariableType.MEMBRANE;
                }
            } else if (vt.equals(VariableType.VOLUME_REGION)) {
            } else if (vt.equals(VariableType.MEMBRANE)) {
                if (domainFuncType != null && domainFuncType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME)) {
                    throw new InconsistentDomainException("Function '" + function.getName() + "' defined on a volume subdomain '" + function.getDomain().getName() + "' references a variable or a function defined on a membrane subdomain");
                }
            } else if (vt.equals(VariableType.MEMBRANE_REGION)) {
                if (funcType.equals(VariableType.VOLUME)) {
                    if (domainFuncType != null && domainFuncType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME)) {
                        throw new InconsistentDomainException("Function '" + function.getName() + "' defined on '" + function.getDomain().getName() + "' references a size function defined on a membrane");
                    }
                    funcType = VariableType.MEMBRANE;
                } else if (funcType.equals(VariableType.VOLUME_REGION)) {
                    if (domainFuncType != null && domainFuncType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME)) {
                        throw new InconsistentDomainException("Function '" + function.getName() + "' defined on '" + function.getDomain().getName() + "' references a size function defined on a membrane");
                    }
                    funcType = VariableType.MEMBRANE_REGION;
                }
            } else if (vt.incompatibleWith(funcType)) {
                throw new InconsistentDomainException("Function domains conflict between variable domains '" + vt.getDefaultLabel() + "' and '" + funcType.getDefaultLabel() + " for function " + function.getName());
            }
        }
    }
    // 
    if (funcType != null && bExplicitFunctionOfSpace) {
        if (funcType.equals(VariableType.MEMBRANE_REGION)) {
            funcType = VariableType.MEMBRANE;
        } else if (funcType.equals(VariableType.VOLUME_REGION)) {
            funcType = VariableType.VOLUME;
        } else if (funcType.equals(VariableType.CONTOUR_REGION)) {
            funcType = VariableType.CONTOUR;
        }
    }
    if (funcType == null) {
        // no knowledge from expression, default variable type
        return VariableType.VOLUME;
    }
    return funcType;
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) FunctionInvocation(cbit.vcell.parser.FunctionInvocation) VariableType(cbit.vcell.math.VariableType) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) ArrayList(java.util.ArrayList) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Expression(cbit.vcell.parser.Expression) InconsistentDomainException(cbit.vcell.math.InconsistentDomainException)

Aggregations

VariableType (cbit.vcell.math.VariableType)54 CartesianMesh (cbit.vcell.solvers.CartesianMesh)17 DataAccessException (org.vcell.util.DataAccessException)15 File (java.io.File)13 ISize (org.vcell.util.ISize)12 Expression (cbit.vcell.parser.Expression)11 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)11 SinglePoint (cbit.vcell.geometry.SinglePoint)10 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)10 Domain (cbit.vcell.math.Variable.Domain)9 ExpressionException (cbit.vcell.parser.ExpressionException)9 DataIdentifier (cbit.vcell.simdata.DataIdentifier)9 ArrayList (java.util.ArrayList)9 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)8 ReservedVariable (cbit.vcell.math.ReservedVariable)8 Variable (cbit.vcell.math.Variable)8 SimDataBlock (cbit.vcell.simdata.SimDataBlock)8 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)8 Hashtable (java.util.Hashtable)8 MathException (cbit.vcell.math.MathException)7