/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateObject(Loadcase bhLoadCase) { int err; int loadCaseId = bhLoadCase.Number; int loadCaseCount = 0; int uID = 1; err = St7.St7GetNumLoadCase(uID, ref loadCaseCount); if (loadCaseCount < loadCaseId) { err = St7.St7NewLoadCase(uID, bhLoadCase.Name); if (!St7ErrorCustom(err, "Could not create a load case number " + loadCaseId)) { return(false); } } else // updating { StringBuilder currentLoadCaseName = new StringBuilder(St7.kMaxStrLen); err = St7.St7GetLoadCaseName(uID, loadCaseId, currentLoadCaseName, St7.kMaxStrLen); if (!String.Equals(currentLoadCaseName.ToString(), bhLoadCase.Name, StringComparison.OrdinalIgnoreCase)) { err = St7.St7SetLoadCaseName(uID, loadCaseId, bhLoadCase.Name); if (!St7ErrorCustom(err, "Could not update a load case number " + loadCaseId)) { return(false); } } } err = St7.St7SetLoadCaseType(uID, loadCaseId, St7LoadCaseTypeFromNature(bhLoadCase.Nature)); err = St7.St7EnableLSALoadCase(uID, loadCaseId, 1); return(true); }
private IMaterialFragment GetPlateIsotropicMaterial(int platePropNumber) { int uID = 1; int err = 0; IMaterialFragment material = null; double[] materialArray = new double[8]; StringBuilder materialName = new StringBuilder(St7.kMaxStrLen); err = St7.St7GetPlateIsotropicMaterial(uID, platePropNumber, materialArray); if (!St7Error(err)) { return(material); } err = St7.St7GetMaterialName(uID, St7.ptPLATEPROP, platePropNumber, materialName, St7.kMaxStrLen); if (!St7Error(err)) { return(material); } // !!!! Materials are set based on Poisson Ratio !!!! if (materialArray[St7.ipPlateIsoPoisson] <= 0.2) { material = BH.Engine.Structure.Create.Concrete(materialName.ToString(), materialArray[St7.ipPlateIsoModulus], materialArray[St7.ipPlateIsoPoisson], materialArray[St7.ipPlateIsoAlpha], materialArray[St7.ipPlateIsoDensity], materialArray[St7.ipPlateIsoDampingRatio]); } else { material = BH.Engine.Structure.Create.Steel(materialName.ToString(), materialArray[St7.ipPlateIsoModulus], materialArray[St7.ipPlateIsoPoisson], materialArray[St7.ipPlateIsoAlpha], materialArray[St7.ipPlateIsoDensity], materialArray[St7.ipPlateIsoDampingRatio]); } return(material); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateObject(LoadCombination bhLoadCombo) { int err; int uID = 1; int loadCaseType = St7.ltLoadCase; int freedomCaseNum = 1; int loadComboId = GetAdapterId <int>(bhLoadCombo); List <Loadcase> allLoadCases = ReadLoadcase(); var comparer = new BHoMObjectNameOrToStringComparer(); err = St7.St7AddLSACombination(uID, bhLoadCombo.Name); if (err != St7.ERR7_NoError) { err = St7.St7SetLSACombinationName(uID, loadComboId, bhLoadCombo.Name); if (!St7ErrorCustom(err, "Could not create or update a load combination number " + loadComboId)) { return(false); } } foreach (Tuple <double, ICase> tuple in bhLoadCombo.LoadCases) { Loadcase ldcas = allLoadCases.Where(x => x.Number == (tuple.Item2 as Loadcase).Number).FirstOrDefault(); int lCaseNum = ldcas.Number; // int lCaseNum = GetAdapterId<int>(ldcas); err = St7.St7SetLSACombinationFactor(uID, loadCaseType, loadComboId, lCaseNum, freedomCaseNum, tuple.Item1); if (!St7ErrorCustom(err, "Could not set load case " + lCaseNum + " factor for a load combo " + loadComboId)) { return(false); } } return(true); }
private List <ILoad> ReadGravityLoad(List <Loadcase> loadcases) { int err = 0; List <ILoad> bhLoads = new List <ILoad>(); foreach (Loadcase ldcs in loadcases) { if (ldcs.Nature == LoadNature.Dead) { int dir = 0; double x = 0, y = 0, z = 0; err = St7.St7GetLoadCaseGravityDir(1, GetAdapterId <int>(ldcs), ref dir); if (!St7ErrorCustom(err, "Could not get a direction for gravity lc #" + GetAdapterId <int>(ldcs))) { return(bhLoads); } if (dir == 1) { x = -1; } if (dir == 2) { y = -1; } if (dir == 3) { z = -1; } Vector vector = BH.Engine.Geometry.Create.Vector(x, y, z); bhLoads.Add(BH.Engine.Structure.Create.GravityLoad(ldcs, vector, new BHoMObject[] { })); } } return(bhLoads); }
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); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateObject(FEMesh fEMesh) { int uID = 1; int err = 0; int meshId = GetAdapterId <int>(fEMesh); int platePropId = GetAdapterId <int>(fEMesh.Property); // geometry List <int> nodesIds = fEMesh.Nodes.Select(nd => GetAdapterId <int>(nd)).ToList(); bool refresh = true; foreach (FEMeshFace fEMeshFace in fEMesh.Faces) { int plateId = (int)NextFreeId(typeof(FEMeshFace), refresh); refresh = false; SetAdapterId(fEMeshFace, plateId); int[] connectionNodes = new int[fEMeshFace.NodeListIndices.Count + 1]; connectionNodes[0] = fEMeshFace.NodeListIndices.Count; for (int i = 0; i < fEMeshFace.NodeListIndices.Count; i++) { connectionNodes[i + 1] = nodesIds[fEMeshFace.NodeListIndices[i]]; } err = St7.St7SetElementConnection(uID, St7.tyPLATE, plateId, platePropId, connectionNodes); } return(true); }
public static bool St7Automesh(bool active, double meshSize, int corners) { if (!active) { return(false); } int uID = 1; int err = 0; int[] Integers = new int[11]; Integers[St7.ipSurfaceMeshMode] = St7.mmAuto; Integers[St7.ipSurfaceMeshSizeMode] = St7.smAbsolute; Integers[St7.ipSurfaceMeshTargetNodes] = corners; Integers[St7.ipSurfaceMeshTargetPropertyID] = -1; Integers[St7.ipSurfaceMeshAutoCreateProperties] = St7.btFalse; Integers[St7.ipSurfaceMeshMinEdgesPerCircle] = 12; Integers[St7.ipSurfaceMeshApplyTransitioning] = St7.btTrue; Integers[St7.ipSurfaceMeshApplySurfaceCurvature] = St7.btFalse; Integers[St7.ipSurfaceMeshAllowUserStop] = St7.btTrue; Integers[St7.ipSurfaceMeshConsiderNearVertex] = St7.btFalse; Integers[St7.ipSurfaceMeshSelectedFaces] = St7.btFalse; double[] Doubles = new double[4]; Doubles[St7.ipSurfaceMeshSize] = meshSize; Doubles[St7.ipSurfaceMeshLengthRatio] = 0.1; Doubles[St7.ipSurfaceMeshMaximumIncrease] = 0.3; Doubles[St7.ipSurfaceMeshOnEdgesLongerThan] = 0; // err = St7.St7SetEntitySelectState(1, St7.tyGEOMETRYFACE, 1, 0, St7.btTrue); //err = St7.St7SetKeepSelect(1, St7.btFalse); err = St7.St7SurfaceMesh(uID, Integers, Doubles, St7.ieProgressRun); return(St7Error(err)); }
private IMaterialFragment GetBeamPropertyMaterial(int beamProp) { int err = 0; IMaterialFragment material = null; double[] materialArray = new double[9]; StringBuilder materialName = new StringBuilder(St7.kMaxStrLen); err = St7.St7GetBeamMaterialData(1, beamProp, materialArray); if (!St7Error(err)) { return(material); } err = St7.St7GetMaterialName(1, St7.ptBEAMPROP, beamProp, materialName, St7.kMaxStrLen); if (!St7Error(err)) { return(material); } // !!!! Materials are set based on Poisson Ratio !!!! if (materialArray[St7.ipBeamPoisson] <= 0.2) { material = BH.Engine.Structure.Create.Concrete(materialName.ToString(), materialArray[St7.ipBeamModulus], materialArray[St7.ipBeamPoisson], materialArray[St7.ipBeamAlpha], materialArray[St7.ipBeamDensity]); } else { material = BH.Engine.Structure.Create.Steel(materialName.ToString(), materialArray[St7.ipBeamModulus], materialArray[St7.ipBeamPoisson], materialArray[St7.ipBeamAlpha], materialArray[St7.ipBeamDensity]); } return(material); }
private IMaterialFragment GetBrickPropertyMaterial(int brickProp) { int err = 0; IMaterialFragment material = null; double[] materialArray = new double[8]; int materialType = 0; StringBuilder materialName = new StringBuilder(St7.kMaxStrLen); err = St7.St7GetBrickPropertyType(1, brickProp, ref materialType); if (materialType != St7.mtIsotropic) { return(material); // !!! ISOTROPIC ONLY !!! } err = St7.St7GetBrickIsotropicMaterial(1, brickProp, materialArray); if (!St7Error(err)) { return(material); } err = St7.St7GetMaterialName(1, St7.ptBRICKPROP, brickProp, materialName, St7.kMaxStrLen); // !!!! Materials are set based on Poisson Ratio !!!! if (materialArray[St7.ipBeamPoisson] <= 0.2) { material = BH.Engine.Structure.Create.Concrete(materialName.ToString(), materialArray[St7.ipBrickIsoModulus], materialArray[St7.ipBrickIsoPoisson], materialArray[St7.ipBrickIsoAlpha], materialArray[St7.ipBrickIsoDensity]); } else { material = BH.Engine.Structure.Create.Steel(materialName.ToString(), materialArray[St7.ipBrickIsoModulus], materialArray[St7.ipBrickIsoPoisson], materialArray[St7.ipBrickIsoAlpha], materialArray[St7.ipBrickIsoDensity]); } return(material); }
public static bool St7Units(bool active, St7UnitEnum st7UnitEnum) { if (!active) { return(false); } int[] units = new int[St7.kLastUnit]; if (st7UnitEnum == St7UnitEnum.kN_m) { units[St7.ipFORCEU] = St7.fuKILONEWTON; units[St7.ipLENGTHU] = St7.luMETRE; units[St7.ipSTRESSU] = St7.suKILOPASCAL; } else if (st7UnitEnum == St7UnitEnum.N_mm) { units[St7.ipLENGTHU] = St7.luMILLIMETRE; units[St7.ipFORCEU] = St7.fuNEWTON; units[St7.ipSTRESSU] = St7.suMEGAPASCAL; } units[St7.ipMASSU] = St7.muKILOGRAM; units[St7.ipTEMPERU] = St7.tuKELVIN; units[St7.ipENERGYU] = St7.euJOULE; int err = St7.St7SetUnits(1, units); return(St7Error(err)); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateObject(PointLoad pointLoad) { int err = 0; int loadCaseId = GetAdapterId <int>(pointLoad); double[] forces = new double[3]; double[] moments = new double[3]; forces[0] = pointLoad.Force.X; forces[1] = pointLoad.Force.Y; forces[2] = pointLoad.Force.Z; moments[0] = pointLoad.Moment.X; moments[1] = pointLoad.Moment.Y; moments[2] = pointLoad.Moment.Z; foreach (Node node in pointLoad.Objects.Elements) { int nodeId = GetAdapterId <int>(node); err = St7.St7SetNodeForce3(1, nodeId, loadCaseId, forces); if (!St7ErrorCustom(err, "Couldn't set point load for a loadcase " + loadCaseId + " node " + nodeId)) { return(false); } err = St7.St7SetNodeMoment3(1, nodeId, loadCaseId, moments); if (!St7ErrorCustom(err, "Couldn't set point load for a loadcase " + loadCaseId + " node " + nodeId)) { return(false); } } return(true); }
public static void CheckiErr(int iErr) { StringBuilder sb = new StringBuilder(St7.kMaxStrLen); string errorstring; St7.St7GetAPIErrorString(iErr, sb, sb.Capacity); errorstring = sb.ToString(); if (errorstring == "") { St7.St7GetSolverErrorString(iErr, sb, sb.Capacity); errorstring = sb.ToString(); } if (errorstring != "No error.") { MessageBox.Show(errorstring); //Console.WriteLine(""); //Console.WriteLine("Strand7 API error: " + errorstring); //Console.WriteLine("The program has terminated early."); string sFilePath = System.IO.Path.GetTempPath() + "API Error Log.txt"; System.IO.File.WriteAllText(sFilePath, errorstring); Environment.Exit(0); } }
public static bool St7ImportRhino(string fileName, string fileDir, St7UnitEnum st7UnitEnum, bool active = false) { if (!active) { return(false); } int uID = 1; int err = 0; fileDir = fileDir.EndsWith(Path.DirectorySeparatorChar.ToString()) ? fileDir : fileDir + Path.DirectorySeparatorChar; string tempDir = string.Concat(fileDir, "tmp" + Path.DirectorySeparatorChar); if (!Directory.Exists(tempDir)) { Directory.CreateDirectory(tempDir); } int[] Integers = new int[5]; Integers[St7.ipGeomImportProperty] = 1; Integers[St7.ipGeomImportCurvesToBeams] = St7.btFalse; Integers[St7.ipGeomImportGroupsAs] = St7.ggLayers; Integers[St7.ipGeomImportColourAsProperty] = St7.btTrue; if (st7UnitEnum == St7UnitEnum.N_mm) { Integers[St7.ipGeomImportLengthUnit] = St7.luGeomMillimetre; } else if (st7UnitEnum == St7UnitEnum.kN_m) { Integers[St7.ipGeomImportLengthUnit] = St7.luGeomMetre; } double[] Doubles = new double[] { 0.001 }; int Mode = St7.ieQuietRun; err = St7.St7ImportRhino(uID, string.Concat(fileDir, fileName), Integers, Doubles, Mode); int numFaces = 0; err = St7.St7GetTotal(uID, St7.tyGEOMETRYFACE, ref numFaces); foreach (int i in Enumerable.Range(1, numFaces + 1)) { err = St7.St7SetEntitySelectState(uID, St7.tyGEOMETRYFACE, i, 0, St7.btTrue); } err = St7.St7SetKeepSelect(1, St7.btFalse); if (st7UnitEnum == St7UnitEnum.N_mm) { err = St7.St7GraftEdgesToFaces(1, St7.ztAbsolute, 0.01); } else if (st7UnitEnum == St7UnitEnum.kN_m) { err = St7.St7GraftEdgesToFaces(1, St7.ztAbsolute, 0.0001); } return(St7Error(err)); }
public static bool St7SaveFile(bool active = false) { if (!active) { return(false); } int err = St7.St7SaveFile(1); return(St7Error(err)); }
private List <Loadcase> ReadLoadcase(List <string> ids = null) { List <Loadcase> loadCases = new List <Loadcase>(); int err = 0; int loadCaseCount = 0; err = St7.St7GetNumLoadCase(1, ref loadCaseCount); if (!St7ErrorCustom(err, "Could not get loadcases")) { return(loadCases); } for (int ldCs = 1; ldCs <= loadCaseCount; ldCs++) { StringBuilder loadCaseName = new StringBuilder(St7.kMaxStrLen); err = St7.St7GetLoadCaseName(1, ldCs, loadCaseName, St7.kMaxStrLen); if (!St7ErrorCustom(err, "Could not get a name of loadcase " + ldCs)) { continue; } int caseType = 0; err = St7.St7GetLoadCaseType(1, ldCs, ref caseType); if (!St7ErrorCustom(err, "Could not get a type of loadcase " + ldCs)) { continue; } Loadcase ldcase = null; if (caseType == St7.lcNoInertia) { ldcase = BH.Engine.Structure.Create.Loadcase(loadCaseName.ToString(), ldCs); } else if (caseType == St7.lcAccelerations) { ldcase = BH.Engine.Structure.Create.Loadcase(loadCaseName.ToString(), ldCs, LoadNature.Notional); } else if (caseType == St7.lcSeismic) { ldcase = BH.Engine.Structure.Create.Loadcase(loadCaseName.ToString(), ldCs, LoadNature.Seismic); } else if (caseType == St7.lcGravity) { ldcase = BH.Engine.Structure.Create.Loadcase(loadCaseName.ToString(), ldCs, LoadNature.Dead); } else { BHError("Load Type is not supported"); } if (!(ldcase is null)) { SetAdapterId(ldcase, ldCs); ldcase.Number = ldCs; loadCases.Add(ldcase); } } return(loadCases); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateObject(GravityLoad gravityLoad) { int err = 0; Loadcase loadcase = gravityLoad.Loadcase; int loadCaseId = GetAdapterId <int>(loadcase); err = St7.St7SetLoadCaseType(1, loadCaseId, St7.lcGravity); err = St7.St7EnableLSALoadCase(1, loadCaseId, 1); if (!St7ErrorCustom(err, "Couldn't set gravity for a loadcase " + loadCaseId)) { return(false); } int gravityDir = 0; if (gravityLoad.GravityDirection.X != 0) { gravityDir = 1; } if (gravityLoad.GravityDirection.Y != 0) { gravityDir = 2; } if (gravityLoad.GravityDirection.Z != 0) { gravityDir = 3; } err = St7.St7SetLoadCaseGravityDir(1, loadCaseId, gravityDir); if (!St7ErrorCustom(err, "Couldn't set gravity direction for a loadcase " + loadCaseId)) { return(false); } int[] units = new int[St7.kLastUnit]; err = St7.St7GetUnits(1, units); if (!St7ErrorCustom(err, "Couldn't get default units for a loadcase " + loadCaseId)) { return(false); } double temp = St7TempFromTUnints(units[St7.ipTEMPERU]); double accel = St7AccelerationFromLUnints(units[St7.ipLENGTHU]); // Load case defaults array double[] loadVals = new double[13]; loadVals[St7.ipLoadCaseRefTemp] = temp; loadVals[St7.ipLoadCaseAccX] = gravityDir == 1 ? accel : 0; loadVals[St7.ipLoadCaseAccY] = gravityDir == 2 ? accel : 0; loadVals[St7.ipLoadCaseAccZ] = gravityDir == 3 ? accel : 0; err = St7.St7SetLoadCaseDefaults(1, loadCaseId, loadVals); if (!St7ErrorCustom(err, "Couldn't set gravity acceleration for a loadcase " + loadCaseId)) { return(false); } return(true); }
public static OpenResultsOut St7OpenResults(string fileName, string fileDir, bool getCaseNames = true, bool generateCombinations = false, bool generateEnvelopes = false, bool active = false) { if (!active) { return(new OpenResultsOut(false, null, null)); } List <string> caseNames = new List <string>(); List <int> caseIds = new List <int>(); int err = St7.St7CloseResultFile(1); int primaryCases = 0; int secondaryCases = 0; int warningCode = 0; string spectralFileName = string.Empty; int combinations = generateCombinations ? St7.kGenerateNewCombinations : St7.kNoCombinations; fileDir = fileDir.EndsWith(Path.DirectorySeparatorChar.ToString()) ? fileDir : fileDir + Path.DirectorySeparatorChar; err = St7.St7OpenResultFile(1, string.Concat(fileDir, fileName), spectralFileName, combinations, ref primaryCases, ref secondaryCases); if (!St7ErrorCustom(err, "Could not open results file")) { return(new OpenResultsOut(false, null, null)); } if (generateCombinations) { err = St7.St7GenerateLSACombinations(1, ref secondaryCases, ref warningCode); } if (!St7ErrorCustom(err, "Could not generate combinations")) { return(new OpenResultsOut(false, null, null)); } int numLimitEnvelopes = 0; int numCombEnvelopes = 0; int numFactorEnvelopes = 0; if (generateEnvelopes) { err = St7.St7GenerateEnvelopes(1, ref numLimitEnvelopes, ref numCombEnvelopes, ref numFactorEnvelopes); } if (!St7ErrorCustom(err, "Could not generate combinations")) { return(new OpenResultsOut(false, null, null)); } if (getCaseNames) { for (int i = 1; i <= primaryCases + secondaryCases + numLimitEnvelopes + numCombEnvelopes + numFactorEnvelopes; i++) { StringBuilder caseName = new StringBuilder(St7.kMaxStrLen); err = St7.St7GetResultCaseName(1, i, caseName, St7.kMaxStrLen); caseNames.Add(caseName.ToString()); caseIds.Add(i); } } return(new OpenResultsOut(St7Error(err), caseNames, caseIds)); }
private List <ILoad> ReadAreaLoad(List <Loadcase> loadcases) { int uID = 1; int err = 0; List <ILoad> bhLoads = new List <ILoad>(); List <Panel> bhPanels = ReadPanel(); Vector localPressure = new Vector(); Vector globalPressure = new Vector(); foreach (Loadcase ldcs in loadcases) { int ldcsId = GetAdapterId <int>(ldcs); foreach (Panel panel in bhPanels) { BHoMGroup <IAreaElement> panelObjects = new BHoMGroup <IAreaElement>() { Elements = { panel } }; int panelId = GetAdapterId <int>(panel); // local pressures double[] normalPressures = new double[2]; err = St7.St7GetPlateNormalPressure2(uID, panelId, ldcsId, normalPressures); double[] shearPressures = new double[2]; err = St7.St7GetPlateShear2(uID, panelId, ldcsId, shearPressures); localPressure = Vector.ZAxis * (normalPressures[0] - normalPressures[1]) + Vector.XAxis * shearPressures[0] + Vector.YAxis * shearPressures[1]; if (localPressure.Length() > 0) { bhLoads.Add(new AreaUniformlyDistributedLoad() { Loadcase = ldcs, Pressure = localPressure, Objects = panelObjects, Axis = LoadAxis.Local, Projected = false }); } // global pressures double[] globalPressuresZplus = new double[3]; double[] globalPressuresZminus = new double[3]; int projectionFlag = 0; err = St7.St7GetPlateGlobalPressure3S(uID, panelId, St7.psPlateZPlus, ldcsId, ref projectionFlag, globalPressuresZplus); err = St7.St7GetPlateGlobalPressure3S(uID, panelId, St7.psPlateZMinus, ldcsId, ref projectionFlag, globalPressuresZminus); globalPressure = BH.Engine.Geometry.Create.Vector(globalPressuresZplus[0] + globalPressuresZminus[0], globalPressuresZplus[1] + globalPressuresZminus[1], globalPressuresZplus[2] + globalPressuresZminus[2]); bool projected = projectionFlag != St7.ppNone; if (globalPressure.Length() > 0) { bhLoads.Add(new AreaUniformlyDistributedLoad() { Loadcase = ldcs, Pressure = globalPressure, Objects = panelObjects, Axis = LoadAxis.Global, Projected = projected }); } } } return(bhLoads); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ //The List<string> in the methods below can be changed to a list of any type of identification more suitable for the toolkit //If no ids are provided, the convention is to return all elements of the type private List <FEMesh> ReadMesh(List <int> ids = null) { // Just reading mesh without properties. Use all nodes. int uID = 1; int err = 0; int numberPlateElements = 0; err = St7.St7GetTotal(uID, St7.tyPLATE, ref numberPlateElements); if (!St7ErrorCustom(err, "Could not get total number of plate elements.")) { return(null); } List <Node> nodes = ReadNodes(); List <ISurfaceProperty> plateProps = ReadSurfaceProperty(); if (ids == null || ids.Count == 0) { ids = Enumerable.Range(1, numberPlateElements).ToList(); } FEMesh[] meshes = new FEMesh[plateProps.Count]; Dictionary <int, int> platePropsNumbers = new Dictionary <int, int>(); for (int i = 0; i < plateProps.Count; i++) { platePropsNumbers.Add(GetAdapterId <int>(plateProps[i]), i); meshes[i] = new FEMesh(); meshes[i].Nodes = nodes; meshes[i].Property = plateProps[i]; meshes[i].Name = plateProps[i].Name; SetAdapterId(meshes[i], i); } foreach (int id in ids) { int platePropNum = 0; err = St7.St7GetElementProperty(uID, St7.ptPLATEPROP, id, ref platePropNum); int propIndex = platePropsNumbers[platePropNum]; FEMeshFace face = new FEMeshFace(); SetAdapterId(face, id); int[] plateConnection = new int[St7.kMaxElementNode + 1]; err = St7.St7GetElementConnection(uID, St7.tyPLATE, id, plateConnection); if (plateConnection[0] == 3 || plateConnection[0] == 6) // Plate elements Tri3 and Tri6. Firt index is a number of vertices { face.NodeListIndices = new int[] { plateConnection[1] - 1, plateConnection[2] - 1, plateConnection[3] - 1 }.ToList(); } else // All quad elements { face.NodeListIndices = new int[] { plateConnection[1] - 1, plateConnection[2] - 1, plateConnection[3] - 1, plateConnection[4] - 1 }.ToList(); } meshes[propIndex].Faces.Add(face); } return(meshes.ToList()); }
private int addElementToGroup(int uID, int groupID, FEMesh feMesh) { int err = 0; foreach (FEMeshFace fEMeshFace in feMesh.Faces) { int plateId = GetAdapterId <int>(fEMeshFace); err = St7.St7SetEntityGroup(uID, St7.tyPLATE, plateId, groupID); if (!St7Error(err)) { return(err); } } return(0); }
/***************************************************/ /**** Constructors ****/ /***************************************************/ //Add any applicable constructors here, such as linking to a specific file or anything else as well as linking to that file through the (if existing) com link via the API public Strand7Adapter(bool initialise = false, double tolerance = 0.1) { if (initialise) { int err = St7.St7Init(); if (St7Error(err)) { Tolerance = tolerance; AdapterIdFragmentType = typeof(Strand7Id); SetupDependencies(); SetupComparers(); AdapterIdName = BH.Engine.Strand7.Convert.AdapterId; //Sets` the "AdapterId" to "SoftwareName_id". Generally stored as a constant string in the convert class in the } } }
public static BeamResults St7GetBeamResultsEnds(List <int> caseIds, List <int> beamIDs, List <int> beamEnd, St7ResultForceComponent component, St7BeamResultsTypes resultType = St7BeamResultsTypes.BeamForce, St7BeamResultAxis resultAxis = St7BeamResultAxis.Principal, bool active = false) { if (!active) { return(null); } int err; int uID = 1; List <List <double> > valuesResults = new List <List <double> >(); List <List <int> > resultsPerStation = new List <List <int> >(); // output from strand 7 double[] beamResult = new double[St7.kMaxBeamResult]; int numColumns = 0; for (int i = 0; i < beamIDs.Count; i++) { int beamId = beamIDs[i]; List <double> interValues = new List <double>(); List <int> interResPerStation = new List <int>(); foreach (int loadcaseId in caseIds) { err = St7.St7GetBeamResultEndPos(uID, (int)resultType, (int)resultAxis, beamId, loadcaseId, ref numColumns, beamResult); if (component == St7ResultForceComponent.All) { interResPerStation.Add(numColumns); } else { interResPerStation.Add(1); } if (beamEnd[i] == 1) { interValues.AddRange(beamResult.Take(numColumns)); } else { interValues.AddRange(beamResult.Skip(numColumns).Take(numColumns)); } } valuesResults.Add(interValues); resultsPerStation.Add(interResPerStation); } return(new BeamResults(true, new List <List <double> >(), valuesResults, new List <List <int> >(), resultsPerStation)); }
public static bool St7OpenFile(string fileName, string fileDir, bool active = false) { if (!active) { return(false); } int err = St7.St7CloseFile(1); fileDir = fileDir.EndsWith(Path.DirectorySeparatorChar.ToString()) ? fileDir : fileDir + Path.DirectorySeparatorChar; string tempDir = string.Concat(fileDir, "tmp" + Path.DirectorySeparatorChar); if (!Directory.Exists(tempDir)) { Directory.CreateDirectory(tempDir); } err = St7.St7OpenFile(1, string.Concat(fileDir, fileName), tempDir); return(St7Error(err)); }
public static bool St7NoteCustom(int code, string customString) { if (code == St7.ERR7_NoError) { return(true); } StringBuilder errorSb = new StringBuilder(St7.kMaxStrLen); if (St7.ERR7_NoError == St7.St7GetAPIErrorString(code, errorSb, St7.kMaxStrLen)) { Engine.Base.Compute.RecordNote(errorSb.ToString() + ". " + customString); } else if (St7.ERR7_NoError == St7.St7GetSolverErrorString(code, errorSb, St7.kMaxStrLen)) { Engine.Base.Compute.RecordNote(errorSb.ToString() + ". " + customString); } return(false); }
public static bool St7Error(int code) { if (code == St7.ERR7_NoError) { return(true); } StringBuilder errorSb = new StringBuilder(St7.kMaxStrLen); if (St7.ERR7_NoError == St7.St7GetAPIErrorString(code, errorSb, St7.kMaxStrLen)) { Engine.Base.Compute.RecordError(errorSb.ToString()); } else if (St7.ERR7_NoError == St7.St7GetSolverErrorString(code, errorSb, St7.kMaxStrLen)) { Engine.Base.Compute.RecordError(errorSb.ToString()); } return(false); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ //The List<string> in the methods below can be changed to a list of any type of identification more suitable for the toolkit //If no ids are provided, the convention is to return all elements of the type private List <Node> ReadNodes(List <string> ids = null) { int err = 0; int nodeCount = 0; List <Node> nodes = new List <Node>(); double[] XYZ = new double[3]; err = St7.St7GetTotal(1, St7.tyNODE, ref nodeCount); if (!St7Error(err)) { return(nodes); } for (int nn = 0; nn < nodeCount; nn++) { int nodeId = nn + 1; // getting node coordinates err = St7.St7GetNodeXYZ(1, nodeId, XYZ); if (!St7ErrorCustom(err, "Could not get a position of node: " + nodeId.ToString())) { continue; } // getting node restraints // !!! LOCAL RESTRAINTS ARE NOT IMPLEMENTED !!!! read UCS and write it to Orientation property in Node int ucsId = 1; int[] restraints = new int[6]; double[] enforcedDispls = new double[6]; List <bool> bhFixed = new List <bool>(); err = St7.St7GetNodeRestraint6(1, nodeId, 1, ref ucsId, restraints, enforcedDispls); bhFixed = restraints.Select(rst => rst == St7.btTrue).ToList(); double[] translationStiff = new double[3]; err = St7.St7GetNodeKTranslation3F(1, nodeId, 1, ref ucsId, translationStiff); double[] rotationStiff = new double[3]; err = St7.St7GetNodeKRotation3F(1, nodeId, 1, ref ucsId, rotationStiff); List <double> stiffnessVals = new List <double>(); stiffnessVals.AddRange(translationStiff); stiffnessVals.AddRange(rotationStiff); Constraint6DOF bhRestraint = BH.Engine.Structure.Create.Constraint6DOF("", bhFixed, stiffnessVals); Node bhNode = BH.Engine.Structure.Create.Node(BH.Engine.Geometry.Create.Point(XYZ[0], XYZ[1], XYZ[2]), "", bhRestraint); SetAdapterId(bhNode, nodeId); nodes.Add(bhNode); } return(nodes); }
private List <LoadCombination> ReadLoadCombination(List <string> ids = null) { // Linear Load Combinations !! Only !! // only solver generated combinations List <LoadCombination> loadCombinations = new List <LoadCombination>(); int err = 0; int uID = 1; int freedomCase = 1; int loadComboCount = 0; List <Loadcase> allLoadCases = ReadLoadcase(); err = St7.St7GetNumLSACombinations(uID, ref loadComboCount); if (!St7ErrorCustom(err, "Could not get loadCombinations")) { return(loadCombinations); } for (int ldCombo = 1; ldCombo <= loadComboCount; ldCombo++) { StringBuilder loadComboName = new StringBuilder(St7.kMaxStrLen); err = St7.St7GetLSACombinationName(uID, ldCombo, loadComboName, St7.kMaxStrLen); if (!St7ErrorCustom(err, "Could not get a name of load combination " + ldCombo)) { continue; } List <double> loadCaseFactors = new List <double>(); for (int j = 0; j < allLoadCases.Count; j++) { int loadcaseNum = GetAdapterId <int>(allLoadCases[j]); double factor = 0; err = St7.St7GetLSACombinationFactor(uID, St7.ltLoadCase, ldCombo, loadcaseNum, freedomCase, ref factor); if (!St7ErrorCustom(err, "Could not get a factor for a loadcase " + loadcaseNum + " load combo " + ldCombo)) { return(loadCombinations); } loadCaseFactors.Add(factor); } LoadCombination loadCombination = BH.Engine.Structure.Create.LoadCombination(loadComboName.ToString(), ldCombo, allLoadCases, loadCaseFactors); SetAdapterId(loadCombination, ldCombo); loadCombinations.Add(loadCombination); } return(loadCombinations); }
public static bool St7SetBeamTaper(int beamId, int taperAxis, int taperType, double ratioStart, double ratioEnd, bool active = false) { if (!active) { return(false); } int err; int uID = 1; // checking node ids err = St7.St7SetBeamTaper2(1, beamId, taperAxis, taperType, new double[] { ratioStart, ratioEnd }); if (!St7Error(err)) { return(false); } return(true); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateObject(St7RigidMPLink link) { int linkId = GetAdapterId <int>(link); // Geometry int uID = 1; int err = 0; List <int> nodeIds = link.SlaveNodes.Select(nd => GetAdapterId <int>(nd)).ToList(); nodeIds.Insert(0, GetAdapterId <int>(link.MasterNode)); int[] connection = nodeIds.ToArray(); err = St7.St7SetRigidMultiPointLink(uID, linkId, nodeIds.Count, link.UCS, (int)link.UCSPlane, connection); if (!St7Error(err)) { return(false); } return(true); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateObject(BarPreLoad barPointLoad) { int err = 0; int uID = 1; int loadCaseId = GetAdapterId <int>(barPointLoad.Loadcase); // *************************** GLOBAL *************************** foreach (Bar bar in barPointLoad.Objects.Elements) { int barId = GetAdapterId <int>(bar); err = St7.St7SetBeamPreLoad1(uID, barId, loadCaseId, (int)barPointLoad.PreloadType, new double[] { barPointLoad.Prestress }); if (!St7ErrorCustom(err, "Couldn't set global beam preload for a loadcase " + loadCaseId + " beam " + barId)) { return(false); } } return(true); }