Package org.sbml.jsbml

Examples of org.sbml.jsbml.Unit


                .getParentSBMLObject();

            if (elementName.equals("unit")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfUnits)) {
              Unit unit = (Unit) newContextObject;
              unitDefinition.addUnit(unit);

              return unit;
            } else {
              // TODO : SBML syntax error, throw an exception?
View Full Code Here


  /**
   * Test method for {@link org.sbml.jsbml.AbstractNamedSBaseWithUnit#setUnits(org.sbml.jsbml.Unit)}.
   */
  @Test
  public void testSetUnitsUnit() {
    Unit unit = new Unit(kind, sbase.getLevel(), sbase.getVersion());
    sbase.setUnits(unit);
    assertTrue(sbase.isSetUnits());
    assertTrue(sbase.getUnits().equals(kind.toString().toLowerCase()));
    unit.setExponent(2d);
    sbase.setUnits(unit);
    assertTrue(sbase.isSetUnits());
    assertTrue(sbase.isSetUnitsInstance());
    assertTrue(sbase.getUnits().equals(
      '_' + "1_0_0_" + kind.toString() + '_'
        + Double.toString(unit.getExponent()).replace('.', '_')));
  }
View Full Code Here

                .getParentSBMLObject();

            if (elementName.equals("unit")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfUnits)) {
              Unit unit = (Unit) newContextObject;
              unit.initDefaults();
              unitDefinition.addUnit(unit);

              return unit;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
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.getNumUnitDefinitions() == 2);
View Full Code Here

                .getParentSBMLObject();

            if (elementName.equals("unit")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfUnits)) {
              Unit unit = (Unit) newContextObject;
              unitDefinition.addUnit(unit);

              return unit;
            } else {
              // TODO : SBML syntax error, throw an exception?
View Full Code Here

   * @param args
   */
  public static void main(String[] args) {
    int level = 2, version = 1;
    UnitDefinition ud = new UnitDefinition(level, version), ud2;
    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.3);
    // 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(UnitDefinition.printUnits(ud, true));
    System.out.println(UnitDefinition.printUnits(ud.simplify(), true));
    ud.convertToSIUnits();
    System.out.println(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

   * @param args
   */
  public static void main(String[] args) {
    int level = 2, version = 1;
    UnitDefinition 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.3);
    // 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(UnitDefinition.printUnits(ud, true));
    System.out.println(UnitDefinition.printUnits(ud.simplify(), true));
    ud.convertToSIUnits();
    System.out.println(UnitDefinition.printUnits(ud,true));

View Full Code Here

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

  public ASTNodeValue getConstantAvogadro(String name) {
    ASTNodeValue value = new ASTNodeValue(Maths.AVOGADRO, this);
    UnitDefinition perMole = new UnitDefinition();
    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

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.