print()

path = compas_vibro.TEMP
geometry = 'mesh_flat_20x20'
name = 'ansys_{0}_harmonic_s'.format(geometry)

mesh = Mesh.from_json(compas_vibro.get('{0}.json'.format(geometry)))

# make an instance of the stucture object - - - - - - - - - - - - - - - - - - -
s = Structure(path, name)

# add nodes and elements from mesh - - - - - - - - - - - - - - - - - - - - - - -
s.add_nodes_elements_from_mesh(mesh, 'ShellElement', elset='shell')

# add displacements - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
d = FixedDisplacement('boundary', mesh.vertices_on_boundary())
s.add(d)

# add loads - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
load = PointLoad(name='pload', nodes=[100], x=0, y=0, z=1, xx=0, yy=0, zz=0)
s.add(load)

# add sections - - - - - - - - - - - -
section = ShellSection('shell_sec', t=.1)
s.add(section)

# add material - - - - - -
material = ElasticIsotropic('concrete', E=30e9, v=.2, p=2400)

s.add(material)
# add element properties - - - - - - - - -
# make an instance of the stucture object - - - - - - - - - - - - - - - - - - -
s = Structure(path, name)

# add nodes and elements from mesh - - - - - - - - - - - - - - - - - - - - - - -
s.add_nodes_elements_from_mesh(mesh, 'ShellElement', elset='shell')

# add displacements - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# d = FixedDisplacement('boundary', mesh.vertices_on_boundary())
# s.add(d)

bv = {
    vk
    for fk in mesh.faces_where({'is_boundary': True})
    for vk in mesh.face_vertices(fk)
}
d = FixedDisplacement('boundary', list(bv))
s.add(d)

# add loads - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
load = PointLoad(name='pload', nodes=[100], x=0, y=0, z=1, xx=0, yy=0, zz=0)
s.add(load)

# add sections - - - - - - - - - - - -
section = ShellSection('thin_sec', t=.1)
s.add(section)
section = ShellSection('thick_sec', t=.2)
s.add(section)

# add sets - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fins = list(mesh.faces_where({'is_fin': True}))
no_fins = list(mesh.faces_where({'is_fin': False}))