/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA, EvaluationUnit unit) { //OnComponentLoaded(); // Input counter //modelDataCount1 = 1 + modelDataCount2; // RFEM variables var modelName = ""; IModel model = null; IModelData data = null; ILoads loads = null; // Output message var msg = new List <string>(); // Assign GH Input bool run = false; var scale = 0.0; DA.GetData(0, ref run); DA.GetData(1, ref scale); // Do stuff if (run) { if (!DA.GetData(3, ref modelName)) { Component_GetData.ConnectRFEM(ref model, ref data); } else { Component_GetData.ConnectRFEM(modelName, ref model, ref data); } _saveddata = data; try { // Get deformtions _resetLC = true; // Get loads Component_GetData.GetLoadsFromRFEM(model, ref loads); // Get calculation results _results = model.GetCalculation(); var errors = _results.CalculateAll(); if (errors != null) { msg.AddRange(errors.Select(x => x.Description)); } // Update load cases and combos to display in dropdown menu loads.GetLoadCasesAndCombos(ref _lCasesAndCombos, ref _countCases, ref _countCombos, ref _countRcombos); updateDropDownMenu(_lCasesAndCombos); // Get Fe Meshes from RFEM _rfemMesh = _results.GetFeMesh(); _feMeshes = CreateFEMeshes(ref msg); // _controlPoints = CreateControlPoints(ref msg); -> Obtained with displacements } catch (Exception ex) { // Clear output!!! _saveddata = null; _rfemMesh = null; _results = null; _lcresults = null; _feMeshes.Clear(); _meshdisplacements.Clear(); _deformedMeshes.Clear(); _controlPoints.Clear(); _memberdisplacements.Clear(); _deformedMembers.Clear(); throw ex; } Component_GetData.DisconnectRFEM(ref model, ref data); } // Get results to display if (_loadDrop.Items.Count > 0 && _resetLC && msg.Count == 0) { int no = Int16.Parse(_loadDrop.Items[_loadDrop.Value].name.Split(' ')[1]); if (_loadDrop.Value < _countCases) { _lcresults = _results.GetResultsInFeNodes(LoadingType.LoadCaseType, no); } else if (_loadDrop.Value < _countCases + _countCombos) { _lcresults = _results.GetResultsInFeNodes(LoadingType.LoadCombinationType, no); } else if (_loadDrop.Value < _countCases + _countCombos + _countRcombos) { _lcresults = _results.GetResultsInFeNodes(LoadingType.ResultCombinationType, no); } else { msg.Add("Load case or combo not found"); } // Get deformations _meshdisplacements = GetMeshDisplacements(ref msg); _memberdisplacements = GetMemberDisplacements(ref msg); // Set _resetLC to false again _resetLC = false; } // Get output _deformedMeshes = GetDeformedMeshes(scale, ref msg); _deformedMembers = GetDeformedMembers(scale, ref msg); // Assign GH Output DA.SetDataTree(0, _deformedMembers); DA.SetDataTree(1, _deformedMeshes); if (msg.Count != 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, String.Join(System.Environment.NewLine, msg.ToArray())); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA, EvaluationUnit unit) { // RFEM variables var modelName = ""; IModel model = null; IModelData data = null; ILoads loads = null; // Assign GH Input bool run = false; var scale = 0.0; string iLoadCase = ""; DA.GetData(0, ref run); DA.GetData(1, ref scale); // Do stuff if (run) { msg = new List <string>(); if (!DA.GetData(5, ref modelName)) { Component_GetData.ConnectRFEM(ref model, ref data); } else { Component_GetData.ConnectRFEM(modelName, ref model, ref data); } _saveddata = data; try { // Get deformtions _resetLC = true; // Get loads Component_GetData.GetLoadsFromRFEM(model, ref loads); // Update load cases and combos to display in dropdown menu _results = model.GetCalculation(); // Get load cases and combos to var newLoadCasesAndCombos = new List <string>(); newLoadCasesAndCombos = loads.GetLoadCasesAndCombos(ref _countCases, ref _countCombos, ref _countRcombos); if (_lCasesAndCombos == null || _lCasesAndCombos.Count == 0 || !_lCasesAndCombos.Equals(newLoadCasesAndCombos)) { _lCasesAndCombos = newLoadCasesAndCombos; _loadDropLastValue = 0; // reset dropdown menus if run _resultDropLastValue = 0; _lastLoadCase = ""; _lastType = 0; _restoreDropDown = true; } // Get deformed shape? if (_deformationsCheck.Active) { _deformation_results = true; // Get members _rfMembers = Component_GetData.GetRFMembers(data.GetMembers().ToList(), data); // Get Fe Meshes from RFEM _rfemMesh = _results.GetFeMesh(); _feMeshes = CreateFEMeshes(ref msg); } else { _deformation_results = false; } // Disconnect RFEM Component_GetData.DisconnectRFEM(ref model, ref data); // Results are displayed just when the button is set to 0 - if no LC is provided var dummyLC = ""; if (!DA.GetData(2, ref dummyLC)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Set run to false to display results"); return; } } catch (Exception ex) { Component_GetData.DisconnectRFEM(ref model, ref data); // Clear output!!! _saveddata = null; _rfemMesh = null; _results = null; _lcresults = null; outResults = null; _feMeshes.Clear(); _meshdisplacements.Clear(); _meshdisplacementsByType.Clear(); _deformedMeshes.Clear(); _controlPoints.Clear(); _memberdisplacements.Clear(); _memberdisplacementsByType.Clear(); _deformedMembers.Clear(); _sfcNo.Clear(); _memberNo.Clear(); _deformation_results = false; throw ex; } } // do stuff if (msg.Count == 0) // if there are no calculation errors { // Get Load Case Number and result type int result_type = 0; string result_type_name = ""; if (DA.GetData(2, ref iLoadCase)) { if (DA.GetData(3, ref result_type)) { if (result_type <= 0 || result_type > Enum.GetNames(typeof(ResultsValueType)).Length - 1) { _loadDrop.Clear(); _resulttypeDrop.Clear(); _restoreDropDown = true; // for next time AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Provide Valid Result Type."); return; } result_type_name = Enum.GetName(typeof(ResultsValueType), result_type); if (_lastLoadCase != iLoadCase || _lastType != result_type) // otherwise execution comes from change in scale and no need to reset load case { _resetLC = true; } _loadDrop.Clear(); _resulttypeDrop.Clear(); _restoreDropDown = true; // for next time } else { _loadDrop.Clear(); _resulttypeDrop.Clear(); _restoreDropDown = true; // for next time AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Provide Result Type."); return; } } else if (DA.GetData(3, ref result_type)) { _loadDrop.Clear(); _resulttypeDrop.Clear(); _restoreDropDown = true; // for next time AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Provide Load Case or Combo."); return; } else // get values from dropdown menus { if (_lCasesAndCombos.Count == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No results to display"); _loadDrop.Clear(); _resulttypeDrop.Clear(); return; } if (_restoreDropDown) // from previous execution when it was overwritten { updateDropDownMenu(_lCasesAndCombos); _resetLC = true; _restoreDropDown = false; // for next time } iLoadCase = _loadDrop.Items[_loadDrop.Value].name; } // Get results to display // 1) Results from load case or combo for all types 2) Results for selected result type 3) Apply scale if (_resetLC) { int no = Int16.Parse(iLoadCase.Split(' ')[1]); var value = _lCasesAndCombos.IndexOf(iLoadCase); _loadDropLastValue = value; _lastLoadCase = iLoadCase; if (value == -1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"{iLoadCase} has no results. Provide valid load case."); return; } if (value < _countCases) { _lcresults = _results.GetResultsInFeNodes(LoadingType.LoadCaseType, no); } else if (value < _countCases + _countCombos) { _lcresults = _results.GetResultsInFeNodes(LoadingType.LoadCombinationType, no); } else if (value < _countCases + _countCombos + _countRcombos) { _lcresults = _results.GetResultsInFeNodes(LoadingType.ResultCombinationType, no); } else { msg.Add("Load case or combo not found"); return; } // Get analysis results _resultTypes = new HashSet <ResultsValueType>(); outResults = new RFResults(_lcresults, _saveddata, buttonLocal.Active, ref _resultTypes, iLoadCase, _memberForcesCheck.Active, _surfaceForcesCheck.Active, _nodalReactionsCheck.Active, _lineReactionsCheck.Active); // Get deformations if (_deformationsCheck.Active) { if (!_deformation_results) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Run component again to get deformation results."); } else { _meshdisplacements = GetMeshDisplacements(ref _sfcNo, ref msg); _memberdisplacements = GetMemberDisplacements(ref _memberNo, ref msg); _meshdisplacementsByType = GetMeshDisplacementsByType(result_type); _memberdisplacementsByType = GetMemberDisplacementsByType(result_type); } } // Update drop down menu of result types if (result_type == 0) // if no value obtaines through overwrite { _resultDropLastValue = 0; updateDropDownMenu2(_resultTypes.ToList(), ref result_type); } // Set _resetLC to false again _resetLC = false; _resetResultType = true; } if (_resetResultType) // when there are changes in drop down menu { if (result_type == 0) // if no value obtaines through overwrite { result_type = Int32.Parse(_resulttypeDrop.Items[_resulttypeDrop.Value].name); } if (_deformationsCheck.Active) { _meshdisplacementsByType = GetMeshDisplacementsByType(result_type); _memberdisplacementsByType = GetMemberDisplacementsByType(result_type); } // Get analysis results if (result_type > 0) { outResults.ResultType = ((ResultsValueType)result_type).ToString(); } // Set _resetType to false again _resetResultType = false; } _lastType = result_type; // Check results if (_meshdisplacements.DataCount > 0 && _meshdisplacementsByType.DataCount == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"No surface results found for result type {((ResultsValueType)result_type).ToString()}"); } if (_memberdisplacements.DataCount > 0 && _memberdisplacementsByType.DataCount == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"No member results found for result type {((ResultsValueType)result_type).ToString()}"); } // Get output _deformedMeshes = GetDeformedMeshes(scale, ref msg); _deformedMembers = GetDeformedMembers(scale, ref msg); // Output calculation results DA.SetData(0, outResults); // Assign GH Output DA.SetDataList(1, _deformedMembers); DA.SetDataList(2, _memberNo); DA.SetDataList(3, _deformedMeshes); DA.SetDataList(4, _sfcNo); } if (msg.Count > 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, String.Join(System.Environment.NewLine, msg.ToArray())); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA, EvaluationUnit unit) { // RFEM variables var modelName = ""; IModel model = null; IModelData data = null; ILoads loads = null; ICalculation results = null; // Output message var msg = new List <string>(); // Assign GH Input bool run = false; var iLcases = new List <string>(); DA.GetData(0, ref run); // Do stuff if (run) { if (!DA.GetData(3, ref modelName)) { Component_GetData.ConnectRFEM(ref model, ref data); } else { Component_GetData.ConnectRFEM(modelName, ref model, ref data); } try { // Get loads Component_GetData.GetLoadsFromRFEM(model, ref loads); // Get calculation results = model.GetCalculation(); // Update results _maxDisplacements = new List <Vector3d>(); _loadCasesAndCombos = new List <string>(); // Get load cases and combos if (!DA.GetDataList(1, iLcases)) { var errors = results.CalculateApp(); if (errors != null) { msg.AddRange(errors.Select(x => x.Description)); } _loadCasesAndCombos = loads.GetLoadCasesAndCombos(0, 0, 0); } else { _loadCasesAndCombos = iLcases; } // Get results foreach (var lc in _loadCasesAndCombos) { Vector3d displacement = new Vector3d(0, 0, 0); Component_GetResults.GetResults(ref results, lc, ref displacement, ref msg); _maxDisplacements.Add(displacement); } } catch (Exception ex) { // Clear output!!! results = null; _maxDisplacements = null; _loadCasesAndCombos = null; Component_GetData.DisconnectRFEM(ref model, ref data); throw ex; } Component_GetData.DisconnectRFEM(ref model, ref data); } if (msg.Count > 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, String.Join(System.Environment.NewLine, msg.ToArray())); } { DA.SetDataList(0, _loadCasesAndCombos); DA.SetDataList(1, _maxDisplacements); } }