Search in sources :

Example 11 with RationalNumber

use of cbit.vcell.matrix.RationalNumber in project vcell by virtualcell.

the class RayCaster method sampleXYZCoordinates.

public static void sampleXYZCoordinates(ISize sampleSize, Origin origin, Extent extent, RationalNumber[] samplesX, RationalNumber[] samplesY, RationalNumber[] samplesZ, boolean bCellCentered) {
    int numX = sampleSize.getX();
    int numY = sampleSize.getY();
    int numZ = sampleSize.getZ();
    RationalNumber rNumX = new RationalNumber(numX);
    RationalNumber rNumY = new RationalNumber(numY);
    RationalNumber rNumZ = new RationalNumber(numZ);
    RationalNumber ox = RationalNumber.getApproximateFraction(origin.getX());
    RationalNumber oy = RationalNumber.getApproximateFraction(origin.getY());
    RationalNumber oz = RationalNumber.getApproximateFraction(origin.getZ());
    RationalNumber half = new RationalNumber(1l, 2l);
    RationalNumber extentX = RationalNumber.getApproximateFraction(extent.getX());
    RationalNumber extentY = RationalNumber.getApproximateFraction(extent.getY());
    RationalNumber extentZ = RationalNumber.getApproximateFraction(extent.getZ());
    if (bCellCentered) {
        for (int i = 0; i < numX; i++) {
            RationalNumber rI = new RationalNumber(i);
            // ox + ((i+0.5)*extent.getX()/(numX));
            samplesX[i] = rI.add(half).mult(extentX).div(rNumX).add(ox);
        }
        for (int i = 0; i < numY; i++) {
            RationalNumber rI = new RationalNumber(i);
            // oy + ((i+0.5)*extent.getY()/(numY));
            samplesY[i] = rI.add(half).mult(extentY).div(rNumY).add(oy);
        }
        for (int i = 0; i < numZ; i++) {
            RationalNumber rI = new RationalNumber(i);
            // oz + ((i+0.5)*extent.getZ()/(numZ));
            samplesZ[i] = rI.add(half).mult(extentZ).div(rNumZ).add(oz);
        }
    } else {
        for (int i = 0; i < numX; i++) {
            RationalNumber rI = new RationalNumber(i);
            // ox + (i*extent.getX()/(numX-1));
            samplesX[i] = rI.mult(extentX).div(rNumX.sub(RationalNumber.ONE)).add(ox);
        }
        for (int i = 0; i < numY; i++) {
            RationalNumber rI = new RationalNumber(i);
            // oy + (i*extent.getY()/(numY-1));
            samplesY[i] = rI.mult(extentY).div(rNumY.sub(RationalNumber.ONE)).add(oy);
        }
        for (int i = 0; i < numZ; i++) {
            RationalNumber rI = new RationalNumber(i);
            // oz + (i*extent.getZ()/(numZ-1));
            samplesZ[i] = rI.mult(extentZ).div(rNumZ.sub(RationalNumber.ONE)).add(oz);
        }
        // 
        // instead of sampling right on the "edge" of the bounding box formed by origin/extent ... come in a little to avoid incorrect sampling.
        // 
        double epsilonX = 1e-8 * extent.getX() / (numX);
        RationalNumber rEpsilonX = RationalNumber.getApproximateFraction(epsilonX);
        // += epsilonX;
        samplesX[0] = samplesX[0].add(rEpsilonX);
        // -= epsilonX;
        samplesX[samplesX.length - 1] = samplesX[samplesX.length - 1].sub(rEpsilonX);
        double epsilonY = 1e-8 * extent.getY() / (numY);
        RationalNumber rEpsilonY = RationalNumber.getApproximateFraction(epsilonY);
        // += epsilonY;
        samplesY[0] = samplesY[0].add(rEpsilonY);
        // -= epsilonY;
        samplesY[samplesY.length - 1] = samplesY[samplesY.length - 1].sub(rEpsilonY);
        double epsilonZ = 1e-8 * extent.getZ() / (numZ);
        RationalNumber rEpsilonZ = RationalNumber.getApproximateFraction(epsilonZ);
        // += epsilonZ;
        samplesZ[0] = samplesZ[0].add(rEpsilonZ);
        // -= epsilonZ;
        samplesZ[samplesZ.length - 1] = samplesZ[samplesZ.length - 1].sub(rEpsilonZ);
    }
}
Also used : RationalNumber(cbit.vcell.matrix.RationalNumber)

Example 12 with RationalNumber

use of cbit.vcell.matrix.RationalNumber in project vcell by virtualcell.

the class SVDTest method getRationalMatrixFast.

/**
 * Insert the method's description here.
 * Creation date: (5/13/2003 11:06:29 AM)
 * @return Jama.Matrix
 */
public static RationalMatrixFast getRationalMatrixFast(Jama.Matrix matrix) {
    RationalMatrixFast rMatrix = new RationalMatrixFast(matrix.getRowDimension(), matrix.getColumnDimension());
    for (int i = 0; i < rMatrix.getNumRows(); i++) {
        for (int j = 0; j < rMatrix.getNumCols(); j++) {
            RationalNumber r = RationalNumber.getApproximateFraction(matrix.get(i, j));
            rMatrix.set_elem(i, j, r.getNumBigInteger().longValue(), r.getDenBigInteger().longValue());
        }
    }
    return rMatrix;
}
Also used : RationalMatrixFast(cbit.vcell.matrix.RationalMatrixFast) RationalNumber(cbit.vcell.matrix.RationalNumber)

Example 13 with RationalNumber

use of cbit.vcell.matrix.RationalNumber in project vcell by virtualcell.

the class Kinetics method getElectricalUnitFactor.

public final Expression getElectricalUnitFactor(VCUnitDefinition unitFactor) throws PropertyVetoException {
    if (unitFactor.isEquivalent(getReactionStep().getModel().getUnitSystem().getInstance_DIMENSIONLESS())) {
        return null;
    }
    RationalNumber factor = unitFactor.getDimensionlessScale();
    KineticsParameter kineticsParameter = getKineticsParameterFromRole(ROLE_ElectricalUnitFactor);
    if (kineticsParameter == null) {
        kineticsParameter = new KineticsParameter(DefaultNames[ROLE_ElectricalUnitFactor], new Expression(factor), ROLE_ElectricalUnitFactor, unitFactor);
        addKineticsParameter(kineticsParameter);
    } else {
        kineticsParameter.setExpression(new Expression(factor));
        kineticsParameter.setUnitDefinition(unitFactor);
    }
    return new Expression(kineticsParameter, null);
}
Also used : Expression(cbit.vcell.parser.Expression) RationalNumber(cbit.vcell.matrix.RationalNumber)

Example 14 with RationalNumber

use of cbit.vcell.matrix.RationalNumber in project vcell by virtualcell.

the class VCUnitDefinition method getDimensionlessScale.

public RationalNumber getDimensionlessScale() {
    // System.err.println("VCUnitDefinition.getDimensionlessScale(): this unit = "+getSymbol());
    VCUnitDefinition dimensionless = fieldVCUnitSystem.getInstance_DIMENSIONLESS();
    if (isEquivalent(dimensionless)) {
        RationalNumber rationalConversionScale = new RationalNumber(1);
        // System.err.println("VCUnitDefinition.getDimensionlessScale(): conversion scale = "+rationalConversionScale.toString());
        return rationalConversionScale;
    }
    if (isCompatible(dimensionless)) {
        double conversionScale = dimensionless.convertTo(1.0, this);
        RationalNumber rationalConversionScale = RationalNumber.getApproximateFraction(conversionScale);
        // System.err.println("VCUnitDefinition.getDimensionlessScale(): conversion scale = "+rationalConversionScale.toString());
        return rationalConversionScale;
    }
    // System.err.println("VCUnitDefinition.getDimensionlessScale(): not compatable with dimensionless");
    // 
    // this is not strictly a dimensionless since we do not automatically convert between molecules and moles)
    // so have to explicitly look for such cases.
    // 
    final VCUnitDefinition molecules_per_uM_um3 = fieldVCUnitSystem.getInstance("molecules.uM-1.um-3");
    final RationalNumber value_molecules_per_uM_um3 = new RationalNumber(602);
    RationalNumber tempValue = value_molecules_per_uM_um3;
    VCUnitDefinition tempUnit = molecules_per_uM_um3;
    for (int i = 0; i < 10; i++) {
        // System.err.println("VCUnitDefinition.getDimensionlessScale(): mult unit = "+this.multiplyBy(tempUnit).getSymbol());
        if (this.multiplyBy(tempUnit).isCompatible(dimensionless)) {
            double conversionScale = dimensionless.convertTo(1.0, this.multiplyBy(tempUnit));
            RationalNumber rationalConversionScale = RationalNumber.getApproximateFraction(conversionScale).div(tempValue);
            // System.err.println("VCUnitDefinition.getDimensionlessScale(): mult unit = "+this.multiplyBy(tempUnit).getSymbol()+" worked, conversion scale = "+rationalConversionScale.toString());
            return rationalConversionScale;
        }
        // System.err.println("VCUnitDefinition.getDimensionlessScale(): div unit = "+this.divideBy(tempUnit).getSymbol());
        if (this.divideBy(tempUnit).isCompatible(dimensionless)) {
            double conversionScale = dimensionless.convertTo(1.0, this.divideBy(tempUnit));
            RationalNumber rationalConversionScale = RationalNumber.getApproximateFraction(conversionScale).mult(tempValue);
            // System.err.println("VCUnitDefinition.getDimensionlessScale(): div unit = "+this.divideBy(tempUnit).getSymbol()+" worked, conversion scale = "+rationalConversionScale.toString());
            return rationalConversionScale;
        }
        tempValue = tempValue.mult(value_molecules_per_uM_um3);
        tempUnit = tempUnit.multiplyBy(molecules_per_uM_um3);
    }
    throw new RuntimeException("unit " + getSymbol() + " is not dimensionless, cannot be a unit conversion factor");
}
Also used : RationalNumber(cbit.vcell.matrix.RationalNumber)

Example 15 with RationalNumber

use of cbit.vcell.matrix.RationalNumber in project vcell by virtualcell.

the class VCUnitDefinition method raiseTo.

public VCUnitDefinition raiseTo(ucar.units_vcell.RationalNumber rationalNumber) {
    VCUnitDefinition powerUnit = null;
    if (powerMap != null) {
        powerUnit = powerMap.get(rationalNumber);
        if (powerUnit != null) {
            return powerUnit;
        }
    } else {
        powerMap = new HashMap<ucar.units_vcell.RationalNumber, VCUnitDefinition>();
    }
    RationalExp origRationalExpWithoutNumericScale = getSymbolRationalExpWithoutNumericScale(fieldUnitSymbol);
    RationalExp rationalExpWithoutNumericScale = origRationalExpWithoutNumericScale;
    // 
    if (rationalNumber.doubleValue() < 0) {
        rationalExpWithoutNumericScale = rationalExpWithoutNumericScale.inverse();
        rationalNumber = rationalNumber.minus();
    }
    // 
    if (rationalNumber.intValue() == rationalNumber.doubleValue()) {
        for (int i = 1; i < Math.abs(rationalNumber.intValue()); i++) {
            rationalExpWithoutNumericScale = rationalExpWithoutNumericScale.mult(origRationalExpWithoutNumericScale);
        }
        double newNumericScale = Math.pow(fieldUnitSymbol.getNumericScale(), rationalNumber.doubleValue());
        powerUnit = getUnit(newNumericScale, rationalExpWithoutNumericScale);
        powerMap.put(rationalNumber, powerUnit);
        return powerUnit;
    } else {
        throw new RuntimeException("raiseTo( non-integer ) not yet supported");
    }
}
Also used : RationalNumber(cbit.vcell.matrix.RationalNumber) RationalExp(cbit.vcell.matrix.RationalExp)

Aggregations

RationalNumber (cbit.vcell.matrix.RationalNumber)17 Expression (cbit.vcell.parser.Expression)7 RationalExp (cbit.vcell.matrix.RationalExp)3 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)3 RationalMatrixFast (cbit.vcell.matrix.RationalMatrixFast)2 SpeciesContext (cbit.vcell.model.SpeciesContext)2 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)2 PropertyVetoException (java.beans.PropertyVetoException)2 Vector (java.util.Vector)2 SimulationContext (cbit.vcell.mapping.SimulationContext)1 SpeciesContextMapping (cbit.vcell.mapping.SpeciesContextMapping)1 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)1 StructureMapping (cbit.vcell.mapping.StructureMapping)1 Feature (cbit.vcell.model.Feature)1 Membrane (cbit.vcell.model.Membrane)1 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 ArrayList (java.util.ArrayList)1