Search in sources :

Example 16 with VolVariable

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

the class Jacobian method parseMathDesc.

/**
 * This method was created by a SmartGuide.
 * @exception java.lang.Exception The exception description.
 */
private void parseMathDesc() throws MathException {
    Vector equationList = new Vector();
    Enumeration enum1 = subDomain.getEquations();
    while (enum1.hasMoreElements()) {
        Equation equ = (Equation) enum1.nextElement();
        if (equ instanceof OdeEquation) {
            equationList.addElement(equ);
        } else {
            throw new MathException("encountered non-ode equation, unsupported");
        }
    }
    Vector variableList = new Vector();
    enum1 = mathDesc.getVariables();
    while (enum1.hasMoreElements()) {
        Variable var = (Variable) enum1.nextElement();
        if (var instanceof VolVariable) {
            variableList.addElement(var);
        }
    }
    if (equationList.size() != variableList.size()) {
        throw new MathException("there are " + equationList.size() + " equations and " + variableList.size() + " variables");
    }
    numVariables = variableList.size();
    rates = new Expression[numVariables];
    vars = new VolVariable[numVariables];
    for (int i = 0; i < numVariables; i++) {
        OdeEquation odeEqu = (OdeEquation) equationList.elementAt(i);
        rates[i] = odeEqu.getRateExpression();
        vars[i] = (VolVariable) odeEqu.getVariable();
    }
}
Also used : Enumeration(java.util.Enumeration) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) OdeEquation(cbit.vcell.math.OdeEquation) VolVariable(cbit.vcell.math.VolVariable) MathException(cbit.vcell.math.MathException) OdeEquation(cbit.vcell.math.OdeEquation) Equation(cbit.vcell.math.Equation) Vector(java.util.Vector)

Example 17 with VolVariable

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

the class Jacobian method create.

/**
 * This method was created by a SmartGuide.
 * @exception java.lang.Exception The exception description.
 */
private void create() throws ExpressionException {
    Jexp = new Expression[numVariables * numVariables];
    for (int rateIndex = 0; rateIndex < numVariables; rateIndex++) {
        for (int varIndex = 0; varIndex < numVariables; varIndex++) {
            Expression rateExp = rates[rateIndex];
            VolVariable var = vars[varIndex];
            rateExp.bindExpression(mathDesc);
            rateExp = MathUtilities.substituteFunctions(rateExp, mathDesc);
            Expression diff = rateExp.differentiate(var.getName());
            diff.bindExpression(null);
            diff = diff.flatten();
            setJ(rateIndex, varIndex, diff);
            diff.bindExpression(mathDesc);
        }
    }
}
Also used : Expression(cbit.vcell.parser.Expression) VolVariable(cbit.vcell.math.VolVariable)

Example 18 with VolVariable

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

the class SundialsSolver method createStateVariables.

/*
	This method was created in Visual Age
*/
private StateVariable[] createStateVariables() throws MathException, ExpressionException {
    Vector<StateVariable> stateVariables = new Vector<StateVariable>();
    // get Ode's from MathDescription and create ODEStateVariables
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    MathDescription mathDescription = simSymbolTable.getSimulation().getMathDescription();
    Enumeration<Equation> enum1 = ((SubDomain) mathDescription.getSubDomains().nextElement()).getEquations();
    while (enum1.hasMoreElements()) {
        Equation equation = (Equation) enum1.nextElement();
        if (equation instanceof OdeEquation) {
            stateVariables.addElement(new ODEStateVariable((OdeEquation) equation, simSymbolTable));
        } else {
            throw new MathException("encountered non-ode equation, unsupported");
        }
    }
    // Get sensitivity variables
    Variable[] variables = simSymbolTable.getVariables();
    Vector<SensVariable> sensVariables = new Vector<SensVariable>();
    if (getSensitivityParameter() != null) {
        for (int i = 0; i < variables.length; i++) {
            if (variables[i] instanceof VolVariable) {
                VolVariable volVariable = (VolVariable) variables[i];
                SensVariable sv = new SensVariable(volVariable, getSensitivityParameter());
                sensVariables.addElement(sv);
            }
        }
    }
    if (rateSensitivity == null) {
        rateSensitivity = new RateSensitivity(mathDescription, mathDescription.getSubDomains().nextElement());
    }
    if (jacobian == null) {
        jacobian = new Jacobian(mathDescription, mathDescription.getSubDomains().nextElement());
    }
    for (int v = 0; v < sensVariables.size(); v++) {
        stateVariables.addElement(new SensStateVariable((SensVariable) sensVariables.elementAt(v), rateSensitivity, jacobian, sensVariables, simSymbolTable));
    }
    if (stateVariables.size() == 0) {
        throw new MathException("there are no equations defined");
    }
    StateVariable[] stateVars = (StateVariable[]) BeanUtils.getArray(stateVariables, StateVariable.class);
    return (stateVars);
}
Also used : Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) MathDescription(cbit.vcell.math.MathDescription) VolVariable(cbit.vcell.math.VolVariable) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) OdeEquation(cbit.vcell.math.OdeEquation) Equation(cbit.vcell.math.Equation) SubDomain(cbit.vcell.math.SubDomain) OdeEquation(cbit.vcell.math.OdeEquation) MathException(cbit.vcell.math.MathException) Vector(java.util.Vector)

Example 19 with VolVariable

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

the class OdeFileWriter method createStateVariables.

private void createStateVariables() throws Exception {
    Simulation simulation = simTask.getSimulation();
    MathDescription mathDescription = simulation.getMathDescription();
    SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
    // get Ode's from MathDescription and create ODEStateVariables
    Enumeration<Equation> enum1 = mathDescription.getSubDomains().nextElement().getEquations();
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    while (enum1.hasMoreElements()) {
        Equation equation = enum1.nextElement();
        if (equation instanceof OdeEquation) {
            fieldStateVariables.addElement(new ODEStateVariable((OdeEquation) equation, simSymbolTable));
        } else {
            throw new MathException("encountered non-ode equation, unsupported");
        }
    }
    // Get sensitivity variables
    Variable[] variables = simSymbolTable.getVariables();
    Vector<SensVariable> sensVariables = new Vector<SensVariable>();
    Constant sensitivityParameter = solverTaskDescription.getSensitivityParameter();
    if (sensitivityParameter != null) {
        Constant origSensParam = sensitivityParameter;
        Constant overriddenSensParam = (Constant) simSymbolTable.getVariable(origSensParam.getName());
        for (int i = 0; i < variables.length; i++) {
            if (variables[i] instanceof VolVariable) {
                VolVariable volVariable = (VolVariable) variables[i];
                SensVariable sv = new SensVariable(volVariable, overriddenSensParam);
                sensVariables.addElement(sv);
            }
        }
    }
    if (rateSensitivity == null) {
        rateSensitivity = new RateSensitivity(mathDescription, mathDescription.getSubDomains().nextElement());
    }
    if (jacobian == null) {
        jacobian = new Jacobian(mathDescription, mathDescription.getSubDomains().nextElement());
    }
    // get Jacobian and RateSensitivities from MathDescription and create SensStateVariables
    for (int v = 0; v < sensVariables.size(); v++) {
        fieldStateVariables.addElement(new SensStateVariable(sensVariables.elementAt(v), rateSensitivity, jacobian, sensVariables, simSymbolTable));
    }
}
Also used : ReservedVariable(cbit.vcell.math.ReservedVariable) ParameterVariable(cbit.vcell.math.ParameterVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) MathDescription(cbit.vcell.math.MathDescription) VolVariable(cbit.vcell.math.VolVariable) Constant(cbit.vcell.math.Constant) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) OdeEquation(cbit.vcell.math.OdeEquation) Equation(cbit.vcell.math.Equation) Simulation(cbit.vcell.solver.Simulation) OdeEquation(cbit.vcell.math.OdeEquation) MathException(cbit.vcell.math.MathException) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) Vector(java.util.Vector)

Example 20 with VolVariable

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

the class SimulationData method getVarAndFunctionDataIdentifiers.

/**
 * This method was created in VisualAge.
 * @return java.lang.String[]
 */
public synchronized DataIdentifier[] getVarAndFunctionDataIdentifiers(OutputContext outputContext) throws IOException, DataAccessException {
    // Is this zip format?
    boolean bIsChombo = false;
    try {
        bIsChombo = isChombo();
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.out);
    }
    File zipFile1 = getZipFile(bIsChombo, null);
    File zipFile2 = getZipFile(bIsChombo, 0);
    bZipFormat1 = false;
    bZipFormat2 = false;
    if (zipFile1.exists()) {
        bZipFormat1 = true;
    } else if (zipFile2.exists()) {
        bZipFormat2 = true;
    }
    refreshLogFile();
    if (!isComsol()) {
        try {
            refreshMeshFile();
        } catch (MathException e) {
            e.printStackTrace(System.out);
            throw new DataAccessException(e.getMessage());
        }
    }
    if (!isRulesData && !getIsODEData() && !isComsol() && dataFilenames != null) {
        // read variables only when I have never read the file since variables don't change
        if (dataSetIdentifierList.size() == 0) {
            File file = getPDEDataFile(0.0);
            DataSet dataSet = getPDEDataSet(file, 0.0);
            String[] varNames = dataSet.getDataNames();
            int[] varTypeInts = dataSet.getVariableTypeIntegers();
            if (varNames == null) {
                return null;
            }
            dataSetIdentifierList.clear();
            for (int i = 0; i < varNames.length; i++) {
                VariableType varType = null;
                try {
                    varType = VariableType.getVariableTypeFromInteger(varTypeInts[i]);
                } catch (IllegalArgumentException e) {
                    if (LG.isEnabledFor(Level.WARN)) {
                        LG.warn("Exception typing " + varNames[i] + " has unsupported type " + varTypeInts[i] + ": " + e.getMessage());
                    }
                    varType = SimulationData.getVariableTypeFromLength(mesh, dataSet.getDataLength(varNames[i]));
                }
                Domain domain = Variable.getDomainFromCombinedIdentifier(varNames[i]);
                String varName = Variable.getNameFromCombinedIdentifier(varNames[i]);
                dataSetIdentifierList.addElement(new DataSetIdentifier(varName, varType, domain));
            }
            refreshDataProcessingOutputInfo(outputContext);
            if (dataProcessingOutputInfo != null) {
                for (int i = 0; i < dataProcessingOutputInfo.getVariableNames().length; i++) {
                    if (dataProcessingOutputInfo.getPostProcessDataType(dataProcessingOutputInfo.getVariableNames()[i]).equals(DataProcessingOutputInfo.PostProcessDataType.image)) {
                        dataSetIdentifierList.addElement(new DataSetIdentifier(dataProcessingOutputInfo.getVariableNames()[i], VariableType.POSTPROCESSING, null));
                    }
                }
            }
        }
        // always read functions file since functions might change
        getFunctionDataIdentifiers(outputContext);
    }
    if ((isRulesData || getIsODEData()) && dataSetIdentifierList.size() == 0) {
        ODEDataBlock odeDataBlock = getODEDataBlock();
        if (odeDataBlock == null) {
            throw new DataAccessException("Results are not availabe yet. Please try again later.");
        }
        ODESimData odeSimData = odeDataBlock.getODESimData();
        int colCount = odeSimData.getColumnDescriptionsCount();
        // assume index=0 is time "t"
        int DATA_OFFSET = 1;
        dataSetIdentifierList.clear();
        for (int i = 0; i < (colCount - DATA_OFFSET); i++) {
            String varName = odeSimData.getColumnDescriptions(i + DATA_OFFSET).getDisplayName();
            // TODO domain
            Domain domain = null;
            dataSetIdentifierList.addElement(new DataSetIdentifier(varName, VariableType.NONSPATIAL, domain));
        }
    }
    if (isComsol() && dataSetIdentifierList.size() == 0) {
        ComsolSimFiles comsolSimFiles = getComsolSimFiles();
        if (comsolSimFiles.simTaskXMLFile != null) {
            try {
                String xmlString = FileUtils.readFileToString(comsolSimFiles.simTaskXMLFile);
                SimulationTask simTask = XmlHelper.XMLToSimTask(xmlString);
                Enumeration<Variable> variablesEnum = simTask.getSimulation().getMathDescription().getVariables();
                while (variablesEnum.hasMoreElements()) {
                    Variable var = variablesEnum.nextElement();
                    if (var instanceof VolVariable) {
                        dataSetIdentifierList.addElement(new DataSetIdentifier(var.getName(), VariableType.VOLUME, var.getDomain()));
                    } else if (var instanceof MemVariable) {
                        dataSetIdentifierList.addElement(new DataSetIdentifier(var.getName(), VariableType.MEMBRANE, var.getDomain()));
                    } else if (var instanceof Function) {
                        VariableType varType = VariableType.UNKNOWN;
                        if (var.getDomain() != null && var.getDomain().getName() != null) {
                            SubDomain subDomain = simTask.getSimulation().getMathDescription().getSubDomain(var.getDomain().getName());
                            if (subDomain instanceof CompartmentSubDomain) {
                                varType = VariableType.VOLUME;
                            } else if (subDomain instanceof MembraneSubDomain) {
                                varType = VariableType.MEMBRANE;
                            } else if (subDomain instanceof FilamentSubDomain) {
                                throw new RuntimeException("filament subdomains not supported");
                            } else if (subDomain instanceof PointSubDomain) {
                                varType = VariableType.POINT_VARIABLE;
                            }
                        }
                        dataSetIdentifierList.addElement(new DataSetIdentifier(var.getName(), varType, var.getDomain()));
                    } else if (var instanceof Constant) {
                        System.out.println("ignoring Constant " + var.getName());
                    } else if (var instanceof InsideVariable) {
                        System.out.println("ignoring InsideVariable " + var.getName());
                    } else if (var instanceof OutsideVariable) {
                        System.out.println("ignoring OutsideVariable " + var.getName());
                    } else {
                        throw new RuntimeException("unexpected variable " + var.getName() + " of type " + var.getClass().getName());
                    }
                }
            } catch (XmlParseException | ExpressionException e) {
                e.printStackTrace();
                throw new RuntimeException("failed to read sim task file, msg: " + e.getMessage(), e);
            }
        }
    }
    DataIdentifier[] dis = new DataIdentifier[dataSetIdentifierList.size()];
    for (int i = 0; i < dataSetIdentifierList.size(); i++) {
        DataSetIdentifier dsi = (DataSetIdentifier) dataSetIdentifierList.elementAt(i);
        String displayName = dsi.getName();
        if (dsi.isFunction()) {
            AnnotatedFunction f = null;
            for (int j = 0; j < annotatedFunctionList.size(); j++) {
                AnnotatedFunction function = (AnnotatedFunction) annotatedFunctionList.elementAt(j);
                if (function.getName().equals(dsi.getName())) {
                    f = function;
                    break;
                }
            }
            if (f != null) {
                displayName = f.getDisplayName();
            }
        }
        dis[i] = new DataIdentifier(dsi.getName(), dsi.getVariableType(), dsi.getDomain(), dsi.isFunction(), displayName);
    }
    return dis;
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) SimulationTask(cbit.vcell.messaging.server.SimulationTask) InsideVariable(cbit.vcell.math.InsideVariable) VolVariable(cbit.vcell.math.VolVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) MemVariable(cbit.vcell.math.MemVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) Constant(cbit.vcell.math.Constant) FileNotFoundException(java.io.FileNotFoundException) PointSubDomain(cbit.vcell.math.PointSubDomain) ODESimData(cbit.vcell.solver.ode.ODESimData) InsideVariable(cbit.vcell.math.InsideVariable) ExpressionException(cbit.vcell.parser.ExpressionException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) SubDomain(cbit.vcell.math.SubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Function(cbit.vcell.math.Function) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) MemVariable(cbit.vcell.math.MemVariable) DataAccessException(org.vcell.util.DataAccessException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) ComsolSimFiles(org.vcell.vis.io.ComsolSimFiles) VariableType(cbit.vcell.math.VariableType) VolVariable(cbit.vcell.math.VolVariable) XmlParseException(cbit.vcell.xml.XmlParseException) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) MathException(cbit.vcell.math.MathException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) OutsideVariable(cbit.vcell.math.OutsideVariable) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) SubDomain(cbit.vcell.math.SubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) Domain(cbit.vcell.math.Variable.Domain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Aggregations

VolVariable (cbit.vcell.math.VolVariable)46 Variable (cbit.vcell.math.Variable)29 Expression (cbit.vcell.parser.Expression)25 MemVariable (cbit.vcell.math.MemVariable)24 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)19 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)17 ReservedVariable (cbit.vcell.math.ReservedVariable)16 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)15 Constant (cbit.vcell.math.Constant)14 FilamentVariable (cbit.vcell.math.FilamentVariable)13 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)13 Vector (java.util.Vector)13 Function (cbit.vcell.math.Function)12 MathDescription (cbit.vcell.math.MathDescription)11 SubDomain (cbit.vcell.math.SubDomain)11 Equation (cbit.vcell.math.Equation)10 FilamentRegionVariable (cbit.vcell.math.FilamentRegionVariable)10 MathException (cbit.vcell.math.MathException)10 OdeEquation (cbit.vcell.math.OdeEquation)10 Domain (cbit.vcell.math.Variable.Domain)10