S3D Integration

You can automatically integrate your calculation pack with S3D, by writing a s3d_integration.js file. The purpose of this file is to extract data out of your model and analysis results, to run your calculations off. If your calc pack has a s3d_integration.js file and your calculate.js follows the standardised format, your solution will appear in the list in S3D:

From here, your model will be auto-integrated with the following UI:

Layout#

important

This file uses the UI format for S3D! So for instance, use s3d_model.elements not s3d_model.members!

Use this file to compile an array of inputs for your calculator, that can be then run in batches:

module.exports = function(s3d_model, analysis_results) {
//you will be given the model and analysis results to work from
if (!analysis_results) throw new Error("No Analysis Results. Please solve model first."); //if this is required, you can throw an error like this
// Perform Logic, like looping through members in your s3d_model and building your input JSONs
//return a list of inputs, these will get looped through the calculate.js file
return [
{a:100, b:200},
{a:50, b:80},
{a:60, b:150},
{a:22, b:30.33}
]
}

Helper Functions#

StructureHelpers.getDesignForces()#

Returns an array of design forces for each member. It will scan all load combos and determine the worst result for each member in both + and - directions.

StructureHelpers.getDesignForces(analysis_results);

Output:

[
null, //element 0
{
Mx: {
abs: 0,
pos: 0,
neg: 0,
governing_lc_abs: '#0 ULS: Case 1: 1.4D',
governing_lc_pos: '#0 ULS: Case 1: 1.4D',
governing_lc_neg: '#0 ULS: Case 1: 1.4D',
governing_results_arr: // Same as Mz
load_combos: // Same as Mz
},
My: {
abs: 0,
pos: 0,
neg: 0,
governing_lc_abs: '#0 ULS: Case 1: 1.4D',
governing_lc_pos: '#0 ULS: Case 1: 1.4D',
governing_lc_neg: '#0 ULS: Case 1: 1.4D',
governing_results_arr: // Same as Mz
load_combos: // Same as Mz
},
Mz: {
abs: 5.6,
pos: 5.6,
neg: -5.6,
governing_lc_abs: '#0 ULS: Case 1: 1.4D',
governing_lc_pos: '#21 Envelope Absolute Max',
governing_lc_neg: '#0 ULS: Case 1: 1.4D',
governing_results_arr: [
-5.6, -5.34545455, -5.09090909,
-4.83636364, -4.58181818, -4.32727273,
-4.07272727, -3.81818182, -3.56363636,
-3.30909091, -3.05454545, -2.8,
-2.54545455, -2.29090909, -2.03636364,
-1.78181818, -1.52727273, -1.27272727,
-1.01818182, -0.76363636, -0.50909091,
-0.25454545, 0
],
load_combos: {
'#0 ULS: Case 1: 1.4D': { abs: 5.6, pos: 0, neg: -5.6 },
'#1 ULS: Cases 2a: (1.25 or 0.9)D + 1.5L': { abs: 5, pos: 0, neg: -5 },
'#2 ULS: Cases 2b: (1.25 or 0.9)D + 1.5L + 0.5S': { abs: 5, pos: 0, neg: -5 },
'#3 ULS: Cases 2c: (1.25 or 0.9)D + 1.5L + 0.4W': { abs: 5, pos: 0, neg: -5 },
'#4 ULS: Cases 3a: (1.25 or 0.9)D + 1.5S': { abs: 5, pos: 0, neg: -5 },
'#5 ULS: Cases 3b: (1.25 or 0.9)D + 1.5S + 0.5L': { abs: 5, pos: 0, neg: -5 },
'#6 ULS: Cases 3c: (1.25 or 0.9)D + 1.5S + 0.4W': { abs: 5, pos: 0, neg: -5 },
'#7 ULS: Cases 4a: (1.25 or 0.9)D + 1.4W': { abs: 5, pos: 0, neg: -5 },
'#8 ULS: Cases 4b: (1.25 or 0.9)D + 1.4W + 0.5L': { abs: 5, pos: 0, neg: -5 },
'#9 ULS: Cases 4c: (1.25 or 0.9)D + 1.4W + 0.5S': { abs: 5, pos: 0, neg: -5 },
'#10 ULS: Case 5a: D + E': { abs: 4, pos: 0, neg: -4 },
'#11 ULS: Case 5b: D + E + 0.5L + 0.25S': { abs: 4, pos: 0, neg: -4 },
'#12 Dead: unfavorable': { abs: 4, pos: 0, neg: -4 },
'#14 Live: live': { abs: 0, pos: 0, neg: 0 },
'#15 Wind: wind': { abs: 0, pos: 0, neg: 0 },
'#16 Snow: snow': { abs: 0, pos: 0, neg: 0 },
'#17 Seis: Earthquake/Accidental': { abs: 0, pos: 0, neg: 0 },
'#18 DL': { abs: 4, pos: 0, neg: -4 },
'#19 Envelope Min': { abs: 5.6, pos: 0, neg: -5.6 },
'#20 Envelope Max': { abs: 4, pos: 0, neg: -4 },
'#21 Envelope Absolute Max': { abs: 5.6, pos: 5.6, neg: 0 }
}
},
Vx: {
abs: 0,
pos: 0,
neg: 0,
governing_lc_abs: '#0 ULS: Case 1: 1.4D',
governing_lc_pos: '#0 ULS: Case 1: 1.4D',
governing_lc_neg: '#0 ULS: Case 1: 1.4D',
governing_results_arr: // Same as Mz
load_combos: // Same as Mz
},
Vy: {
abs: 1.4,
pos: 1.4,
neg: 0,
governing_lc_abs: '#0 ULS: Case 1: 1.4D',
governing_lc_pos: '#0 ULS: Case 1: 1.4D',
governing_lc_neg: '',
governing_results_arr: // Same as Mz
load_combos: // Same as Mz
},
Vz: {
abs: 0,
pos: 0,
neg: 0,
governing_lc_abs: '#0 ULS: Case 1: 1.4D',
governing_lc_pos: '#0 ULS: Case 1: 1.4D',
governing_lc_neg: '#0 ULS: Case 1: 1.4D',
governing_results_arr: // Same as Mz
load_combos: // Same as Mz
},
dx: {
abs: 0,
pos: 0,
neg: 0,
governing_lc_abs: '#0 ULS: Case 1: 1.4D',
governing_lc_pos: '#0 ULS: Case 1: 1.4D',
governing_lc_neg: '#0 ULS: Case 1: 1.4D',
governing_results_arr: // Same as Mz
load_combos: // Same as Mz
},
dy: {
abs: 5.47462005,
pos: 5.47462005,
neg: -5.47462005,
governing_lc_abs: '#0 ULS: Case 1: 1.4D',
governing_lc_pos: '#21 Envelope Absolute Max',
governing_lc_neg: '#0 ULS: Case 1: 1.4D',
governing_results_arr: // Same as Mz
load_combos: // Same as Mz
},
dz: {
abs: 0,
pos: 0,
neg: 0,
governing_lc_abs: '#0 ULS: Case 1: 1.4D',
governing_lc_pos: '#0 ULS: Case 1: 1.4D',
governing_lc_neg: '#0 ULS: Case 1: 1.4D',
governing_results_arr: // Same as Mz
load_combos: // Same as Mz
},
M_end: 5.6,
V_end: 1.4
}
];
tip

For members that are rigid links, getDesignForces will return no design forces.

StructureHelpers.getMemberLength()#

Returns the member's length, including if offsets are used

StructureHelpers.getMemberLength(s3d_model, elem_id, consider_offsets)

StructureHelpers.ezDesignForces()#

The ezDesignForces helper is an alternative to StructureHelpers.getDesignForces(). It returns the internal forces of each member about the geometric and principal axes of its section as drawn in section builder, per load combination and station, or aggregated (envelopes).

const result = StructureHelpers.ezDesignForces(S3D.results.getAll(true), S3D.model_data, options);

Options#

All options are optional. Unknown options and values throw an error.

OptionDefaultAccepts
members"all""all", or a list of member IDs, e.g. ["6", "8"]. With "all", members that cannot be processed (not in the model, a requested action missing in a load combination, a number of stations that changes) are skipped and listed with the reason in meta.skipped_members; a listed member throws instead.
load_combinations"user_defined"A type ("user_defined", "load_case", "load_group"), "all" (all three types), an ID, a filter { type, criteria }, or a list of these (their union), e.g. ["user_defined", "15"] or [{ criteria: "serviceability" }, "load_case"]. In a filter, type and criteria each take a value or a list, and both must match. criteria is the load combination's criteria in the model ("strength", "serviceability", "other", or any other value the model uses); only user-defined load combinations have one. Envelopes cannot be selected: use aggregate. Incomplete load combinations selected by type or filter are skipped and listed in meta.skipped_load_combinations; an incomplete one listed by ID throws.
axes["geometric", "principal"]One or both.
actions["axial", "bmd_y", "bmd_z", "sfd_y", "sfd_z", "torsion"]Any of these six, plus the resultants "bmd_res" (√(bmd_y² + bmd_z²)) and "sfd_res" (√(sfd_y² + sfd_z²)). Any subset can be requested: rotating a moment or shear needs both of its components, so they are read from the results, but only the requested actions are returned. Resultants are computed at each station before any aggregation (so their envelope is the largest resultant, not the resultant of the envelopes), are never negative, and are the same about every axis. Useful for circular and other axisymmetric sections.
aggregate[]Levels to replace by their max/min: any of "member", "load_combination", "station". "member" requires "station" (members have different stations).

Result#

{
meta: {
schema: "ezDesignForces/2",
version: "2.0.0", // of ezDesignForces (semver)
levels: ["member", "load_combination", "station", "axis", "action"], // levels present in data, in order
aggregated: [], // levels removed by options.aggregate
leaf: ["before", "after"], // keys of each leaf (["max", "min", "abs_max"] when aggregated)
axes: ["geometric", "principal"],
actions: ["axial", "bmd_y", "bmd_z", "sfd_y", "sfd_z", "torsion"],
units: { force: "kn", moment: "kn-m", station: "% of member length" },
load_combinations: { "1": { name: "ULS: Case 1: 1.4D_Dead only", type: "user_defined", criteria: "strength" }, ... }, // criteria null for load cases and groups
skipped_load_combinations: {}, // e.g. { "3": "incomplete" }: skipped from a type selection
skipped_members: {}, // e.g. { "12": 'no "torsion" results in load combination 3' }, with members "all"
members: {
"6": {
section_id: 5, section_name: "75 x 350", element_type: "normal",
stations: [0, 12.5, 25, 37.5, 50, 62.5, 75, 87.5, 100], // station keys "0".."8" index this list
transformations: { rotation: 0, mirror_y: false, mirror_z: false }, // section builder operations removed
principal_angle: 0 // degrees, null when unknown (then no principal axis for this member)
}, ...
}
},
data: {
"6": { "1": { "4": { // member, load combination, station index
geometric: { axial: [0, 0], bmd_y: [16.572, 16.572], bmd_z: [9.568, 9.568], ... }, // [before, after]
principal: { ... }
} } }, ...
}
}

A model without load combinations is solved by S3D as one user-defined combination, "Default Load Combo", with ID 0 and no criteria: the default selection includes it, a { criteria } filter does not. Members without force results in the selected load combinations (e.g. rigid links) are not in data. Each leaf is [before, after]: the value just before and just after the station. They differ only at a discontinuity, e.g. under a point load. To read a value between two stations, interpolate from after at station i to before at station i + 1.

Aggregation#

Aggregated levels disappear from data (the order of the other levels is unchanged), and each leaf becomes { max, min, abs_max }:

  • max / min: { value, capped, member, load_combination, station, side, concurrent }. The location keys say what governs: the member and load combination (only when those levels are aggregated), the station position and the side ("before"/"after"). concurrent holds every requested action at that point.
  • capped: max.capped is Math.max(max.value, 0) and min.capped is Math.min(min.value, 0): the largest demand of each sign (tension and compression, sagging and hogging). It is 0 when there is none; the location keys still describe value.
  • abs_max: a copy of max or min, whichever has the larger magnitude (max on a tie), without capped: { value, signed, from, ...location, concurrent }, where value is the magnitude, signed the value with its sign and from is "max" or "min".
aggregatePathLeaf
[]data["6"]["1"]["4"].geometric.bmd_z[before, after]
["station"]data["6"]["1"].geometric.bmd_zmax / min: { value, capped, station, side, concurrent }
["load_combination", "station"]data["6"].geometric.bmd_zEnvelope: max / min: { value, capped, load_combination, station, side, concurrent }
["member", "load_combination", "station"]data.geometric.bmd_zGoverning member: as above, plus member
["load_combination"]data["6"]["4"].geometric.bmd_zEnvelope diagram: max / min: { value, capped, load_combination }, abs_max: { value, signed, from, load_combination }, every key a [before, after] pair

Ties keep the first value found (members, load combinations and stations in ascending order, before then after).

// Envelope of every member
const envelope = StructureHelpers.ezDesignForces(S3D.results.getAll(true), S3D.model_data, {
aggregate: ["load_combination", "station"]
});
// envelope.data["6"].geometric.bmd_z = {
// max: {
// value: 19.82, capped: 19.82, load_combination: "2", station: 50, side: "before",
// concurrent: { axial: 0, bmd_y: 34.329, bmd_z: 19.82, sfd_y: 0, sfd_z: 0, torsion: 0 }
// },
// min: {
// value: -1.522, capped: -1.522, load_combination: "8", station: 50, side: "before",
// concurrent: { axial: 0, bmd_y: 15.083, bmd_z: -1.522, sfd_y: 0, sfd_z: 0, torsion: 0 }
// },
// abs_max: {
// value: 19.82, signed: 19.82, from: "max", load_combination: "2", station: 50, side: "before",
// concurrent: { axial: 0, bmd_y: 34.329, bmd_z: 19.82, sfd_y: 0, sfd_z: 0, torsion: 0 }
// }
// };
// Design compression and tension of member 6 (axial is compression positive)
const N_c = envelope.data["6"].geometric.axial.max.capped; // 0 when the member is never in compression
const N_t = -envelope.data["6"].geometric.axial.min.capped; // 0 when the member is never in tension
// Serviceability load combinations only
const sls = StructureHelpers.ezDesignForces(S3D.results.getAll(true), S3D.model_data, {
load_combinations: { criteria: "serviceability" },
aggregate: ["load_combination", "station"]
});

Axes and sign conventions#

  • Geometric axes: the axes of the section as drawn in section builder, before rotations and mirrors. Usually, this means the strong flexural axis is about the horizontal axis Z and the weak flexural axis is about the vertical axis Y. Section builder rotates a shape clockwise about its centroid first (as seen in section builder, z right, y up), then mirrors it; ezDesignForces undoes the mirrors first, then the rotation. mirror_z (about the z-axis) flips sfd_y and bmd_z, mirror_y flips sfd_z and bmd_y, and a single mirror (not both) also flips torsion.
  • Principal axes: the geometric axes rotated by meta.members[id].principal_angle, so that z_p is the principal axis closest to the geometric z-axis (whether it is the strong or the weak axis). The angle uses S3D's alpha convention, clockwise as seen in section builder, in [-45, 45) degrees (-45 for equal angles, as S3D reports them): it is the alpha section builder shows for the shape drawn without rotation or mirrors. It is derived from the section's alpha, which S3D measures on the transformed section. For symmetric sections, principal and geometric axes are the same.
  • Only single-shape sections are un-transformed. Built-up sections (several shapes) are used as built, since each shape is rotated and mirrored about its own centroid. The hole of a hollow section (e.g. HSS from the database) is not a separate shape.
  • Only members of type normal and normal_continuous are un-transformed and have principal axes.
  • Signs are S3D's: axial is positive in compression, bmd_z is positive in sagging (y up), and sfd_y and torsion are opposite to the right-hand rule.
  • Normal stresses from principal forces (matches S3D's max_combined_normal_stress / min_combined_normal_stress): take the coordinates z, y of the shape as drawn, relative to its centroid, and the principal angle a = principal_angle: z_p = z cos(a) - y sin(a), y_p = z sin(a) + y cos(a). Then sigma = N / A + bmd_z * y_p / I_zp + bmd_y * z_p / I_yp, with the principal forces and the second moments of area about those axes (I_zp = integral of y_p^2, I_yp = integral of z_p^2). Compression is positive, as in S3D. S3D's section Iz / Iy may belong to the other axis, so compute I_zp / I_yp about z_p / y_p.

UnitHelpers.convert()#

Convert units from one system to another. This is very useful when trying to control the inputs coming into your calculation.js file. For instance, say someone is using a model that is in ft, but your calculator only works for mm, you can use UnitHelpers.convert( member_length , s3d_units.length, "mm"); to take it from whatever system the s3d_model is and translate that input to mm

UnitHelpers.convert( value , unit_from, unit_to);
//examples:
UnitHelpers.convert( 1223 ,"ft", "in");
UnitHelpers.convert( 1223 , s3d_units.length, "mm"); //convert the S3D model unit to a fixed input unit

Logger#

The global logger() function is available to add to the quick design logs

Warnings#

The global warn() function is available to notify users of warning when running calculations

Example#

Below is an example of a more advanced integration for aluminimum design. It takes in the s3d_model and results, in order to compile an array of inputs. It imports the member's length, section properties and design forces.

module.exports = function(s3d_model, analysis_results) {
if (!analysis_results) throw new Error("No Analysis Results. Please solve model first.");
let s3d_units = s3d_model.settings.units;
let materials = s3d_model.materials;
let default_input = {"L":0,"b":null,"d":null,"t1":2.5,"t2":4.5,"J":0,"welded":"No","alloy":"6005","temper":"T5","Mz":1800000,"My":500000,"Vz":20000,"Vy":20000,"Nc":0,"Nt":20000}
let all_design_forces = StructureHelpers.getDesignForces(analysis_results);
let design_members = [];
var members = s3d_model.elements;
for (var i =0; i < members.length; i++) {
var this_member = members[i];
if (!this_member) continue;
let this_member_input = JSON.parse(JSON.stringify(default_input)); //start with this
let span_L = StructureHelpers.getMemberLength(s3d_model, i);
let design_forces = all_design_forces[i];
if (!design_forces) {
logger("&nbsp; Member #" + i + " has no design forces, skipping member.");
continue;
}
this_member_input.L = UnitHelpers.convert(span_L, s3d_units.length, "mm");
this_member_input.Mz = UnitHelpers.convert(design_forces.Mz_abs, s3d_units.moment, "N-mm");
this_member_input.My = UnitHelpers.convert(design_forces.My_abs, s3d_units.moment, "N-mm");
this_member_input.Vz = UnitHelpers.convert(design_forces.Vz_abs, s3d_units.force, "N");
this_member_input.Vy = UnitHelpers.convert(design_forces.Vy_abs, s3d_units.force, "N");
this_member_input.Nc = UnitHelpers.convert(design_forces.Vx_pos, s3d_units.force, "N");
this_member_input.Nt = UnitHelpers.convert(design_forces.Vx_neg, s3d_units.force, "N");
//sections data
let section_id = this_member[2];
let section_obj = s3d_model.sections[section_id];
let material_id = section_obj.material_id;
this_member_input.J = UnitHelpers.convert(section_obj.J, s3d_units.section_length+"^4", "mm^4");
let shape = section_obj.aux.polygons[0].shape;
let dims = section_obj.aux.polygons[0].dimensions;
this_member_input.t1 = "";
this_member_input.t2 = "";
if (shape == "hollow rectangle") {
this_member_input.shape = "hollow rectangular";
this_member_input.s3d_section = section_id;
this_member_input.legs = 2;
this_member_input.b = UnitHelpers.convert(dims.b.value, s3d_units.section_length, "mm");
this_member_input.d = UnitHelpers.convert(dims.h.value, s3d_units.section_length, "mm");
this_member_input.t1 = UnitHelpers.convert(dims.t.value, s3d_units.section_length, "mm");
this_member_input.t2 = UnitHelpers.convert(dims.tb.value, s3d_units.section_length, "mm");
} else {
this_member_input.shape = "custom";
this_member_input.s3d_section = section_id;
if (section_obj.aux.depth) this_member_input.d = UnitHelpers.convert(section_obj.aux.depth, s3d_units.section_length, "mm");
if (section_obj.aux.width) this_member_input.b = UnitHelpers.convert(section_obj.aux.width, s3d_units.section_length, "mm");
if (section_obj.aux.polygons[0] && section_obj.aux.polygons[0].alum) {
var alum_obj = section_obj.aux.polygons[0].alum;
if (alum_obj.hasOwnProperty("number_of_legs")) this_member_input.legs = alum_obj.number_of_legs;
if (alum_obj.hasOwnProperty("leg_thickness")) this_member_input.t1 = UnitHelpers.convert(alum_obj.leg_thickness, s3d_units.section_length, "mm");
if (alum_obj.hasOwnProperty("leg_height")) this_member_input.d = UnitHelpers.convert(alum_obj.leg_height, s3d_units.section_length, "mm");
}
}
if (!this_member_input.t2 && this_member_input.t1) this_member_input.t2 = this_member_input.t1; //just make them the same if blank
//clean and round some data
this_member_input.L = parseFloat(this_member_input.L.toFixed(0))
this_member_input.J = parseFloat(this_member_input.J.toFixed(0))
this_member_input.Mz = parseFloat(this_member_input.Mz.toFixed(0))
this_member_input.My = parseFloat(this_member_input.My.toFixed(0))
this_member_input.Vy = parseFloat(this_member_input.Vy.toFixed(0))
this_member_input.Vz = parseFloat(this_member_input.Vz.toFixed(0))
this_member_input.Nc = parseFloat(this_member_input.Nc.toFixed(0))
this_member_input.Nt = parseFloat(this_member_input.Nt.toFixed(0))
if (this_member_input.h) this_member_input.h = parseFloat(this_member_input.h.toFixed(0))
if (this_member_input.b) this_member_input.b = parseFloat(this_member_input.b.toFixed(0))
design_members[i] = this_member_input; //add to array
}
if (design_members.length == 0) { //always a good idea - tell the user why this could be the case
throw new Error("No Members Imported. Check your materials are set to 'aluminum' and that the sections are hollow rectangular");
}
return design_members;
}

Formatting Results#

You can control the S3D Results table with the following options

KeyValue
s3d_symbolThe heading to show in the S3D Results table.
s3d_infoThe info tip to show in the S3D Results table.

How to Test Code#

To test your code, first start by creating a Draft. Then take the UID of that draft and run the following code in your S3D console:

S3D.quick_design.import("my-uid")

This will open up the module on the left panel and run your latest s3d_integration.js file on the server.