Search in sources :

Example 11 with ParticleProperties

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

the class RunSims method isSmoldynTimeStepOK.

private boolean isSmoldynTimeStepOK(Simulation sim) {
    for (int jobIndex = 0; jobIndex < sim.getScanCount(); jobIndex++) {
        SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(sim, jobIndex);
        double Dmax = 0;
        MathDescription mathDesc = sim.getMathDescription();
        Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
        while (subDomainEnumeration.hasMoreElements()) {
            SubDomain subDomain = subDomainEnumeration.nextElement();
            // }
            for (ParticleProperties particleProperties : subDomain.getParticleProperties()) {
                try {
                    Expression newExp = new Expression(particleProperties.getDiffusion());
                    newExp.bindExpression(simSymbolTable);
                    newExp = simSymbolTable.substituteFunctions(newExp).flatten();
                    try {
                        double diffConstant = newExp.evaluateConstant();
                        Dmax = Math.max(Dmax, diffConstant);
                    } catch (ExpressionException ex) {
                        throw new ExpressionException("diffusion coefficient for variable " + particleProperties.getVariable().getQualifiedName() + " is not a constant. Constants are required for all diffusion coefficients");
                    }
                } catch (Exception ex) {
                }
            }
        }
        double s = sim.getMeshSpecification().getDx(sim.hasCellCenteredMesh());
        double dt = sim.getSolverTaskDescription().getTimeStep().getDefaultTimeStep();
        if (dt >= s * s / (2 * Dmax)) {
            smoldynTimestepVars = new SmoldynTimeStepVars(s, Dmax);
            return false;
        }
    }
    return true;
}
Also used : SubDomain(cbit.vcell.math.SubDomain) MathDescription(cbit.vcell.math.MathDescription) Expression(cbit.vcell.parser.Expression) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) ParticleProperties(cbit.vcell.math.ParticleProperties) ExpressionException(cbit.vcell.parser.ExpressionException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException)

Example 12 with ParticleProperties

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

the class SmoldynFileWriter method writeDiffusions.

private void writeDiffusions() throws ExpressionBindingException, ExpressionException, MathException {
    // writer diffusion properties
    printWriter.println("# diffusion properties");
    Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
    while (subDomainEnumeration.hasMoreElements()) {
        SubDomain subDomain = subDomainEnumeration.nextElement();
        List<ParticleProperties> particlePropertiesList = subDomain.getParticleProperties();
        for (ParticleProperties pp : particlePropertiesList) {
            String variableName = null;
            if (subDomain instanceof MembraneSubDomain) {
                variableName = getVariableName(pp.getVariable(), subDomain);
            } else {
                variableName = getVariableName(pp.getVariable(), null);
            }
            try {
                double diffConstant = subsituteFlattenToConstant(pp.getDiffusion());
                printWriter.println(SmoldynVCellMapper.SmoldynKeyword.difc + " " + variableName + " " + diffConstant);
            } catch (NotAConstantException ex) {
                throw new ExpressionException("diffusion coefficient for variable " + variableName + " is not a constant. Constants are required for all diffusion coefficients");
            }
        }
    }
    printWriter.println();
}
Also used : CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) ParticleProperties(cbit.vcell.math.ParticleProperties) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 13 with ParticleProperties

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

the class MembraneParticleDiffusionVisitor method hasMembraneDiffusion.

private boolean hasMembraneDiffusion(MathDescription mathDesc) throws ExpressionException {
    // 
    for (SubDomain subDomain : Collections.list(mathDesc.getSubDomains())) {
        if (subDomain instanceof MembraneSubDomain) {
            MembraneSubDomain membraneSubDomain = (MembraneSubDomain) subDomain;
            for (ParticleProperties particleProperties : membraneSubDomain.getParticleProperties()) {
                Expression diffusionCoef = particleProperties.getDiffusion();
                diffusionCoef = MathUtilities.substituteFunctions(diffusionCoef, mathDesc);
                diffusionCoef = diffusionCoef.flatten();
                if (!diffusionCoef.isZero()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Expression(cbit.vcell.parser.Expression) ParticleProperties(cbit.vcell.math.ParticleProperties)

Aggregations

ParticleProperties (cbit.vcell.math.ParticleProperties)13 SubDomain (cbit.vcell.math.SubDomain)9 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)7 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)7 Expression (cbit.vcell.parser.Expression)7 ExpressionException (cbit.vcell.parser.ExpressionException)6 MathDescription (cbit.vcell.math.MathDescription)5 ParticleInitialCondition (cbit.vcell.math.ParticleProperties.ParticleInitialCondition)5 ArrayList (java.util.ArrayList)5 ParticleJumpProcess (cbit.vcell.math.ParticleJumpProcess)4 ParticleInitialConditionCount (cbit.vcell.math.ParticleProperties.ParticleInitialConditionCount)4 ParticleVariable (cbit.vcell.math.ParticleVariable)4 Variable (cbit.vcell.math.Variable)4 VolumeParticleVariable (cbit.vcell.math.VolumeParticleVariable)4 Element (org.jdom.Element)4 GeometryClass (cbit.vcell.geometry.GeometryClass)3 Constant (cbit.vcell.math.Constant)3 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)3 MathException (cbit.vcell.math.MathException)3 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)3