from Cuboid_1 import *

from sfepy.mechanics.matcoefs import stiffness_from_youngpoisson

def stress_strain(out, pb, state, extend=False):
    """
    Calculate and output strain and stress for given displacements.
    """
    from sfepy.base.base import Struct

    ev = pb.evaluate
    strain = ev('ev_cauchy_strain.2.Omega(u)', mode='el_avg')

    out['cauchy_strain'] = Struct(name='output_data', mode='cell',
                                  data=strain, dofs=None)
    stress = ev('ev_cauchy_stress.2.Omega(Steel.D, u)', mode='el_avg',)

    out['cauchy_stress'] = Struct(name='output_data', mode='cell',
                                  data=stress, dofs=None)

    return out

Steel = materials['Steel'][0]
Steel.update({'D' : stiffness_from_youngpoisson(2, young, poisson)})
options.update({'post_process_hook' : 'stress_strain',})

from sfepy.postprocess.viewer import Viewer

view = Viewer('block.vtk')
view(vector_mode='warp_norm', rel_scaling=1,is_scalar_bar=True, is_wireframe=True)
