Detailed look at the source code
The provided examples utilize common code in the SBDAutomationLibrary
class library project.
SBD Automation Library
Item | Description |
---|---|
SBDControl.cs | Control block definition. |
SBDDesignBeam.cs | Design beam definition. |
SBDDesignSection.cs | Design section definition. |
SBDHelper.cs | Configuration definition and common helper functions. |
SBDMaterial.cs | Material property definition. |
SBDLineBeam.cs | Line beam definition. |
SBDModel.cs | General project setting definitions. |
SBDOutput.cs | Result output definition. |
SBDRefinedModel.cs | Refined structural model definition. |
SBDStructuralModel.cs | Contains definition of line beams and refined model. |
SBD Examples
Item | Description |
---|---|
SBDEntry.cs | Application entry point. |
SBDMain.cs | The main code that you will be modifying to suit. |
You will be substituting code in the SBDMain
code file to suit your tasks, but it is recommended that the units in the SBDAutomationLibrary project remain untouched and as they contain the interface definitions for SBD data. The library units may be updated in the future.
For you own automation, as a beginner, it is recommended to do the following steps:
- Go to
File | New | Project
. - Select
Console App
as the project template. - Delete the default
Program.cs
file. - Right-click on the new project in the Solution Explorer and select
Add | New Item
. - Choose
Class
and give it a suitable name. - Copy and paste the code from the SBDEntry.cs file of one of the
SBD Examples
into the newly created class file. - Repeat steps 4-6 to add another class file.
- Copy and paste the code from the SBDMain.cs file of one of the
SBD Examples
into the second class file. - Right-click on the project in the Solution Explorer and select
Add | New Item
. - Choose "JavaScript JSON Configuration File" and give it a suitable name.
- Copy and paste the code from the
config.cs
file of one of theSBD Examples
into the JSON configuration file. - If CSV output is required, add the
CsvHelper
NuGet dependency package.
Example 1: Modify existing JSON file
SBDMain.cs
The main class method is Run()
.
public void Run()
{
try
{
Stopwatch sw = new Stopwatch();
sw.Start();
This code snippet starts the timer.
config = Configuration.GetConfiguration("config.json");
_ = config ?? throw new Exception("config is null");
if (!File.Exists(config.Input))
{
Console.WriteLine("The specified input file does not exist. {0}", config.Input);
return;
}
This code snippet reads and parses the configuration file.
using (StreamReader r = new(config.Input))
{
string jsonString = r.ReadToEnd();
var model = Json.ToClass<Model>(jsonString);
if (model is null) return;
SBD.Model = model;
Console.WriteLine("Data version: " + model.Version);
This code snippet parses the Structural Bridge Design model. For detailed information about each parameter in the model, please refer to the Automation Schema topic.
ChangeModelExample();
This method servers as an example of changing the Structural Bridge Design model. We take a closer look later in this section.
config.SetOverrides();
This helper code keeps the model settings in synch with the configuration file.
string model_file = Automate.SaveModel("Example_1.json", config);
This code snippet saves the model before the automation is run.
if (Automate.RunSBD(model_file, config))
This method runs the automation by calling the SBD process as described in Automate from the Command Prompt.
{
if (config.CreateCSV)
{
WriteAllCSVResults();
}
WriteAllCSVResults()
outputs the results as comma-separated values in a file.
OutputParametersExample();
As an example of direct result extraction, this method retrieves specific results from the output and displays them. It searches the output commands array and retrieves the desired values, for example.
<...>
double val = sectionResult.MaxCrackSpacing.GetValueOrDefault() * 1000;
Console.WriteLine("Maximum crack spacing, Sr,max: " + val.ToString("0.#") + "mm");
<...>
As you type, C# IntelliSense shows the available members together with a description, for example.
}
else
{
Console.WriteLine("Unable to run SBD.");
}
}
GC.Collect();
sw.Stop();
Console.WriteLine("Loop finished in " + sw.Elapsed.ToString());
if (config.AutoClose == false)
{
Console.WriteLine("Finished - press a key.");
if (!Console.IsInputRedirected)
{
Console.ReadKey();
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message + ":" + e.StackTrace);
Debug.WriteLine(e.Message + ":" + e.InnerException + ":" + e.StackTrace);
System.Threading.Thread.Sleep(20000);
}
finally
{
}
}
Here some cleanup is done and finishing tasks are completed.
In this method, we copy an existing design section, modify it to fit our requirements, and obtain the results for both the original and modified sections.
You can learn how to use the Visual Studio or Visual Studio Code debugger to step through this code line-by-line, allowing you to follow the program execution. Additionally, you can use the debugger to watch the values of variables as they are changed by your code.
To copy an existing model element, you can use the CloneJson() method, e.g.
DesignSection? section = SBD.Model.DesignSections.SectionsArray[0].CloneJson();
where DesignSections
is an object that contains an array of sections. SectionsArray[0]
refers to the first section in the array. Similarly, SectionsArray[1]
would refer to the second section, and so on.
Example 2: Building a model from scratch
Although Example 1 demonstrates copying a predefined section, it is also possible to build a section (or any other item) from scratch. To learn how to create an original section, including reinforcement and loading, you can refer to the CreateSection()
function in the SBDExample2
project.
private static DesignSection CreateSection()
{
const double section_diameter = 1.0;
DesignSection section = new()
{
Name = "My section",
};
section.ElementsArray.Add(new()
{
Shape = "CIRCLE",
Diameter = section_diameter,
HookRef = 0,
HookY = 0.0,
HookZ = 0.0,
PropertyRef = "MP1"
});
section.ElementsArray.Add(new()
{
Shape = "8_BASE",
Side = 0.2,
HookRef = 0,
HookY = 0.0,
HookZ = 0.0,
PropertyRef = "VOID"
});
const int num_bars = 17;
const double sectorAngle = 360.0 / 17;
for (int b = 0; b < num_bars; ++b)
{
double delta = Json.ConvertToRadians(sectorAngle * b);
const double cover = 0.050;
const double bar_diameter = 0.032;
double dist = (section_diameter - bar_diameter) / 2 - cover;
section.Reinforcement.Add(new()
{
Y = dist * Math.Cos(delta),
Z = dist * Math.Sin(delta),
Diameter = bar_diameter,
PropertyRef = "MP2"
});
}
section.LoadsArray.Add(new()
{
Name = "ULS Loadcase",
Combination = "ULS_PERSISTENT_TRANSIENT",
Set = "B",
Equation = "6.10A",
UltimateLoads = { 1130.5, 0, -25.92, 351.44, 0, 0 }
});
return section;
}
The above code is equivalent to the following JSON:
{
"name": "My section",
"elementsArray": [
{
"shape": "CIRCLE",
"diameter": 1,
"hookRef": 0,
"hookY": 0,
"hookZ": 0,
"propertyRef": "MP1"
},
{
"shape": "8_BASE",
"side": 0.2,
"hookRef": 0,
"hookY": 0,
"hookZ": 0,
"propertyRef": "VOID"
}
],
"reinforcement": [
{
"y": -0.42661032526281339,
"z": -0.07974729073239149,
"diameter": 0.032,
"propertyRef": "MP2"
},
{
"y": -0.36899423690665262,
"z": -0.22847155868877234,
"diameter": 0.032,
"propertyRef": "MP2"
}
// other reinforcment bar objects not shown
],
"loadsArray": [
{
"name": "ULS Loadcase",
"combination": "ULS_PERSISTENT_TRANSIENT",
"set": "B",
"equation": "6.10A",
"ultimateLoads": [1130.5, 0, -25.92, 351.44, 0, 0]
}
]
}
Another approach is to define an SBD model that includes materials and general parameters but does not contain any sections or beams. You can save this model as a JSON file within SBD. Later, you can use this saved model as a starting point and add sections or beams to it as needed.
This method allows you to have a base model with common materials and parameters already defined, which can save time when creating new models.
SBDControl
This code file contains all the classes responsible for controlling the automation process.
For example, the following code iterates over each command:
foreach (Command command in commandArray)
Command types include the various design section and design beam analyses that can be automated.
SBDDesignBeam
This code file contains all the classes responsible for design beam definition.
SBDDesignSection
This code file contains all the classes responsible for design section definition.
SBDHelper
This code file contains the configuration definition class and common helper functions.
SBDMaterial
This code file contains all the classes responsible for material property definition.
For example, to create a new project, add a material and save the model as json, replace the Run
method in SBDAtmLibrary.cs
with the following:
public void Run()
{
try
{
SBD.Model = new Model
{
Version = "1.0"
};
SBD.Model.Settings.DesignCode = "EU";
Material material = new()
{
Type = "CONCRETE",
DesignCode = "EN1992-2",
Strength = 32000,
Name = "My concrete"
};
SBD.Model.Materials.MaterialArray.Add(material);
Automate.SaveModel("c:\\MyModel.json", null);
GC.Collect();
}
catch (Exception e)
{
Console.WriteLine(e.Message + ":" + e.StackTrace);
Debug.WriteLine(e.Message + ":" + e.InnerException + ":" + e.StackTrace);
}
}
To create a valid model file, we need to specify the design code.
The JSON file created by the above code can be opened directly in SBD:
```json
{
"version": "1.0",
"settings": {
"designCode": "EU"
},
"materials": {
"materialArray": [
{
"type": "CONCRETE",
"designCode": "EN1992-2",
"strength": 32000.0,
"name": "My concrete"
}
]
}
}
SBDModel
This code file defines the general project settings, structural model, design section, design beam and material definitions. It also gives access to the automation control object.
SBDOutput
This code file defines the available result output parameters.
For example, these are the available design section shear parameters:
public bool? Cracked { get; set; }
public double? ShearWidth { get; set; }
public double? ShearDepth { get; set; }
public double? VRdMax { get; set; }
public double? VRdc { get; set; }
public double? VEd { get; set; }
public double? AswPerS { get; set; }
public double? ZOverD { get; set; }
public double? PhiVuMax { get; set; }
public double? VuMin { get; set; }
public double? VStarEq { get; set; }
public double? AsvPerS { get; set; }
Refer to the code file for individual parameter documentation .