public static bool St7SetNodeLoad_Id(int loadCase, int nodeId, oM.Geometry.Vector force, oM.Geometry.Vector moment, bool active = false) { if (!active) { return(false); } int err; int uID = 1; double[] forces = new double[3]; double[] moments = new double[3]; forces[0] = force.X; forces[1] = force.Y; forces[2] = force.Z; moments[0] = moment.X; moments[1] = moment.Y; moments[2] = moment.Z; err = St7.St7SetNodeForce3(uID, nodeId, loadCase, forces); if (!St7ErrorCustom(err, "Couldn't set point load for a loadcase " + loadCase + " node " + nodeId)) { return(false); } err = St7.St7SetNodeMoment3(uID, nodeId, loadCase, moments); if (!St7ErrorCustom(err, "Couldn't set point load for a loadcase " + loadCase + " node " + nodeId)) { return(false); } return(true); }
/***************************************************/ public static void CopyCharacteristics(this IMaterialFragment toMaterial, StructuralAsset fromAsset) { double density = fromAsset.Density.ToSI(UnitType.UT_MassDensity); #if (REVIT2020 || REVIT2021) #else double dampingRatio = fromAsset.DampingRatio; #endif oM.Geometry.Vector youngsModulus = BH.Engine.Geometry.Create.Vector(fromAsset.YoungModulus.X.ToSI(UnitType.UT_Stress), fromAsset.YoungModulus.Y.ToSI(UnitType.UT_Stress), fromAsset.YoungModulus.Z.ToSI(UnitType.UT_Stress)); oM.Geometry.Vector thermalExpansionCoeff = BH.Engine.Geometry.Create.Vector(fromAsset.ThermalExpansionCoefficient.X.ToSI(UnitType.UT_ThermalExpansion), fromAsset.ThermalExpansionCoefficient.Y.ToSI(UnitType.UT_ThermalExpansion), fromAsset.ThermalExpansionCoefficient.Z.ToSI(UnitType.UT_ThermalExpansion)); oM.Geometry.Vector poissonsRatio = BH.Engine.Geometry.Create.Vector(fromAsset.PoissonRatio.X, fromAsset.PoissonRatio.Y, fromAsset.PoissonRatio.Z); oM.Geometry.Vector shearModulus = BH.Engine.Geometry.Create.Vector(fromAsset.ShearModulus.X.ToSI(UnitType.UT_Stress), fromAsset.ShearModulus.Y.ToSI(UnitType.UT_Stress), fromAsset.ShearModulus.Z.ToSI(UnitType.UT_Stress)); toMaterial.Density = density; #if (REVIT2020 || REVIT2021) #else toMaterial.DampingRatio = dampingRatio; #endif if (toMaterial is Aluminium) { Aluminium material = toMaterial as Aluminium; material.YoungsModulus = youngsModulus.X; material.ThermalExpansionCoeff = thermalExpansionCoeff.X; material.PoissonsRatio = poissonsRatio.X; } else if (toMaterial is Concrete) { Concrete material = toMaterial as Concrete; material.YoungsModulus = youngsModulus.X; material.ThermalExpansionCoeff = thermalExpansionCoeff.X; material.PoissonsRatio = poissonsRatio.X; } else if (toMaterial is Steel) { Steel material = toMaterial as Steel; material.YoungsModulus = youngsModulus.X; material.ThermalExpansionCoeff = thermalExpansionCoeff.X; material.PoissonsRatio = poissonsRatio.X; } else if (toMaterial is Timber) { Timber material = toMaterial as Timber; material.YoungsModulus = youngsModulus; material.ThermalExpansionCoeff = thermalExpansionCoeff; material.PoissonsRatio = poissonsRatio; } else if (toMaterial is GenericIsotropicMaterial) { GenericIsotropicMaterial material = toMaterial as GenericIsotropicMaterial; material.YoungsModulus = youngsModulus.X; material.ThermalExpansionCoeff = thermalExpansionCoeff.X; material.PoissonsRatio = poissonsRatio.X; } }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static IMaterialFragment FromRFEM(this rf.Material material) { IMaterialFragment bhMaterial = null; string[] stringArr = material.TextID.Split('@'); MaterialType matType = material.GetMaterialType();// Engine.Adapters.RFEM.Query.GetMaterialType(material); string matName = Engine.Adapters.RFEM.Query.GetMaterialName(material); switch (matType) { case MaterialType.Aluminium: bhMaterial = Engine.Structure.Create.Aluminium(matName); break; case MaterialType.Steel: bhMaterial = Engine.Structure.Create.Steel(matName); break; case MaterialType.Concrete: bhMaterial = Engine.Structure.Create.Concrete(matName); break; case MaterialType.Timber: //TODO: as this uses vector over double assumption is the the below turns Timber into an incorrect Isotropic material !!! BH.oM.Geometry.Vector young = new oM.Geometry.Vector() { X = material.ElasticityModulus, Y = material.ElasticityModulus, Z = material.ElasticityModulus }; BH.oM.Geometry.Vector poissons = new oM.Geometry.Vector() { X = material.PoissonRatio, Y = material.PoissonRatio, Z = material.PoissonRatio }; BH.oM.Geometry.Vector shear = new oM.Geometry.Vector() { X = material.ShearModulus, Y = material.ShearModulus, Z = material.ShearModulus }; BH.oM.Geometry.Vector thermal = new oM.Geometry.Vector() { X = material.ThermalExpansion, Y = material.ThermalExpansion, Z = material.ThermalExpansion }; bhMaterial = Engine.Structure.Create.Timber(matName, young, poissons, shear, thermal, material.SpecificWeight, 0.05); break; case MaterialType.Rebar: case MaterialType.Tendon: case MaterialType.Glass: case MaterialType.Cable: case MaterialType.Undefined: default: break; } bhMaterial.SetAdapterId(typeof(RFEMId), material.No); return(bhMaterial); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static oM.Geometry.Basis BasisFromRevit(this Transform transform) { if (transform == null) { return(null); } BH.oM.Geometry.Vector x = new oM.Geometry.Vector { X = transform.BasisX.X, Y = transform.BasisX.Y, Z = transform.BasisX.Z }; BH.oM.Geometry.Vector y = new oM.Geometry.Vector { X = transform.BasisY.X, Y = transform.BasisY.Y, Z = transform.BasisY.Z }; BH.oM.Geometry.Vector z = new oM.Geometry.Vector { X = transform.BasisZ.X, Y = transform.BasisZ.Y, Z = transform.BasisZ.Z }; return(new oM.Geometry.Basis(x, y, z)); }
public static CoordSystems St7GetUCSs(bool active = false) { if (!active) { return(new CoordSystems(false, new List <Cartesian>())); } int err; int uID = 1; int num_UCS = 0; err = St7.St7GetNumUCS(uID, ref num_UCS); if (!St7Error(err)) { return(new CoordSystems(false, new List <Cartesian>())); } int UCSType = St7.csCartesian; List <Cartesian> UCSs = new List <Cartesian>(); for (int i = 1; i <= num_UCS; i++) { double[] UCSDoubles_current = new double[9]; int current_id = 0; err = St7.St7GetUCSID(uID, i, ref current_id); err = St7.St7GetUCS(uID, current_id, ref UCSType, UCSDoubles_current); oM.Geometry.Point origin = Geometry.Create.Point(UCSDoubles_current[0], UCSDoubles_current[1], UCSDoubles_current[2]); oM.Geometry.Vector x = Geometry.Create.Point(UCSDoubles_current[3], UCSDoubles_current[4], UCSDoubles_current[5]) - origin; oM.Geometry.Vector y = Geometry.Create.Point(UCSDoubles_current[6], UCSDoubles_current[7], UCSDoubles_current[8]) - origin; Cartesian cs = Geometry.Create.CartesianCoordinateSystem(origin, x, y); UCSs.Add(cs); if (!St7Error(err)) { return(new CoordSystems(false, new List <Cartesian>())); } } return(new CoordSystems(true, UCSs)); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateObject(Node bhnode) { double[] XYZ = new double[3]; // Geometry int uID = 1; int err = 0; int nodeId = GetAdapterId <int>(bhnode); XYZ[0] = bhnode.Position.X; XYZ[1] = bhnode.Position.Y; XYZ[2] = bhnode.Position.Z; err = St7.St7SetNodeXYZ(1, nodeId, XYZ); if (!St7Error(err)) { return(false); } oM.Geometry.Vector xVector = bhnode.Orientation.X; oM.Geometry.Vector yVector = bhnode.Orientation.Y; double[] UCSDoubles = new double[] { 0, 0, 0, xVector.X, xVector.Y, xVector.Z, yVector.X, yVector.Y, yVector.Z }; int UCSType = St7.csCartesian; int num_UCS = 0; int UCSid = 0; err = St7.St7GetNumUCS(uID, ref num_UCS); if (!St7Error(err)) { return(false); } bool ucsExists = false; for (int i = 1; i <= num_UCS; i++) { double[] UCSDoubles_current = new double[9]; int current_id = 0; err = St7.St7GetUCSID(uID, i, ref current_id); err = St7.St7GetUCS(uID, current_id, ref UCSType, UCSDoubles_current); if (UCSDoubles_current.SequenceEqual(UCSDoubles)) { UCSid = i; ucsExists = true; break; } } if (!ucsExists) { UCSid = num_UCS + 1; err = St7.St7SetUCS(uID, UCSid, UCSType, UCSDoubles); err = St7.St7SetUCSName(uID, UCSid, bhnode.Name); } // Restraints if (bhnode.Support == null) { return(true); } SetAdapterId(bhnode.Support, UCSid); int freedomCase = 1; object freedomCaseObj; if (bhnode.CustomData.TryGetValue("Freedom", out freedomCaseObj)) { freedomCase = (int)freedomCaseObj; while (St7.St7SetFreedomCaseType(uID, freedomCase, St7.fcNormalFreedom) != St7.ERR7_NoError) // there is no such freedom case, creating new { err = St7.St7NewFreedomCase(uID, "fc " + freedomCase.ToString()); if (!St7Error(err)) { return(false); } } } int[] restraints = new int[6]; restraints[0] = (bhnode.Support.TranslationX == oM.Structure.Constraints.DOFType.Fixed) ? St7.btTrue : St7.btFalse; restraints[1] = (bhnode.Support.TranslationY == oM.Structure.Constraints.DOFType.Fixed) ? St7.btTrue : St7.btFalse; restraints[2] = (bhnode.Support.TranslationZ == oM.Structure.Constraints.DOFType.Fixed) ? St7.btTrue : St7.btFalse; restraints[3] = (bhnode.Support.RotationX == oM.Structure.Constraints.DOFType.Fixed) ? St7.btTrue : St7.btFalse; restraints[4] = (bhnode.Support.RotationY == oM.Structure.Constraints.DOFType.Fixed) ? St7.btTrue : St7.btFalse; restraints[5] = (bhnode.Support.RotationZ == oM.Structure.Constraints.DOFType.Fixed) ? St7.btTrue : St7.btFalse; double[] enforcedDispls = Enumerable.Repeat(0.0, 6).ToArray(); err = St7.St7SetNodeRestraint6(uID, nodeId, freedomCase, UCSid, restraints, enforcedDispls); if (!St7Error(err)) { return(false); } // Stiffness Translational double[] translationalStiffness = new double[3]; translationalStiffness[0] = bhnode.Support.TranslationalStiffnessX; translationalStiffness[1] = bhnode.Support.TranslationalStiffnessY; translationalStiffness[2] = bhnode.Support.TranslationalStiffnessZ; err = St7.St7SetNodeKTranslation3F(uID, nodeId, freedomCase, UCSid, translationalStiffness); if (!St7Error(err)) { return(false); } // Stiffness Rotational double[] rotationalStiffness = new double[3]; rotationalStiffness[0] = bhnode.Support.RotationalStiffnessX; rotationalStiffness[1] = bhnode.Support.RotationalStiffnessY; rotationalStiffness[2] = bhnode.Support.RotationalStiffnessZ; err = St7.St7SetNodeKRotation3F(uID, nodeId, freedomCase, UCSid, rotationalStiffness); if (!St7Error(err)) { return(false); } return(true); }
/***************************************************/ public static XYZ ToRevit(this oM.Geometry.Vector vector) { return(new XYZ(vector.X.FromSI(UnitType.UT_Length), vector.Y.FromSI(UnitType.UT_Length), vector.Z.FromSI(UnitType.UT_Length))); }
public static FreeFormProfile FreeFormProfile(IEnumerable <ICurve> edges, bool centreProfile = true) { IEnumerable <ICurve> result = edges.ToList(); List <Point> cPoints = edges.SelectMany(x => x.IControlPoints()).ToList(); // Any Point not on the XY-Plane if (cPoints.Any(x => Math.Abs(x.Z) > Tolerance.Distance)) { // Is Planar Plane plane = Geometry.Compute.FitPlane(cPoints); bool failedProject = false; if (cPoints.Any(x => x.Distance(plane) > Tolerance.Distance)) { Reflection.Compute.RecordWarning("The Profiles curves are not Planar"); try { // Get biggest contributing curve and fit a plane to it plane = Geometry.Compute.IJoin(edges.ToList()).OrderBy(x => Geometry.Query.Area(x)).Last().ControlPoints().FitPlane(); result = edges.Select(x => x.IProject(plane)).ToList(); Reflection.Compute.RecordWarning("The Profiles curves have been projected onto a plane fitted through the biggest curve's control points."); cPoints = result.SelectMany(x => Geometry.Query.IControlPoints(x)).ToList(); } catch { failedProject = true; } } if (!failedProject) { // Is Coplanar with XY if (plane.Normal.IsParallel(oM.Geometry.Vector.ZAxis) == 0) { Reflection.Compute.RecordWarning("The Profiles curves are not coplanar with the XY-Plane. Automatic orientation has occured."); plane.Normal = plane.Normal.Z > 0 ? plane.Normal : -plane.Normal; double rad = plane.Normal.Angle(oM.Geometry.Vector.ZAxis); Line axis = plane.PlaneIntersection(oM.Geometry.Plane.XY); result = result.Select(x => x.IRotate(axis.Start, axis.TangentAtParameter(0), rad)).ToList(); cPoints = result.SelectMany(x => Geometry.Query.IControlPoints(x)).ToList(); } // Is on XY if (cPoints.FirstOrDefault().Distance(oM.Geometry.Plane.XY) > Tolerance.Distance) { Reflection.Compute.RecordWarning("The Profiles curves are not on the XY-Plane. Automatic translation has occured."); Point p = cPoints.FirstOrDefault(); Vector v = new oM.Geometry.Vector() { X = p.X, Y = p.Y, Z = p.Z }; result = result.Select(x => x.ITranslate(-v)).ToList(); } } } bool couldCentre = false; if (!result.Any(x => x.ISubParts().Any(y => y is NurbsCurve))) { // Join the curves List <PolyCurve> joinedCurves = Geometry.Compute.IJoin(result.ToList()).ToList(); // Is Closed if (joinedCurves.Any(x => !x.IsClosed())) { Reflection.Compute.RecordWarning("The Profiles curves does not form closed curves"); } // Has non-zero area if (joinedCurves.Any(x => Geometry.Query.IArea(x) < Tolerance.Distance)) { Reflection.Compute.RecordWarning("One or more of the profile curves have close to zero area."); } if (!joinedCurves.Any(x => x.ISubParts().Any(y => y is Ellipse))) { // Check curve curve Intersections bool intersects = false; for (int i = 0; i < joinedCurves.Count - 1; i++) { for (int j = i + 1; j < joinedCurves.Count; j++) { if (joinedCurves[i].CurveIntersections(joinedCurves[j]).Count > 0) { intersects = true; break; } } if (intersects) { break; } } if (intersects) { Engine.Reflection.Compute.RecordWarning("The Profiles curves are intersecting eachother."); } if (centreProfile) { try { //Try centering the curves around the origin; List <List <ICurve> > curves = result.ToList().IJoin().Cast <ICurve>().ToList().DistributeOutlines(); Point centroid = curves.Select(x => x[0]).Centroid(curves.SelectMany(x => x.Skip(1))); Vector tranlation = Point.Origin - centroid; result = result.Select(x => x.ITranslate(tranlation)).ToList(); couldCentre = true; } catch (Exception e) { } } } // Is SelfInteersecting if (joinedCurves.Any(x => Geometry.Query.IsSelfIntersecting(x))) { Engine.Reflection.Compute.RecordWarning("One or more of the Profiles curves is intersecting itself."); } } if (centreProfile && !couldCentre) { Engine.Reflection.Compute.RecordWarning("Failed to align the centroid of the provided edgecurve with the global origin."); } return(new FreeFormProfile(result)); }