private static void TestCuda() { var model = StructureGenerator.Generate3DFrameElementGrid(2, 2, 2); //model.Nodes[4].Constraints = model.Nodes[5].Constraints = model.Nodes[6].Constraints = Constraints.Fixed; //model.Nodes[7].Constraints = Constraint.FromString("011101"); var t = model.Nodes.Select(i => i.Constraints).ToArray(); StructureGenerator.AddRandomiseLoading(model, true, false, LoadCase.DefaultLoadCase); var config = new SolverConfiguration(); //config.SolverFactory = new CudaSolver.CuSparseDirectSpdSolverFactory(); config.LoadCases.AddRange(new List <LoadCase>() { LoadCase.DefaultLoadCase }); model.Solve_MPC(config); //model.Solve(config); //model.Solve(); var tmp = model.LastResult.Displacements.First().Value; }
public void DoTheBenchmark() { var sw = System.Diagnostics.Stopwatch.StartNew(); var st = GetCaseModel(); var case1 = new LoadCase("c1", LoadType.Other); var case2 = new LoadCase("c2", LoadType.Other); foreach (var nde in st.Nodes) { nde.Loads.Add(new NodalLoad(Util.GetRandomForce(), case1)); nde.Loads.Add(new NodalLoad(Util.GetRandomForce(), case2)); } var type = SolverType; var conf = new SolverConfiguration() { //SolverGenerator = i => CalcUtil.CreateBuiltInSolver(type, i), SolverFactory = CalcUtil.CreateBuiltInSolverFactory(type) }; GC.Collect(); Logger.Log(""); Logger.Log("\tSolver type: {0}", Util.GetEnumDescription(SolverType)); var listener = new Common.ConsoleTraceListener(); st.Trace.Listeners.Add(listener); try { st.Solve_MPC(conf); sw.Restart(); st.LastResult.AddAnalysisResultIfNotExists_MPC(case1); sw.Stop(); Logger.Log("\t\tgeneral solve time: {0}", sw.Elapsed); sw.Restart(); st.LastResult.AddAnalysisResultIfNotExists_MPC(case2); sw.Stop(); Logger.Log("\t\textra solve time per LoadCase: {0}", sw.Elapsed); } catch (Exception ex) { Logger.Log("\t\tFailed, err = {0}", ex.Message); } sw.Stop(); GC.Collect(); }
private static void TestIntelMkl() { var model = StructureGenerator.Generate3DBarElementGrid(1, 1, 2); //model.Nodes[4].Constraints = model.Nodes[5].Constraints = model.Nodes[6].Constraints = Constraints.Fixed; //model.Nodes[7].Constraints = Constraint.FromString("011101"); var t = model.Nodes.Select(i => i.Constraints).ToArray(); StructureGenerator.AddRandomiseLoading(model, true, false, LoadCase.DefaultLoadCase); var config = new SolverConfiguration(); config.SolverFactory = new IntelMklSolver.MklPardisoDirectSPDSolverFactory(); config.LoadCases = new List <LoadCase>() { LoadCase.DefaultLoadCase }; model.Solve_MPC(config); //model.Solve(config); //model.Solve(); var tmp = model.LastResult.Displacements.First().Value; }
public void DoTheBenchmark() { var sw = Stopwatch.StartNew(); var st = GetCaseModel(); var case1 = new LoadCase("c1", LoadType.Other); var case2 = new LoadCase("c2", LoadType.Other); foreach (var nde in st.Nodes) { nde.Loads.Add(new NodalLoad(Util.GetRandomForce(), case1)); nde.Loads.Add(new NodalLoad(Util.GetRandomForce(), case2)); } var type = SolverType; var conf = new SolverConfiguration { SolverGenerator = i => Util.CreateInternalSolver(type, i) }; GC.Collect(); Logger.Log(""); Logger.Log("\tSolver type: {0}", Util.GetEnumDescription(SolverType)); try { st.Solve(conf); sw.Restart(); st.LastResult.AddAnalysisResultIfNotExists(case1); sw.Stop(); Logger.Log("\t\tgeneral solve time: {0}", sw.Elapsed); sw.Restart(); st.LastResult.AddAnalysisResultIfNotExists(case2); sw.Stop(); Logger.Log("\t\textra solve time per LoadCase: {0}", sw.Elapsed); } catch (Exception ex) { Logger.Log("\t\tFailed, err = {0}", ex.Message); } sw.Stop(); GC.Collect(); }
public ISolverConfiguration Create( OPTANO.Modeling.Optimization.SolverConfiguration solverConfiguration) { ISolverConfiguration instance = null; try { instance = new SolverConfiguration( solverConfiguration); } catch (Exception exception) { this.Log.Error("Exception message: " + exception.Message + " and stacktrace " + exception.StackTrace); } return(instance); }
public ISolverConfiguration Create( OPTANO.Modeling.Optimization.SolverConfiguration solverConfiguration) { ISolverConfiguration instance = null; try { instance = new SolverConfiguration( solverConfiguration); } catch (Exception exception) { this.Log.Error( exception.Message, exception); } return(instance); }
private static void TestIntelMkl() { var oldPath = Environment.GetEnvironmentVariable("PATH"); var newPath = oldPath + @"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.0.124\windows\redist\intel64_win\mkl;"; Environment.SetEnvironmentVariable("PATH", newPath); //BriefFiniteElementNet.PardisoThing.test_pardiso.Main(null); return; var model = StructureGenerator.Generate3DBarElementGrid(1, 1, 2); //model.Nodes[4].Constraints = model.Nodes[5].Constraints = model.Nodes[6].Constraints = Constraints.Fixed; //model.Nodes[7].Constraints = Constraint.FromString("011101"); var t = model.Nodes.Select(i => i.Constraints).ToArray(); StructureGenerator.AddRandomiseLoading(model, true, false, LoadCase.DefaultLoadCase); var config = new SolverConfiguration(); //config.SolverFactory = new IntelMklSolver.MklPardisoDirectSPDSolverFactory(); config.LoadCases.AddRange(new List <LoadCase>() { LoadCase.DefaultLoadCase }); model.Solve_MPC(config); //model.Solve(config); //model.Solve(); var tmp = model.LastResult.Displacements.First().Value; }
public void Validate() { var code = Createf3DdInputFile(); var input = System.IO.Path.GetTempFileName(); var output = System.IO.Path.GetTempFileName(); System.IO.File.WriteAllText(input, code); var start = new System.Diagnostics.ProcessStartInfo(); start.Arguments = string.Format(@"""{0}"" ""{1}"" ", input, output); start.FileName = "frame3dd.exe"; start.RedirectStandardOutput = true; start.RedirectStandardError = true; start.UseShellExecute = false; if (!System.IO.File.Exists(start.FileName)) { Console.WriteLine(@"frame3dd.exe not found, please download it from http://master.dl.sourceforge.net/project/frame3dd/frame3dd/0.20091203/Frame3DD_20091203_win32.zip and place frame3dd.exe beside this application."); return; } using (var process = Process.Start(start)) { using (StreamReader reader = process.StandardOutput) { Frame3ddOutputMessage = reader.ReadToEnd(); } using (StreamReader reader = process.StandardError) { Frame3ddErrorMessage = reader.ReadToEnd(); } } if (!string.IsNullOrEmpty(Frame3ddErrorMessage)) { Console.WriteLine("Error message from Frame3dd.exe stderr: "); Console.WriteLine(Frame3ddErrorMessage); } var nodeLoadCases = model.Nodes.SelectMany(i => i.Loads).Select(i => i.Case).Distinct().ToList(); var elementLoadCases = model.Elements.SelectMany(i => i.Loads).Select(i => i.Case).Distinct().ToList(); var allCases = nodeLoadCases; allCases.AddRange(elementLoadCases); var cmb = new LoadCombination(); allCases.ForEach(i => cmb[i] = 1.0); //Process.Start(@"C:\Program Files (x86)\Notepad++\notepad++.exe", output); var cfg = new SolverConfiguration(); cfg.LoadCases = allCases; //cfg.SolverGenerator = i => new CholeskySolver(i); cfg.SolverFactory = new CholeskySolverFactory(); model.Solve(cfg); var disps = model.Nodes.Select(i => i.GetNodalDisplacement(cmb)).ToArray(); var f3ds = ReadF3dDisplacementVector(output); var myds = ReadMyDisplacementVector(cmb); var d = GetAbsDifference(f3ds, myds); //var dm = GetRelativeDifference(f3ds, myds).Max(); Console.WriteLine(""); Console.WriteLine("========== Absolute error in result from BFE against results from FRAME3DD application:"); var minError = d.Min(i => Math.Abs(i)); var avgnError = d.Average(i => Math.Abs(i)); var maxError = d.Max(i => Math.Abs(i)); Console.WriteLine(""); Console.WriteLine("--ABSOLUTE ERRORS "); Console.WriteLine("Min : {0} ({1:E})", minError, minError); Console.WriteLine("Average : {0} ({1:E})", avgnError, avgnError); Console.WriteLine("Max : {0} ({1:E})", maxError, maxError); var err = Enumerable.Range(0, f3ds.Length).Select(i => d[i] * Math.Max(Math.Abs(f3ds[i]), Math.Abs(myds[i]))).Sum() / Enumerable.Range(0, f3ds.Length).Select(i => Math.Max(Math.Abs(f3ds[i]), Math.Abs(myds[i]))).Sum(); Console.WriteLine(""); Console.WriteLine("--RELATIVE ERRORS "); Console.WriteLine("Average (regarding weight of values) : {0:0.00}% ({1:E})", err * 100, err); }
/// <summary> /// Gets the stiffness center of specified <see cref="element"/>. /// Stiffness center of rigid element. /// </summary> /// <param name="model"></param> /// <param name="element"></param> /// <returns>stiffness centers</returns> public Point[] GetCenters(Model model, RigidElement_MPC element, LoadCase loadCase) { //model = model.Clone(); var perm = CalcUtil.GenerateP_Delta_Mpc(model, loadCase, new Mathh.GaussRrefFinder()); var adj = GetAdjacencyGraph(perm.Item1); var dofGroups = CalcUtil.EnumerateGraphPartsAsGroups(adj); //var parts=CalcUtil. var cse_x = new LoadCase("tmp_case_x1", LoadType.Other); var stl = new VirtualConstraint(); stl.AppliedLoadCases.Add(cse_x); stl.Nodes.AddRange(element.Nodes); stl.Constraint = Constraints.Fixed; stl.Settlement = Displacement.Zero; model.MpcElements.Add(stl); var cnf = new SolverConfiguration(cse_x); cnf.SolverFactory = new CholeskySolverFactory(); model.Solve_MPC(cnf); var frc = Force.Zero; foreach (var node in stl.Nodes) { var force = node.GetTotalExternalForces(cse_x); frc += force.Move(node.Location, Point.Origins); } //move frc to a place without moment, only with force { var fx = frc.Fx; var fy = frc.Fy; var fz = frc.Fz; var mx = frc.Mx; var my = frc.My; var mz = frc.Mz; var fv = new Vector(fx, fy, fz); var mv = new Vector(-mx, -my, -mz); var f = new Matrix(4, 3); // TODO: MAT - set values directly f.SetRow(0, new double[] { 0, fz, -fy }); f.SetRow(1, new double[] { -fz, 0, fx }); f.SetRow(2, new double[] { fy, -fx, 0 }); f.SetRow(3, new double[] { fx, fy, fz }); var p0 = new Matrix(3, 4); p0[0, 1] = p0[1, 2] = p0[2, 3] = 1; var p1 = new Matrix(3, 4); p1[0, 0] = p1[1, 2] = p1[2, 3] = 1; var p2 = new Matrix(3, 4); p2[0, 0] = p2[1, 1] = p2[2, 3] = 1; var d0 = p0 * f; var d1 = p1 * f; var d2 = p2 * f; var det0 = d0.Det3x3(); var det1 = d1.Det3x3(); var det2 = d2.Det3x3(); var sols = new List <Vector>(); if (det0 != 0) { var sol0 = (d0.Inv3x3() * mv.ToMatrix()).ToVector(); sols.Add(sol0); } if (det1 != 0) { var sol1 = (d1.Inv3x3() * mv.ToMatrix()).ToVector(); sols.Add(sol1); } if (det2 != 0) { var sol2 = (d2.Inv3x3() * mv.ToMatrix()).ToVector(); sols.Add(sol2); } } throw new NotImplementedException(); }
private void openToolStripButton_Click(object sender, EventArgs e) { //Stream stream = null; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); openFileDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { try { var configuration = new SolverConfiguration <GeneticAlgorithmConfiguration>(); configuration.Path = openFileDialog.FileName; solver = new GeneticAlgorithm.GeneticAlgorithm(configuration.Configuration); //if ((stream = openFileDialog.OpenFile()) != null) //{ // using (stream) // { using (TextReader reader = File.OpenText(configuration.Configuration.File)) { outputFileName = string.Format("{0}_{1}.txt", configuration.Configuration.File.Replace(".dat", ""), DateTime.Now.Ticks); string text = reader.ReadLine(); string[] bits = text.Split(' '); int members = int.Parse(bits[0]); int relations = int.Parse(bits[1]); configuration.Configuration.PeopleNumber = members; relationships = new Dictionary <int, Dictionary <int, bool> >(); for (int i = 1; i <= members; i++) { relationships.Add(i, new Dictionary <int, bool>()); } for (int i = 0; i < relations; i++) { text = reader.ReadLine(); bits = text.Split(' '); int memberOne = int.Parse(bits[0]); int memberTwo = int.Parse(bits[1]); relationships[memberOne].Add(memberTwo, true); } solver.Relationships = relationships; startToolStripButton.Enabled = true; } // } //} } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } }