|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Globalization; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using BriefFiniteElementNet.Common; |
| 8 | +using BriefFiniteElementNet.Elements; |
| 9 | +using BriefFiniteElementNet.MpcElements; |
| 10 | +using HtmlTags; |
| 11 | + |
| 12 | +namespace BriefFiniteElementNet.Validation.Case_05 |
| 13 | +{ |
| 14 | + [ValidationCase("Console beam with tetrahedron", typeof(RigidElement_MPC))] |
| 15 | + public class Validator : IValidationCase |
| 16 | + { |
| 17 | + public ValidationResult Validate() |
| 18 | + { |
| 19 | + var model = StructureGenerator.Generate3DTetrahedralElementGrid(2, 2, 50); |
| 20 | + |
| 21 | + RigidElement_MPC mpc; |
| 22 | + |
| 23 | + { |
| 24 | + var e = 210e9; |
| 25 | + |
| 26 | + |
| 27 | + foreach (var elm in model.Elements) |
| 28 | + { |
| 29 | + if (elm is TetrahedronElement) |
| 30 | + { |
| 31 | + var tet = elm as TetrahedronElement; |
| 32 | + |
| 33 | + tet.Material = new Materials.UniformIsotropicMaterial(e, 0.25); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + var dx = model.Nodes.Max(i => i.Location.X) - model.Nodes.Min(i => i.Location.X); |
| 38 | + var dy = model.Nodes.Max(i => i.Location.Y) - model.Nodes.Min(i => i.Location.Y); |
| 39 | + var dz = model.Nodes.Max(i => i.Location.Z) - model.Nodes.Min(i => i.Location.Z); |
| 40 | + |
| 41 | + var l = dz;// model.Nodes.Max(i => i.Location.Z); |
| 42 | + |
| 43 | + var cnt = model.Nodes.Where(i => i.Location.Z == l); |
| 44 | + |
| 45 | + var f = 1e7; |
| 46 | + var I = dy * dx * dx * dx / 12; |
| 47 | + var rigid = mpc = new MpcElements.RigidElement_MPC() {UseForAllLoads = true}; |
| 48 | + |
| 49 | + foreach (var node in cnt) |
| 50 | + { |
| 51 | + node.Loads.Add(new NodalLoad(new Force(f / cnt.Count(), 0, 0, 0, 0, 0))); |
| 52 | + rigid.Nodes.Add(node); |
| 53 | + } |
| 54 | + |
| 55 | + model.MpcElements.Add(rigid); |
| 56 | + model.Trace.Listeners.Add(new ConsoleTraceListener()); |
| 57 | + model.Solve_MPC(); |
| 58 | + |
| 59 | + |
| 60 | + var delta = f * l * l * l / (3 * e * I); |
| 61 | + |
| 62 | + var t = cnt.FirstOrDefault().GetNodalDisplacement(); |
| 63 | + |
| 64 | + var ratio = delta / t.DX; |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | + { |
| 69 | + var span = new HtmlTag("span"); |
| 70 | + span.Add("p").Text("Validation of rigid element"); |
| 71 | + span.Add("paragraph").Text("The rigid element connects different nodes through non-deformable elements. "); |
| 72 | + span.Add("h3").Text("Model Definition"); |
| 73 | + |
| 74 | + span.Add("paragraph").Text(string.Format(CultureInfo.CurrentCulture, "A console beam with tetrahedron, at the end (tip of console) nodes are connected with a rigid element.")).AddClosedTag("br"); |
| 75 | + |
| 76 | + span.Add("paragraph").Text("The start of beam is totally fixed in the 3D space.").AddClosedTag("br"); |
| 77 | + span.Add("paragraph").Text("The end of beam is loaded with a vertical load.").AddClosedTag("br"); |
| 78 | + span.Add("paragraph").Text("All nodes connected to rigid element should have a rigid body displacement.").AddClosedTag("br"); |
| 79 | + |
| 80 | + var mpcNodes = mpc.Nodes.ToArray(); |
| 81 | + |
| 82 | + var disps = mpcNodes.Select(i => Tuple.Create(i.Location, i.GetNodalDisplacement())); |
| 83 | + |
| 84 | + |
| 85 | + span.Add("h3").Text("Validation Result"); |
| 86 | + |
| 87 | + if (disps.Any(i => double.IsNaN(i.Item2.DX)|| double.IsNaN(i.Item2.DY)|| double.IsNaN(i.Item2.DZ)|| double.IsNaN(i.Item2.RX))) |
| 88 | + { |
| 89 | + span.Add("paragraph").Add("h1").Text(string.Format("Validation failed, there are NaNs in the result for nodal displacements")); |
| 90 | + } |
| 91 | + |
| 92 | + span.Add("paragraph").Text(string.Format("Validation output for nodal displacements:")); |
| 93 | + var n1 = model.Nodes[1].GetNodalDisplacement(); |
| 94 | + var n2 = model.Nodes[2].GetNodalDisplacement(); |
| 95 | + var diff = n1 - n2; |
| 96 | + //linear beam with loads -> rigid elements introduces rigid body -> Y and Z (translations perpendicular to the beam) are non zero and scaled. Set to zero to avoid confusion with result. |
| 97 | + diff.DY = diff.DZ = 0.0; |
| 98 | + |
| 99 | + //span.Add("p").AddClass("bg-info").Text(string.Format("-Max ABSOLUTE Error: {0:e3}", diff));//htmltags cannot encode the delta and teta chars so will use vector length |
| 100 | + span.Add("p").AddClass("bg-info") |
| 101 | + .Text(string.Format("-Max ABSOLUTE Error: Displacement:{0:e3} , Rotation:{1:e3}", |
| 102 | + diff.Displacements.Length, diff.Rotations.Length)); |
| 103 | + |
| 104 | + var buf = new ValidationResult(); |
| 105 | + buf.Span = span; |
| 106 | + buf.Title = "Rigid element Validation, Console beam with tetrahedron"; |
| 107 | + |
| 108 | + return buf; |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | +} |
0 commit comments