Package org.sbml.jsbml

Examples of org.sbml.jsbml.Unit


   */
  public static void main(String[] args) {
    int level = 2, version = 1;
    UnitDefinition ud, ud2;
    ud = new UnitDefinition(level, version);
    ud.addUnit(new Unit(Unit.Kind.VOLT, 2, level, version));
    ud.addUnit(new Unit(Unit.Kind.SIEMENS, 4, level, version));
    ud.addUnit(new Unit(Unit.Kind.AMPERE, 1, level, version));
    ud.addUnit(new Unit(Unit.Kind.WEBER, 0, level, version));
    Unit u = new Unit(Unit.Kind.WATT, 3, level, version);
    u.setMultiplier(5);
    // u.setOffset(-271.15);
    ud.addUnit(u);
    ud.addUnit(new Unit(Unit.Kind.NEWTON, 2, level, version));
    ud.addUnit(new Unit(Unit.Kind.GRAM, 0, level, version));
    System.out.println("Initial unit:\t\t" + UnitDefinition.printUnits(ud, true));
    System.out.println("Simplified unit:\t" + UnitDefinition.printUnits(ud.simplify(), true));
    ud.convertToSIUnits();
    System.out.println("SI units:\t\t" + UnitDefinition.printUnits(ud,true));
//
//    // AMPERE CELSIUS GRAM NEWTON SIEMENS VOLT WEBER
//    // A °C^3 1 N^2 S^4 V^2 1
//   
    ud = new UnitDefinition(level, version);
    ud.addUnit(new Unit(-3, Unit.Kind.JOULE, level, version));
    ud.addUnit(new Unit(-3, Unit.Kind.MOLE, level, version));
   
    ud2 = new UnitDefinition(level, version);
    ud2.addUnit(new Unit(Unit.Kind.JOULE, 5, level, version));
    ud2.addUnit(new Unit(Unit.Kind.MOLE, 5, level, version));
   
    System.out.printf("\n%s / %s\t=\t", UnitDefinition.printUnits(ud, true), UnitDefinition.printUnits(ud2, true));
    ud.divideBy(ud2);
    ud.simplify();
    System.out.println(UnitDefinition.printUnits(ud, true));
   
    ud = new UnitDefinition(level, version);
    ud.addUnit(new Unit(-3, Unit.Kind.MOLE, 2, level, version));
    ud.addUnit(new Unit(-3, Unit.Kind.LITRE, -2, level, version));
    ud2 = new UnitDefinition(level, version);
    ud2.addUnit(new Unit(-3, Unit.Kind.MOLE, level, version));
    ud2.addUnit(new Unit(-3, Unit.Kind.LITRE, -1, level, version));
   
    System.out.printf("\n%s * %s\t=\t", UnitDefinition.printUnits(ud, true), UnitDefinition.printUnits(ud2, true));
   
    ud.multiplyWith(ud2);
    ud.simplify();
    System.out.println(UnitDefinition.printUnits(ud, true));
   
    ud = new UnitDefinition(level, version);
    ud.addUnit(new Unit(18, Unit.Kind.JOULE, 6, level, version));
    ud2 = new UnitDefinition(level, version);
    ud2.addUnit(new Unit(-3, Unit.Kind.MOLE, -6, level, version));
   
    System.out.printf("\n%s / %s\t=\t", UnitDefinition.printUnits(ud, true), UnitDefinition.printUnits(ud2, true));
    ud.divideBy(ud2);
    ud.simplify();
    System.out.println(UnitDefinition.printUnits(ud, true));
   
    ud = new UnitDefinition(level, version);
    ud.addUnit(new Unit(18, Unit.Kind.JOULE, 6, level, version));
    ud.addUnit(new Unit(-3, Unit.Kind.MOLE, -6, level, version));
    ud2 = new UnitDefinition(level, version);
    ud2.addUnit(new Unit(Unit.Kind.JOULE, level, version));
    ud2.addUnit(new Unit(Unit.Kind.MOLE, -1, level, version));
   
    System.out.printf("\n%s / %s\t=\t", UnitDefinition.printUnits(ud, true), UnitDefinition.printUnits(ud2, true));
    ud.divideBy(ud2);
    ud.simplify();
    System.out.println(UnitDefinition.printUnits(ud, true));
   
    ud = new UnitDefinition(level, version);
    ud.addUnit(new Unit(-3, Unit.Kind.MOLE, 1d, level, version));
    ud.addUnit(new Unit(Unit.Kind.LITRE, -1d, level, version));
    ud2 = new UnitDefinition(level, version);
    ud2.addUnit(new Unit(-3, Unit.Kind.MOLE, 1d, level, version));
    ud2.addUnit(new Unit(Unit.Kind.LITRE, -1d, level, version));
    ud.divideBy(ud2);
    System.out.println(UnitDefinition.printUnits(ud, true));
    ud.simplify();
    System.out.println(UnitDefinition.printUnits(ud, true));
  }
View Full Code Here


   
    // Some hard-coded default stuff:
    // Before SBML l3, exponent, scale and multiplier had default values.
    // => Restore them when upgrading to l3
    if (sbase instanceof Unit) {
      Unit ud = ((Unit) sbase);
      if ((sbase.getLevel() < 3) && (level >= 3)) {
        if (!ud.isSetExponent()) {
          ud.setExponent(1d);
        }
        if (!ud.isSetScale()) {
          ud.setScale(0);
        }
        if (!ud.isSetMultiplier()) {
          ud.setMultiplier(1d);
        }
      }
    }
   
    // Set level and version
View Full Code Here

   */
  public static String toHTML(UnitDefinition ud) {
    StringBuilder sb = new StringBuilder();
    if (ud != null) {
      for (int i = 0; i < ud.getUnitCount(); i++) {
        Unit unit = ud.getUnit(i);
        if (i > 0) {
          sb.append(' ');
          sb.append(C_DOT);
          sb.append(' ');
        }
View Full Code Here

      // TODO: If there is a different value in a later SBML specification, this must be checked here.
    ASTNodeValue value = new ASTNodeValue(Maths.AVOGADRO_L3V1, this);
    UnitDefinition perMole = new UnitDefinition(level, version);
    perMole.setLevel(level);
    perMole.setId("per_mole");
    perMole.addUnit(new Unit(Kind.MOLE, -1, level, version));
    value.setUnits(perMole);
    return value;
  }
View Full Code Here

   *
   * @return
   */
  private ASTNodeValue invalid() {
    UnitDefinition ud = new UnitDefinition(level, version);
    ud.addUnit(new Unit(level, version));
    return new ASTNodeValue(ud, this);
  }
View Full Code Here

        left.getUnits().simplify();
        right.getUnits().simplify();
        int mean, scale1, scale2;
        double v1 = left.toNumber().doubleValue(), v2 = right.toNumber().doubleValue();
        for (int i = 0; i < left.getUnits().getUnitCount(); i++) {
          Unit u1 = left.getUnits().getUnit(i);
          Unit u2 = right.getUnits().getUnit(i);
          if (((u1.getMultiplier() != u2.getMultiplier())
              && (u1.getScale() != u2.getScale()) && (u1.getExponent() != u2.getExponent()))
              && (u1.getMultiplier() != 0d) && (u2.getMultiplier() != 0d)) {

            mean = (Math.abs(u1.getScale()) + Math.abs(u2.getScale())) / 2;

            if (u1.getScale() > mean) {
              scale1 = Math.abs(u1.getScale()) - mean;
              scale2 = mean - u2.getScale();

            } else {
              scale2 = Math.abs(u2.getScale()) - mean;
              scale1 = mean - u1.getScale();
            }

            if (u1.getExponent() < 0) {
              scale1 = -scale1;
              scale2 = -scale2;
            }

            if (scale1 > mean) {
              v1 = v1 * Math.pow(10d, -scale1 * u1.getExponent());
              v2 = v2 * Math.pow(10d, -scale2 * u2.getExponent());

            } else {
              v1 = v1 * Math.pow(10d, scale1 * u1.getExponent());
              v2 = v2 * Math.pow(10d, scale2 * u2.getExponent());
            }

            if (u1.getMultiplier() > 1d) {
              v1 = v1 * u1.getMultiplier();
              u1.setMultiplier(1d);
            }

            if (u2.getMultiplier() > 1d) {
              v2 = v2 * u2.getMultiplier();
              u2.setMultiplier(1d);
            }

            u1.setScale(mean);
            u2.setScale(mean);

          }

        }
        left.setValue(v1);
 
View Full Code Here

  }

  @Test
  public void test_Model_createUnit() {
    UnitDefinition ud;
    Unit u;
    M.createUnitDefinition();
    M.createUnitDefinition();
    u = M.createUnit(Kind.LITRE);
    assertTrue(u != null);
    assertTrue(M.getUnitDefinitionCount() == 2);
View Full Code Here

    ud6 = new UnitDefinition("ud6", level, version);
    ud7 = new UnitDefinition("ud7", level, version);
   
    // mole per litre
    ud1.addUnit(Kind.MOLE);
    ud1.addUnit(new Unit(Kind.LITRE, -1d, level, version));
   
    // micro litre
    ud2.addUnit(new Unit(-6, Kind.LITRE, level, version));
   
    // hours
    ud3.addUnit(new Unit(3600d, 0, Kind.SECOND, 1d, level, version));
   
    // minutes
    ud4.addUnit(new Unit(60d, 0, Kind.SECOND, 1d, level, version));
   
    // micro mole
    ud5.addUnit(new Unit(-6, Kind.MOLE, level, version));
   
    // milli litre
    ud6.addUnit(new Unit(-3, Kind.LITRE, level, version));
   
    // seconds
    ud7.addUnit(new Unit(Kind.SECOND, level, version));
  }
View Full Code Here

    UnitDefinition uuu = new UnitDefinition("energy", level, version);
    int scale = 12;
    double multiplier = 10E-10d;
    double noise = 1E-23d;
    double exp = 1d;
    uuu.addUnit(new Unit(multiplier + noise, scale, Kind.JOULE, exp, level, version));
    uuu.getUnit(0).removeMultiplier();
    assertTrue(UnitDefinition.printUnits(uuu, true).equals("kJ"));
  }
View Full Code Here

    udef = ud3.clone().divideBy(ud4).simplify();
    printTask('/', ud3, ud4, udef);
    assertTrue(UnitDefinition.printUnits(udef, true).equals("60*dimensionless"));
   
    UnitDefinition u1 = new UnitDefinition(level, version);
    u1.addUnit(new Unit(-3, Unit.Kind.JOULE, level, version));
    u1.addUnit(new Unit(-3, Unit.Kind.MOLE, level, version));
   
    UnitDefinition u2 = new UnitDefinition(level, version);
    u2.addUnit(new Unit(Unit.Kind.JOULE, 5, level, version));
    u2.addUnit(new Unit(Unit.Kind.MOLE, 5, level, version));
   
    udef = u1.clone().divideBy(u2).simplify();
    printTask('/', u1, u2, udef);
    double pow = Math.pow(10, 3d/4d);
    assertTrue(UnitDefinition.printUnits(udef, true).equals('('+ Double.toString(pow) +"*J)^(-4)*(" + Double.toString(pow) + "*mol)^(-4)"));
   
    UnitDefinition u3 = new UnitDefinition(level, version);
    u3.addUnit(new Unit(Kind.MOLE, -4d, level, version));
    u3.addUnit(new Unit(Kind.SECOND, -1d, level, version));
    udef = ud5.clone().multiplyWith(u3).simplify();
    printTask('*', ud5, u3, udef);
    assertTrue(UnitDefinition.printUnits(udef, true).equals("hmol^(-3)*s^(-1)"));
   
    u1 = ud5.clone().raiseByThePowerOf(5d);
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.Unit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.