//access to helperfunctions; (include() function enables using functions in another script
include("helperfunctions.js")

// clear all inputs; run() function executes another script
run("ClearInput.js")

// count of objects
var ioutlinePointsCount = 28
var ioutlineLinesCount = 20
var ielementPointsCount = 14
var ielementsCount = 9

// initialize tolerances
general.tolerance_for_directions = 0.0005
general.tolerance_for_lines = 0.0005
general.tolerance_for_points = 0.0005
general.tolerance_for_planes = 0.0005

//convert mm in m
dh = dh/1000
db = db/1000
dr = dr/1000
dc = dc/1000
dt = dt/1000

// analysis method
general.solver_model = general.THIN_WALLED
general.has_effective_section_properties_active = true
general.effective_section_standard = general.EN_1993_1_3_COLD_FORMED

//material
Material(1, smaterial)

// initialize points
createEmptyPoints(ioutlinePointsCount + ielementPointsCount)

// element points
points[1].coordinates = $V([0, 0])
points[2].coordinates = $V([-dc, 0])
points[3].coordinates = $V([-dc-dr, -dr])
points[4].coordinates = $V([-dc-dr, -dr-dh])
points[5].coordinates = $V([-dc, -2*dr-dh])
points[6].coordinates = $V([db-dc, -2*dr-dh])
points[7].coordinates = $V([db-dc+dr, -dr-dh])
points[8].coordinates = $V([db-dc+dr, -dr])
points[9].coordinates = $V([db-dc, 0])
points[10].coordinates = $V([db-2*dc, 0])

// elements arc points
points[11].coordinates = $V([-dc-dr/sqrt(2), -dr+dr/sqrt(2)])
points[12].coordinates = $V([-dc-dr/sqrt(2), -dr-dh-dr/sqrt(2)])
points[13].coordinates = $V([db-dc+dr/sqrt(2), -dr-dh-dr/sqrt(2)])
points[14].coordinates = $V([db-dc+dr/sqrt(2), -dr+dr/sqrt(2)])

// outline points
points[15].coordinates = $V([0, -dt/2])
points[16].coordinates = $V([0, dt/2])
points[17].coordinates = $V([-dc, -dt/2])
points[18].coordinates = $V([-dc, dt/2])
points[19].coordinates = $V([-dc-dr+dt/2, -dr])
points[20].coordinates = $V([-dc-dr-dt/2, -dr])
points[21].coordinates = $V([-dc-dr+dt/2, -dr-dh])
points[22].coordinates = $V([-dc-dr-dt/2, -dr-dh])
points[23].coordinates = $V([-dc, -2*dr-dh+dt/2])
points[24].coordinates = $V([-dc, -2*dr-dh-dt/2])
points[25].coordinates = $V([db-dc, -2*dr-dh+dt/2])
points[26].coordinates = $V([db-dc, -2*dr-dh-dt/2])
points[27].coordinates = $V([db-dc+dr-dt/2, -dr-dh])
points[28].coordinates = $V([db-dc+dr+dt/2, -dr-dh])
points[29].coordinates = $V([db-dc+dr-dt/2, -dr])
points[30].coordinates = $V([db-dc+dr+dt/2, -dr])
points[31].coordinates = $V([db-dc, -dt/2])
points[32].coordinates = $V([db-dc, dt/2])
points[33].coordinates = $V([db-2*dc, -dt/2])
points[34].coordinates = $V([db-2*dc, dt/2])

//outline arc points
points[35].coordinates = $V([-dc-(dr-dt/2)/sqrt(2), -dr+(dr-dt/2)/sqrt(2)])
points[36].coordinates = $V([-dc-(dr+dt/2)/sqrt(2), -dr+(dr+dt/2)/sqrt(2)])
points[37].coordinates = $V([-dc-(dr-dt/2)/sqrt(2), -dr-dh-(dr-dt/2)/sqrt(2)])
points[38].coordinates = $V([-dc-(dr+dt/2)/sqrt(2), -dr-dh-(dr+dt/2)/sqrt(2)])
points[39].coordinates = $V([db-dc+(dr-dt/2)/sqrt(2), -dr-dh-(dr-dt/2)/sqrt(2)])
points[40].coordinates = $V([db-dc+(dr+dt/2)/sqrt(2), -dr-dh-(dr+dt/2)/sqrt(2)])
points[41].coordinates = $V([db-dc+(dr-dt/2)/sqrt(2), -dr+(dr-dt/2)/sqrt(2)])
points[42].coordinates = $V([db-dc+(dr+dt/2)/sqrt(2), -dr+(dr+dt/2)/sqrt(2)])

// initialize elements
createEmptyElements(ielementsCount)
setLineElement(1, [1, 2], dt)
setLineElement(2, [3, 4], dt)
setLineElement(3, [5, 6], dt)
setLineElement(4, [7, 8], dt)
setLineElement(5, [9, 10], dt)
setArcElement(6, [2, 3], dt, points[11])
setArcElement(7, [4, 5], dt, points[12])
setArcElement(8, [6, 7], dt, points[13])
setArcElement(9, [8, 9], dt, points[14])

// initialize lines
createEmptyLines(ioutlineLinesCount)
setLine(1, [16, 18])
setArcLine(2, [18, 20], points[36])
setLine(3, [20, 22])
setArcLine(4, [22, 24], points[38])
setLine(5, [24, 26])
setArcLine(6, [26, 28], points[40])
setLine(7, [28, 30])
setArcLine(8, [30, 32], points[42])
setLine(9, [32, 34])
setLine(10, [34, 33])
setLine(11, [33, 31])
setArcLine(12, [31, 29], points[41])
setLine(13, [29, 27])
setArcLine(14, [27, 25], points[39])
setLine(15, [25, 23])
setArcLine(16, [23, 21], points[37])
setLine(17, [21, 19])
setArcLine(18, [19, 17], points[35])
setLine(19, [17, 15])
setLine(20, [15, 16])

// initialize parts
parts.create()
parts[1].boundary_lines = "1-20"
parts[1].material = 1

// initialize loads and internal forces
load_cases.create()
load_cases[1].internal_forces.create()
setInternalForces(1, 1, 1, 0.5, -1000, 0, 0, 0, 0, 0, 0, 0)

