# -*- coding: utf-8 -*-
# AUTO-GENERATED by abaqus-agent build_model.py
# DO NOT EDIT - regenerate from spec.yaml
# RUN: abaqus cae noGUI=build_model_script.py -- <workdir> <spec_path>

import sys
import os

# workdir is passed as first argument after --
workdir = sys.argv[-2] if len(sys.argv) >= 3 else os.getcwd()
os.chdir(workdir)

from abaqus import *
from abaqusConstants import *
import part, material, section, assembly, step, load, mesh, job, visualization

if 'Cantilever' not in mdb.models:
    mdb.Model(name='Cantilever')

# ── Geometry & Mesh ──────────────────────────────────────────────────────────

def _sketch_rect(model, w, h):
    s = model.ConstrainedSketch(name='__profile__', sheetSize=200.0)
    s.rectangle(point1=(0.0, 0.0), point2=(w, h))
    return s

p = mdb.models['Cantilever'].Part(name='Part-1', dimensionality=THREE_D,
    type=DEFORMABLE_BODY)
p.BaseSolidExtrude(sketch=_sketch_rect(mdb.models['Cantilever'], 10.0, 10.0), depth=100.0)
p.Set(name='ALL', cells=p.cells)
p.Set(name='FIXED_END', faces=p.faces.getByBoundingBox(xMin=-0.01, xMax=10.0+0.01,
    yMin=-0.01, yMax=10.0+0.01, zMin=-0.01, zMax=0.01))
p.Set(name='LOAD_END',  faces=p.faces.getByBoundingBox(xMin=-0.01, xMax=10.0+0.01,
    yMin=-0.01, yMax=10.0+0.01, zMin=100.0-0.01, zMax=100.0+0.01))
p.Surface(name='LOAD_SURF', side1Faces=p.faces.getByBoundingBox(xMin=-0.01, xMax=10.0+0.01,
    yMin=-0.01, yMax=10.0+0.01, zMin=100.0-0.01, zMax=100.0+0.01))
p.seedPart(size=5.0, deviationFactor=0.1, minSizeFactor=0.1)
p.generateMesh()
p.Set(name='TIP_NODES', nodes=p.nodes.getByBoundingBox(xMin=10.0/2-0.05, xMax=10.0/2+0.05,
    yMin=10.0/2-0.05, yMax=10.0/2+0.05,
    zMin=100.0-0.01, zMax=100.0+0.01))


# ── Material ─────────────────────────────────────────────────────────────────
mdb.models['Cantilever'].Material(name='Steel')
mdb.models['Cantilever'].materials['Steel'].Elastic(
    table=((210000.0, 0.3),))
# density not specified


# ── Section & Assignment ─────────────────────────────────────────────────────
mdb.models['Cantilever'].HomogeneousSolidSection(
    name='Section-1', material='Steel', thickness=None)
mdb.models['Cantilever'].parts['Part-1'].SectionAssignment(
    region=mdb.models['Cantilever'].parts['Part-1'].sets['ALL'],
    sectionName='Section-1', offset=0.0,
    offsetType=MIDDLE_SURFACE, offsetField='', thicknessAssignment=FROM_SECTION)

# ── Assembly ─────────────────────────────────────────────────────────────────
a = mdb.models['Cantilever'].rootAssembly
a.DatumCsysByDefault(CARTESIAN)
a.Instance(name='Part-1-1', part=mdb.models['Cantilever'].parts['Part-1'], dependent=ON)

# ── Step, BC, Load, Output ───────────────────────────────────────────────────

mdb.models['Cantilever'].StaticStep(name='Step-1', previous='Initial',
    description='Static analysis', timePeriod=1.0,
    initialInc=0.1, minInc=1e-5, maxInc=1.0,
    nlgeom=OFF)

a = mdb.models['Cantilever'].rootAssembly
inst = a.instances['Part-1-1']

# Fixed BC
mdb.models['Cantilever'].EncastreBC(
    name='Fixed', createStepName='Initial',
    region=a.instances['Part-1-1'].sets['FIXED_END'])

# Load
mdb.models['Cantilever'].ConcentratedForce(
    name='Load-1', createStepName='Step-1',
    region=a.instances['Part-1-1'].sets['TIP_NODES'],
    cf2=-1.0, amplitude=UNSET,
    distributionType=UNIFORM, field='', localCsys=None)

# Field outputs
mdb.models['Cantilever'].fieldOutputRequests['F-Output-1'].setValues(
    variables=('S', 'E', 'U', 'RF'))

# History outputs - tip node
mdb.models['Cantilever'].HistoryOutputRequest(
    name='TIP', createStepName='Step-1',
    region=a.instances['Part-1-1'].sets['TIP_NODES'],
    variables=('U1', 'U2', 'U3'))




# ── Write Job ────────────────────────────────────────────────────────────────
mdb.Job(name='Cantilever', model='Cantilever',
        description='', type=ANALYSIS,
        atTime=None, waitMinutes=0, waitHours=0,
        queue=None, memory=90, memoryUnits=PERCENTAGE,
        getMemoryFromAnalysis=True,
        explicitPrecision=SINGLE, nodalOutputPrecision=SINGLE,
        echoPrint=OFF, modelPrint=OFF, contactPrint=OFF, historyPrint=OFF,
        userSubroutine='', scratch='', resultsFormat=ODB,
        multiprocessingMode=DEFAULT, numCpus=1, numGPUs=0)

mdb.jobs['Cantilever'].writeInput(consistencyChecking=OFF)
print('INP_WRITTEN: ' + workdir + '/Cantilever.inp')
mdb.saveAs('Cantilever')
print('CAE_WRITTEN: ' + workdir + '/Cantilever.cae')
