public string WholeSyntaxGenerator(SimulationConfig config) { string code = @" using System; using System.IO; using System.Runtime; using System.Collections.Generic; using CalcEngine; namespace Particles { public static class Simulation{ public static ulong Iteration; public static double StepTime, ActualTime; public static void Update(ulong iter, double sTime, double aTime){ Iteration = iter; StepTime = sTime; ActualTime = aTime; } } "; foreach (var p in config.particleBlueprints) { code += ClassSyntaxGenerator(p); } code += "}"; return(code); }
public MultipleSimulation(SimulationConfig C, SimulationState S, Emitter E, Writer W, ILogger L) { Config = C; State = S; Emitter = E; Writer = W; Logger = L; //Simulation = Sim; }
public SmallSimulation(SimulationConfig C, SimulationState S, Emitter E, Writer W) { Config = C; State = S; Emitter = E; Writer = W; for (int i = 0; i < Config.Threads; i++) { threads.Add(new Thread(CalculateParticle)); } }
public void testSeri() { ParticleBlueprint p1 = new ParticleBlueprint(); ParticleBlueprint p2 = new ParticleBlueprint(); p1.properties = new Dictionary <string, string>(); p1.methods = new Dictionary <string, string>(); p2.properties = new Dictionary <string, string>(); p2.methods = new Dictionary <string, string>(); p1.Name = "Point"; p1.Quantity = 1000; p1.properties.Add("position", "VectorD3"); p1.properties.Add("tposition", "VectorD3"); p1.properties.Add("mass", "double"); p1.methods.Add("Initialize()", "Random r = new Random(); position = new VectorD3(r.NextDouble() * 10, r.NextDouble() * 10, 0); mass = r.NextDouble(); tposition = new VectorD3(0,0,0);"); p1.methods.Add("Calculate(Point p)", "tposition += new VectorD3(1,2,3)"); p1.methods.Add("Calculate(Hole p)", "position += p.position"); p1.methods.Add("Update()", "position += tposition;"); p2.Name = "Hole"; p2.Quantity = 13; p2.properties.Add("position", "VectorD3"); p2.methods.Add("Initialize()", "Random r = new Random(); position = new VectorD3(r.NextDouble() * 10, r.NextDouble() * 10, 0);"); p2.methods.Add("Calculate(Point p)", ""); p2.methods.Add("Calculate(Hole p)", ""); SimulationConfig config = new SimulationConfig(); config.particleBlueprints = new List <ParticleBlueprint>() { p1, p2, }; //config.SimulationBoxSize = new VectorD3(5, 12, 20); //config.Threads = 128; string jsonString = JsonConvert.SerializeObject(config); Console.Write(jsonString); File.WriteAllText("PointSim.conig", jsonString); }
public Logger(SimulationConfig config, SimulationState state) { Config = config; State = state; DefaultPath = Path.GetFullPath(Config.OutputPath) + "\\SimLog.txt"; if (DefaultPath == null) { DefaultPath = ""; } loggerPath = DefaultPath; File.WriteAllText(loggerPath, "\t\t\tSIMULATION LOGGER(STANDARD)\n" + "\t\t\t--------------------------\n\n" + "\tDate: " + DateTime.Now.ToString() + "\n" + "\tHardware information:\n" + "\t\t- Machine name: " + Environment.MachineName + "\n\t\t- Real processor count: " + Environment.ProcessorCount + "\n\t\t- System: " + Environment.OSVersion.ToString() + "\n\tWirtual Assistent: false (function not implemented yet)" + "\n\tWirtual Assistent name: null" + "\n\n\n\tPath to simulation configuration file: " + Config.Path + "\n\tPath to Visualizer.exe: " + Config.PathToVisualiserEXE + "\n\tPath to output: " + Config.OutputPath); if (State.ErrorList.Count != 0) { string s = "\n\n\tThere were some loading error: \n"; foreach (var v in State.ErrorList) { s += "\t\t" + v.Message + "\n"; } File.AppendAllText(loggerPath, s); } }
public ConfigLoader(SimulationConfig Config, SimulationState State) { config = Config; state = State; }
public Test(SimulationConfig Config) { config = Config; }
static void Main(string[] args) { IServiceCollection services = new ServiceCollection(); ServiceHandler sh = new ServiceHandler(); ServiceProvider provider = sh.ConfigureServices(services); SimulationConfig config = provider.GetService <SimulationConfig>(); if (args.Length > 0) { if (Char.IsDigit(args[0][0])) { config.Port = Int32.Parse(args[0]); } else { config.Path = args[0]; provider.GetService <ConfigLoader>().Load(config.Path); } } //Folder preparation if (!provider.GetService <IFolderManager>().Create()) { Console.WriteLine("Folder creating error has occured:\n\t" + provider.GetService <SimulationState>().ErrorList.Last().Message); Environment.Exit(-1); } ISimulation simulation = provider.GetService <ISimulation>(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); simulation.Run(); stopWatch.Stop(); string time = TimeSpan.FromSeconds(stopWatch.ElapsedMilliseconds / 1000.0f).ToString(@"hh\:mm\:ss\:fff"); Console.WriteLine("\n\n\tElapsed Time: " + time); ulong pc = 0; foreach (var p in config.particleBlueprints) { pc += p.Quantity; } provider.GetRequiredService <ILogger>().Add("\n\n\n\tSimulation performed succesfully\n\n\t\tTotal particle count: " + pc + "\n\tElapsed Time: " + time); if (config.PathToVisualiserEXE != "") { var proc = Process.Start(config.PathToVisualiserEXE, Path.GetFullPath(config.Path) + " " + Path.GetFullPath(config.OutputPath)); } //var t = provider.GetService<Test>(); //t.testDeseri(); }
public Emitter(SimulationConfig Config, SimulationState State, ILogger Logger) { config = Config; state = State; logger = Logger; }
public Writer(SimulationConfig C, SimulationState S) { Config = C; State = S; }
public Simulation(SimulationConfig C, SimulationState S, Emitter E) { Config = C; State = S; Emitter = E; }
public MultipleFolderManager(SimulationConfig c, SimulationState s) { Config = c; State = s; }