]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Initial support. Added simulation tests for models in rootFiles
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 17 Mar 2014 14:02:27 +0000 (14:02 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 17 Mar 2014 14:02:27 +0000 (14:02 +0000)
refs #4766

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29141 ac1ea38d-2e2b-0410-8846-a27921b304fc

12 files changed:
org.simantics.sysdyn.tests/META-INF/MANIFEST.MF
org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scl/SCLTestScripts.java [new file with mode: 0644]
org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scl/SCLTests.java [new file with mode: 0644]
org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_DiscoveryAndExploitationOfResources.sts [new file with mode: 0644]
org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_GlobalCarbonCycle.sts [new file with mode: 0644]
org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_PredatorAndLimitedPrey.sts [new file with mode: 0644]
org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_ResourceExploitationUseRecycling.sts [new file with mode: 0644]
org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_TouristsEnvironmentsAndHotelFacilities.sts [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java
org.simantics.sysdyn/scl/Sysdyn.scl
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java

index 62fbacb3cea4eae841d1c01b3aa7a7560eb3a1c0..ff6e3bc51f00cf8b161e52fa6b5cba72558a6df7 100644 (file)
@@ -5,7 +5,8 @@ Bundle-SymbolicName: org.simantics.sysdyn.tests
 Bundle-Version: 1.0.0.qualifier
 Bundle-Activator: org.simantics.sysdyn.tests.Activator
 Require-Bundle: org.simantics.modelica;bundle-version="1.0.0",
- org.junit;bundle-version="4.8.2"
+ org.junit;bundle-version="4.8.2",
+ org.simantics.db.testing;bundle-version="1.0.0"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Import-Package: org.osgi.framework
diff --git a/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scl/SCLTestScripts.java b/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scl/SCLTestScripts.java
new file mode 100644 (file)
index 0000000..40755c9
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.sysdyn.tests.scl;\r
+\r
+import junit.runner.Version;\r
+\r
+import org.junit.Test;\r
+import org.simantics.db.testing.base.ScriptTestBase;\r
+\r
+public class SCLTestScripts extends ScriptTestBase {\r
+\r
+       public SCLTestScripts() {\r
+               super("../scripts");\r
+       System.out.println("JUnit version is: " + Version.id());\r
+       }\r
+\r
+    @Test public void ImportModel_DiscoveryAndExploitationOfResources() { test(300); }\r
+    @Test public void ImportModel_GlobalCarbonCycle() { test(300); }\r
+    @Test public void ImportModel_PredatorAndLimitedPrey() { test(300); }\r
+    @Test public void ImportModel_ResourceExploitationUseRecycling() { test(300); }\r
+    @Test public void ImportModel_TouristsEnvironmentsAndHotelFacilities() { test(300); }\r
+    \r
+}
\ No newline at end of file
diff --git a/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scl/SCLTests.java b/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scl/SCLTests.java
new file mode 100644 (file)
index 0000000..db9b75c
--- /dev/null
@@ -0,0 +1,24 @@
+package org.simantics.sysdyn.tests.scl;\r
+\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.junit.runners.Suite.SuiteClasses;\r
+import org.simantics.db.testing.common.RegressionSuiteRunner;\r
+\r
+@RunWith(RegressionSuiteRunner.class)\r
+@SuiteClasses({SCLTestScripts.class})\r
+\r
+public class SCLTests {\r
+\r
+       @BeforeClass\r
+    public static void setUp() {\r
+\r
+    }\r
+       \r
+       @Test\r
+       public static void asd() {\r
+               System.out.println("asd");\r
+       }\r
+       \r
+}\r
diff --git a/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_DiscoveryAndExploitationOfResources.sts b/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_DiscoveryAndExploitationOfResources.sts
new file mode 100644 (file)
index 0000000..e7e584f
--- /dev/null
@@ -0,0 +1,8 @@
+>import "File"\r
+>import "Simantics/Misc"\r
+>import "Simantics/Testing"\r
+>import "Simantics/Sysdyn"\r
+>m = importModel $ (getSystemProperty "scl.test.path")  + "/../../../../../../../org.simantics.sysdyn.feature/rootFiles/sampleModels/Discovery And Exploitation Of Resources.sysdyn"\r
+>exp = fromJust $ possibleResourceChild m "Experiment"\r
+>id = activateExperiment exp\r
+>run id\r
diff --git a/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_GlobalCarbonCycle.sts b/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_GlobalCarbonCycle.sts
new file mode 100644 (file)
index 0000000..d731bc9
--- /dev/null
@@ -0,0 +1,10 @@
+>import "File"\r
+>import "Simantics/Misc"\r
+>import "Simantics/Testing"\r
+>import "Simantics/Sysdyn"\r
+>m = importModel $ (getSystemProperty "scl.test.path")  + "/../../../../../../../org.simantics.sysdyn.feature/rootFiles/sampleModels/Global Carbon Cycle.sysdyn"\r
+>exp = fromJust $ possibleResourceChild m "Experiment"\r
+>id = activateExperiment exp\r
+>run id\r
+>withinEpsilon (lastValue exp id "/Carbon In Biosphere") 2710.604 0.001\r
+True
\ No newline at end of file
diff --git a/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_PredatorAndLimitedPrey.sts b/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_PredatorAndLimitedPrey.sts
new file mode 100644 (file)
index 0000000..4f754f6
--- /dev/null
@@ -0,0 +1,8 @@
+>import "File"\r
+>import "Simantics/Misc"\r
+>import "Simantics/Testing"\r
+>import "Simantics/Sysdyn"\r
+>m = importModel $ (getSystemProperty "scl.test.path")  + "/../../../../../../../org.simantics.sysdyn.feature/rootFiles/sampleModels/Predator And Limited Prey.sysdyn"\r
+>exp = fromJust $ possibleResourceChild m "Experiment"\r
+>id = activateExperiment exp\r
+>run id\r
diff --git a/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_ResourceExploitationUseRecycling.sts b/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_ResourceExploitationUseRecycling.sts
new file mode 100644 (file)
index 0000000..dca003e
--- /dev/null
@@ -0,0 +1,8 @@
+>import "File"\r
+>import "Simantics/Misc"\r
+>import "Simantics/Testing"\r
+>import "Simantics/Sysdyn"\r
+>m = importModel $ (getSystemProperty "scl.test.path")  + "/../../../../../../../org.simantics.sysdyn.feature/rootFiles/sampleModels/Resource Exploitation Use Recycling.sysdyn"\r
+>exp = fromJust $ possibleResourceChild m "Experiment"\r
+>id = activateExperiment exp\r
+>run id\r
diff --git a/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_TouristsEnvironmentsAndHotelFacilities.sts b/org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts/ImportModel_TouristsEnvironmentsAndHotelFacilities.sts
new file mode 100644 (file)
index 0000000..f77a497
--- /dev/null
@@ -0,0 +1,8 @@
+>import "File"\r
+>import "Simantics/Misc"\r
+>import "Simantics/Testing"\r
+>import "Simantics/Sysdyn"\r
+>m = importModel $ (getSystemProperty "scl.test.path")  + "/../../../../../../../org.simantics.sysdyn.feature/rootFiles/sampleModels/Tourists Environments And Hotel Facilities.sysdyn"\r
+>exp = fromJust $ possibleResourceChild m "Experiment"\r
+>id = activateExperiment exp\r
+>run id\r
index 41b8aaa6ba647975026d0a4f97ead2b87fda8f70..6756bb5ef99da7753b0ac1a32ddacce0347934db 100644 (file)
@@ -49,6 +49,7 @@ import org.simantics.sysdyn.SysdynResource;
 import org.simantics.sysdyn.ui.editor.SysdynEditorNamingService;\r
 import org.simantics.ui.workbench.IEditorNamingService;\r
 import org.simantics.utils.FileUtils;\r
+import org.simantics.utils.ui.BundleUtils;\r
 \r
 public class SysdynProject extends AbstractProjectFeature {\r
        private static final String DEFAULT_PERSPECTIVE = "org.simantics.sysdyn.ui.perspective";\r
@@ -58,6 +59,17 @@ public class SysdynProject extends AbstractProjectFeature {
                final IProject project = getProject();\r
                final Session session = getSession();\r
 \r
+               try {\r
+                       File base = BundleUtils.findFile("org.simantics.sysdyn.ui", "");\r
+                       File f = new File(base, "../org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts");\r
+                       if(f.exists()) {\r
+                               System.setProperty("scl.test.path", f.getAbsolutePath());\r
+                       }\r
+               } catch (Exception e) {\r
+                       \r
+               }\r
+               \r
+\r
                getProjectElement().setHint(ProjectKeys.DEFAULT_PERSPECTIVE, DEFAULT_PERSPECTIVE);\r
                \r
                // Multi for simupedia use\r
index 21010c105d866967b7fb25c57a9948b5bfbc7a6a..b32a845a27caa419680124c6a7f9c06563e0bb97 100644 (file)
@@ -1,3 +1,4 @@
+include "UI/Progress"\r
 include "Simantics/DB"\r
 include "Simantics/Variables"\r
 \r
@@ -84,8 +85,15 @@ importJava "org.simantics.sysdyn.utils.DocumentationUtils" where
     formatDate :: Long -> <ReadGraph> String \r
     \r
     @JavaName importModel\r
-    importModel :: String -> <Proc> ()\r
+    importModel :: String -> <Proc> Resource\r
     \r
     @JavaName isParameter\r
     isParameter :: Variable -> <ReadGraph> Boolean\r
+\r
+    lastValue :: Resource -> String -> String -> Double\r
+\r
+importJava "org.simantics.sysdyn.manager.SysdynExperiments" where\r
+    \r
+    activateExperiment :: Resource -> String\r
+    run :: String -> ()\r
     
\ No newline at end of file
index 9834ff5db5c7bc42f04efe38cab661769a777eca..71ea423e1d9563618e40bd0160a5b5f5fb0144a1 100644 (file)
@@ -24,10 +24,12 @@ public class ValueIndexVariable extends IndexVariable<double[]> {
            super(graph, parent, indexes);\r
        }\r
 \r
+       public static double[] UNRESOLVED = new double[0];\r
+       \r
        @Override\r
        public double[] getValue() {\r
            if(experiment == null)\r
-               return new double[0];\r
+               return UNRESOLVED;\r
 \r
         Collection<SysdynResult> results = experiment.getActiveResults();\r
                ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
@@ -43,7 +45,7 @@ public class ValueIndexVariable extends IndexVariable<double[]> {
                            if(ds != null && ds.values != null && ds.values.length > 0) {\r
                                result[i] =  ds.values[ds.values.length-1];\r
                            } else {\r
-                               result[i] = 0;\r
+                               return UNRESOLVED;\r
                            }\r
                        }\r
                    }\r
index 296c0ddd62e31401d45b06374d956a947711a365..b3e3960975acb0bd587829d36c53fa6bdf3cb2b8 100644 (file)
@@ -6,21 +6,30 @@ import java.util.Collections;
 import java.util.Comparator;\r
 import java.util.Date;\r
 import java.util.List;\r
+import java.util.concurrent.TimeUnit;\r
 \r
 import org.eclipse.core.runtime.NullProgressMonitor;\r
+import org.simantics.Simantics;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.databoard.util.Base64;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.request.ObjectsWithSupertype;\r
+import org.simantics.db.common.request.UniqueRead;\r
+import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.common.utils.ListUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.EvaluatingListener;\r
+import org.simantics.db.layer0.util.EvaluatingListener.Criterion;\r
+import org.simantics.db.layer0.util.EvaluatingListener.Evaluation;\r
 import org.simantics.db.layer0.variable.Variables;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.modeling.ModelingResources;\r
+import org.simantics.scl.runtime.function.FunctionImpl1;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.adapter.ValueIndexVariable;\r
 import org.simantics.sysdyn.manager.SysdynModel;\r
 import org.simantics.sysdyn.manager.SysdynModelManager;\r
 import org.simantics.sysdyn.representation.Book;\r
@@ -33,6 +42,7 @@ import org.simantics.sysdyn.representation.Stock;
 import org.simantics.sysdyn.representation.Variability;\r
 import org.simantics.sysdyn.representation.Variable;\r
 import org.simantics.sysdyn.utils.imports.ImportUtils;\r
+import org.simantics.utils.DataContainer;\r
 \r
 public class DocumentationUtils {\r
     \r
@@ -469,8 +479,18 @@ public class DocumentationUtils {
      * \r
      * @param path\r
      */\r
-    public static void importModel(String path) {\r
-        ImportUtils.importModelFile(path, new NullProgressMonitor());\r
+    public static Resource importModel(String path) {\r
+       final DataContainer<Resource> m = new DataContainer<Resource>();\r
+        ImportUtils.importModelFile(path, new NullProgressMonitor(), new FunctionImpl1<Resource,WriteRequest>() {\r
+\r
+               @Override\r
+               public WriteRequest apply(Resource model) {\r
+                       m.set(model);\r
+                       return null;\r
+               }\r
+               \r
+        });\r
+        return m.get();\r
     }\r
 \r
     public static boolean isParameter(ReadGraph graph, org.simantics.db.layer0.variable.Variable variable) throws DatabaseException {\r
@@ -492,4 +512,43 @@ public class DocumentationUtils {
         Resource expression = expressions.get(0);\r
         return graph.isInstanceOf(expression, SR.ParameterExpression);\r
     }\r
+    \r
+    public static double lastValue(final Resource experiment, final String runId, final String path) throws DatabaseException {\r
+       \r
+               try {\r
+                       double[] values = EvaluatingListener.<double[]>trySyncRequest(Simantics.getSession(),\r
+                                       \r
+                                       new UniqueRead<double[]>(){\r
+                                               @SuppressWarnings("unchecked")\r
+                                               @Override\r
+                                               public double[] perform(ReadGraph graph) throws DatabaseException{\r
+                                                       \r
+                                               org.simantics.db.layer0.variable.Variable var = Variables.getVariable(graph, experiment);\r
+                                               if(var == null) return null;\r
+                                               org.simantics.db.layer0.variable.Variable run = var.getPossibleChild(graph, runId);\r
+                                               if(run == null) return null;\r
+                                               org.simantics.db.layer0.variable.Variable v = run.browsePossible(graph, path + "#value#");\r
+                                               if(v == null) return null;\r
+                                               return  v.getPossibleValue(graph);\r
+                                                       \r
+                                               }               \r
+                                       }, \r
+                                       new Criterion<double[]>() {\r
+\r
+                                               @Override\r
+                                               public Evaluation evaluate(double[] result) {\r
+                                                       if(result == null) return Evaluation.DISCARD;\r
+                                                       return (result != ValueIndexVariable.UNRESOLVED) ? Evaluation.ACCEPT : Evaluation.IGNORE;\r
+                                               }\r
+                                               \r
+                                       },\r
+                                       15, TimeUnit.SECONDS);\r
+                       return values[0];\r
+               } catch (InterruptedException e) {\r
+                       e.printStackTrace();\r
+                       return Double.NaN;\r
+               }\r
+       \r
+    }\r
+    \r
 }\r