public void LogLineShouldNotLogAnything() { ILogger logger = new NoLogger(); logger.LogLine("test"); Assert.AreEqual(string.Empty, logger.ToString()); }
private void InitializeProjections(int httpPort) { var logger = new NoLogger(); var endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), httpPort); var pm = new ProjectionsManager(logger, endpoint, TimeSpan.FromSeconds(2)); Tags.ForEach(async tag => { var source = ReadTaggedProjectionSource(tag); await pm.CreateContinuousAsync(tag, source, new UserCredentials("admin", "changeit")); }); }
static void LoktaVolterraHardoded() { var logger = new NoLogger(); var model = new DAEProblem(); var integrator = new ExplicitEuler(); integrator.StepSize = 0.1; integrator.EndTime = 200; var N1 = new Variable("N1", 5); var N2 = new Variable("N2", 10); var dN1 = new Variable("dN1dt", 0); var dN2 = new Variable("dN2dt", 0); var e1 = new Variable("e1", 0.09); var g1 = new Variable("g1", 0.01); var e2 = new Variable("e2", 0.04); var g2 = new Variable("g2", 0.01); var eq1 = new Equation(N1 * (e1 - g1 * N2) - dN1); var eq2 = new Equation(-N2 * (e2 - g2 * N1) - dN2); model.AlgebraicVariables.Add(N1); model.AlgebraicVariables.Add(N2); model.DifferentialVariables.Add(dN1); model.DifferentialVariables.Add(dN2); model.Equations.Add(eq1); model.Equations.Add(eq2); model.Mapping.Add(dN1, N1); model.Mapping.Add(dN2, N2); model.Initialize(new NoLogger()); var results = integrator.Integrate(model, logger); using (var sw = new StreamWriter(Environment.CurrentDirectory + "\\results.csv")) { sw.WriteLine("time;" + string.Join("; ", model.AlgebraicVariables.Select(v => v.Name))); foreach (var result in results) { sw.WriteLine(result.ToString()); } } }
static void LotkaVolterraParsed() { string input = @"class LotkaVolterra Real N1 = 10; Real N2 = 5; parameter Real e1 = 0.09; parameter Real g1 = 0.01; parameter Real e2 = 0.04; parameter Real g2 = 0.01; equation der(N1) = N1*(e1-g1*N2); der(N2) = -N2*(e2-g2*N1); end LotkaVolterra; "; var parser = new ModelicaParser(); var printer = new ModelicaTreePrinter(); var translator = new ModelTranslatorV1(); var status = parser.TryParseProgram(input, out var prog, out var error, out var position); if (status) { var ast = printer.Transform(prog); // Console.WriteLine(ast); var logger = new NoLogger(); var model = translator.Translate(prog.ClassDefinitions.Last()); var integrator = new ExplicitEuler(); integrator.Discretize(model); integrator.StepSize = 1; integrator.EndTime = 800; model.Initialize(new NoLogger()); Stopwatch w = new Stopwatch(); w.Start(); var results = integrator.Integrate(model, logger); w.Stop(); Console.WriteLine("Integration took " + w.ElapsedMilliseconds + "ms"); using (var sw = new StreamWriter(Environment.CurrentDirectory + "\\results.csv")) { sw.WriteLine("time;" + string.Join("; ", model.AlgebraicVariables.Select(v => v.Name))); foreach (var result in results) { sw.WriteLine(result.ToString()); // Console.WriteLine(result.ToString()); } } } else { Console.WriteLine(error); } //} //catch (Exception e) //{ // Console.WriteLine(e.Message); //} }
void Test(ModelicaTestElement node) { if (node.ElementType == ModelicaTestElementType.Folder) { foreach (var child in node.Children) { Test(child); } node.TotalSubelements = node.Children.Sum(n => n.TotalSubelements); if (node.Children.Count > 0 && node.TotalSubelements > 0) { node.PercentParsed = node.Children.Sum(n => n.PercentParsed * n.TotalSubelements) / node.TotalSubelements; node.PercentTranslated = node.Children.Sum(n => n.PercentTranslated * n.TotalSubelements) / node.TotalSubelements; node.PercentSolved = node.Children.Sum(n => n.PercentSolved * n.TotalSubelements) / node.TotalSubelements; } else { node.PercentParsed = 1.0; node.PercentTranslated = 1.0; node.PercentSolved = 1.0; } } else { node.TotalSubelements = 1; var input = File.ReadAllText(node.Path); var parser = new ModelicaParser(); try { var status = parser.TryParseProgram(input, out var prog, out var error, out var position); if (status) { node.PercentParsed = 1.0; var translator = new ModelTranslatorV1(); var model = translator.Translate(prog.ClassDefinitions.Last()); node.PercentTranslated = 1.0; var integrator = new ImplicitEuler(); integrator.StepSize = 0.1; integrator.EndTime = 0.1; var logger = new NoLogger(); integrator.Discretize(model); model.Initialize(logger); var results = integrator.Integrate(model, logger); node.PercentSolved = 1.0; } else { Console.WriteLine($"Error parsing file {node.Path}"); Console.WriteLine(error); Console.WriteLine(); } } catch (Exception e) { Console.WriteLine(e.Message); } } }
public bool Simulate(string sourceCode) { var status = parser.TryParseProgram(sourceCode, out var prog, out var error, out var position); if (status) { var translator = new ModelTranslatorV1(); var flattening = new Flattening(); var ast = prog.ClassDefinitions.Last(); var instance = flattening.Transform(ast); DAEProblem model = null; try { model = translator.Translate(instance); } catch (Exception e) { _eventAggregator.PublishOnUIThreadAsync(new UpdateSolverStatusMessage($"{e.Message}", SolverStatus.Error)); } var integrator = createIntegratorFromAnnotation(ast); integrator.StepSize = 0.1; integrator.EndTime = 1; integrator.OnIteration += (i) => OnIteration(integrator, i); updateIntegratorSettings(ast, integrator); var logger = new NoLogger(); try { integrator.Discretize(model); model.Initialize(logger); } catch (Exception e) { _eventAggregator.PublishOnUIThreadAsync(new UpdateSolverStatusMessage($"{e.Message}", SolverStatus.Error)); return(false); } if (model.SystemToSolve.NumberOfEquations != model.SystemToSolve.NumberOfVariables) { _eventAggregator.PublishOnUIThreadAsync(new UpdateSolverStatusMessage($"System not square! V={model.SystemToSolve.NumberOfVariables}, E={model.SystemToSolve.NumberOfEquations}", SolverStatus.Error)); return(false); } Stopwatch w = new Stopwatch(); _eventAggregator.PublishOnUIThreadAsync(new UpdateSolverStatusMessage("Integration started", SolverStatus.Busy)); try { w.Start(); var results = integrator.Integrate(model, logger); w.Stop(); Console.WriteLine("Integration took " + w.ElapsedMilliseconds + "ms"); _eventAggregator.PublishOnUIThreadAsync(new UpdateModelResultMessage() { ModelName = model.Name, AlgebraicStates = model.AlgebraicVariables, DifferentialStates = model.DifferentialVariables, TimeSteps = results }); _eventAggregator.PublishOnUIThreadAsync(new UpdateSolverStatusMessage($"Integration finished ({w.ElapsedMilliseconds} ms)", SolverStatus.OK)); } catch (Exception e) { _eventAggregator.PublishOnUIThreadAsync(new UpdateSolverStatusMessage($"{e.Message}", SolverStatus.Error)); return(false); } } else { _eventAggregator.PublishOnUIThreadAsync(new UpdateSolverStatusMessage(error, SolverStatus.Error)); } return(true); }