# Run a steel member design check

A design **check** verifies the sections already in the model against a
design code. It does not change the model. To have SPACE GASS pick new
sections, see [Design steel members](/examples/run-steel-design).

## Before you start

- The model has **static analysis results** for the load cases you
  want to check. A design run does not analyse the model for you.
- Your seat is **licensed** for the design code (step 1 shows how to
  confirm).
- The snippets continue from the
  [Simple Beam](/examples/simple-beam) tutorial after its analysis
  step: `client` is the connected client, `member` is the beam and
  `ulsCase` is the ULS combination.

## 1. Confirm the design code is licensed

`GET /job/design/steel-member/codes` lists every design code with
whether this seat can run it. The `code` value is what goes in the
route for the run and settings endpoints.

<CodeTabs>
```csharp title="C#"
var designCode = DesignCode.As4100;

var codes = await client.Job.Design.SteelMember.Codes.GetAsync();
var as4100 = codes!.First(c => c.Code == designCode);
if (as4100.IsLicensed != true)
    throw new Exception("This seat is not licensed for AS 4100.");
```

```python title="Python"
design_code = models.DesignCode.As4100

codes = await client.job.design.steel_member.codes.get()
as4100 = next(c for c in codes if c.code == design_code)
if not as4100.is_licensed:
    raise RuntimeError("This seat is not licensed for AS 4100.")
```

```bash title="curl"
curl http://localhost:34560/api/v1/job/design/steel-member/codes
# [{"code":"As4100","isLicensed":true,"label":"AS4100"}, ...]
```
</CodeTabs>

## 2. Create a design group

A design group is one row of **Design - Steel Members** in SPACE GASS.
It holds the design inputs for one or more members that are designed
as a unit. `members` is a comma-separated list of member Ids.

A new group takes its compression effective lengths from a buckling
analysis. This model has not run one, so give the lengths directly.
Without this the run fails.

<CodeTabs>
```csharp title="C#"
var group = await client.Job.Design.SteelMembers.PostAsync(
    new SteelMemberCreate
    {
        Members = $"{member.Id}",
        MemberType = SteelMemberType.Beam,
        LoadHeightPosition = LoadHeightPosition.Top,
        // Compression effective lengths, as actual lengths
        LengthUnitBasis = LengthUnitBasis.Actual,
        CalculateLcMajorFromBuckling = false,
        LcMajor = 6.0,
        CalculateLcMinorFromBuckling = false,
        LcMinor = 6.0,
        // Lateral-torsional buckling length from the flange restraints
        CalculateLbFromFlangeRestraints = true,
    });
```

```python title="Python"
group = await client.job.design.steel_members.post(
    models.SteelMemberCreate(
        members=str(member.id),
        member_type=models.SteelMemberType.Beam,
        load_height_position=models.LoadHeightPosition.Top,
        # Compression effective lengths, as actual lengths
        length_unit_basis=models.LengthUnitBasis.Actual,
        calculate_lc_major_from_buckling=False,
        lc_major=6.0,
        calculate_lc_minor_from_buckling=False,
        lc_minor=6.0,
        # Lateral-torsional buckling length from the flange restraints
        calculate_lb_from_flange_restraints=True,
    ))
```

```bash title="curl"
curl -X POST http://localhost:34560/api/v1/job/design/steel-members \
  -H "Content-Type: application/json" \
  -d '{
    "members": "1",
    "memberType": "Beam",
    "loadHeightPosition": "Top",
    "lengthUnitBasis": "Actual",
    "calculateLcMajorFromBuckling": false, "lcMajor": 6.0,
    "calculateLcMinorFromBuckling": false, "lcMinor": 6.0,
    "calculateLbFromFlangeRestraints": true
  }'
```
</CodeTabs>

## 3. Choose what to check

The general settings say which design groups and load cases the run
covers. Both take SG list format (`"1,3-7,10"`). They are saved with
the job.

<CodeTabs>
```csharp title="C#"
await client.Job.Design.SteelMember.Settings.PatchAsync(
    new SteelMemberDesignGeneralSettingsUpdate
    {
        Groups = $"{group!.Id}",
        LoadCases = $"{ulsCase.Id}",
        Stations = 10,          // points checked along each member
    });
```

```python title="Python"
await client.job.design.steel_member.settings.patch(
    models.SteelMemberDesignGeneralSettingsUpdate(
        groups=str(group.id),
        load_cases=str(uls_case.id),
        stations=10,            # points checked along each member
    ))
```

```bash title="curl"
curl -X PATCH http://localhost:34560/api/v1/job/design/steel-member/settings \
  -H "Content-Type: application/json" \
  -d '{"groups": "1", "loadCases": "10", "stations": 10}'
```
</CodeTabs>

## 4. Run the check

Design runs work like analysis runs: start one, then poll
`GET /job/design/runs/{runId}` until `status` is `Completed`, `Failed`
or `Cancelled`.

Each design code has its own settings. Pass them in `codeSettings` to
apply them to this run; they are also saved with the job.

<CodeTabs>
```csharp title="C#"
var run = await client.Job.Design.SteelMember[designCode.ToString()].RunCheck.PostAsync(
    new SteelMemberDesignRunCheckRequest
    {
        CodeSettings = new SteelMemberDesignSettingsAs4100Update
        {
            SlendernessRatioCheck = true,
        },
    });

DesignRun result;
do
{
    await Task.Delay(500);
    result = (await client.Job.Design.Runs[run!.RunId!.Value].GetAsync())!;
}
while (result.Status is not (RunStatus.Completed or RunStatus.Failed or RunStatus.Cancelled));

if (result.Status != RunStatus.Completed)
    throw new Exception($"Design run did not complete: {result.ErrorMessage}");

Console.WriteLine($"Checked {result.CheckedCount}: {result.PassedCount} passed, {result.FailedCount} failed");
// Checked 1: 1 passed, 0 failed
```

```python title="Python"
run = await client.job.design.steel_member.by_code(design_code.value).run_check.post(
    models.SteelMemberDesignRunCheckRequest(
        code_settings=models.SteelMemberDesignSettingsAs4100Update(
            slenderness_ratio_check=True,
        )))

while True:
    await asyncio.sleep(0.5)
    result = await client.job.design.runs.by_run_id(run.run_id).get()
    if result.status in (models.RunStatus.Completed,
                         models.RunStatus.Failed,
                         models.RunStatus.Cancelled):
        break

if result.status != models.RunStatus.Completed:
    raise RuntimeError(f"Design run did not complete: {result.error_message}")

print(f"Checked {result.checked_count}: {result.passed_count} passed, {result.failed_count} failed")
# Checked 1: 1 passed, 0 failed
```

```bash title="curl"
curl -X POST http://localhost:34560/api/v1/job/design/steel-member/As4100/run-check \
  -H "Content-Type: application/json" \
  -d '{"codeSettings": {"code": "As4100", "slendernessRatioCheck": true}}'
# -> {"runId": "...", "status": "Running", ...}

curl http://localhost:34560/api/v1/job/design/runs/{runId}
```
</CodeTabs>

## 5. Read the results

`GET /job/query/design/steel-member/check-summary` returns one row per
design group. A group passes when its `loadFactor` is at least
`loadFactorLimit` (1.0 unless you changed it).

<CodeTabs>
```csharp title="C#"
var summary = await client.Job.Query.Design.SteelMember.CheckSummary.GetAsync(
    config => config.QueryParameters.SteelMembers = $"{group.Id}");

foreach (var row in summary!.Results!)
{
    Console.WriteLine($"Group {row.SteelMember}: {row.Section}");
    Console.WriteLine($"  Load factor {row.LoadFactor:F3}, {row.Status}");
    Console.WriteLine($"  Critical case {row.CriticalCase}, governed by {row.Failure}");
}
// Group 1: 360 UB 44.7
//   Load factor 2.623, PassedWithWarnings
//   Critical case 10, governed by Member
```

```python title="Python"
summary = await client.job.query.design.steel_member.check_summary.get(
    steel_members=str(group.id))

for row in summary.results:
    print(f"Group {row.steel_member}: {row.section}")
    print(f"  Load factor {row.load_factor:.3f}, {row.status.value}")
    print(f"  Critical case {row.critical_case}, governed by {row.failure}")
# Group 1: 360 UB 44.7
#   Load factor 2.623, PassedWithWarnings
#   Critical case 10, governed by Member
```

```bash title="curl"
curl "http://localhost:34560/api/v1/job/query/design/steel-member/check-summary?steelMembers=1"
```
</CodeTabs>

| `status` | Meaning |
|---|---|
| `Passed` | The group meets the code for every case checked |
| `PassedWithWarnings` | It passes, with warnings to review in the design report |
| `Failed` | `failureType` says why: `LoadFactor`, `Slenderness`, `Seismic` or `DesignError` |

## Run this example locally

A complete version that also builds and analyses the beam is in the
repo as
[`Example.SteelDesignCheck`](https://github.com/SpaceGass/space-gass-api/tree/main/sdks/csharp/examples/Example.SteelDesignCheck) (C#) and
[`steel_design_check`](https://github.com/SpaceGass/space-gass-api/tree/main/sdks/python/examples/steel_design_check) (Python).
Clone and run:

<CodeTabs>
```bash title="C#"
git clone https://github.com/SpaceGass/space-gass-api.git
cd space-gass-api/sdks/csharp/examples/Example.SteelDesignCheck
dotnet run
```

```bash title="Python"
git clone https://github.com/SpaceGass/space-gass-api.git
cd space-gass-api/sdks/python/examples/steel_design_check
pip install space-gass-api    # once per environment
python steel_design_check.py
```
</CodeTabs>

## See also

- [Design steel members](/examples/run-steel-design) — let SPACE GASS
  select the sections.
- [Run a linear static analysis](/examples/run-linear-static-analysis)
  — the results a design run needs.
- [Simple Beam Model](/examples/simple-beam) — the model these
  snippets continue from.
