Solid Cross Section

[14]:
import time
from opensg.mesh.segment import  SolidBounMesh
from opensg.core.solid import  compute_timo_boun
import opensg.utils as utils
import opensg.core.stress_recov as stress_recov
tic = time.time()

# Read 2D yaml
segid=9
filename='../data/Solid_2DSG/2Dbar_urc_npl_1_ar_5-segment_'
mesh_yaml=filename+str(segid)+'.yaml'
segment_mesh = SolidBounMesh(mesh_yaml)
material_parameters, density = segment_mesh.material_database
meshdata = segment_mesh.meshdata

# Timoshenko stiffness and mass matrix
timo=compute_timo_boun(material_parameters, meshdata)
mass=utils.solid.get_mass_solid(meshdata, density)

# Print output
print('Boundary Origin:', meshdata['origin'],'\n')
print('2D Mass matrix \n',mass)
print('\n 2D Timo Stiffness\n', timo[0])
print('\n Time Taken: 2D yaml',str(time.time()-tic))
[11]:
#Dehomogenization

beam_out=utils.beamdyn_trans.beam_reaction(filename)

# Local strain and local displacement
strain_m,u_loc=stress_recov.local_strain(timo,beam_out,segid,meshdata)

# Local stress (quadrature points) and local stress(elemental nodes)
stress_m_quad, coord_quad, stress_m, coord_node=stress_recov.stress_eval(material_parameters, meshdata, strain_m)

[12]:
import dolfinx
filename='solid_cross_section'
stress_m.name = "Stress" # Set a name for Paraview
#strain_m.name='Strain'
#u_loc.name='Displacement'
with dolfinx.io.XDMFFile(meshdata['mesh'].comm, filename+'.xdmf', "a") as xdmf:
    xdmf.write_function(stress_m, 0.0)
    #xdmf.write_function(strain_m, 0.0)
    #xdmf.write_function(u_loc, 0.0)
[13]:
# Visualize plot
import pyvista
pyvista.start_xvfb()
u_topology, u_cell_types, u_geometry=dolfinx.plot.vtk_mesh(meshdata['mesh'],meshdata['mesh'].topology.dim)
grid = pyvista.UnstructuredGrid(u_topology, u_cell_types, u_geometry)
grid.cell_data["Marker"] = meshdata['subdomains'].values[:]
grid.set_active_scalars("Marker")
u_plotter = pyvista.Plotter()
u_plotter.add_mesh(grid)
u_plotter.view_yz() # x is beam axis
u_plotter.show()
../_images/tutorials_solid_cross_section_4_0.png
[ ]: