<commit_before>from sfepy.terms.terms import *
from sfepy.terms.terms_base import CouplingVectorScalar

class DivGradTerm( Term ):
    r"""
    :Description:
    Diffusion term.

    :Definition:
    .. math::
        \int_{\Omega} \nu\ \nabla \ul{v} : \nabla \ul{u}
    """
    name = 'dw_div_grad'
    arg_types = ('material', 'virtual', 'state')
    geometry = [(Volume, 'virtual')]

    function = staticmethod(terms.term_ns_asm_div_grad)
        
    def __call__( self, diff_var = None, chunk_size = None, **kwargs ):
        mat, virtual, state = self.get_args( **kwargs )
        ap, vg = virtual.get_approximation( self.get_current_group(), 'Volume' )
        n_el, n_qp, dim, n_ep = ap.get_v_data_shape( self.integral_name )

        if diff_var is None:
            shape = (chunk_size, 1, dim * n_ep, 1 )
            mode = 0
        elif diff_var == self.get_arg_name( 'state' ):
            shape = (chunk_size, 1, dim * n_ep, dim * n_ep )
            mode = 1
        else:
            raise StopIteration

        vec = state()
        for out, chunk in self.char_fun( chunk_size, shape ):
            status = self.function( out, vec, 0, mat,
                                    vg, ap.econn, chunk, mode )
            yield out, chunk, status

class ConvectTerm( Term ):
    r"""
    :Description:
    Nonlinear convective term.

    :Definition:
    .. math::
        \int_{\Omega} ((\ul{u} \cdot \nabla) \ul{u}) \cdot \ul{v}
    """
    name = 'dw_convect'
    arg_types = ('virtual', 'state')
    geometry = [(Volume, 'virtual')]

    def __init__(self, name, sign, **kwargs):
        Term.__init__(self, name, sign, function=terms.term_ns_asm_convect,
                      **kwargs)
        
    def __call__( self, diff_var = None, chunk_size = None, **kwargs ):
        virtual, state = self.get_args( **kwargs )
        ap, vg = virtual.get_approximation( self.get_current_group(), 'Volume' )
        n_el, n_qp, dim, n_ep = ap.get_v_data_shape( self.integral_name )

        if diff_var is None:
            shape = (chunk_size, 1, dim * n_ep, 1 )
            mode = 0
        elif diff_var == self.get_arg_name( 'state' ):
            shape = (chunk_size, 1, dim * n_ep, dim * n_ep )
            mode = 1
        else:
            raise StopIteration

        vec = state()
        bf = ap.get_base( 'v', 0, self.integral_name )
        for out, chunk in self.char_fun( chunk_size, shape ):
            status = self.function( out, vec, 0, bf,
                                    vg, ap.econn, chunk, mode )
            yield out, chunk, status

class LinearConvectTerm( Term ):
    r"""
    :Description:
    Linearized convective term.

    :Definition:
    .. math::
        \int_{\Omega} ((\ul{b} \cdot \nabla) \ul{u}) \cdot \ul{v}
    """
    name = 'dw_lin_convect'
    arg_types = ('virtual', 'parameter', 'state')
    geometry = [(Volume, 'virtual')]

    function = staticmethod(terms.dw_lin_convect)
        
    def __call__( self, diff_var = None, chunk_size = None, **kwargs ):
        virtual, par, state = self.get_args( **kwargs )
        ap, vg = virtual.get_approximation( self.get_current_group(), 'Volume' )
        n_el, n_qp, dim, n_ep = ap.get_v_data_shape( self.integral_name )

        if diff_var is None:
            shape = (chunk_size, 1, dim * n_ep, 1 )
            mode = 0
        elif diff_var == self.get_arg_name( 'state' ):
            shape = (chunk_size, 1, dim * n_ep, dim * n_ep )
            mode = 1
        else:
            raise StopIteration

        vec1 = par()
        vec2 = state()
        bf = ap.get_base( 'v', 0, self.integral_name )
        for out, chunk in self.char_fun( chunk_size, shape ):
            status = self.function( out, vec1, 0, vec2, 0,
                                    bf, vg, ap.econn, chunk, mode )
            yield out, chunk, status

class LinearConvectQTerm( Term ):
    r"""
    :Description:
    Linearized convective term evaluated in quadrature points.

    :Definition:
    .. math::
        ((\ul{b} \cdot \nabla) \ul{u})|_{qp}
    """
    name = 'dq_lin_convect'
    arg_types = ('parameter', 'state')
    geometry = [(Volume, 'state')]

    function = staticmethod(terms.dw_lin_convect)
        
    def __call__( self, diff_var = None, chunk_size = None, **kwargs ):
        par, state = self.get_args( **kwargs )
        ap, vg = state.get_approximation( self.get_current_group(), 'Volume' )
        n_el, n_qp, dim, n_ep = ap.get_v_data_shape( self.integral_name )

        if diff_var is None:
            shape = (chunk_size, n_qp, dim, 1 )
            mode = 2
        else:
            raise StopIteration

        vec1 = par()
        vec2 = state()
        bf = ap.get_base( 'v', 0, self.integral_name )
        for out, chunk in self.char_fun( chunk_size, shape ):
            status = self.function( out, vec1, 0, vec2, 0,
                                    bf, vg, ap.econn, chunk, mode )
            yield out, chunk, status

class StokesGrad( CouplingVectorScalar ):

    def get_fargs_grad( self, diff_var = None, chunk_size = None, **kwargs ):
        virtual, state = self.get_args( **kwargs )
        apr, vgr = virtual.get_approximation( self.get_current_group(),
                                              'Volume' )
        apc, vgc = state.get_approximation( self.get_current_group(),
                                            'Volume' )

        self.set_data_shape( apr, apc )
        shape, mode = self.get_shape_grad( diff_var, chunk_size )

        vec = self.get_vector( state )
        bf = apc.get_base( 'v', 0, self.integral_name )

        if 'material' in self.arg_types:
            coef, = self.get_args(['material'], **kwargs)

        else:
            coef = nm.ones((1, self.data_shape_r[1], 1, 1), dtype=nm.float64)

        return (coef, vec, 0, bf, vgr, apc.econn), shape, mode

class StokesDiv( CouplingVectorScalar ):

    def get_fargs_div( self, diff_var = None, chunk_size = None, **kwargs ):
        state, virtual = self.get_args( **kwargs )
        apr, vgr = virtual.get_approximation( self.get_current_group(),
                                              'Volume' )
        apc, vgc = state.get_approximation( self.get_current_group(),
                                            'Volume' )

        self.set_data_shape( apr, apc )
        shape, mode = self.get_shape_div( diff_var, chunk_size )

        vec = self.get_vector( state )
        bf = apr.get_base( 'v', 0, self.integral_name )

        if 'material' in self.arg_types:
            coef, = self.get_args(['material'], **kwargs)

        else:
            coef = nm.ones((1, self.data_shape_r[1], 1, 1), dtype=nm.float64)

        return (coef, vec, 0, bf, vgc, apc.econn), shape, mode

class StokesEval( CouplingVectorScalar ):

    def get_fargs_eval( self, diff_var = None, chunk_size = None, **kwargs ):
        par_v, par_s = self.get_args( **kwargs )
        aps, vgs = par_s.get_approximation( self.get_current_group(),
                                            'Volume' )
        apv, vgv = par_v.get_approximation( self.get_current_group(),
                                            'Volume' )
        self.set_data_shape( aps, apv )
        return (par_v, par_s, vgv), (chunk_size, 1, 1, 1), 0<commit_msg>fixes for dw_stokes_w<commit_after>from sfepy.terms.terms import *
from sfepy.terms.terms_base import CouplingVectorScalar

class DivGradTerm( Term ):
    r"""
    :Description:
    Diffusion term.

    :Definition:
    .. math::
        \int_{\Omega} \nu\ \nabla \ul{v} : \nabla \ul{u}
    """
    name = 'dw_div_grad'
    arg_types = ('material', 'virtual', 'state')
    geometry = [(Volume, 'virtual')]

    function = staticmethod(terms.term_ns_asm_div_grad)
        
    def __call__( self, diff_var = None, chunk_size = None, **kwargs ):
        mat, virtual, state = self.get_args( **kwargs )
        ap, vg = virtual.get_approximation( self.get_current_group(), 'Volume' )
        n_el, n_qp, dim, n_ep = ap.get_v_data_shape( self.integral_name )

        if diff_var is None:
            shape = (chunk_size, 1, dim * n_ep, 1 )
            mode = 0
        elif diff_var == self.get_arg_name( 'state' ):
            shape = (chunk_size, 1, dim * n_ep, dim * n_ep )
            mode = 1
        else:
            raise StopIteration

        vec = state()
        for out, chunk in self.char_fun( chunk_size, shape ):
            status = self.function( out, vec, 0, mat,
                                    vg, ap.econn, chunk, mode )
            yield out, chunk, status

class ConvectTerm( Term ):
    r"""
    :Description:
    Nonlinear convective term.

    :Definition:
    .. math::
        \int_{\Omega} ((\ul{u} \cdot \nabla) \ul{u}) \cdot \ul{v}
    """
    name = 'dw_convect'
    arg_types = ('virtual', 'state')
    geometry = [(Volume, 'virtual')]

    def __init__(self, name, sign, **kwargs):
        Term.__init__(self, name, sign, function=terms.term_ns_asm_convect,
                      **kwargs)
        
    def __call__( self, diff_var = None, chunk_size = None, **kwargs ):
        virtual, state = self.get_args( **kwargs )
        ap, vg = virtual.get_approximation( self.get_current_group(), 'Volume' )
        n_el, n_qp, dim, n_ep = ap.get_v_data_shape( self.integral_name )

        if diff_var is None:
            shape = (chunk_size, 1, dim * n_ep, 1 )
            mode = 0
        elif diff_var == self.get_arg_name( 'state' ):
            shape = (chunk_size, 1, dim * n_ep, dim * n_ep )
            mode = 1
        else:
            raise StopIteration

        vec = state()
        bf = ap.get_base( 'v', 0, self.integral_name )
        for out, chunk in self.char_fun( chunk_size, shape ):
            status = self.function( out, vec, 0, bf,
                                    vg, ap.econn, chunk, mode )
            yield out, chunk, status

class LinearConvectTerm( Term ):
    r"""
    :Description:
    Linearized convective term.

    :Definition:
    .. math::
        \int_{\Omega} ((\ul{b} \cdot \nabla) \ul{u}) \cdot \ul{v}
    """
    name = 'dw_lin_convect'
    arg_types = ('virtual', 'parameter', 'state')
    geometry = [(Volume, 'virtual')]

    function = staticmethod(terms.dw_lin_convect)
        
    def __call__( self, diff_var = None, chunk_size = None, **kwargs ):
        virtual, par, state = self.get_args( **kwargs )
        ap, vg = virtual.get_approximation( self.get_current_group(), 'Volume' )
        n_el, n_qp, dim, n_ep = ap.get_v_data_shape( self.integral_name )

        if diff_var is None:
            shape = (chunk_size, 1, dim * n_ep, 1 )
            mode = 0
        elif diff_var == self.get_arg_name( 'state' ):
            shape = (chunk_size, 1, dim * n_ep, dim * n_ep )
            mode = 1
        else:
            raise StopIteration

        vec1 = par()
        vec2 = state()
        bf = ap.get_base( 'v', 0, self.integral_name )
        for out, chunk in self.char_fun( chunk_size, shape ):
            status = self.function( out, vec1, 0, vec2, 0,
                                    bf, vg, ap.econn, chunk, mode )
            yield out, chunk, status

class LinearConvectQTerm( Term ):
    r"""
    :Description:
    Linearized convective term evaluated in quadrature points.

    :Definition:
    .. math::
        ((\ul{b} \cdot \nabla) \ul{u})|_{qp}
    """
    name = 'dq_lin_convect'
    arg_types = ('parameter', 'state')
    geometry = [(Volume, 'state')]

    function = staticmethod(terms.dw_lin_convect)
        
    def __call__( self, diff_var = None, chunk_size = None, **kwargs ):
        par, state = self.get_args( **kwargs )
        ap, vg = state.get_approximation( self.get_current_group(), 'Volume' )
        n_el, n_qp, dim, n_ep = ap.get_v_data_shape( self.integral_name )

        if diff_var is None:
            shape = (chunk_size, n_qp, dim, 1 )
            mode = 2
        else:
            raise StopIteration

        vec1 = par()
        vec2 = state()
        bf = ap.get_base( 'v', 0, self.integral_name )
        for out, chunk in self.char_fun( chunk_size, shape ):
            status = self.function( out, vec1, 0, vec2, 0,
                                    bf, vg, ap.econn, chunk, mode )
            yield out, chunk, status

class StokesGrad( CouplingVectorScalar ):

    def get_fargs_grad( self, diff_var = None, chunk_size = None, **kwargs ):
        virtual, state = self.get_args(['virtual', 'state'], **kwargs)
        apr, vgr = virtual.get_approximation( self.get_current_group(),
                                              'Volume' )
        apc, vgc = state.get_approximation( self.get_current_group(),
                                            'Volume' )

        self.set_data_shape( apr, apc )
        shape, mode = self.get_shape_grad( diff_var, chunk_size )

        vec = self.get_vector( state )
        bf = apc.get_base( 'v', 0, self.integral_name )

        if 'material' in self.arg_types:
            coef, = self.get_args(['material'], **kwargs)

        else:
            coef = nm.ones((1, self.data_shape_r[1], 1, 1), dtype=nm.float64)

        return (coef, vec, 0, bf, vgr, apc.econn), shape, mode

class StokesDiv( CouplingVectorScalar ):

    def get_fargs_div( self, diff_var = None, chunk_size = None, **kwargs ):
        state, virtual = self.get_args(['state', 'virtual'], **kwargs)
        apr, vgr = virtual.get_approximation( self.get_current_group(),
                                              'Volume' )
        apc, vgc = state.get_approximation( self.get_current_group(),
                                            'Volume' )

        self.set_data_shape( apr, apc )
        shape, mode = self.get_shape_div( diff_var, chunk_size )

        vec = self.get_vector( state )
        bf = apr.get_base( 'v', 0, self.integral_name )

        if 'material' in self.arg_types:
            coef, = self.get_args(['material'], **kwargs)

        else:
            coef = nm.ones((1, self.data_shape_r[1], 1, 1), dtype=nm.float64)

        return (coef, vec, 0, bf, vgc, apc.econn), shape, mode

class StokesEval( CouplingVectorScalar ):

    def get_fargs_eval( self, diff_var = None, chunk_size = None, **kwargs ):
        par_v, par_s = self.get_args(['parameter_v', 'parameter_s'], **kwargs)
        aps, vgs = par_s.get_approximation( self.get_current_group(),
                                            'Volume' )
        apv, vgv = par_v.get_approximation( self.get_current_group(),
                                            'Volume' )
        self.set_data_shape( aps, apv )
        return (par_v, par_s, vgv), (chunk_size, 1, 1, 1), 0
{'fraction_non_alphanumeric': 0.12479452054794521, 'fraction_numerical': 0.0073972602739726025, 'mean_word_length': 1.9431566216488612, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6624343', 'n_tokens_mistral': 4894, 'n_tokens_neox': 4667, 'n_words': 1196}