<commit_before>import os
from sfepy import top_dir
from sfepy.base.base import debug, nm
from sfepy.homogenization.micmac import get_homog_coefs_linear
from sfepy.homogenization.recovery import save_recovery_region, recover_micro_hook

def post_process( out, pb, state, extend = False ):
    from sfepy.base.base import Struct
    from sfepy.fem.evaluate import eval_term_op

    if isinstance( state, dict ):
        pass
    else:
        stress = eval_term_op( state, 'de_cauchy_stress.i1.Omega( solid.D, u )', pb )
        strain = eval_term_op( state, 'de_cauchy_strain.i1.Omega( u )', pb )
        out['cauchy_strain'] = Struct( name = 'output_data',
                                       mode = 'cell', data = strain,
                                       dofs = None )
        out['cauchy_stress'] = Struct( name = 'output_data',
                                       mode = 'cell', data = stress,
                                       dofs = None )

        if pb.conf.options.get_default_attr('recover_micro', False):

            rname = pb.conf.options.recovery_region
            region = pb.domain.regions[rname]

            save_recovery_region( pb, rname );

            rstrain = eval_term_op( state, 'de_cauchy_strain.i1.%s( u )' % rname, pb )

            recover_micro_hook( pb.conf.options.micro_filename,
                                region, {'strain' : rstrain} )

    return out

def get_elements(coors, domain=None):
    return {0 : nm.arange(50, domain.shape.n_el, 100)}

functions = {
    'get_elements' : (get_elements,),
    'get_homog' : (lambda ts, coors, mode = None, region = None, ig = None:
                   get_homog_coefs_linear( ts, coors, mode, region, ig,
                                           micro_filename = options['micro_filename'] ), )
}

filename_mesh = top_dir + '/meshes/3d/cylinder.mesh'

regions = {
    'Omega' : ('all', {}),
    'Left' : ('nodes in (x < 0.001)', {}),
    'Right' : ('nodes in (x > 0.099)', {}),
    'Recovery' : ('elements by get_elements', {}),
}

materials = {
    'solid' : ('Omega', None, 'get_homog'),
}

fields = {
    '3_displacement': ((3,1), 'real', 'Omega', {'Omega' : '3_4_P1'}),
}

integrals = {
    'i1' : ('v', 'gauss_o1_d3'),
}

variables = {
    'u' : ('unknown field', '3_displacement', 0),
    'v' : ('test field', '3_displacement', 'u'),
}

ebcs = {
    'Fixed' : ('Left', {'u.all' : 0.0}),
    'PerturbedSurface' : ('Right', {'u.0' : 0.02, 'u.1' : 0.0, 'u.2' : 0.0}),
}

equations = {
    'balance_of_forces' :
    """dw_lin_elastic.i1.Omega( solid.D, v, u ) = 0""",
}

solvers = {
    'ls' : ('ls.scipy_direct', {}),
    'newton' : ('nls.newton',
                { 'i_max'      : 1,
                  'eps_a'      : 1e-8,
                  'problem'   : 'nonlinear'}),
}

fe = {
    'chunk_size' : 10000
}

options = {
    'nls' : 'newton',
    'ls' : 'ls',
    'output_dir' : 'output',
    'post_process_hook' : 'post_process',
    'output_prefix' : 'macro:',
    'recover_micro': True,
    'recovery_region' : 'Recovery',
    'micro_filename' : 'examples/homogenization/linear_homogenization_up.py',<commit_msg>fixed problem with eps_a<commit_after>import os
from sfepy import top_dir
from sfepy.base.base import debug, nm
from sfepy.homogenization.micmac import get_homog_coefs_linear
from sfepy.homogenization.recovery import save_recovery_region, recover_micro_hook

def post_process( out, pb, state, extend = False ):
    from sfepy.base.base import Struct
    from sfepy.fem.evaluate import eval_term_op

    if isinstance( state, dict ):
        pass
    else:
        stress = eval_term_op( state, 'de_cauchy_stress.i1.Omega( solid.D, u )', pb )
        strain = eval_term_op( state, 'de_cauchy_strain.i1.Omega( u )', pb )
        out['cauchy_strain'] = Struct( name = 'output_data',
                                       mode = 'cell', data = strain,
                                       dofs = None )
        out['cauchy_stress'] = Struct( name = 'output_data',
                                       mode = 'cell', data = stress,
                                       dofs = None )

        if pb.conf.options.get_default_attr('recover_micro', False):

            rname = pb.conf.options.recovery_region
            region = pb.domain.regions[rname]

            save_recovery_region( pb, rname );

            rstrain = eval_term_op( state, 'de_cauchy_strain.i1.%s( u )' % rname, pb )

            recover_micro_hook( pb.conf.options.micro_filename,
                                region, {'strain' : rstrain} )

    return out

def get_elements(coors, domain=None):
    return {0 : nm.arange(50, domain.shape.n_el, 100)}

functions = {
    'get_elements' : (get_elements,),
    'get_homog' : (lambda ts, coors, mode = None, region = None, ig = None:
                   get_homog_coefs_linear( ts, coors, mode, region, ig,
                                           micro_filename = options['micro_filename'] ), )
}

filename_mesh = top_dir + '/meshes/3d/cylinder.mesh'

regions = {
    'Omega' : ('all', {}),
    'Left' : ('nodes in (x < 0.001)', {}),
    'Right' : ('nodes in (x > 0.099)', {}),
    'Recovery' : ('elements by get_elements', {}),
}

materials = {
    'solid' : ('Omega', None, 'get_homog'),
}

fields = {
    '3_displacement': ((3,1), 'real', 'Omega', {'Omega' : '3_4_P1'}),
}

integrals = {
    'i1' : ('v', 'gauss_o1_d3'),
}

variables = {
    'u' : ('unknown field', '3_displacement', 0),
    'v' : ('test field', '3_displacement', 'u'),
}

ebcs = {
    'Fixed' : ('Left', {'u.all' : 0.0}),
    'PerturbedSurface' : ('Right', {'u.0' : 0.02, 'u.1' : 0.0, 'u.2' : 0.0}),
}

equations = {
    'balance_of_forces' :
    """dw_lin_elastic.i1.Omega( solid.D, v, u ) = 0""",
}

solvers = {
    'ls' : ('ls.scipy_direct', {}),
    'newton' : ('nls.newton',
                { 'i_max'      : 1,
                  'eps_a'      : 1e-6,
                  'problem'   : 'nonlinear'}),
}

fe = {
    'chunk_size' : 10000
}

options = {
    'nls' : 'newton',
    'ls' : 'ls',
    'output_dir' : 'output',
    'post_process_hook' : 'post_process',
    'output_prefix' : 'macro:',
    'recover_micro': True,
    'recovery_region' : 'Recovery',
    'micro_filename' : 'examples/homogenization/linear_homogenization_up.py',
{'fraction_non_alphanumeric': 0.15970555288846217, 'fraction_numerical': 0.016642662826052167, 'mean_word_length': 2.245067497403946, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7649660', 'n_tokens_mistral': 2321, 'n_tokens_neox': 2190, 'n_words': 452}