<commit_before>"""This module defines isotropic, linear elastic materials.

Materials defined in this module can operate on physical space of
dimension dim = 2 or 3. dim = 2 refers to plane strain elasticity, while
dim = 3 refers to classical 3D elasticity.

To create a plane stress material with shear modulus mu and Poisson
ratio nu, a plane strain material should be created, with the same shear
modulus mu, and fictitious Poisson ratio nu / (1 + nu).

"""

from cython cimport boundscheck
from cython cimport cdivision
from cython cimport wraparound
from libc.math cimport M_SQRT2

from janus.green cimport AbstractGreenOperator


def create(g, nu, dim=3):
    """Create a new isotropic, linear and elastic material.

    Args:
        g: the shear modulus
        nu: the Poisson ratio
        dim: the dimension of the physical space (default 3)

    Returns:
        A new instance of IsotropicLinearElasticMaterial.

    """
    return IsotropicLinearElasticMaterial(g, nu, dim)


@cdivision(True)
cpdef double poisson_from_bulk_and_shear_moduli(double k, double g, int dim=3):
    """Compute the Poisson ratio from the bulk and shear moduli.

    No checks are performed on the positivity of the bulk and shear
    moduli, or on the validity of the returned Poisson ratio (which
    should lie between -1 and 1/2).

    Args:
        k: the bulk modulus
        g: the shear modulus
        dim: the dimension of the physical space (default 3). Must be 2
            (plane strain elasticity) or 3 (3D elasticity).


    Returns:
        The Poisson ratio.

    """
    if dim == 2:
        return (k - g) / (2. * k)
    elif dim == 3:
        return (3 * k - 2 * g) / (2 * (3 * k + g))
    else:
        raise ValueError('dim must be 2 or 3 (was {0})'.format(dim))


cdef class IsotropicLinearElasticMaterial:

    """Isotropic, linear and elastic materials.

    Args:
        g: the shear modulus
        nu: the Poisson ratio
        dim: the dimension of the physical space (default 3)

    Attributes:
        k: the bulk modulus (read-only)
        g: the shear modulus (read-only)
        nu: the Poisson ratio (read-only)
        dim: the dimension of the physical space (read-only)

    """

    @cdivision(True)
    def __cinit__(self, double g, double nu, int dim=3):
        if g < 0.0:
            raise ValueError('g must be >= 0 (was {0})'.format(g))
        if dim == 2 and nu > 0.5:
            raise ValueError('nu must be <= 1/2 (was {0})'.format(nu))
        if dim == 3 and (nu < -1.0 or nu > 0.5):<commit_msg>Doc: progressively get rid of Google Style.<commit_after>"""This module defines isotropic, linear elastic materials.

Materials defined in this module can operate on physical space of
dimension 2 or 3; all functions and methods defined in this module refer to
this dimension as `dim`, which is therefore *not documented*:

* ``dim == 2``: plane strain elasticity,
* ``dim == 3``: classical 3D elasticity.

To create a plane stress material with shear modulus ``g`` and Poisson ratio
``nu``, a plane strain material should be created, with same shear modulus
``g``, and fictitious Poisson ratio ``nu/(1+nu)``.
"""

from cython cimport boundscheck
from cython cimport cdivision
from cython cimport wraparound
from libc.math cimport M_SQRT2

from janus.green cimport AbstractGreenOperator


def create(g, nu, dim=3):
    """Create a new isotropic, linear and elastic material.

    Returns a new instance of :class:`IsotropicLinearElasticMaterial`
    with shear modulus `g` and Poisson ratio `nu`.
    """
    return IsotropicLinearElasticMaterial(g, nu, dim)


@cdivision(True)
cpdef double poisson_from_bulk_and_shear_moduli(double k, double g, int dim=3):
    """Compute the Poisson ratio from the bulk and shear moduli.

    No checks are performed on the positivity of the bulk modulus `k` and
    shear modulus `g`, or on the validity of the returned Poisson ratio
    (which should lie between -1 and 1/2).
    """
    if dim == 2:
        return (k - g) / (2. * k)
    elif dim == 3:
        return (3 * k - 2 * g) / (2 * (3 * k + g))
    else:
        raise ValueError('dim must be 2 or 3 (was {0})'.format(dim))


cdef class IsotropicLinearElasticMaterial:

    """Isotropic, linear and elastic materials.

    :param g: Shear modulus (``float``).
    :param nu: Poisson ratio (``float``).
    :param dim: Dimension of the physical space (``int``, optional).
    """

    @cdivision(True)
    def __cinit__(self, double g, double nu, int dim=3):
        if g < 0.0:
            raise ValueError('g must be >= 0 (was {0})'.format(g))
        if dim == 2 and nu > 0.5:
            raise ValueError('nu must be <= 1/2 (was {0})'.format(nu))
        if dim == 3 and (nu < -1.0 or nu > 0.5):
{'fraction_non_alphanumeric': 0.09776182432432433, 'fraction_numerical': 0.01731418918918919, 'mean_word_length': 2.876432078559738, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4031737', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1365, 'n_words': 619}