Package org.geppetto.core.model.runtime

Examples of org.geppetto.core.model.runtime.RuntimeTreeRoot


public class TestNetworkSerialization {

  @Test
  public void testVisualGroups() {

    RuntimeTreeRoot runtime = new RuntimeTreeRoot("root");

    EntityNode hhcell = new EntityNode("hhcell");
   
    EntityNode purkinje = new EntityNode("purkinje");

    AspectNode electrical = new AspectNode("electrical");
    AspectNode electrical2 = new AspectNode("electrical");

    AspectSubTreeNode visualization = electrical.getSubTree(AspectTreeType.VISUALIZATION_TREE);
    SphereNode sphere = new SphereNode("purkinje");
    visualization.addChild(sphere);

    runtime.addChild(hhcell);
    runtime.addChild(purkinje);
    hhcell.getAspects().add(electrical);
    purkinje.getAspects().add(electrical2);
    electrical.setParent(hhcell);
    electrical2.setParent(purkinje);
   
    VisualGroupNode group = new VisualGroupNode("group");
    group.setName("Group 1");
    group.setHighSpectrumColor("red");
    group.setLowSpectrumColor("yellow");
    group.setType("group");
   
    VisualGroupElementNode soma = new VisualGroupElementNode("soma");
    soma.setDefaultColor("orange");
    PhysicalQuantity quantity = new PhysicalQuantity();
    quantity.setScalingFactor("ms");
    quantity.setValue(new DoubleValue(12));
    soma.setParameter(quantity);
   
    VisualGroupElementNode synapse = new VisualGroupElementNode("synapse");
    synapse.setDefaultColor("orange");
    PhysicalQuantity quantity2 = new PhysicalQuantity();
    quantity2.setScalingFactor("ms");
    quantity2.setValue(new DoubleValue(12));
    synapse.setParameter(quantity2);
   
    group.getVisualGroupElements().add(soma);
    group.getVisualGroupElements().add(synapse);
   
    visualization.addChild(group);
   
    SerializeTreeVisitor visitor = new SerializeTreeVisitor();
    runtime.apply(visitor);
    String serialized = visitor.getSerializedTree();
    System.out.println(serialized);

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonParser jp = new JsonParser();
View Full Code Here


  }
 
  @Test
  public void testConnection() {

    RuntimeTreeRoot runtime = new RuntimeTreeRoot("root");

    EntityNode hhcell = new EntityNode("hhcell");
   
    EntityNode purkinje = new EntityNode("purkinje");

    AspectNode electrical = new AspectNode("electrical");
    AspectNode electrical2 = new AspectNode("electrical");

    AspectSubTreeNode visualization = new AspectSubTreeNode(
        AspectTreeType.VISUALIZATION_TREE);

    SphereNode sphere = new SphereNode("purkinje");
    visualization.addChild(sphere);

    runtime.addChild(hhcell);
    runtime.addChild(purkinje);
    hhcell.getAspects().add(electrical);
    purkinje.getAspects().add(electrical2);
    electrical.setParent(hhcell);
    electrical2.setParent(purkinje);

    ConnectionNode con1 = new ConnectionNode("Connection_1");
    con1.setEntityInstancePath(hhcell.getInstancePath());
    con1.setType(ConnectionType.TO);
    con1.setParent(hhcell);
    con1.setName("Connection1");
    hhcell.getConnections().add(con1);
    VisualObjectReferenceNode visObj = new VisualObjectReferenceNode("Vis");
    visObj.setAspectInstancePath(electrical.getInstancePath());
    visObj.setVisualObjectId(sphere.getId());
    TextMetadataNode text = new TextMetadataNode("Text");
    text.setValue(new DoubleValue(2));
   
    URLMetadataNode url = new URLMetadataNode("URL");
    url.setValue(new DoubleValue(2));
    url.setURL("hhtp://url.com");
   
    FunctionNode function = new FunctionNode("Function");
    function.setExpression("x=y^2");
    function.setName("hello");
   
    con1.getCustomNodes().add(text);
    con1.getCustomNodes().add(url);
    con1.getCustomNodes().add(function);
    con1.getVisualReferences().add(visObj);
   
    ConnectionNode con2 = new ConnectionNode("Connection_2");
    con2.setEntityInstancePath(purkinje.getInstancePath());
    con2.setType(ConnectionType.FROM);
    con2.setParent(purkinje);
    purkinje.getConnections().add(con2);
   
    SerializeTreeVisitor visitor = new SerializeTreeVisitor();
    runtime.apply(visitor);
    String serialized = visitor.getSerializedTree();
    System.out.println(serialized);

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonParser jp = new JsonParser();
View Full Code Here

  }

  @Test
  public void testNetworks() {

    RuntimeTreeRoot runtimeTree = new RuntimeTreeRoot("RuntimeTree");

    EntityNode entity1 = new EntityNode("Entity1");
    EntityNode entity2 = new EntityNode("Entity2");
    EntityNode entity3 = new EntityNode("Entity3");

    AspectNode aspectA = new AspectNode("Aspect1");
    aspectA.setId("12");
    TestSimulator sim = new TestSimulator();
    aspectA.setSimulator(sim);
    TestModelInterpreter modelInt = new TestModelInterpreter();
    aspectA.setModelInterpreter(modelInt);

    AspectNode aspectB = new AspectNode("Aspect2");
    aspectA.setId("125");
    aspectA.setSimulator(sim);
    aspectA.setModelInterpreter(modelInt);

    AspectNode aspectC = new AspectNode("Aspect3");
    aspectB.setId("123");
    aspectB.setSimulator(sim);
    aspectB.setModelInterpreter(modelInt);

    AspectSubTreeNode model = new AspectSubTreeNode(
        AspectTreeType.MODEL_TREE);
    model.setModified(true);

    DynamicsSpecificationNode dynamics = new DynamicsSpecificationNode(
        "Dynamics");

    PhysicalQuantity value = new PhysicalQuantity();
    value.setScalingFactor("10");
    value.setUnit("ms");
    value.setValue(new DoubleValue(10));
    dynamics.setInitialConditions(value);

    FunctionNode function = new FunctionNode("Function");
    function.setExpression("y=x+2");
    List<String> argumentsF = new ArrayList<String>();
    argumentsF.add("1");
    argumentsF.add("2");
    function.setArgument(argumentsF);

    dynamics.setDynamics(function);

    ParameterSpecificationNode parameter = new ParameterSpecificationNode(
        "Parameter");

    PhysicalQuantity value1 = new PhysicalQuantity();
    value1.setScalingFactor("10");
    value1.setUnit("ms");
    value1.setValue(new DoubleValue(10));

    parameter.setValue(value1);

    FunctionNode functionNode = new FunctionNode("FunctionNode");
    functionNode.setExpression("y=x^2");
    List<String> arguments = new ArrayList<String>();
    arguments.add("1");
    functionNode.setArgument(arguments);

    AspectSubTreeNode visualization = new AspectSubTreeNode(
        AspectTreeType.VISUALIZATION_TREE);
    visualization.setModified(true);

    SphereNode sphere = new SphereNode("sphere");
    Point p = new Point();
    p.setX(new Double(3.3));
    p.setY(new Double(4));
    p.setZ(new Double(-1.444));
    sphere.setPosition(p);
    sphere.setRadius(new Double(33));

    CylinderNode cylinder = new CylinderNode("cylinder");
    Point p2 = new Point();
    p2.setX(new Double(6.3));
    p2.setY(new Double(8));
    p2.setZ(new Double(-3.999));
    cylinder.setPosition(p2);
    Point p3 = new Point();
    p3.setX(new Double(6.3));
    p3.setY(new Double(8));
    p3.setZ(new Double(-3.999));
    cylinder.setDistal(p3);
    cylinder.setRadiusBottom(new Double(34.55));
    cylinder.setRadiusTop(new Double(34.55));

    CylinderNode cylinder2 = new CylinderNode("cylinder");
    cylinder2.setPosition(p2);
    cylinder2.setDistal(p3);
    cylinder2.setRadiusBottom(new Double(34.55));
    cylinder2.setRadiusTop(new Double(34.55));

    CylinderNode cylinder3 = new CylinderNode("cylinder");
    cylinder3.setPosition(p2);
    cylinder3.setDistal(p3);
    cylinder3.setRadiusBottom(new Double(34.55));
    cylinder3.setRadiusTop(new Double(34.55));

    CylinderNode cylinder4 = new CylinderNode("cylinder");
    cylinder4.setPosition(p2);
    cylinder4.setDistal(p3);
    cylinder4.setRadiusBottom(new Double(34.55));
    cylinder4.setRadiusTop(new Double(34.55));

    CylinderNode cylinder5 = new CylinderNode("cylinder");
    cylinder5.setPosition(p2);
    cylinder5.setDistal(p3);
    cylinder5.setRadiusBottom(new Double(34.55));
    cylinder5.setRadiusTop(new Double(34.55));

    CompositeNode vg = new CompositeNode("vg");
    vg.addChild(sphere);
    vg.addChild(cylinder);
    vg.addChild(cylinder2);
    vg.addChild(cylinder3);
    vg.addChild(cylinder4);
    vg.addChild(cylinder5);

    CompositeNode vg2 = new CompositeNode("vg2");
    vg2.addChild(cylinder);
    vg2.addChild(cylinder2);
    vg2.addChild(cylinder3);
    vg2.addChild(cylinder4);
    vg2.addChild(cylinder5);
    vg2.addChild(sphere);

    AspectSubTreeNode simulation = new AspectSubTreeNode(
        AspectTreeType.WATCH_TREE);
    simulation.setModified(true);

    CompositeNode hhpop = new CompositeNode("hhpop[0]");

    VariableNode v = new VariableNode("v");
    PhysicalQuantity quantity = new PhysicalQuantity();
    quantity.setValue(ValuesFactory.getDoubleValue(20d));

    PhysicalQuantity quantity2 = new PhysicalQuantity();
    quantity2.setValue(ValuesFactory.getDoubleValue(100d));

    v.addPhysicalQuantity(quantity);
    v.addPhysicalQuantity(quantity2);

    ParameterNode a1 = new ParameterNode("a");

    runtimeTree.addChild(entity1);
    runtimeTree.addChild(entity2);
    entity1.addChild(entity2);
    entity2.addChild(entity3);
    entity2.getAspects().add(aspectB);
    entity1.getAspects().add(aspectA);
    entity3.getAspects().add(aspectC);
    aspectC.setParent(entity3);
    aspectB.setParent(entity2);
    aspectA.setParent(entity1);
    aspectA.addChild(model);
    model.addChild(parameter);
    model.addChild(dynamics);
    model.addChild(functionNode);
    model.setModified(false);
    AspectNode parentAspect = ((AspectNode) model.getParent());
    parentAspect.setModified(false);

    aspectA.addChild(visualization);
    visualization.addChild(vg);
    visualization.addChild(vg2);
    visualization.setModified(false);
    parentAspect = ((AspectNode) visualization.getParent());
    parentAspect.setModified(false);

    aspectA.addChild(simulation);
    simulation.addChild(hhpop);
    simulation.setModified(false);
    parentAspect = ((AspectNode) simulation.getParent());
    parentAspect.setModified(false);
    hhpop.addChild(v);
    hhpop.addChild(a1);

    SerializeTreeVisitor visitor = new SerializeTreeVisitor();
    runtimeTree.apply(visitor);
    String serialized = visitor.getSerializedTree();
    System.out.println(serialized);

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonParser jp = new JsonParser();
View Full Code Here

  }

  @Test
  public void testNetworksModifiedFlag() {

    RuntimeTreeRoot runtimeTree = new RuntimeTreeRoot("RuntimeTree");

    EntityNode entity1 = new EntityNode("Entity1");
    EntityNode entity2 = new EntityNode("Entity2");
    EntityNode entity3 = new EntityNode("Entity3");
    EntityNode entity4 = new EntityNode("Entity4");
    EntityNode entity5 = new EntityNode("Entity5");

    AspectNode aspectA = new AspectNode("Aspect1");
    aspectA.setId("12");
    TestSimulator sim = new TestSimulator();
    aspectA.setSimulator(sim);
    TestModelInterpreter modelInt = new TestModelInterpreter();
    aspectA.setModelInterpreter(modelInt);

    AspectNode aspectB = new AspectNode("Aspect2");
    aspectA.setId("125");
    aspectA.setSimulator(sim);
    aspectA.setModelInterpreter(modelInt);

    AspectNode aspectC = new AspectNode("Aspect3");
    aspectB.setId("123");
    aspectB.setSimulator(sim);
    aspectB.setModelInterpreter(modelInt);

    AspectSubTreeNode model = new AspectSubTreeNode(
        AspectTreeType.MODEL_TREE);
    model.setModified(true);

    DynamicsSpecificationNode dynamics = new DynamicsSpecificationNode(
        "Dynamics");

    PhysicalQuantity value = new PhysicalQuantity();
    value.setScalingFactor("10");
    value.setUnit("ms");
    value.setValue(new DoubleValue(10));
    dynamics.setInitialConditions(value);

    FunctionNode function = new FunctionNode("Function");
    function.setExpression("y=x+2");
    List<String> argumentsF = new ArrayList<String>();
    argumentsF.add("1");
    argumentsF.add("2");
    function.setArgument(argumentsF);

    dynamics.setDynamics(function);

    ParameterSpecificationNode parameter = new ParameterSpecificationNode(
        "Parameter");

    PhysicalQuantity value1 = new PhysicalQuantity();
    value1.setScalingFactor("10");
    value1.setUnit("ms");
    value1.setValue(new DoubleValue(10));

    parameter.setValue(value1);

    FunctionNode functionNode = new FunctionNode("FunctionNode");
    functionNode.setExpression("y=x^2");
    List<String> arguments = new ArrayList<String>();
    arguments.add("1");
    functionNode.setArgument(arguments);

    AspectSubTreeNode visualization = new AspectSubTreeNode(
        AspectTreeType.VISUALIZATION_TREE);
    visualization.setModified(true);

    SphereNode sphere = new SphereNode("sphere");
    Point p = new Point();
    p.setX(new Double(3.3));
    p.setY(new Double(4));
    p.setZ(new Double(-1.444));
    sphere.setPosition(p);
    sphere.setRadius(new Double(33));

    CylinderNode cylinder = new CylinderNode("cylinder");
    Point p2 = new Point();
    p2.setX(new Double(6.3));
    p2.setY(new Double(8));
    p2.setZ(new Double(-3.999));
    cylinder.setPosition(p2);
    Point p3 = new Point();
    p3.setX(new Double(6.3));
    p3.setY(new Double(8));
    p3.setZ(new Double(-3.999));
    cylinder.setDistal(p3);
    cylinder.setRadiusBottom(new Double(34.55));
    cylinder.setRadiusTop(new Double(34.55));

    CylinderNode cylinder2 = new CylinderNode("cylinder");
    cylinder2.setPosition(p2);
    cylinder2.setDistal(p3);
    cylinder2.setRadiusBottom(new Double(34.55));
    cylinder2.setRadiusTop(new Double(34.55));

    CylinderNode cylinder3 = new CylinderNode("cylinder");
    cylinder3.setPosition(p2);
    cylinder3.setDistal(p3);
    cylinder3.setRadiusBottom(new Double(34.55));
    cylinder3.setRadiusTop(new Double(34.55));

    CylinderNode cylinder4 = new CylinderNode("cylinder");
    cylinder4.setPosition(p2);
    cylinder4.setDistal(p3);
    cylinder4.setRadiusBottom(new Double(34.55));
    cylinder4.setRadiusTop(new Double(34.55));

    CylinderNode cylinder5 = new CylinderNode("cylinder");
    cylinder5.setPosition(p2);
    cylinder5.setDistal(p3);
    cylinder5.setRadiusBottom(new Double(34.55));
    cylinder5.setRadiusTop(new Double(34.55));

    CompositeNode vg = new CompositeNode("vg");
    vg.addChild(sphere);
    vg.addChild(cylinder);
    vg.addChild(cylinder2);
    vg.addChild(cylinder3);
    vg.addChild(cylinder4);
    vg.addChild(cylinder5);

    CompositeNode vg2 = new CompositeNode("vg2");
    vg2.addChild(cylinder);
    vg2.addChild(cylinder2);
    vg2.addChild(cylinder3);
    vg2.addChild(cylinder4);
    vg2.addChild(cylinder5);
    vg2.addChild(sphere);

    AspectSubTreeNode simulation = new AspectSubTreeNode(
        AspectTreeType.WATCH_TREE);
    simulation.setModified(true);

    CompositeNode hhpop = new CompositeNode("hhpop[0]");

    VariableNode v = new VariableNode("v");
    PhysicalQuantity quantity = new PhysicalQuantity();
    quantity.setValue(ValuesFactory.getDoubleValue(20d));

    PhysicalQuantity quantity2 = new PhysicalQuantity();
    quantity2.setValue(ValuesFactory.getDoubleValue(100d));

    v.addPhysicalQuantity(quantity);
    v.addPhysicalQuantity(quantity2);

    ParameterNode a1 = new ParameterNode("a");

    runtimeTree.addChild(entity1);
    runtimeTree.addChild(entity4);
    entity1.addChild(entity2);
    entity2.addChild(entity3);
    entity4.addChild(entity5);
    entity2.getAspects().add(aspectB);
    entity1.getAspects().add(aspectA);
    entity3.getAspects().add(aspectC);
    aspectC.setParent(entity3);
    aspectB.setParent(entity2);
    aspectA.setParent(entity1);
    aspectA.addChild(model);
    model.addChild(parameter);
    model.addChild(dynamics);
    model.addChild(functionNode);

    aspectA.addChild(visualization);
    visualization.addChild(vg);
    visualization.addChild(vg2);
    entity5.updateParentEntitiesFlags(true);

    aspectA.addChild(simulation);
    simulation.addChild(hhpop);
    hhpop.addChild(v);
    hhpop.addChild(a1);

    SerializeTreeVisitor visitor = new SerializeTreeVisitor();
    runtimeTree.apply(visitor);
    String serialized = visitor.getSerializedTree();
    System.out.println(serialized);

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonParser jp = new JsonParser();
View Full Code Here

  }

  @Test
  public void testNetworksModifiedFlag2() {

    RuntimeTreeRoot runtimeTree = new RuntimeTreeRoot("RuntimeTree");

    EntityNode entity1 = new EntityNode("Entity1");
    EntityNode entity2 = new EntityNode("Entity2");
    EntityNode entity3 = new EntityNode("Entity3");
    EntityNode entity4 = new EntityNode("Entity4");
    EntityNode entity5 = new EntityNode("Entity5");

    AspectNode aspectA = new AspectNode("Aspect1");
    aspectA.setId("12");
    TestSimulator sim = new TestSimulator();
    aspectA.setSimulator(sim);
    TestModelInterpreter modelInt = new TestModelInterpreter();
    aspectA.setModelInterpreter(modelInt);

    AspectNode aspectB = new AspectNode("Aspect2");
    aspectA.setId("125");
    aspectA.setSimulator(sim);
    aspectA.setModelInterpreter(modelInt);

    AspectNode aspectC = new AspectNode("Aspect3");
    aspectB.setId("123");
    aspectB.setSimulator(sim);
    aspectB.setModelInterpreter(modelInt);

    AspectSubTreeNode model = new AspectSubTreeNode(
        AspectTreeType.MODEL_TREE);
    model.setModified(true);

    DynamicsSpecificationNode dynamics = new DynamicsSpecificationNode(
        "Dynamics");

    PhysicalQuantity value = new PhysicalQuantity();
    value.setScalingFactor("10");
    value.setUnit("ms");
    value.setValue(new DoubleValue(10));
    dynamics.setInitialConditions(value);

    FunctionNode function = new FunctionNode("Function");
    function.setExpression("y=x+2");
    List<String> argumentsF = new ArrayList<String>();
    argumentsF.add("1");
    argumentsF.add("2");
    function.setArgument(argumentsF);

    dynamics.setDynamics(function);

    ParameterSpecificationNode parameter = new ParameterSpecificationNode(
        "Parameter");

    PhysicalQuantity value1 = new PhysicalQuantity();
    value1.setScalingFactor("10");
    value1.setUnit("ms");
    value1.setValue(new DoubleValue(10));

    parameter.setValue(value1);

    FunctionNode functionNode = new FunctionNode("FunctionNode");
    functionNode.setExpression("y=x^2");
    List<String> arguments = new ArrayList<String>();
    arguments.add("1");
    functionNode.setArgument(arguments);

    AspectSubTreeNode visualization = new AspectSubTreeNode(
        AspectTreeType.VISUALIZATION_TREE);
    visualization.setModified(true);

    SphereNode sphere = new SphereNode("sphere");
    Point p = new Point();
    p.setX(new Double(3.3));
    p.setY(new Double(4));
    p.setZ(new Double(-1.444));
    sphere.setPosition(p);
    sphere.setRadius(new Double(33));

    CylinderNode cylinder = new CylinderNode("cylinder");
    Point p2 = new Point();
    p2.setX(new Double(6.3));
    p2.setY(new Double(8));
    p2.setZ(new Double(-3.999));
    cylinder.setPosition(p2);
    Point p3 = new Point();
    p3.setX(new Double(6.3));
    p3.setY(new Double(8));
    p3.setZ(new Double(-3.999));
    cylinder.setDistal(p3);
    cylinder.setRadiusBottom(new Double(34.55));
    cylinder.setRadiusTop(new Double(34.55));

    CylinderNode cylinder2 = new CylinderNode("cylinder");
    cylinder2.setPosition(p2);
    cylinder2.setDistal(p3);
    cylinder2.setRadiusBottom(new Double(34.55));
    cylinder2.setRadiusTop(new Double(34.55));

    CylinderNode cylinder3 = new CylinderNode("cylinder");
    cylinder3.setPosition(p2);
    cylinder3.setDistal(p3);
    cylinder3.setRadiusBottom(new Double(34.55));
    cylinder3.setRadiusTop(new Double(34.55));

    CylinderNode cylinder4 = new CylinderNode("cylinder");
    cylinder4.setPosition(p2);
    cylinder4.setDistal(p3);
    cylinder4.setRadiusBottom(new Double(34.55));
    cylinder4.setRadiusTop(new Double(34.55));

    CylinderNode cylinder5 = new CylinderNode("cylinder");
    cylinder5.setPosition(p2);
    cylinder5.setDistal(p3);
    cylinder5.setRadiusBottom(new Double(34.55));
    cylinder5.setRadiusTop(new Double(34.55));

    CompositeNode vg = new CompositeNode("vg");
    vg.addChild(sphere);
    vg.addChild(cylinder);
    vg.addChild(cylinder2);
    vg.addChild(cylinder3);
    vg.addChild(cylinder4);
    vg.addChild(cylinder5);

    CompositeNode vg2 = new CompositeNode("vg2");
    vg2.addChild(cylinder);
    vg2.addChild(cylinder2);
    vg2.addChild(cylinder3);
    vg2.addChild(cylinder4);
    vg2.addChild(cylinder5);
    vg2.addChild(sphere);

    AspectSubTreeNode simulation = new AspectSubTreeNode(
        AspectTreeType.WATCH_TREE);
    simulation.setModified(true);

    CompositeNode hhpop = new CompositeNode("hhpop[0]");

    VariableNode v = new VariableNode("v");
    PhysicalQuantity quantity = new PhysicalQuantity();
    quantity.setValue(ValuesFactory.getDoubleValue(20d));

    PhysicalQuantity quantity2 = new PhysicalQuantity();
    quantity2.setValue(ValuesFactory.getDoubleValue(100d));

    v.addPhysicalQuantity(quantity);
    v.addPhysicalQuantity(quantity2);

    ParameterNode a1 = new ParameterNode("a");

    runtimeTree.addChild(entity1);
    runtimeTree.addChild(entity4);
    entity1.addChild(entity2);
    entity2.addChild(entity3);
    entity4.addChild(entity5);
    entity2.getAspects().add(aspectB);
    entity1.getAspects().add(aspectA);
    entity3.getAspects().add(aspectC);
    aspectC.setParent(entity3);
    aspectB.setParent(entity2);
    aspectA.setParent(entity1);
    aspectA.addChild(model);
    model.addChild(parameter);
    model.addChild(dynamics);
    model.addChild(functionNode);

    aspectA.addChild(visualization);
    visualization.addChild(vg);
    visualization.addChild(vg2);

    aspectA.setModified(true);
    aspectB.setModified(true);
    entity2.updateParentEntitiesFlags(true);
    entity5.updateParentEntitiesFlags(true);

    aspectA.addChild(simulation);
    simulation.addChild(hhpop);
    hhpop.addChild(v);
    hhpop.addChild(a1);

    SerializeTreeVisitor visitor = new SerializeTreeVisitor();
    runtimeTree.apply(visitor);
    String serialized = visitor.getSerializedTree();
    System.out.println(serialized);

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonParser jp = new JsonParser();
View Full Code Here

import com.google.gson.JsonParser;

public class TestTreeSerialization {
  @Test
  public void testTreeSerialization() {
    RuntimeTreeRoot runtime = new RuntimeTreeRoot("root");

    EntityNode entity_A = new EntityNode("Entity_A");

    AspectNode aspect_A = new AspectNode("Aspect_A");

    AspectSubTreeNode simulation = new AspectSubTreeNode(
        AspectTreeType.WATCH_TREE);

    VariableNode dummyNode = new VariableNode("dummyFloat");
    PhysicalQuantity quantity = new PhysicalQuantity();
    quantity.setValue(ValuesFactory.getDoubleValue(50d));
    dummyNode.addPhysicalQuantity(quantity);

    PhysicalQuantity quantity2 = new PhysicalQuantity();
    quantity2.setValue(ValuesFactory.getDoubleValue(100d));
    dummyNode.addPhysicalQuantity(quantity2);

    VariableNode anotherDummyNode = new VariableNode("dummyDouble");

    PhysicalQuantity quantity3 = new PhysicalQuantity();
    quantity3.setValue(ValuesFactory.getDoubleValue(20d));
    anotherDummyNode.addPhysicalQuantity(quantity3);

    PhysicalQuantity quantity4 = new PhysicalQuantity();
    quantity4.setValue(ValuesFactory.getDoubleValue(100d));
    anotherDummyNode.addPhysicalQuantity(quantity4);

    runtime.addChild(entity_A);
    entity_A.getAspects().add(aspect_A);
    aspect_A.setParent(entity_A);
    aspect_A.addChild(simulation);
    simulation.addChild(dummyNode);
    simulation.addChild(anotherDummyNode);

    simulation.setModified(true);
    aspect_A.setModified(true);
    entity_A.setModified(true);

    SerializeTreeVisitor visitor = new SerializeTreeVisitor();
    runtime.apply(visitor);
    String serialized = visitor.getSerializedTree();
    System.out.println(serialized);

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonParser jp = new JsonParser();
View Full Code Here

  }

  @Test
  public void testTreeWithUnits() {

    RuntimeTreeRoot runtime = new RuntimeTreeRoot("root");

    EntityNode entity_A = new EntityNode("Entity_A");

    AspectNode aspect_A = new AspectNode("Aspect_A");

    AspectSubTreeNode simulation = new AspectSubTreeNode(
        AspectTreeType.WATCH_TREE);

    AValue val = ValuesFactory.getDoubleValue(50d);
    AValue val2 = ValuesFactory.getDoubleValue(100d);

    PhysicalQuantity quantity = new PhysicalQuantity();
    quantity.setValue(val);
    quantity.setUnit("V");
    quantity.setScalingFactor("1.E3");

    PhysicalQuantity quantity2 = new PhysicalQuantity();
    quantity2.setValue(val2);
    quantity2.setScalingFactor("1.E3");
    quantity2.setUnit("V");

    VariableNode dummyNode = new VariableNode("dummyFloat");
    dummyNode.addPhysicalQuantity(quantity);
    dummyNode.addPhysicalQuantity(quantity2);

    VariableNode anotherDummyNode = new VariableNode("dummyDouble");

    AValue val3 = ValuesFactory.getDoubleValue(50d);
    AValue val4 = ValuesFactory.getDoubleValue(100d);

    PhysicalQuantity quantity3 = new PhysicalQuantity();
    quantity3.setValue(val3);
    quantity3.setUnit("mV");
    quantity3.setScalingFactor("1.E3");

    PhysicalQuantity quantity4 = new PhysicalQuantity();
    quantity4.setValue(val4);
    quantity4.setScalingFactor("1.E3");
    quantity4.setUnit("mV");

    anotherDummyNode.addPhysicalQuantity(quantity3);
    anotherDummyNode.addPhysicalQuantity(quantity4);

    runtime.addChild(entity_A);
    entity_A.getAspects().add(aspect_A);
    aspect_A.setParent(entity_A);
    aspect_A.addChild(simulation);
    simulation.addChild(dummyNode);
    simulation.addChild(anotherDummyNode);

    simulation.setModified(true);
    aspect_A.setModified(true);
    entity_A.setModified(true);

    SerializeTreeVisitor visitor = new SerializeTreeVisitor();
    runtime.apply(visitor);
    String serialized = visitor.getSerializedTree();
    System.out.println(serialized);

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonParser jp = new JsonParser();
View Full Code Here

  }

  @Test
  public void emulateJLemsSimulation() {

    RuntimeTreeRoot runtime = new RuntimeTreeRoot("root");

    EntityNode hhcell = new EntityNode("hhcell");

    AspectNode electrical = new AspectNode("electrical");

    AspectSubTreeNode visualization = new AspectSubTreeNode(
        AspectTreeType.VISUALIZATION_TREE);

    SphereNode sphere = new SphereNode("hhcell");
    visualization.addChild(sphere);

    AspectSubTreeNode simulation = new AspectSubTreeNode(
        AspectTreeType.WATCH_TREE);

    CompositeNode hhpop = new CompositeNode("hhpop[0]");
    CompositeNode bio = new CompositeNode("bioPhys1");
    CompositeNode membrane = new CompositeNode("membraneProperties");
    CompositeNode naChans = new CompositeNode("naChans");
    CompositeNode na = new CompositeNode("na");
    CompositeNode m = new CompositeNode("m");

    VariableNode v = new VariableNode("v");
    PhysicalQuantity quantity = new PhysicalQuantity();
    quantity.setValue(ValuesFactory.getDoubleValue(20d));

    PhysicalQuantity quantity2 = new PhysicalQuantity();
    quantity2.setValue(ValuesFactory.getDoubleValue(100d));

    VariableNode spiking = new VariableNode("spiking");

    VariableNode q = new VariableNode("q");

    v.addPhysicalQuantity(quantity);
    v.addPhysicalQuantity(quantity2);

    spiking.addPhysicalQuantity(quantity);
    q.addPhysicalQuantity(quantity);

    simulation.addChild(hhpop);
    hhpop.addChild(v);
    hhpop.addChild(spiking);
    hhpop.addChild(bio);
    bio.addChild(membrane);
    membrane.addChild(naChans);
    naChans.addChild(na);
    na.addChild(m);
    m.addChild(q);

    runtime.addChild(hhcell);
    hhcell.getAspects().add(electrical);
    electrical.setParent(hhcell);
    electrical.addChild(simulation);

    simulation.setModified(true);
    electrical.setModified(true);
    electrical.setModified(true);

    SerializeTreeVisitor visitor = new SerializeTreeVisitor();
    runtime.apply(visitor);
    String serialized = visitor.getSerializedTree();
    System.out.println(serialized);

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonParser jp = new JsonParser();
View Full Code Here

  }

  @Test
  public void emulateSmallLiquidSimulation() {

    RuntimeTreeRoot runtime = new RuntimeTreeRoot("root");

    EntityNode small = new EntityNode("small");

    AspectNode fluid = new AspectNode("fluid");

    AspectSubTreeNode visualization = new AspectSubTreeNode(
        AspectTreeType.VISUALIZATION_TREE);

    CompositeNode elastic = new CompositeNode("Elastic");
    CompositeNode liquid = new CompositeNode("Liquid");
    CompositeNode boundary = new CompositeNode("Boundary");

    ParticleNode p0 = new ParticleNode("p[0]");
    ParticleNode p1 = new ParticleNode("p[1]");
    ParticleNode p2 = new ParticleNode("p[2]");

    visualization.addChild(elastic);
    visualization.addChild(liquid);
    visualization.addChild(boundary);

    fluid.addChild(visualization);
    visualization.setModified(true);

    liquid.addChild(p0);
    liquid.addChild(p1);
    liquid.addChild(p2);

    AspectSubTreeNode simulation = new AspectSubTreeNode(
        AspectTreeType.WATCH_TREE);

    // CompositeNode dummyNode0 = new CompositeNode("particle[0]");
    CompositeNode particle = new CompositeNode("particle[1]");
    CompositeNode position = new CompositeNode("position");

    VariableNode anotherDummyNode0 = new VariableNode("v");
    PhysicalQuantity quantity = new PhysicalQuantity();
    quantity.setValue(ValuesFactory.getDoubleValue(20d));

    PhysicalQuantity quantity2 = new PhysicalQuantity();
    quantity2.setValue(ValuesFactory.getDoubleValue(100d));

    anotherDummyNode0.addPhysicalQuantity(quantity);
    anotherDummyNode0.addPhysicalQuantity(quantity2);

    VariableNode anotherDummyNode1 = new VariableNode("v");
    PhysicalQuantity quantity3 = new PhysicalQuantity();
    quantity3.setValue(ValuesFactory.getDoubleValue(55d));

    PhysicalQuantity quantity4 = new PhysicalQuantity();
    quantity4.setValue(ValuesFactory.getDoubleValue(65d));

    anotherDummyNode1.addPhysicalQuantity(quantity3);
    anotherDummyNode1.addPhysicalQuantity(quantity4);

    simulation.addChild(particle);
    particle.addChild(position);
    position.addChild(anotherDummyNode1);

    runtime.addChild(small);
    small.getAspects().add(fluid);
    fluid.setParent(small);
    fluid.addChild(simulation);

    simulation.setModified(true);
    fluid.setModified(true);
    small.updateParentEntitiesFlags(true);

    SerializeTreeVisitor visitor = new SerializeTreeVisitor();
    runtime.apply(visitor);
    String serialized = visitor.getSerializedTree();
    System.out.println(serialized);

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonParser jp = new JsonParser();
View Full Code Here

  /**
   * Skeleton tree test. One entity, one aspect, and all subtrees modified
   */
  @Test
  public void testSkeletonRuntimeTree() {
    RuntimeTreeRoot runtime = new RuntimeTreeRoot("root");

    EntityNode entity_A = new EntityNode("Entity_A");

    AspectNode aspect_A = new AspectNode("Aspect_A");

    AspectSubTreeNode model = new AspectSubTreeNode(
        AspectTreeType.MODEL_TREE);

    AspectSubTreeNode visualization = new AspectSubTreeNode(
        AspectTreeType.VISUALIZATION_TREE);

    AspectSubTreeNode simulation = new AspectSubTreeNode(
        AspectTreeType.WATCH_TREE);

    runtime.addChild(entity_A);
    entity_A.getAspects().add(aspect_A);
    entity_A.setModified(true);
    aspect_A.setParent(entity_A);
    aspect_A.setModified(true);
    aspect_A.addChild(model);
    aspect_A.addChild(visualization);
    aspect_A.addChild(simulation);

    SerializeTreeVisitor visitor = new SerializeTreeVisitor();
    runtime.apply(visitor);
    String serialized = visitor.getSerializedTree();
    System.out.println(serialized);

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonParser jp = new JsonParser();
View Full Code Here

TOP

Related Classes of org.geppetto.core.model.runtime.RuntimeTreeRoot

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.