public void ParseGWACommand()
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new StructuralNode();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            counter++;       // Reference
            counter++;       // Name
            counter++;       // Color
            counter++;       // Type
            var mass = GetGSAMass(Convert.ToInt32(pieces[counter++]));

            obj.Mass = mass;
            counter++; // group
            this.GSAId        = Convert.ToInt32(pieces[counter++]);
            obj.ApplicationId = Helper.GetApplicationId(this.GetGSAKeyword(), this.GSAId);
            // Rest is unimportant for 0D element

            this.Value = obj;
        }
Пример #2
0
        public void MergeTestAutoMapperNode()
        {
            var newObj = new StructuralNode {
                Value = new List <double> {
                    1, 2, 3
                }, Stiffness = new StructuralVectorSix(10, 11, 12, 13, 14, 15)
            };
            var existingObj = new StructuralNode {
                Value = new List <double> {
                    4, 5, 6
                }
            };

            var m = SetupGSAMerger();

            var exceptionThrown = false;

            try
            {
                var testResult = m.Map(newObj, existingObj);
            }
            catch
            {
                exceptionThrown = true;
            }

            Assert.IsFalse(exceptionThrown);
            Assert.IsNotNull(existingObj.Stiffness);
            Assert.IsTrue(existingObj.Stiffness.Value.SequenceEqual(new List <double> {
                10, 11, 12, 13, 14, 15
            }));
            Assert.IsTrue(existingObj.Value.SequenceEqual(new List <double> {
                1, 2, 3
            }));
        }
Пример #3
0
        public void MergeTestAutoMapperBaseTypes()
        {
            var newObj = new StructuralNode {
                Value = new List <double> {
                    1, 2, 3
                }
            };
            var existingObj = new StructuralNode {
                Value = new List <double> {
                    4, 5, 6
                }
            };

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <StructuralNode, StructuralNode>();
                cfg.CreateMap <SpecklePoint, SpecklePoint>();
                cfg.ForAllPropertyMaps(pm => true, (pm, c) => c.ResolveUsing(new IgnoreNullResolver(), pm.SourceMember.Name));
            });

            config.AssertConfigurationIsValid();

            var m = config.CreateMapper();

            var testResult = m.Map(newObj, existingObj);

            Assert.IsTrue(existingObj.Value.SequenceEqual(new List <double> {
                1, 2, 3
            }));
        }
 public static string ToNative(this StructuralNode node)
 {
     return(string.Join("\n", new[] { new GSANode()
                                      {
                                          Value = node
                                      }.SetGWACommand(), new GSA0DElement()
                                      {
                                          Value = node
                                      }.SetGWACommand() }));
 }
        public static string ToNative(this SpecklePoint inputObject)
        {
            var convertedObject = new StructuralNode();

            foreach (var p in convertedObject.GetType().GetProperties().Where(p => p.CanWrite))
            {
                var inputProperty = inputObject.GetType().GetProperty(p.Name);
                if (inputProperty != null)
                {
                    p.SetValue(convertedObject, inputProperty.GetValue(inputObject));
                }
            }

            return(convertedObject.ToNative());
        }
Пример #6
0
    public static string ToNative(this SpecklePoint inputObject)
    {
      return SchemaConversion.Helper.ToNativeTryCatch(inputObject, () =>
      {
        var convertedObject = new StructuralNode();

        foreach (var p in convertedObject.GetType().GetProperties().Where(p => p.CanWrite))
        {
          var inputProperty = inputObject.GetType().GetProperty(p.Name);
          if (inputProperty != null)
            p.SetValue(convertedObject, inputProperty.GetValue(inputObject));
        }

        return convertedObject.ToNative();
      });
    }
        public void ParseGWACommand()
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new StructuralNode();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            this.GSAId        = Convert.ToInt32(pieces[counter++]);
            obj.ApplicationId = Helper.GetApplicationId(this.GetGSAKeyword(), this.GSAId);
            obj.Name          = pieces[counter++].Trim(new char[] { '"' });
            counter++; // Color
            obj.Value = new List <double>
            {
                Convert.ToDouble(pieces[counter++]),
                Convert.ToDouble(pieces[counter++]),
                Convert.ToDouble(pieces[counter++])
            };

            //counter += 3; // TODO: Skip unknown fields in NODE.3

            while (counter < pieces.Length)
            {
                var s = pieces[counter++];

                switch (s)
                {
                case "NO_GRID":
                case "NO_REST":
                case "NO_MESH":
                case "NO_STIFF":
                    continue;

                case "GRID":
                    counter++; // Grid place
                    counter++; // Datum
                    counter++; // Grid line A
                    counter++; // Grid line B
                    break;

                case "REST":
                    obj.Restraint = new StructuralVectorBoolSix(new bool[6]);
                    for (var i = 0; i < 6; i++)
                    {
                        obj.Restraint.Value[i] = pieces[counter++] == "0" ? false : true;
                    }
                    this.ForceSend = true;
                    break;

                case "STIFF":
                    obj.Stiffness = new StructuralVectorSix(new double[6]);
                    for (var i = 0; i < 6; i++)
                    {
                        obj.Stiffness.Value[i] = Convert.ToDouble(pieces[counter++]);
                    }
                    this.ForceSend = true;
                    break;

                case "MESH":
                    obj.GSALocalMeshSize = pieces[counter++].ToDouble();
                    counter++; // Edge length
                    counter++; // Radius
                    counter++; // Tie to mesh
                    counter++; // Column rigidity
                    counter++; // Column prop
                    counter++; // Column node
                    counter++; // Column angle
                    counter++; // Column factor
                    counter++; // Column slab factor
                    break;

                default: // Axis
                    string gwaRec = null;
                    obj.Axis = Helper.Parse0DAxis(Convert.ToInt32(s), Initialiser.Interface, out gwaRec, obj.Value.ToArray());
                    if (gwaRec != null)
                    {
                        this.SubGWACommand.Add(gwaRec);
                    }
                    break;
                }
            }

            this.Value = obj;
        }
Пример #8
0
        public static string ToNative(this StructuralNode node)
        {
            if (string.IsNullOrEmpty(node.ApplicationId) || node.Value == null || node.Value.Count < 3)
            {
                return("");
            }

            return(Helper.ToNativeTryCatch(node, () =>
            {
                var keyword = GsaRecord.GetKeyword <GsaNode>();
                var massKeyword = GsaRecord.GetKeyword <GsaPropMass>();

                var index = Initialiser.AppResources.Proxy.NodeAt(node.Value[0], node.Value[1], node.Value[2], Initialiser.AppResources.Settings.CoincidentNodeAllowance);
                var streamId = Initialiser.AppResources.Cache.LookupStream(node.ApplicationId);

                var existingGwa = Initialiser.AppResources.Cache.GetGwa(keyword, index);
                GsaNode gsaNode;
                if (existingGwa == null || existingGwa.Count() == 0 || string.IsNullOrEmpty(existingGwa.First()))
                {
                    gsaNode = new GsaNode()
                    {
                        Index = index,
                        ApplicationId = node.ApplicationId,
                        Name = node.Name,
                        StreamId = streamId,
                        X = node.Value[0],
                        Y = node.Value[1],
                        Z = node.Value[2],
                    };
                }
                else
                {
                    gsaNode = new GsaNode();
                    if (!gsaNode.FromGwa(existingGwa.First()))
                    {
                        //TO DO: add error mesage
                        return "";
                    }
                }

                if (node.Mass.HasValue && node.Mass.Value > 0)
                {
                    int?massIndex = null;
                    GsaPropMass gsaPropMass = null;

                    //Assume the PROP_MASS has the same Application ID as this node
                    //Check if the existing mass with the App ID still has the mass required by this StructuralNode
                    massIndex = Initialiser.AppResources.Cache.LookupIndex(massKeyword, node.ApplicationId);
                    if (massIndex.HasValue)
                    {
                        var massGwa = Initialiser.AppResources.Cache.GetGwa(massKeyword, massIndex.Value);
                        if (massGwa != null && massGwa.Count() > 0 && !string.IsNullOrEmpty(massGwa.First()))
                        {
                            gsaPropMass = new GsaPropMass();
                            gsaPropMass.FromGwa(massGwa.First());

                            if (Math.Abs(gsaPropMass.Mass - node.Mass.Value) > massEpsilon)
                            {
                                gsaPropMass.Mass = node.Mass.Value;
                            }
                        }
                    }

                    if (gsaPropMass == null)
                    {
                        gsaPropMass = new GsaPropMass()
                        {
                            ApplicationId = gsaNode.ApplicationId,
                            StreamId = streamId,
                            Index = Initialiser.AppResources.Cache.ResolveIndex(massKeyword, gsaNode.ApplicationId),
                            Mass = node.Mass.Value
                        };
                        if (!string.IsNullOrEmpty(node.Name))
                        {
                            gsaPropMass.Name = "Mass for " + node.Name;
                        }
                    }
                    if (gsaPropMass.Gwa(out var massGwaLines, false))
                    {
                        Initialiser.AppResources.Cache.Upsert(massKeyword, gsaPropMass.Index.Value, massGwaLines.First(), streamId, gsaPropMass.ApplicationId, GsaRecord.GetGwaSetCommandType <GsaPropMass>());
                    }
                }
        public static List <SpeckleObject> ToSpeckle(this BoundaryConditions myRestraint)
        {
            var points = new List <XYZ>();

            var restraintType = myRestraint.GetBoundaryConditionsType();

            if (restraintType == BoundaryConditionsType.Point)
            {
                var point = myRestraint.Point;
                points.Add(point);
            }
            else if (restraintType == BoundaryConditionsType.Line)
            {
                var curve = myRestraint.GetCurve();
                points.Add(curve.GetEndPoint(0));
                points.Add(curve.GetEndPoint(1));
            }
            else if (restraintType == BoundaryConditionsType.Area)
            {
                var loops = myRestraint.GetLoops();
                foreach (var loop in loops)
                {
                    foreach (var curve in loop)
                    {
                        points.Add(curve.GetEndPoint(0));
                        points.Add(curve.GetEndPoint(1));
                    }
                }
                points = points.Distinct().ToList();
            }

            var coordinateSystem = myRestraint.GetDegreesOfFreedomCoordinateSystem();
            var axis             = new StructuralAxis(
                new StructuralVectorThree(new double[] { coordinateSystem.BasisX.X, coordinateSystem.BasisX.Y, coordinateSystem.BasisX.Z }),
                new StructuralVectorThree(new double[] { coordinateSystem.BasisY.X, coordinateSystem.BasisY.Y, coordinateSystem.BasisY.Z }),
                new StructuralVectorThree(new double[] { coordinateSystem.BasisZ.X, coordinateSystem.BasisZ.Y, coordinateSystem.BasisZ.Z })
                );

            var restraint = new StructuralVectorBoolSix(new bool[6]);
            var stiffness = new StructuralVectorSix(new double[6]);

            var listOfParams = new BuiltInParameter[] {
                BuiltInParameter.BOUNDARY_DIRECTION_X,
                BuiltInParameter.BOUNDARY_DIRECTION_Y,
                BuiltInParameter.BOUNDARY_DIRECTION_Z,
                BuiltInParameter.BOUNDARY_DIRECTION_ROT_X,
                BuiltInParameter.BOUNDARY_DIRECTION_ROT_Y,
                BuiltInParameter.BOUNDARY_DIRECTION_ROT_Z
            };

            var listOfSpringParams = new BuiltInParameter[] {
                BuiltInParameter.BOUNDARY_RESTRAINT_X,
                BuiltInParameter.BOUNDARY_RESTRAINT_Y,
                BuiltInParameter.BOUNDARY_RESTRAINT_Z,
                BuiltInParameter.BOUNDARY_RESTRAINT_ROT_X,
                BuiltInParameter.BOUNDARY_RESTRAINT_ROT_Y,
                BuiltInParameter.BOUNDARY_RESTRAINT_ROT_Z,
            };

            for (var i = 0; i < 6; i++)
            {
                switch (myRestraint.get_Parameter(listOfParams[i]).AsInteger())
                {
                case 0:
                    restraint.Value[i] = true;
                    break;

                case 1:
                    restraint.Value[i] = false;
                    break;

                case 2:
                    stiffness.Value[i] = myRestraint.get_Parameter(listOfSpringParams[i]).AsDouble();
                    break;
                }
            }
            restraint.GenerateHash();
            stiffness.GenerateHash();

            var myNodes = new List <SpeckleObject>();

            foreach (var point in points)
            {
                var myPoint = (SpeckleCoreGeometryClasses.SpecklePoint)SpeckleCore.Converter.Serialise(point);
                var myNode  = new StructuralNode();
                myNode.basePoint = myPoint;
                myNode.Axis      = axis;
                myNode.Restraint = restraint;
                myNode.Stiffness = stiffness;
                myNodes.Add(myNode);
            }

            return(myNodes);
        }
 //TODO
 public static Element ToNative(this StructuralNode myBeam)
 {
     return(null);
 }
    public static SpeckleObject ToSpeckle(this GsaNode dummyObject)
    {
      var nodeKw = GsaRecord.GetKeyword<GsaNode>();
      var springKw = GsaRecord.GetKeyword<GsaPropSpr>();
      var massKw = GsaRecord.GetKeyword<GsaPropMass>();
      var loadTaskKw = GsaRecord.GetKeyword<GsaLoadCase>();
      var comboKw = GsaRecord.GetKeyword<GsaCombination>();

      var newNodeLines = Initialiser.AppResources.Cache.GetGwaToSerialise(nodeKw);

      var sendResults = GetNodeResultSettings(out var embedResults, out var resultTypes, out var resultCases);

      if (sendResults)
      {
        Initialiser.AppResources.Proxy.LoadResults(ResultGroup.Node, out int numErrorRows, resultCases, newNodeLines.Keys.ToList());
        if (numErrorRows > 0)
        {
          Initialiser.AppResources.Messenger.Message(MessageIntent.Display, MessageLevel.Error, "Unable to process " + numErrorRows + " rows of node results");
          Initialiser.AppResources.Messenger.Message(MessageIntent.TechnicalLog, MessageLevel.Error, "Unable to process " + numErrorRows + " rows of node results");
        }
      }
      
      //This method produces two types of SpeckleStructural objects
      var structuralNodes = new List<StructuralNode>();
      var structural0dSprings = new List<Structural0DSpring>();

      int numToBeSent = 0;

#if DEBUG
      foreach (var i in newNodeLines.Keys)
#else
        Parallel.ForEach(newNodeLines.Keys, i =>
#endif
      {
        GsaNode gsaNode = null;
        var objNode = Helper.ToSpeckleTryCatch(nodeKw, i, () =>
        {
          gsaNode = new GsaNode();
          if (gsaNode.FromGwa(newNodeLines[i]))
          {
            var structuralNode = new StructuralNode()
            {
              Name = gsaNode.Name,
              ApplicationId = SpeckleStructuralGSA.Helper.GetApplicationId(nodeKw, i),
              Value = new List<double>() { gsaNode.X, gsaNode.Y, gsaNode.Z },
              Restraint = GetRestraint(gsaNode)
            };

            if (gsaNode.MeshSize.HasValue && gsaNode.MeshSize.Value > 0)
            {
              structuralNode.GSALocalMeshSize = gsaNode.MeshSize.Value;
            }

            if (gsaNode.MassPropertyIndex.HasValue && gsaNode.MassPropertyIndex.Value > 0)
            {
              var massGwas = Initialiser.AppResources.Cache.GetGwa(massKw, gsaNode.MassPropertyIndex.Value);
              if (massGwas != null && massGwas.Count() > 0 && !string.IsNullOrEmpty(massGwas.First()))
              {
                var gsaPropMass = new GsaPropMass();
                if (gsaPropMass.FromGwa(massGwas.First()) && gsaPropMass.Mass > 0)
                {
                  structuralNode.Mass = gsaPropMass.Mass;
                }
              }
            }
            return structuralNode;
          }
          return new SpeckleNull();
        });

        if (objNode !=null && !(objNode is SpeckleNull))
        {
          var structuralNode = (StructuralNode)objNode;
          GSANodeResult gsaNodeResult = null;

          //Embed results if appropriate as the last thing to do to the new Speckle object before being added to the collection of objects to be sent
          if (sendResults)
          {
            if (Initialiser.AppResources.Proxy.GetResultHierarchy(ResultGroup.Node, i, out var results) && results != null)
            {
              var orderedLoadCases = results.Keys.OrderBy(k => k).ToList();
              if (embedResults)
              {
                foreach (var loadCase in orderedLoadCases)
                {
                  if (!Helper.FilterResults(results[loadCase], out Dictionary<string, object> sendableResults))
                  {
                    continue;
                  }
                  var nodeResult = new StructuralNodeResult()
                  {
                    IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis,
                    TargetRef = structuralNode.ApplicationId,
                    Value = sendableResults
                  };
                  var loadCaseRef = Helper.GsaCaseToRef(loadCase, loadTaskKw, comboKw);
                  if (!string.IsNullOrEmpty(loadCaseRef))
                  {
                    //nodeResult.LoadCaseRef = loadCaseRef;
                    nodeResult.LoadCaseRef = loadCase;
                  }
                  if (structuralNode.Result == null)
                  {
                    //Can't just allocate an empty dictionary as the Result set property won't allow it
                    structuralNode.Result = new Dictionary<string, object>() { { loadCase, nodeResult } };
                  }
                  else
                  {
                    structuralNode.Result.Add(loadCase, nodeResult);
                  }
                }
              }
              else
              {
                foreach (var loadCase in orderedLoadCases)
                {
                  if (!Helper.FilterResults(results[loadCase], out Dictionary<string, object> sendableResults))
                  {
                    continue;
                  }
                  var nodeResult = new StructuralNodeResult()
                  {
                    IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis,
                    TargetRef = structuralNode.ApplicationId,
                    Value = sendableResults
                  };
                  var loadCaseRef = Helper.GsaCaseToRef(loadCase, loadTaskKw, comboKw);
                  if (!string.IsNullOrEmpty(loadCaseRef))
                  {
                    //nodeResult.LoadCaseRef = loadCaseRef;
                    nodeResult.LoadCaseRef = loadCase;
                  }
                  gsaNodeResult = new GSANodeResult { Value = nodeResult, GSAId = i };
                  Initialiser.GsaKit.GSASenderObjects.Add(gsaNodeResult);
                }
              }
            }
          }
          var senderObjectGsaNode = new GSANode()
          {
            Value = structuralNode,
            GSAId = i
          };
          if (gsaNodeResult != null)
          {
            senderObjectGsaNode.ForceSend = true;
          }
          Initialiser.GsaKit.GSASenderObjects.Add(senderObjectGsaNode);
          numToBeSent++;

          //Add spring object if appropriate
          if (gsaNode.SpringPropertyIndex.HasValue && gsaNode.SpringPropertyIndex.Value > 0)
          {
            var objSpring = Helper.ToSpeckleTryCatch(nodeKw, i, () =>
            {
              var springPropRef = SpeckleStructuralGSA.Helper.GetApplicationId(springKw, gsaNode.SpringPropertyIndex.Value);
              if (!string.IsNullOrEmpty(springPropRef))
              {
                var structural0dSpring = new Structural0DSpring()
                {
                //The application ID might need a better mechanism to allow a StructuralNode and Structural0DSpring previously received
                //that originally created the one node to be separated out again to produce the Application ID to use here for this spring
                //TO DO - review, for now just append a string to ensure the same Application ID value isn't used twice
                ApplicationId = gsaNode.ApplicationId + "_spring",
                  Name = gsaNode.Name,
                  Value = new List<double>() { gsaNode.X, gsaNode.Y, gsaNode.Z },
                  PropertyRef = springPropRef,
                  Dummy = false
                };
                return structural0dSpring;
              }
              return new SpeckleNull();
            });
            if (!(objSpring is SpeckleNull))
            {
              Initialiser.GsaKit.GSASenderObjects.Add(new GSA0DSpring() { Value = (Structural0DSpring)objSpring, GSAId = i });
              numToBeSent++;
            }
          } //if spring object needs to be added
        } //if node object was successfully created
      }
#if !DEBUG
      );
#endif

      if (sendResults)
      {
        Initialiser.AppResources.Proxy.ClearResults(ResultGroup.Node);
      }

      return (numToBeSent > 0) ? new SpeckleObject() : new SpeckleNull();
    }