Exemplo n.º 1
0
        public void RunMikeSheDataAssimilation()
        {
            string modelConfigDir = @"c:\devel_nils\Test_5x5\Distributed\base\";
            string modelconfigOmi = "MIKESHE_WM_Test_5x5.omi";

            string odaConfigDir = @"C:\devel_nils\Test_5x5\";
            string odaFileName  = "EnKF_test1.oda";

            MikeSheOpenMIModelFactory mikeSheOpenMIModelFactory = new MikeSheOpenMIModelFactory();

            mikeSheOpenMIModelFactory.Initialize(modelConfigDir, new[] { modelconfigOmi });

            OpenDA.DotNet.OpenMI.Bridge.ModelFactory.InsertModelFactory(mikeSheOpenMIModelFactory);

            ModelFactory openDaModelFactory = new ModelFactory();

            openDaModelFactory.Initialize(null, null);

            //IModelInstance modelInstance = openDaModelFactory.GetInstance(new string[] { }, outputLevel: 0);

            ApplicationRunnerSingleThreaded applicationRunner = new ApplicationRunnerSingleThreaded();

            applicationRunner.initialization(new File(odaConfigDir), odaFileName, true);
            //old? applicationRunner.runSingleThreaded();
        }
Exemplo n.º 2
0
        public void RunMikeSheSimulationFromOpenDaConfig()
        {
            MikeSheOpenMIModelFactory mikeSheOpenMIModelFactory = new MikeSheOpenMIModelFactory();

            OpenDA.DotNet.OpenMI.Bridge.ModelFactory.InsertModelFactory(mikeSheOpenMIModelFactory);

            string odaDirectoryPath = "../../testData";
            string odaFileName      = "MikeSimulation.oda";

            ApplicationRunnerSingleThreaded applicationRunner = new ApplicationRunnerSingleThreaded();

            applicationRunner.initialization(new java.io.File(odaDirectoryPath), odaFileName, true);
            //old applicationRunner.runSingleThreaded();
        }
Exemplo n.º 3
0
 public void RunDummyModelSimulation()
 {
     try
     {
         DotNet.Bridge.ModelFactory.InsertModelFactory(new ModelFactory());
         ApplicationRunnerSingleThreaded applicationRunner = new ApplicationRunnerSingleThreaded();
         applicationRunner.initialize(new java.io.File("."), @"..\..\testData\dummyModel\DummyModelSimulation.oda");
         applicationRunner.runSingleThreaded();
     }
     catch (Exception e)
     {
         // TEST NOT COMPLETE YET
     }
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            System.Console.WriteLine(Directory.GetCurrentDirectory());
            string mikeSheConfigFile = "";
            string odaDirectoryPath  = "";
            string odaFileName       = "";

            // Args Requires 2 fields:
            // 1) the MikeSHEConfig.txt
            // 2) the .oda file
            if (args[0] != null && args[1] != null)
            {
                // CHECK if files exist using Relative Paths.
                string currentDirectory = System.IO.Directory.GetCurrentDirectory();



                //string arg1 = currentDirectory + args[0];
                //string arg2 = currentDirectory + args[1];

                // Make full paths in case we are using a relative path
                Uri uri1, uri2;
                if (args[0].Substring(1, 1).Equals(":"))
                {
                    uri1 = new Uri(args[0]);
                }
                else
                {
                    uri1 = new Uri(Path.Combine(currentDirectory, args[0]));
                }
                if (args[1].Substring(1, 1).Equals(":"))
                {
                    uri2 = new Uri(args[1]);
                }
                else
                {
                    uri2 = new Uri(Path.Combine(currentDirectory, args[1]));
                }
                string file1 = Path.GetFullPath(uri1.AbsolutePath);
                string file2 = Path.GetFullPath(uri2.AbsolutePath);

                // IF RELATIVE PATHS
                if (System.IO.File.Exists(file1) && System.IO.File.Exists(file2))
                {
                    mikeSheConfigFile = file1;
                    odaFileName       = System.IO.Path.GetFileName(file2);
                    odaDirectoryPath  = System.IO.Path.GetDirectoryName(file2);
                }
                // ELSE IF ABSOLUTE PATHS
                else if (System.IO.File.Exists(args[0]) && System.IO.File.Exists(args[2]))
                {
                    mikeSheConfigFile = args[0];
                    odaFileName       = System.IO.Path.GetFileName(args[1]);
                    odaDirectoryPath  = System.IO.Path.GetDirectoryName(args[1]);
                }
                else
                {
                    throw new System.IO.FileNotFoundException(" One or more of the files were not found \n" + args[0] +
                                                              "\n" + args[1]);
                }
            }
            else
            {
                // Args Requires 2 fields:
                // 1) the MikeSHEConfig.txt
                // 2) the .oda file
                System.Console.WriteLine("Takes two args 1) the mikeSHEConfig.txt   and   2) the OpenDA  .oda file.\n");
            }


            MikeSheOpenMIModelFactory mikeSheOpenMIModelFactory = new MikeSheOpenMIModelFactory();

            mikeSheOpenMIModelFactory.Initialize(Path.GetDirectoryName(mikeSheConfigFile), new[] { Path.GetFileName(mikeSheConfigFile) });

            OpenDA.DotNet.OpenMI.Bridge.ModelFactory.InsertModelFactory(mikeSheOpenMIModelFactory);

            ModelFactory openDaModelFactory = new ModelFactory();

            openDaModelFactory.Initialize(null, null);
            ApplicationRunnerSingleThreaded applicationRunner = new ApplicationRunnerSingleThreaded();

            //OLD? applicationRunner.initialize(new java.io.File(odaDirectoryPath), odaFileName);
            applicationRunner.initialization(new java.io.File(odaDirectoryPath), odaFileName, true);

            //OLD? applicationRunner.runSingleThreaded();

            System.Console.WriteLine("Done. Hit a key!");
            System.Console.ReadKey();
        }
Exemplo n.º 5
0
        public void RunApplication(IModelFactory dotNetModelFactory)
        {
            if (dotNetModelFactory != null)
            {
                // Tell OpenDA what model factory to use
                ModelFactory.InsertModelFactory(dotNetModelFactory);
            }
            // run the openda application
            ApplicationRunnerSingleThreaded applicationRunner;

            try
            {
                applicationRunner = new ApplicationRunnerSingleThreaded();
                applicationRunner.initialize(new java.io.File(odaDirectoryName), odaFileName);
                applicationRunner.runSingleThreaded();
            }
            catch (Exception e)
            {
                String message = "Error running OpenDA application.\nDetailed error message: " + e.Message;
                ModelFactory.AppendLogMessage(message);
                Console.WriteLine(message);
                return;
            }

            if (true)             // TODO: applicationRunner.getStatus()== ApplicationRunnerJ2N.Status.FINISHED // DONE)
            {
                // get a reference to the model instance selected by the algorithm as optimal

                IAlgorithm          algorithm = applicationRunner.getAlgorithm();
                IStochModelInstance calibratedStochModel;
                if (algorithm is Dud)
                {
                    Dud dud = ((Dud)algorithm);
                    calibratedStochModel = dud.getBestEstimate();
                }
                else if (algorithm is SparseDud)
                {
                    SparseDud sparseDud = ((SparseDud)algorithm);
                    calibratedStochModel = sparseDud.getBestEstimate();
                }
                else if (algorithm is Powell)
                {
                    Powell powell = ((Powell)algorithm);
                    calibratedStochModel = powell.getBestEstimate();
                }
                else if (algorithm is Simplex)
                {
                    Simplex simplex = ((Simplex)algorithm);
                    calibratedStochModel = simplex.getBestEstimate();
                }
                else if (algorithm is AbstractSequentialAlgorithm)
                {
                    AbstractSequentialAlgorithm asAlgorithm = ((AbstractSequentialAlgorithm)algorithm);
                    calibratedStochModel = asAlgorithm.getMainModel();
                    if (calibratedStochModel == null)
                    {
                        Console.WriteLine("No main model set by ensemble algorithm");
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("Unknown Algoritm type: " + algorithm.GetType());
                    return;
                }

                // Get the model instance out of the stochModel->java2dotnet->modelInstance layers
                if (calibratedStochModel is BBStochModelInstance)
                {
                    org.openda.interfaces.IModelInstance modelInstance = ((BBStochModelInstance)calibratedStochModel).getModel();
                    if (modelInstance is ModelInstanceN2J)
                    {
                        ResultingModelInstance = ((ModelInstanceN2J)modelInstance).getDotNetModelInstance();
                    }
                    else
                    {
                        string message = "Unknown java 2 dotnet model instance type: " + modelInstance.GetType();
                        ModelFactory.AppendLogMessage(message);
                        Console.WriteLine(message);
                    }
                }
                else
                {
                    string message = "Unknown Stoch model instance type: " + calibratedStochModel.GetType();
                    ModelFactory.AppendLogMessage(message);
                    Console.WriteLine(message);
                }
            }
        }