Skip to content

Commit

Permalink
Merge branch 'main' into feature/GSAGH-367-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kpne authored Oct 13, 2023
2 parents 6b2c394 + 67f6a95 commit eb1cb7a
Show file tree
Hide file tree
Showing 28 changed files with 155 additions and 129 deletions.
Binary file not shown.
21 changes: 17 additions & 4 deletions GsaGH/Components/0_Model/SaveGsaModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class SaveGsaModel : GH_OasysDropDownComponent {
public override OasysPluginInfo PluginInfo => GsaGH.PluginInfo.Instance;
protected override Bitmap Icon => Resources.SaveGsaModel;
private string _fileNameLastSaved;
private bool _saveInputOverride = false;

public SaveGsaModel() : base("Save GSA Model", "Save",
"Saves your GSA model from this parametric nightmare", CategoryName.Name(),
Expand Down Expand Up @@ -95,8 +96,9 @@ protected override void SolveInternal(IGH_DataAccess da) {
da.GetData(2, ref fileName);

bool save = false;
if (da.GetData(1, ref save) && save) {
if (da.GetData(1, ref save) && (save || _saveInputOverride)) {
Save(ref gsaModel, fileName);
_saveInputOverride = false;
}

da.SetData(0, new GsaModelGoo(gsaModel));
Expand All @@ -121,7 +123,12 @@ internal void Save(ref GsaModel model, string fileNameAndPath) {
}

internal void SaveButtonClick() {
UpdateUI();
if (string.IsNullOrEmpty(_fileNameLastSaved)) {
SaveAsButtonClick();
return;
}

_saveInputOverride = true;
}

internal void SaveAsButtonClick() {
Expand Down Expand Up @@ -153,9 +160,15 @@ internal void SaveAsButtonClick() {
}

internal void OpenGsaExe() {
if (!string.IsNullOrEmpty(_fileNameLastSaved)) {
Process.Start(_fileNameLastSaved);
if (string.IsNullOrEmpty(_fileNameLastSaved)) {
Params.Input[0].CollectData();
var tempModel = (GsaModelGoo)Params.Input[0].VolatileData.AllData(true).First();
string tempPath = Path.GetTempPath() + tempModel.Value.Guid.ToString() + ".gwb";
GsaModel gsaModel = tempModel.Value;
Save(ref gsaModel, tempPath);
}

Process.Start(_fileNameLastSaved);
}
}
}
22 changes: 14 additions & 8 deletions GsaGH/Components/3_Loads/CreateGridPointLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,19 @@ protected override void SolveInternal(IGH_DataAccess da) {
GH_Convert.ToPoint3d(ghPt, ref point3d, GH_Conversion.Both);
}

gridPointLoad.ApiLoad.X = point3d.X;
gridPointLoad.ApiLoad.Y = point3d.Y;

GsaGridPlaneSurface gridPlaneSurface;
Plane plane = Plane.WorldXY;
var ghTyp = new GH_ObjectWrapper();
if (da.GetData(2, ref ghTyp)) {
switch (ghTyp.Value) {
case GsaGridPlaneSurfaceGoo gridplanesurfacegoo: {
case GsaGridPlaneSurfaceGoo gridplanesurfacegoo:
gridPlaneSurface = gridplanesurfacegoo.Value.Duplicate();
gridPointLoad.GridPlaneSurface = gridPlaneSurface;
_expansionType = ExpansionType.UseGpsSettings;
UpdateMessage(gridPlaneSurface.GridSurface.ElementType
== GsaAPI.GridSurface.Element_Type.ONE_DIMENSIONAL ? "1D" : "2D");
break;
}

case GH_Plane pln:
plane = pln.Value;
gridPlaneSurface = new GsaGridPlaneSurface(plane);
Expand All @@ -173,7 +170,7 @@ protected override void SolveInternal(IGH_DataAccess da) {
== GsaAPI.GridSurface.Element_Type.ONE_DIMENSIONAL ? "1D" : "2D");
break;

default: {
default:
if (GH_Convert.ToInt32(ghTyp.Value, out int id, GH_Conversion.Both)) {
gridPointLoad.ApiLoad.GridSurface = id;
gridPointLoad.GridPlaneSurface = null;
Expand All @@ -186,11 +183,10 @@ protected override void SolveInternal(IGH_DataAccess da) {
}

break;
}
}
} else {
plane = Plane.WorldXY;
plane.Origin = point3d;
plane.Origin = new Point3d(0, 0, point3d.Z);
gridPlaneSurface = new GsaGridPlaneSurface(plane, true);
gridPointLoad.GridPlaneSurface = gridPlaneSurface;

Expand Down Expand Up @@ -220,6 +216,16 @@ protected override void SolveInternal(IGH_DataAccess da) {
}
}

var plnNormal = new Vector3d(plane.Normal);
plnNormal.Unitize();
if (plnNormal.Z != 1) {
this.AddRuntimeRemark("The grid plane basis is not defined in world coordinates. \n" +
"The input point´s X and Y coordinates are use as the grid plane´s local coordiantes.");
}

gridPointLoad.ApiLoad.X = point3d.X;
gridPointLoad.ApiLoad.Y = point3d.Y;

string dir = "Z";
GsaAPI.Direction direc = GsaAPI.Direction.Z;

Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/5_Results/Element2dStresses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void InitialiseDropdowns() {
_selectedItems = new List<string>();

_dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Stress));
_selectedItems.Add(_stresshUnit.ToString());
_selectedItems.Add(Pressure.GetAbbreviation(_stresshUnit));

_isInitialised = true;
}
Expand Down
85 changes: 18 additions & 67 deletions GsaGH/Components/5_Results/Element3dDisplacements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ protected override void RegisterInputParams(GH_InputParamManager pManager) {

protected override void RegisterOutputParams(GH_OutputParamManager pManager) {
string unitAbbreviation = Length.GetAbbreviation(_lengthUnit);

string note = ResultNotes.Note2dResults;

pManager.AddGenericParameter("Translations X [" + unitAbbreviation + "]", "Ux",
"Translations in X-direction in Global Axis." + note, GH_ParamAccess.tree);
pManager.AddGenericParameter("Translations Y [" + unitAbbreviation + "]", "Uy",
Expand All @@ -86,14 +84,6 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) {
"Translations in Z-direction in Global Axis." + note, GH_ParamAccess.tree);
pManager.AddGenericParameter("Translations |XYZ| [" + unitAbbreviation + "]", "|U|",
"Combined |XYZ| Translations." + note, GH_ParamAccess.tree);
pManager.AddGenericParameter("Rotations XX [rad]", "Rxx",
"Rotations around X-axis in Global Axis." + note, GH_ParamAccess.tree);
pManager.AddGenericParameter("Rotations YY [rad]", "Ryy",
"Rotations around Y-axis in Global Axiss." + note, GH_ParamAccess.tree);
pManager.AddGenericParameter("Rotations ZZ [rad]", "Rzz",
"Rotations around Z-axis in Global Axis." + note, GH_ParamAccess.tree);
pManager.AddGenericParameter("Rotations |XYZ| [rad]", "|R|",
"Combined |XXYYZZ| Rotations." + note, GH_ParamAccess.tree);
}

protected override void SolveInternal(IGH_DataAccess da) {
Expand All @@ -105,10 +95,6 @@ protected override void SolveInternal(IGH_DataAccess da) {
var outTransY = new DataTree<GH_UnitNumber>();
var outTransZ = new DataTree<GH_UnitNumber>();
var outTransXyz = new DataTree<GH_UnitNumber>();
var outRotX = new DataTree<GH_UnitNumber>();
var outRotY = new DataTree<GH_UnitNumber>();
var outRotZ = new DataTree<GH_UnitNumber>();
var outRotXyz = new DataTree<GH_UnitNumber>();

var ghTypes = new List<GH_ObjectWrapper>();
if (!da.GetDataList(0, ghTypes)) {
Expand Down Expand Up @@ -147,68 +133,33 @@ protected override void SolveInternal(IGH_DataAccess da) {
continue;
}

Parallel.For(0, 2, thread => // split computation in two for xyz and xxyyzz
{
switch (thread) {
case 0: {
foreach (KeyValuePair<int, ConcurrentDictionary<int, GsaResultQuantity>> kvp in
foreach (KeyValuePair<int, ConcurrentDictionary<int, GsaResultQuantity>> kvp in
vals[perm - 1].XyzResults) {
int elementId = kvp.Key;
ConcurrentDictionary<int, GsaResultQuantity> res = kvp.Value;
if (res.Count == 0) {
continue;
}

var path = new GH_Path(result.CaseId,
result.SelectedPermutationIds == null ? 0 : perm, elementId);

outTransX.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.X.ToUnit(_lengthUnit))),
path); // use ToUnit to capture changes in dropdown
outTransY.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Y.ToUnit(_lengthUnit))), path);
outTransZ.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Z.ToUnit(_lengthUnit))), path);
outTransXyz.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Xyz.ToUnit(_lengthUnit))), path);
}

break;
}
case 1: {
foreach (KeyValuePair<int, ConcurrentDictionary<int, GsaResultQuantity>> kvp in
vals[perm - 1].XxyyzzResults) {
int elementId = kvp.Key;
ConcurrentDictionary<int, GsaResultQuantity> res = kvp.Value;
if (res.Count == 0) {
continue;
}

var path = new GH_Path(result.CaseId,
result.SelectedPermutationIds == null ? 0 : perm, elementId);

outRotX.AddRange(res.Select(x => new GH_UnitNumber(x.Value.X)),
path); // always use [rad] units
outRotY.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Y)), path);
outRotZ.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Z)), path);
outRotXyz.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Xyz)), path);
}

break;
}
int elementId = kvp.Key;
ConcurrentDictionary<int, GsaResultQuantity> res = kvp.Value;
if (res.Count == 0) {
continue;
}
});

var path = new GH_Path(result.CaseId,
result.SelectedPermutationIds == null ? 0 : perm, elementId);
// use ToUnit to capture changes in dropdown
outTransX.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.X.ToUnit(_lengthUnit))), path);
outTransY.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Y.ToUnit(_lengthUnit))), path);
outTransZ.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Z.ToUnit(_lengthUnit))), path);
outTransXyz.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Xyz.ToUnit(_lengthUnit))), path);
}
}
}

da.SetDataTree(0, outTransX);
da.SetDataTree(1, outTransY);
da.SetDataTree(2, outTransZ);
da.SetDataTree(3, outTransXyz);
da.SetDataTree(4, outRotX);
da.SetDataTree(5, outRotY);
da.SetDataTree(6, outRotZ);
da.SetDataTree(7, outRotXyz);

PostHog.Result(result.Type, 3, GsaResultsValues.ResultType.Displacement);
}
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/5_Results/Element3dStresses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void InitialiseDropdowns() {
_selectedItems = new List<string>();

_dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Stress));
_selectedItems.Add(_stresshUnit.ToString());
_selectedItems.Add(Pressure.GetAbbreviation(_stresshUnit));

_isInitialised = true;
}
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/5_Results/FootfallResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override void SolveInstance(IGH_DataAccess da) {

case GsaResultGoo goo: {
result = goo.Value;
if (result.Type == CaseType.Combination) {
if (result.Type == CaseType.CombinationCase) {
this.AddRuntimeError("Footfall Result only available for Analysis Cases");
return;
}
Expand Down
8 changes: 4 additions & 4 deletions GsaGH/Components/5_Results/GetResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected override void SolveInstance(IGH_DataAccess da) {
if (type.ToUpper().StartsWith("A")) {
resultType = CaseType.AnalysisCase;
} else if (type.ToUpper().StartsWith("C")) {
resultType = CaseType.Combination;
resultType = CaseType.CombinationCase;
} else {
this.AddRuntimeError("Error converting input " + Params.Input[1].NickName
+ " to 'Analysis' or 'Combination'");
Expand Down Expand Up @@ -145,7 +145,7 @@ protected override void SolveInstance(IGH_DataAccess da) {

break;

case CaseType.Combination:
case CaseType.CombinationCase:
if (_combinationCaseResults == null) {
_combinationCaseResults = model.Model.CombinationCaseResults();
if (_combinationCaseResults == null || _combinationCaseResults.Count == 0) {
Expand Down Expand Up @@ -177,8 +177,8 @@ IReadOnlyDictionary<int, ReadOnlyCollection<NodeResult>> tempNodeCombResult
}

if (!_result.ContainsKey(
new Tuple<CaseType, int>(CaseType.Combination, caseId))) {
_result.Add(new Tuple<CaseType, int>(CaseType.Combination, caseId),
new Tuple<CaseType, int>(CaseType.CombinationCase, caseId))) {
_result.Add(new Tuple<CaseType, int>(CaseType.CombinationCase, caseId),
new GsaResult(model, _combinationCaseResults[caseId], caseId, permutationIDs));
}

Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/5_Results/GlobalPerformanceResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected override void SolveInternal(IGH_DataAccess da) {

case GsaResultGoo goo: {
result = goo.Value;
if (result.Type == CaseType.Combination) {
if (result.Type == CaseType.CombinationCase) {
this.AddRuntimeError("Global Result only available for Analysis Cases");
return;
}
Expand Down
20 changes: 10 additions & 10 deletions GsaGH/Components/5_Results/SelectResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public override void SetSelected(int i, int j) {
}
case 0: {
if (_selectedItems[i] == _type[1]) {
if (_resultType == CaseType.Combination) {
if (_resultType == CaseType.CombinationCase) {
return;
}

_resultType = CaseType.Combination;
_resultType = CaseType.CombinationCase;
UpdateDropdowns();
}

Expand All @@ -74,7 +74,7 @@ public override void SetSelected(int i, int j) {
string.Join(string.Empty, _selectedItems[i].ToCharArray().Where(char.IsDigit)));
if (newId != _caseId) {
_caseId = newId;
if (_resultType == CaseType.Combination) {
if (_resultType == CaseType.CombinationCase) {
UpdatePermutations();
}
}
Expand Down Expand Up @@ -187,8 +187,8 @@ protected override void SolveInternal(IGH_DataAccess da) {
}
} else if (type.ToUpper().StartsWith("C")) {
_selectedItems[0] = _dropDownItems[0][1];
if (_resultType != CaseType.Combination) {
_resultType = CaseType.Combination;
if (_resultType != CaseType.CombinationCase) {
_resultType = CaseType.CombinationCase;
if (_dropDownItems.Count < 3) {
_dropDownItems.Add(new List<string>() {
"All",
Expand All @@ -213,7 +213,7 @@ protected override void SolveInternal(IGH_DataAccess da) {
var ghACase = new GH_Integer();
if (da.GetData(2, ref ghACase)) {
if (GH_Convert.ToInt32(ghACase, out int analCase, GH_Conversion.Both)) {
if (_resultType == CaseType.Combination && _caseId != analCase) {
if (_resultType == CaseType.CombinationCase && _caseId != analCase) {
UpdatePermutations();
}

Expand Down Expand Up @@ -267,7 +267,7 @@ protected override void SolveInternal(IGH_DataAccess da) {

break;

case CaseType.Combination:
case CaseType.CombinationCase:
if (_combinationCaseResults == null) {
_combinationCaseResults = _gsaModel.Model.CombinationCaseResults();
if (_combinationCaseResults == null || _combinationCaseResults.Count == 0) {
Expand Down Expand Up @@ -319,7 +319,7 @@ protected override void UpdateUIFromSelectedItems() {
if (_selectedItems[0] == _type[0]) {
_resultType = CaseType.AnalysisCase;
} else if (_selectedItems[0] == _type[1]) {
_resultType = CaseType.Combination;
_resultType = CaseType.CombinationCase;
}

if (_selectedItems[1].ToLower() == "all") {
Expand Down Expand Up @@ -363,7 +363,7 @@ private void UpdateDropdowns() {
_dropDownItems[1] = cases;
_selectedItems[1] = type[0] + _caseId.ToString();

if (_resultType == CaseType.Combination) {
if (_resultType == CaseType.CombinationCase) {
if (_dropDownItems.Count < 3) {
_dropDownItems.Add(new List<string>() {
"All",
Expand All @@ -390,7 +390,7 @@ private void UpdateDropdowns() {
}

private void UpdatePermutations() {
if (_resultType != CaseType.Combination) {
if (_resultType != CaseType.CombinationCase) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/5_Results/TotalLoadsAndReactions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected override void SolveInternal(IGH_DataAccess da) {

case GsaResultGoo goo: {
result = goo.Value;
if (result.Type == CaseType.Combination) {
if (result.Type == CaseType.CombinationCase) {
this.AddRuntimeError("Global Result only available for Analysis Cases");
return;
}
Expand Down
Loading

0 comments on commit eb1cb7a

Please sign in to comment.