Beispiel #1
0
class FabricLayer(ReinfLayer):
    """Reinforcement with a grid structure
    """
    name = 'Fabric layer'
    width = Float(100, CS=True)
    spacing = Float(14, CS=True)
    A_roving = Float(1, CS=True)

    A = tr.Property(Float, depends_on='+CS')
    """cross section area of reinforcement layers"""
    @tr.cached_property
    def _get_A(self):
        return int(self.width / self.spacing) * self.A_roving

    P = tr.Property(Float, depends_on='+CS')
    """cross section area of reinforcement layers"""

    @tr.cached_property
    def _get_P(self):
        raise NotImplementedError

    def _matmod_default(self):
        return 'carbon'

    ipw_view = View(
        Item('matmod', latex=r'\mathrm{behavior}'),
        Item('z', latex='z \mathrm{[mm]}'),
        Item('width', latex='\mathrm{fabric~width} \mathrm{[mm]}'),
        Item('spacing', latex='\mathrm{rov~spacing} \mathrm{[mm]}'),
        Item('A_roving', latex='A_r \mathrm{[mm^2]}'),
        Item('A', latex=r'A [mm^2]', readonly=True),
    )
Beispiel #2
0
class TFBilinear(TimeFunction):
    loading_ratio = Float(0.5, TIME=True)
    time_ratio = Float(0.5, TIME=True)

    ipw_view = View(
        Item('t_max'),
        Item('loading_ratio', editor=FloatRangeEditor(low=0, high=1)),
        Item('time_ratio', editor=FloatRangeEditor(low=0, high=1)),
        Item('range_factor'))

    range_factor = Float(1)

    def _generate_time_function(self):
        # Define the monotonic range beyond the unit range
        # allow for interactive extensions. The fact
        d_history = np.array([
            0, 1 * self.loading_ratio * self.range_factor,
            1 * self.range_factor
        ])
        t_arr = np.array([
            0, self.t_max * self.time_ratio * self.range_factor,
            self.t_max * self.range_factor
        ])
        return interp1d(t_arr,
                        d_history,
                        bounds_error=False,
                        fill_value=self.t_max)
Beispiel #3
0
class MonotonicLoadingScenario(LoadingScenario):

    n_incr = Int(10, BC=True)
    maximum_loading = Float(1.0, BC=True,
                            enter_set=True, auto_set=False,
                            symbol='\phi_{\max}',
                            desc='load factor at maximum load level',
                            unit='-')

    ipw_view = bu.View(
        bu.Item("n_incr"),
        bu.Item('maximum_loading'),
    )

    xy_arrays = Property(depends_on="state_changed")
    @cached_property
    def _get_xy_arrays(self):
        t_arr = np.linspace(0, self.t_max, self.n_incr)
        d_arr = np.linspace(0, self.maximum_loading, self.n_incr)
        return t_arr, d_arr

    def write_figure(self, f, rdir, rel_study_path):
        print('FNAME', self.node_name)
        fname = 'fig_' + self.node_name.replace(' ', '_') + '.pdf'
        print('FNAME', fname)
        self._update_xy_arrays()
        f.write(r'''
\multicolumn{3}{r}{\includegraphics[width=5cm]{%s}}\\
''' % join(rel_study_path, fname))
        self.savefig(join(rdir, fname))
Beispiel #4
0
class BarLayer(ReinfLayer):
    """"Layer consisting of discrete bar reinforcement"""
    name = 'Bar layer'
    ds = Float(16, CS=True)
    count = Int(1, CS=True)

    A = tr.Property(Float, depends_on='+CS')
    """cross section area of reinforcement layers"""
    @tr.cached_property
    def _get_A(self):
        return self.count * np.pi * (self.ds / 2.)**2

    P = tr.Property(Float, depends_on='+CS')
    """permeter of reinforcement layers"""

    @tr.cached_property
    def _get_P(self):
        return self.count * np.pi * (self.ds)

    def _matmod_default(self):
        return 'steel'

    ipw_view = View(
        Item('matmod', latex=r'\mathrm{behavior}'),
        Item('z', latex=r'z \mathrm{[mm]}'),
        Item('ds', latex=r'ds \mathrm{[mm]}'),
        Item('count', latex='count'),
        Item('A', latex=r'A [mm^2]'),
    )
class CrossSectionShapeBase(InteractiveModel):
    """"This class describes the geometry of the cross section."""
    name = 'Cross Section Shape'

    H = Float(400, GEO=True)

    ipw_view = View(Item('H', minmax=(10, 3000), latex='H [mm]'))
Beispiel #6
0
class TimeFunction(Model):
    name = 'time function'
    t_max = Float(1.0, TIME=True)
    t_shift = Float(0.0, TIME=True)

    def __call__(self, arg):
        return self.time_function(arg)

    time_function = tr.Property(depends_on='state_changed')

    @tr.cached_property
    def _get_time_function(self):
        return self._generate_time_function()

    def update_plot(self, axes):
        t_range = np.linspace(0, self.t_max, 500)
        f_range = self.time_function(t_range)
        axes.plot(t_range, f_range)
        axes.set_xlabel(r'$t$ [-]')
        axes.set_ylabel(r'$\theta$ [-]')
Beispiel #7
0
class TFMonotonic(TimeFunction):

    ipw_view = View(Item('t_max'), Item('range_factor'))

    range_factor = Float(10000)

    def _generate_time_function(self):
        # Define the monotonic range beyond the unit range
        # allow for interactive extensions. The fact
        d_history = np.array([0, 1 * self.range_factor])
        t_arr = np.array([0, self.t_max * self.range_factor])
        return interp1d(t_arr, d_history)
Beispiel #8
0
class ReinfLayer(InteractiveModel):
    # TODO: changes in the ipw interactive window doesn't reflect on mkappa
    #  (maybe because these are lists and changing the elements doesn't notify)
    name = 'Reinf layer'

    cs_layout = tr.WeakRef

    z = Float(50, CS=True)
    """z positions of reinforcement layers"""

    P = Float(100, CS=True)
    """Perimeter"""

    A = Float(100, CS=True)
    """Cross sectional area"""

    matmod = EitherType(
        options=[('steel', SteelReinfMatMod), ('carbon', CarbonReinfMatMod)])

    ipw_view = View(
        Item('matmod',
             latex=r'\mathrm{behavior}',
             editor=EitherTypeEditor(show_properties=False)),
        Item('z', latex='z \mathrm{[mm]}'),
        Item('A', latex='A \mathrm{[mm^2]}'),
    )

    tree = ['matmod']

    def get_N(self, eps):
        return self.A * self.matmod_.get_sig(eps)

    def update_plot(self, ax):
        eps_range = self.matmod_.get_eps_plot_range()
        N_range = self.get_N(eps_range)
        ax.plot(eps_range, N_range, color='red')
        ax.fill_between(eps_range, N_range, 0, color='red', alpha=0.1)
        ax.set_xlabel(r'$\varepsilon$ [-]')
        ax.set_ylabel(r'$F$ [N]')
class MATS3DIfcElastic(MATSEval):

    node_name = "Elastic interface"

    E_n = Float(1e+6, tooltip='Normal stiffness of the interface [MPa]',
                MAT=True, unit='MPa/m', symbol='E_\mathrm{n}',
                desc='Normal stiffness of the interface',
                auto_set=False, enter_set=True)

    E_s = Float(1.0, tooltip='Shear stiffness of the interface [MPa]',
                MAT=True, unit='MPa/m', symbol='E_\mathrm{s}',
                desc='Shear-modulus of the interface',
                auto_set=True, enter_set=True)

    state_var_shapes = {}

    D_rs = Property(depends_on='E_n,E_s')

    @cached_property
    def _get_D_rs(self):
        return np.array([[self.E_n, 0, 0],
                         [0, self.E_s, 0],
                         [0, 0, self.E_s]], dtype=np.float_)

    def get_corr_pred(self, u_r, tn1):
        tau = np.einsum(
            'rs,...s->...r',
            self.D_rs, u_r)
        grid_shape = tuple([1 for _ in range(len(u_r.shape[:-1]))])
        D = self.D_rs.reshape(grid_shape + self.D_rs.shape)
        return tau, D

    ipw_view = View(
        Item('E_s'),
        Item('E_n')
    )
Beispiel #10
0
class TFCyclicSin(TimeFunction):
    number_of_cycles = Int(10, TIME=True)
    phase_shift = Float(0, TIME=True)

    ipw_view = View(Item('number_of_cycles'), Item('phase_shift'),
                    Item('t_max'))

    def _generate_time_function(self):
        t = sp.symbols(r't')
        p = self.phase_shift
        tf = sp.sin(2 * self.number_of_cycles * sp.pi * t / self.t_max)
        if p > 0:
            T = self.t_max / self.number_of_cycles
            pT = p * T
            tf = sp.Piecewise((0, t < pT), (tf.subs(t, t - pT), True))
        return sp.lambdify(t, tf, 'numpy')
Beispiel #11
0
class LoadingScenario(MFnLineArray, BMCSLeafNode, RInputRecord):
    """Loading scenario.
    """
    def reset(self):
        return

    node_name = Str('loading scenario')

    t_max = Float(1.)

    xdata = Property
    def _get_xdata(self):
        return self.xy_arrays[0]

    ydata = Property
    def _get_ydata(self):
        return self.xy_arrays[1]

    def update_plot(self, axes):
        axes.plot(self.xdata, self.ydata)
        axes.fill_between(self.xdata, self.ydata, 0, alpha=0.1)
class Rectangle(CrossSectionShapeBase):

    B = Float(200, GEO=True)

    ipw_view = View(
        *CrossSectionShapeBase.ipw_view.
        content,  # this will add View Items of the base class CrossSectionShapeBase
        Item('B', minmax=(10, 500), latex='B \mathrm{[mm]}'))

    def get_cs_area(self):
        return self.B * self.H

    def get_cs_i(self):
        return self.B * self.H**3 / 12

    def get_b(self, z_positions_array):
        return np.full_like(z_positions_array, self.B)

    def update_plot(self, ax):

        ax.fill(
            [-self.B / 2, self.B / 2, self.B / 2, -self.B / 2, -self.B / 2],
            [0, 0, self.H, self.H, 0],
            color='gray',
            alpha=0.2)
        ax.plot(
            [-self.B / 2, self.B / 2, self.B / 2, -self.B / 2, -self.B / 2],
            [0, 0, self.H, self.H, 0],
            color='black')
        ax.autoscale_view()
        ax.set_aspect('equal')

        ax.annotate('Area = {} $mm^2$'.format(int(Rectangle.get_cs_area(self)),
                                              0),
                    xy=(-self.H / 2 * 0.8, self.H / 2),
                    color='blue')
        ax.annotate('I = {} $mm^4$'.format(int(Rectangle.get_cs_i(self)), 0),
                    xy=(-self.H / 2 * 0.8, self.H / 2 * 0.8),
                    color='blue')
Beispiel #13
0
class TFCyclicNonsymmetricConstant(TimeFunction):
    number_of_cycles = Int(10, TIME=True)
    unloading_ratio = Float(0.5, TIME=True)
    shift_cycles = Int(0, TIME=True)

    ipw_view = View(
        Item('number_of_cycles'), Item('shift_cycles'),
        Item('unloading_ratio', editor=FloatRangeEditor(low=0, high=1)),
        Item('t_max'))

    def _generate_time_function(self):
        d_1 = np.zeros(1)
        d_2 = np.zeros(((self.number_of_cycles + self.shift_cycles) * 2, ))
        d_2.reshape(-1, 2)[self.shift_cycles:, 0] = 1
        d_2.reshape(-1, 2)[self.shift_cycles:, 1] = self.unloading_ratio
        d_history = d_2.flatten()
        d_arr = np.hstack((d_1, d_history))
        t_arr = np.linspace(0, self.t_max, len(d_arr))
        return interp1d(t_arr,
                        d_arr,
                        bounds_error=False,
                        fill_value=self.t_max)
class Circle(CrossSectionShapeBase):

    # TODO->Rostia: provide input field instead minmax range
    # H from the base class is used as the D, for the diameter of the circular section

    H = Float(250, GEO=True)

    ipw_view = View(Item('H', minmax=(10, 3000), latex='D [mm]'), )

    def get_cs_area(self):
        return np.pi * self.H * self.H

    def get_cs_i(self):
        return np.pi * self.H**4 / 4

    def get_b(self, z_positions_array):
        return np.full_like(z_positions_array, self.H)

        # TODO->Saeed: complete this

    def update_plot(self, ax):
        # TODO->Saeed: fix this

        circle = MPL_Circle((0, self.H / 2),
                            self.H / 2,
                            facecolor=(.5, .5, .5, 0.2),
                            edgecolor=(0, 0, 0, 1))

        ax.add_patch(circle)
        ax.autoscale_view()
        ax.set_aspect('equal')
        ax.annotate('Area = {} $mm^2$'.format(int(self.get_cs_area()), 0),
                    xy=(-self.H / 2 * 0.8, self.H / 2),
                    color='blue')
        ax.annotate('I = {} $mm^4$'.format(int(self.get_cs_i()), 0),
                    xy=(-self.H / 2 * 0.8, self.H / 2 * 0.8),
                    color='blue')
Beispiel #15
0
class VDNTIM(MATS3DEval):
    """
    Vectorized uncoupled normal tngential interface model
    """
    # -------------------------------------------------------------------------
    # Elasticity
    # -------------------------------------------------------------------------
    name = 'equiv damage NTIM'

    E_N = Float(10000, MAT=True)

    E_T = Float(1000, MAT=True)

    epsilon_0 = Float(59.0e-6, MAT=True,
                      label="a",
                      desc="Lateral pressure coefficient",
                      enter_set=True,
                      auto_set=False)

    epsilon_f = Float(250.0e-6, MAT=True,
                      label="a",
                      desc="Lateral pressure coefficient",
                      enter_set=True,
                      auto_set=False)

    c_T = Float(0.01, MAT=True,
                label="a",
                desc="Lateral pressure coefficient",
                enter_set=True,
                auto_set=False)

    ipw_view = View(
        Item('E_T', readonly=True),
        Item('E_N', readonly=True),
        Item('epsilon_0'),
        Item('epsilon_f'),
        Item('c_T'),
        Item('eps_max'),
        Item('n_eps')
    )

    n_D = 3

    state_var_shapes = dict(
        kappa=(),
        omega_N=(),
        omega_T=()
    )

    def get_e_equiv(self, eps_N, eps_T):
        r"""
        Returns a list of the microplane equivalent strains
        based on the list of microplane strain vectors
        """
        # positive part of the normal strain magnitude for each microplane
        e_N_pos = (np.abs(eps_N) + eps_N) / 2.0
        # tangent strain ratio
        c_T = self.c_T
        # equivalent strain for each microplane
        eps_equiv = np.sqrt(e_N_pos * e_N_pos + c_T * eps_T)
        return eps_equiv

    def get_normal_law(self, eps_N, eps_T_a, kappa, omega_N, omega_T):
        E_N = self.E_N
        E_T = self.E_T
        eps_T = np.sqrt(np.einsum('...a,...a->...', eps_T_a, eps_T_a))
        eps_equiv = self.get_e_equiv(eps_N, eps_T)
        kappa[...] = np.max(np.array([kappa, eps_equiv]), axis=0)
        epsilon_0 = self.epsilon_0
        epsilon_f = self.epsilon_f
        I = np.where(kappa >= epsilon_0)
        omega_N[I] = (
            1.0 - (epsilon_0 / kappa[I] *
                   np.exp(-1.0 * (kappa[I] - epsilon_0) / (epsilon_f - epsilon_0))
            )
        )
        sig_N = (1 - omega_N) * E_N * eps_N
        sig_T_a = (1 - omega_N[..., np.newaxis]) * E_T * eps_T_a
        sig_a = np.concatenate([sig_N[...,np.newaxis], sig_T_a], axis=-1)
        return sig_a

    def get_corr_pred(self, eps_a, t_n1, **Eps):
        eps_a_ = np.einsum('...a->a...',eps_a)
        eps_N = eps_a_[0,...]
        eps_T_a = np.einsum('a...->...a', eps_a_[1:,...])
        sig_a = self.get_normal_law(eps_N, eps_T_a, **Eps)

        D_ = np.zeros(eps_a.shape + (eps_a.shape[-1],))
        D_[..., 0, 0] = self.E_N# * (1 - omega_N)
        D_[..., 1, 1] = self.E_T# * (1 - omega_T)
        D_[..., 2, 2] = self.E_T# * (1 - omega_T)
        D_[..., 3, 3] = self.E_T# * (1 - omega_T)

        return sig_a, D_

    def get_eps_NT_p(self, **Eps):
        """Plastic strain tensor
        """
        return None

    def plot_idx(self, ax_sig, ax_d_sig, idx=0):
        eps_max = self.eps_max
        n_eps = self.n_eps
        eps1_range = np.linspace(1e-9,eps_max,n_eps)
        Eps = { var : np.zeros( (1,) + shape )
            for var, shape in self.state_var_shapes.items()
        }
        eps_range = np.zeros((n_eps, 4))
        eps_range[:,idx] = eps1_range

        # monotonic load in the normal direction
        sig1_range, d_sig11_range = [], []
        for eps_a in eps_range:
            sig_a, D_range = self.get_corr_pred(eps_a[np.newaxis, ...], 1, **Eps)
            sig1_range.append(sig_a[0, idx])
            d_sig11_range.append(D_range[0, idx, idx])
        sig1_range = np.array(sig1_range, dtype=np.float_)
        eps1_range = eps1_range[:len(sig1_range)]

        ax_sig.plot(eps1_range, sig1_range,color='blue')
        d_sig11_range = np.array(d_sig11_range, dtype=np.float_)
        ax_d_sig.plot(eps1_range, d_sig11_range, linestyle='dashed', color='gray')
        ax_sig.set_xlabel(r'$\varepsilon_{11}$ [-]')
        ax_sig.set_ylabel(r'$\sigma_{11}$ [MPa]')
        ax_d_sig.set_ylabel(r'$\mathrm{d} \sigma_{11} / \mathrm{d} \varepsilon_{11}$ [MPa]')
        ax_d_sig.plot(eps1_range[:-1],
                    (sig1_range[:-1]-sig1_range[1:])/(eps1_range[:-1]-eps1_range[1:]),
                    color='orange', linestyle='dashed')

    def subplots(self, fig):
        ax_sig_N, ax_sig_T = fig.subplots(1,2)
        ax_d_sig_N = ax_sig_N.twinx()
        ax_d_sig_T = ax_sig_T.twinx()
        return ax_sig_N, ax_d_sig_N, ax_sig_T, ax_d_sig_T

    def update_plot(self, axes):
        ax_sig_N, ax_d_sig_N, ax_sig_T, ax_d_sig_T = axes
        self.plot_idx(ax_sig_N, ax_d_sig_N, 0)
        self.plot_idx(ax_sig_T, ax_d_sig_T, 1)
Beispiel #16
0
class MKappa(InteractiveModel, InjectSymbExpr):
    """Class returning the moment curvature relationship."""
    name = 'Moment-Curvature'

    symb_class = MKappaSymbolic
    cs_design = Instance(CrossSectionDesign, ())

    tree = ['cs_design']
    # Use PrototypedFrom only when the prototyped object is a class
    # (The prototyped attribute behaves similarly
    # to a delegated attribute, until it is explicitly
    # changed; from that point forward, the prototyped attribute
    # changes independently from its prototype.)
    # (it's kind of like tr.DelegatesTo('cs_design.cross_section_shape'))
    cross_section_shape = tr.DelegatesTo('cs_design')
    cross_section_shape_ = tr.DelegatesTo('cs_design')
    cross_section_layout = tr.DelegatesTo('cs_design')
    matrix_ = tr.DelegatesTo('cs_design')

    # Geometry
    H = tr.DelegatesTo('cross_section_shape_')

    DEPSTR = 'state_changed'

    n_m = Int(
        100,
        DSC=True,
        desc=
        'Number of discretization points along the height of the cross-section'
    )

    # @todo: fix the dependency - `H` should be replaced by _GEO
    z_m = tr.Property(depends_on=DEPSTR)

    @tr.cached_property
    def _get_z_m(self):
        return np.linspace(0, self.H, self.n_m)

    low_kappa = Float(0.0, BC=True, GEO=True)
    high_kappa = Float(0.00002, BC=True, GEO=True)
    n_kappa = Int(100, BC=True)
    step_kappa = tr.Property(Float, depends_on='low_kappa, high_kappa')

    @tr.cached_property
    def _get_step_kappa(self):
        return float((self.high_kappa - self.low_kappa) / self.n_kappa)

    kappa_slider = Float(0.0000001)

    ipw_view = View(
        Item(
            'low_kappa',
            latex=r'\text{Low}~\kappa'),  #, editor=FloatEditor(step=0.00001)),
        Item('high_kappa', latex=r'\text{High}~\kappa'
             ),  # , editor=FloatEditor(step=0.00001)),
        Item('n_kappa', latex='n_{\kappa}'),
        Item('plot_strain'),
        Item('solve_for_eps_bot_pointwise'),
        Item('n_m', latex='n_m'),
        Item('kappa_slider', latex='\kappa', readonly=True),
        # editor=FloatRangeEditor(low_name='low_kappa',
        #                         high_name='high_kappa',
        #                         n_steps_name='n_kappa')
        # ),
        time_editor=HistoryEditor(
            var='kappa_slider',
            min_var='low_kappa',
            max_var='high_kappa',
        ),
    )

    idx = tr.Property(depends_on='kappa_slider')

    apply_material_safety_factors = tr.Bool(False)

    @tr.cached_property
    def _get_idx(self):
        ks = self.kappa_slider
        idx = np.argmax(ks <= self.kappa_t)
        return idx

    kappa_t = tr.Property(tr.Array(np.float_), depends_on=DEPSTR)
    '''Curvature values for which the bending moment must be found
    '''

    @tr.cached_property
    def _get_kappa_t(self):
        return np.linspace(self.low_kappa, self.high_kappa, self.n_kappa)

    z_j = tr.Property

    def _get_z_j(self):
        return self.cross_section_layout.z_j

    A_j = tr.Property

    def _get_A_j(self):
        return self.cross_section_layout.A_j

    # Normal force in steel (tension and compression)
    def get_N_s_tj(self, kappa_t, eps_bot_t):
        # get the strain at the height of the reinforcement
        eps_z_tj = self.symb.get_eps_z(kappa_t[:, np.newaxis],
                                       eps_bot_t[:, np.newaxis],
                                       self.z_j[np.newaxis, :])
        # Get the crack bridging force in each reinforcement layer
        # given the corresponding crack-bridge law.
        N_s_tj = self.cross_section_layout.get_N_tj(eps_z_tj)
        return N_s_tj

    # TODO - [RC] avoid repeated evaluations of stress profile in
    #            N and M calculations for the same inputs as it
    #            is the case now.
    def get_sig_c_z(self, kappa_t, eps_bot_t, z_tm):
        """Get the stress profile over the height"""
        eps_z = self.symb.get_eps_z(kappa_t[:, np.newaxis],
                                    eps_bot_t[:, np.newaxis], z_tm)
        sig_c_z = self.matrix_.get_sig(eps_z)
        return sig_c_z

    # Normal force in concrete (tension and compression)
    def get_N_c_t(self, kappa_t, eps_bot_t):
        z_tm = self.z_m[np.newaxis, :]
        b_z_m = self.cross_section_shape_.get_b(z_tm)
        N_z_tm2 = b_z_m * self.get_sig_c_z(kappa_t, eps_bot_t, z_tm)
        return np.trapz(N_z_tm2, x=z_tm, axis=-1)

    def get_N_t(self, kappa_t, eps_bot_t):
        N_s_t = np.sum(self.get_N_s_tj(kappa_t, eps_bot_t), axis=-1)
        N_c_t = self.get_N_c_t(kappa_t, eps_bot_t)
        return N_c_t + N_s_t

    # SOLVER: Get eps_bot to render zero force

    # num_of_trials = tr.Int(30)

    eps_bot_t = tr.Property(depends_on=DEPSTR)
    r'''Resolve the tensile strain to get zero normal force for the prescribed curvature'''

    # @tr.cached_property
    # def _get_eps_bot_t(self):
    #     initial_step = (self.high_kappa - self.low_kappa) / self.num_of_trials
    #     for i in range(self.num_of_trials):
    #         print('Solution started...')
    #         res = root(lambda eps_bot_t: self.get_N_t(self.kappa_t, eps_bot_t),
    #                    0.0000001 + np.zeros_like(self.kappa_t), tol=1e-6)
    #         if res.success:
    #             print('success high_kappa: ', self.high_kappa)
    #             if i == 0:
    #                 print('Note: high_kappa success from 1st try! selecting a higher value for high_kappa may produce '
    #                       'a more reliable result!')
    #             return res.x
    #         else:
    #             print('failed high_kappa: ', self.high_kappa)
    #             self.high_kappa -= initial_step
    #             self.kappa_t = np.linspace(self.low_kappa, self.high_kappa, self.n_kappa)
    #
    #     print('No solution', res.message)
    #     return res.x

    # @tr.cached_property
    # def _get_eps_bot_t(self):
    #     res = root(lambda eps_bot_t: self.get_N_t(self.kappa_t, eps_bot_t),
    #                0.0000001 + np.zeros_like(self.kappa_t), tol=1e-6)
    #     if not res.success:
    #         raise SolutionNotFoundError('No solution', res.message)
    #     return res.x

    solve_for_eps_bot_pointwise = Bool(True, BC=True, GEO=True)

    @tr.cached_property
    def _get_eps_bot_t(self):
        if self.solve_for_eps_bot_pointwise:
            """ INFO: Instability in eps_bot solutions was caused by unsuitable init_guess value causing a convergence 
            to non-desired solutions. Solving the whole kappa_t array improved the init_guess after each
            calculated value, however, instability still there. The best results were obtained by taking the last 
            solution as the init_guess for the next solution like in the following.. """
            # One by one solution for kappa values
            eps_bot_sol_for_pos_kappa = self._get_eps_bot_piecewise_sol(
                kappa_pos=True)
            eps_bot_sol_for_neg_kappa = self._get_eps_bot_piecewise_sol(
                kappa_pos=False)
            res = np.concatenate(
                [eps_bot_sol_for_neg_kappa, eps_bot_sol_for_pos_kappa])
            return res
        else:
            # Array solution for the whole kappa_t
            res = root(lambda eps_bot_t: self.get_N_t(self.kappa_t, eps_bot_t),
                       0.0000001 + np.zeros_like(self.kappa_t),
                       tol=1e-6)
            if not res.success:
                print('No solution', res.message)
            return res.x

    def _get_eps_bot_piecewise_sol(self, kappa_pos=True):
        if kappa_pos:
            kappas = self.kappa_t[np.where(self.kappa_t >= 0)]
        else:
            kappas = self.kappa_t[np.where(self.kappa_t < 0)]

        res = []
        if kappa_pos:
            init_guess = 0.00001
            kappa_loop_list = kappas
        else:
            init_guess = -0.00001
            kappa_loop_list = reversed(kappas)

        for kappa in kappa_loop_list:
            sol = root(
                lambda eps_bot: self.get_N_t(np.array([kappa]), eps_bot),
                np.array([init_guess]),
                tol=1e-6).x[0]

            # This condition is to avoid having init_guess~0 which causes non-convergence
            if abs(sol) > 1e-5:
                init_guess = sol
            res.append(sol)

        if kappa_pos:
            return res
        else:
            return list(reversed(res))

    # POSTPROCESSING
    kappa_cr = tr.Property(depends_on=DEPSTR)
    '''Curvature at which a critical strain is attained at the eps_bot'''

    @tr.cached_property
    def _get_kappa_cr(self):
        res = root(lambda kappa: self.get_N_t(kappa, self.eps_cr),
                   0.0000001 + np.zeros_like(self.eps_cr),
                   tol=1e-10)
        if not res.success:
            print('No kappa_cr solution (for plot_norm() function)',
                  res.message)
        return res.x

    M_s_t = tr.Property(depends_on=DEPSTR)
    '''Bending moment (steel)
    '''

    @tr.cached_property
    def _get_M_s_t(self):
        if len(self.z_j) == 0:
            return np.zeros_like(self.kappa_t)

        eps_z_tj = self.symb.get_eps_z(self.kappa_t[:, np.newaxis],
                                       self.eps_bot_t[:, np.newaxis],
                                       self.z_j[np.newaxis, :])

        # Get the crack bridging force in each reinforcement layer
        # given the corresponding crack-bridge law.
        N_tj = self.cross_section_layout.get_N_tj(eps_z_tj)
        return -np.einsum('tj,j->t', N_tj, self.z_j)

    M_c_t = tr.Property(depends_on=DEPSTR)
    '''Bending moment (concrete)
    '''

    @tr.cached_property
    def _get_M_c_t(self):
        z_tm = self.z_m[np.newaxis, :]
        b_z_m = self.cross_section_shape_.get_b(z_tm)
        N_z_tm2 = b_z_m * self.get_sig_c_z(self.kappa_t, self.eps_bot_t, z_tm)
        return -np.trapz(N_z_tm2 * z_tm, x=z_tm, axis=-1)

    M_t = tr.Property(depends_on=DEPSTR)
    '''Bending moment
    '''

    @tr.cached_property
    def _get_M_t(self):
        # print('M - k recalculated')
        eta_factor = 1.
        return eta_factor * (self.M_c_t + self.M_s_t)

    # @tr.cached_property
    # def _get_M_t(self):
    #     initial_step = (self.high_kappa - self.low_kappa) / self.num_of_trials
    #     for i in range(self.num_of_trials):
    #         try:
    #             M_t = self.M_c_t + self.M_s_t
    #         except SolutionNotFoundError:
    #             print('failed high_kappa: ', self.high_kappa)
    #             self.high_kappa -= initial_step
    #         else:
    #             # This will run when no exception has been received
    #             print('success high_kappa: ', self.high_kappa)
    #             if i == 0:
    #                 print('Note: high_kappa success from 1st try! selecting a higher value for high_kappa may produce '
    #                       'a more reliable result!')
    #             return M_t
    #     print('No solution has been found!')
    #     return M_t

    N_s_tj = tr.Property(depends_on=DEPSTR)
    '''Normal forces (steel)
    '''

    @tr.cached_property
    def _get_N_s_tj(self):
        return self.get_N_s_tj(self.kappa_t, self.eps_bot_t)

    eps_tm = tr.Property(depends_on=DEPSTR)
    '''strain profiles
    '''

    @tr.cached_property
    def _get_eps_tm(self):
        return self.symb.get_eps_z(self.kappa_t[:, np.newaxis],
                                   self.eps_bot_t[:, np.newaxis],
                                   self.z_m[np.newaxis, :])

    sig_tm = tr.Property(depends_on=DEPSTR)
    '''strain profiles
    '''

    @tr.cached_property
    def _get_sig_tm(self):
        return self.get_sig_c_z(self.kappa_t, self.eps_bot_t,
                                self.z_m[np.newaxis, :])

    M_norm = tr.Property(depends_on=DEPSTR)
    '''
    '''

    @tr.cached_property
    def _get_M_norm(self):
        # Section modulus @TODO optimize W for var b
        W = (self.b * self.H**2) / 6
        sig_cr = self.E_ct * self.eps_cr
        return W * sig_cr

    kappa_norm = tr.Property()

    def _get_kappa_norm(self):
        return self.kappa_cr

    inv_M_kappa = tr.Property(depends_on=DEPSTR)
    '''Return the inverted data points
    '''

    @tr.cached_property
    def _get_inv_M_kappa(self):
        try:
            """cut off the descending tails"""
            M_t = self.M_t
            I_max = np.argmax(M_t)
            I_min = np.argmin(M_t)
            M_I = np.copy(M_t[I_min:I_max + 1])
            kappa_I = np.copy(self.kappa_t[I_min:I_max + 1])
            # find the index corresponding to zero kappa
            idx = np.argmax(0 <= kappa_I)
            # and modify the values such that the
            # Values of moment are non-descending
            M_plus = M_I[idx:]
            M_diff = M_plus[:, np.newaxis] - M_plus[np.newaxis, :]
            n_ij = len(M_plus)
            ij = np.mgrid[0:n_ij:1, 0:n_ij:1]
            M_diff[np.where(ij[1] >= ij[0])] = 0
            i_x = np.argmin(M_diff, axis=1)
            M_I[idx:] = M_plus[i_x]
            return M_I, kappa_I
        except ValueError:
            print(
                'M inverse has not succeeded, the M-Kappa solution may have failed due to '
                'a wrong kappa range or not suitable material law!')
            return np.array([0]), np.array([0])

    def get_kappa_M(self, M):
        M_I, kappa_I = self.inv_M_kappa
        return np.interp(M, M_I, kappa_I)

    def plot_norm(self, ax1, ax2):
        idx = self.idx
        ax1.plot(self.kappa_t / self.kappa_norm, self.M_t / self.M_norm)
        ax1.plot(self.kappa_t[idx] / self.kappa_norm,
                 self.M_t[idx] / self.M_norm,
                 marker='o')
        ax2.barh(self.z_j,
                 self.N_s_tj[idx, :],
                 height=2,
                 color='red',
                 align='center')
        # ax2.fill_between(eps_z_arr[idx,:], z_arr, 0, alpha=0.1);
        ax3 = ax2.twiny()
        #  ax3.plot(self.eps_tm[idx, :], self.z_m, color='k', linewidth=0.8)
        ax3.plot(self.sig_tm[idx, :], self.z_m)
        ax3.axvline(0, linewidth=0.8, color='k')
        ax3.fill_betweenx(self.z_m, self.sig_tm[idx, :], 0, alpha=0.1)
        mpl_align_xaxis(ax2, ax3)

    M_scale = Float(1e+6)
    plot_strain = Bool(False)

    def plot(self, ax1, ax2, ax3):
        self.plot_mk_and_stress_profile(ax1, ax2)
        if self.plot_strain:
            self.plot_strain_profile(ax3)
        else:
            self.plot_mk_inv(ax3)

    @staticmethod
    def subplots(fig):
        ax1, ax2, ax3 = fig.subplots(1, 3)
        return ax1, ax2, ax3

    def update_plot(self, axes):
        self.plot(*axes)

    def plot_mk_inv(self, ax3):
        try:
            M, kappa = self.inv_M_kappa
            ax3.plot(M / self.M_scale, kappa)
        except ValueError:
            print(
                'M inverse has not succeeded, the M-Kappa solution may have failed due to a wrong kappa range!'
            )

        ax3.set_xlabel('Moment [kNm]')
        ax3.set_ylabel('Curvature[mm$^{-1}$]')

    def plot_mk_and_stress_profile(self, ax1, ax2):
        self.plot_mk(ax1)
        idx = self.idx
        ax1.plot(self.kappa_t[idx],
                 self.M_t[idx] / self.M_scale,
                 color='orange',
                 marker='o')

        if len(self.z_j):
            ax2.barh(self.z_j,
                     self.N_s_tj[idx, :] / self.A_j,
                     height=4,
                     color='red',
                     align='center')
            ax2.set_ylabel('z [mm]')
            ax2.set_xlabel('$\sigma_r$ [MPa]')

        ax22 = ax2.twiny()
        ax22.set_xlabel('$\sigma_c$ [MPa]')
        ax22.plot(self.sig_tm[idx, :], self.z_m)
        ax22.axvline(0, linewidth=0.8, color='k')
        ax22.fill_betweenx(self.z_m, self.sig_tm[idx, :], 0, alpha=0.1)
        mpl_align_xaxis(ax2, ax22)

    def plot_mk(self, ax1):
        ax1.plot(self.kappa_t, self.M_t / self.M_scale, label='M-K')
        ax1.set_ylabel('Moment [kNm]')
        ax1.set_xlabel('Curvature [mm$^{-1}$]')
        ax1.legend()

    def plot_strain_profile(self, ax):
        ax.set_ylabel('z [mm]')
        ax.set_xlabel(r'$\varepsilon$ [-]')
        ax.plot(self.eps_tm[self.idx, :], self.z_m)
        ax.axvline(0, linewidth=0.8, color='k')
        ax.fill_betweenx(self.z_m, self.eps_tm[self.idx, :], 0, alpha=0.1)

    def get_mk(self):
        return self.M_t / self.M_scale, self.kappa_t
class IShape(CrossSectionShapeBase):

    H = Float(900, GEO=True)
    B_w = Float(50, GEO=True)
    B_f_bot = Float(200, GEO=True)
    B_f_top = Float(200, GEO=True)
    H_f_bot = Float(145, GEO=True)
    H_f_top = Float(145, GEO=True)

    ipw_view = View(
        *CrossSectionShapeBase.ipw_view.content,
        Item('B_w', minmax=(10, 3000), latex=r'B_w \mathrm{[mm]}'),
        Item('B_f_bot', minmax=(10, 3000), latex=r'B_{f_{bot}} \mathrm{[mm]}'),
        Item('B_f_top', minmax=(10, 3000), latex=r'B_{f_{top}} \mathrm{[mm]}'),
        Item('H_f_bot', minmax=(10, 3000), latex=r'H_{f_{bot}} \mathrm{[mm]}'),
        Item('H_f_top', minmax=(10, 3000), latex=r'H_{f_{top}} \mathrm{[mm]}'),
    )

    def get_cs_area(self):
        return self.B_f_bot * self.H_f_bot + self.B_f_top * self.H_f_top + self.B_w * (
            self.H - self.H_f_top - self.H_f_bot)

    def get_cs_i(self):
        pass

    get_b = tr.Property(tr.Callable, depends_on='+input')

    @tr.cached_property
    def _get_get_b(self):
        z_ = sp.Symbol('z')
        b_p = sp.Piecewise((self.B_f_bot, z_ < self.H_f_bot),
                           (self.B_w, z_ < self.H - self.H_f_top),
                           (self.B_f_top, True))
        return sp.lambdify(z_, b_p, 'numpy')

    def update_plot(self, ax):
        # Start drawing from bottom center of the cross section
        cs_points = np.array([[self.B_f_bot / 2, 0],
                              [self.B_f_bot / 2, self.H_f_bot],
                              [self.B_w / 2, self.H_f_bot],
                              [self.B_w / 2, self.H - self.H_f_top],
                              [self.B_f_top / 2, self.H - self.H_f_top],
                              [self.B_f_top / 2, self.H],
                              [-self.B_f_top / 2, self.H],
                              [-self.B_f_top / 2, self.H - self.H_f_top],
                              [-self.B_w / 2, self.H - self.H_f_top],
                              [-self.B_w / 2, self.H_f_bot],
                              [-self.B_f_bot / 2, self.H_f_bot],
                              [-self.B_f_bot / 2, 0]])

        cs = Polygon(cs_points)

        patch_collection = PatchCollection([cs],
                                           facecolor=(.5, .5, .5, 0.2),
                                           edgecolors=(0, 0, 0, 1))

        ax.add_collection(patch_collection)
        # ax.scatter(0, TShape.get_cs_i(self)[0], color='white', s=self.B_w, marker="+")

        ax.autoscale_view()
        ax.set_aspect('equal')

        ax.annotate('Area = {} $mm^2$'.format(int(IShape.get_cs_area(self)),
                                              0),
                    xy=(0, self.H / 2),
                    color='blue')
class TShape(CrossSectionShapeBase):

    B_f = Float(400, GEO=True)
    B_w = Float(100, GEO=True)
    H_w = Float(300, GEO=True)

    ipw_view = View(
        *CrossSectionShapeBase.ipw_view.content,
        Item('B_f', minmax=(10, 3000), latex=r'B_f \mathrm{[mm]}'),
        Item('B_w', minmax=(10, 3000), latex=r'B_w \mathrm{[mm]}'),
        Item('H_w', minmax=(10, 3000), latex=r'H_w \mathrm{[mm]}'),
    )

    def get_cs_area(self):
        return self.B_w * self.H_w + self.B_f * (self.H - self.H_w)

    def get_cs_i(self):
        A_f = self.B_f * (self.H - self.H_w)
        Y_f = (self.H - self.H_w) / 2 + self.H_w
        I_f = self.B_f * (self.H - self.H_w)**3 / 12
        A_w = self.B_w * self.H_w
        Y_w = self.H_w / 2
        I_w = self.B_w * self.H_w**3 / 12
        Y_c = (Y_f * A_f + Y_w * A_w) / (A_f + A_w)
        I_c = I_f + A_f * (Y_c - Y_f)**2 + I_w + A_w * (Y_c - Y_w)**2
        return Y_c, I_c

    get_b = tr.Property(tr.Callable, depends_on='+input')

    @tr.cached_property
    def _get_get_b(self):
        z_ = sp.Symbol('z')
        b_p = sp.Piecewise((self.B_w, z_ < self.H_w), (self.B_f, True))
        return sp.lambdify(z_, b_p, 'numpy')

    def update_plot(self, ax):
        # Start drawing from bottom center of the cross section
        cs_points = np.array([[self.B_w / 2, 0], [self.B_w / 2, self.H_w],
                              [self.B_f / 2, self.H_w], [self.B_f / 2, self.H],
                              [-self.B_f / 2, self.H],
                              [-self.B_f / 2, self.H_w],
                              [-self.B_w / 2, self.H_w], [-self.B_w / 2, 0]])

        cs = Polygon(cs_points)

        patch_collection = PatchCollection([cs],
                                           facecolor=(.5, .5, .5, 0.2),
                                           edgecolors=(0, 0, 0, 1))

        ax.add_collection(patch_collection)
        ax.scatter(0,
                   TShape.get_cs_i(self)[0],
                   color='white',
                   s=self.B_w,
                   marker="+")

        ax.autoscale_view()
        ax.set_aspect('equal')

        ax.annotate('Area = {} $mm^2$'.format(int(TShape.get_cs_area(self)),
                                              0),
                    xy=(-self.H / 2 * 0.8, (self.H / 2 + self.H_w / 2)),
                    color='blue')
        ax.annotate('I = {} $mm^4$'.format(int(TShape.get_cs_i(self)[1]), 0),
                    xy=(-self.H / 2 * 0.8, (self.H / 2 + self.H_w / 2) * 0.9),
                    color='blue')
        ax.annotate('$Y_c$',
                    xy=(0, TShape.get_cs_i(self)[0] * 0.85),
                    color='purple')
class MATS2DScalarDamage(MATS2DEval):
    r'''Isotropic damage model.
    '''

    name = 'isotropic damage model'
    node_name = 'isotropic damage model'

    tree = ['omega_fn','strain_norm']

    omega_fn = EitherType(
        options=[('exp-slope', ExpSlopeDamageFn),
                 ('linear', LinearDamageFn),
                 ('abaqus', AbaqusDamageFn),
                 ('fracture-energy', GfDamageFn),
                 ('weibull-CDF', WeibullDamageFn),
                 ],
        MAT=True,
        on_option_change='link_omega_to_mats'
    )

    D_alg = Float(0)
    r'''Selector of the stiffness calculation.
    '''

    eps_max = Float(0.03, ALG=True)
    # upon change of the type attribute set the link to the material model
    def link_omega_to_mats(self):
        self.omega_fn_.trait_set(mats=self,
                                 E_name='E',
                                 x_max_name='eps_max')

    #=========================================================================
    # Material model
    #=========================================================================
    strain_norm = EitherType(
        options=[('Rankine', SN2DRankine),
                 ('Masars', SN2DMasars),
                 ('Energy', SN2DEnergy)],
        on_option_change='link_strain_norm_to_mats'
    )

    def link_strain_norm_to_mats(self):
        self.strain_norm_.trait_set(mats=self)

    state_var_shapes = {'kappa': (),
                        'omega': ()}
    r'''
    Shapes of the state variables
    to be stored in the global array at the level 
    of the domain.
    '''

    def get_corr_pred(self, eps_ab_n1, tn1, kappa, omega):
        r'''
        Corrector predictor computation.
        @param eps_app_eng input variable - engineering strain
        '''
        eps_eq = self.strain_norm_.get_eps_eq(eps_ab_n1, kappa)
        I = self.omega_fn_.get_f_trial(eps_eq, kappa)
        eps_eq_I = eps_eq[I]
        kappa[I] = eps_eq_I
        omega[I] = self._omega(eps_eq_I)
        phi = (1.0 - omega)
        D_abcd = np.einsum(
            '...,abcd->...abcd',
            phi, self.D_abcd
        )
        sig_ab = np.einsum(
            '...abcd,...cd->...ab',
            D_abcd, eps_ab_n1
        )
        if self.D_alg > 0:
            domega_ds_I = self._omega_derivative(eps_eq_I)
            deps_eq_I = self.strain_norm_.get_deps_eq(eps_ab_n1[I])
            D_red_I = np.einsum('...,...ef,cdef,...ef->...cdef', domega_ds_I,
                                deps_eq_I, self.D_abcd, eps_ab_n1[I]) * self.D_alg
            D_abcd[I] -= D_red_I

        return sig_ab, D_abcd

    def _omega(self, kappa):
        return self.omega_fn_(kappa)

    def _omega_derivative(self, kappa):
        return self.omega_fn_.diff(kappa)

    ipw_view = View(
        Item('E'),
        Item('nu'),
        Item('strain_norm'),
        Item('omega_fn'),
        Item('stress_state'),
        Item('D_alg', latex=r'\theta_\mathrm{alg. stiff.}',
                editor=FloatRangeEditor(low=0,high=1)),
        Item('eps_max'),
        Item('G_f', latex=r'G_\mathrm{f}^{\mathrm{estimate}}', readonly=True),
    )

    G_f = tr.Property(Float, depends_on='state_changed')
    @tr.cached_property
    def _get_G_f(self):
        eps_max = self.eps_max
        n_eps = 1000
        eps11_range = np.linspace(1e-9,eps_max,n_eps)
        eps_range = np.zeros((len(eps11_range), 2, 2))
        eps_range[:,1,1] = eps11_range
        state_vars = { var : np.zeros( (len(eps11_range),) + shape )
            for var, shape in self.state_var_shapes.items()
        }
        sig_range, D = self.get_corr_pred(eps_range, 1, **state_vars)
        sig11_range = sig_range[:,1,1]
        return np.trapz(sig11_range, eps11_range)

    def subplots(self, fig):
        ax_sig = fig.subplots(1,1)
        ax_d_sig = ax_sig.twinx()
        return ax_sig, ax_d_sig

    def update_plot(self, axes):
        ax_sig, ax_d_sig = axes
        eps_max = self.eps_max
        n_eps = 100
        eps11_range = np.linspace(1e-9,eps_max,n_eps)
        eps_range = np.zeros((n_eps, 2, 2))
        eps_range[:,0,0] = eps11_range
        state_vars = { var : np.zeros( (n_eps,) + shape )
            for var, shape in self.state_var_shapes.items()
        }
        sig_range, D_range = self.get_corr_pred(eps_range, 1, **state_vars)
        sig11_range = sig_range[:,0,0]
        ax_sig.plot(eps11_range, sig11_range,color='blue')
        d_sig1111_range = D_range[...,0,0,0,0]
        ax_d_sig.plot(eps11_range, d_sig1111_range,
                      linestyle='dashed', color='gray')
        ax_sig.set_xlabel(r'$\varepsilon_{11}$ [-]')
        ax_sig.set_ylabel(r'$\sigma_{11}$ [MPa]')
        ax_d_sig.set_ylabel(r'$\mathrm{d} \sigma_{11} / \mathrm{d} \varepsilon_{11}$ [MPa]')

        ax_d_sig.plot(eps11_range[:-1],
                    (sig11_range[:-1]-sig11_range[1:])/(eps11_range[:-1]-eps11_range[1:]),
                    color='orange', linestyle='dashed')

    def get_omega(self, eps_ab, tn1, **Eps):
        return Eps['omega']

    var_dict = tr.Property(tr.Dict(tr.Str, tr.Callable))
    '''Dictionary of response variables
    '''
    @tr.cached_property
    def _get_var_dict(self):
        var_dict = dict(omega=self.get_omega)
        var_dict.update(super()._get_var_dict())
        return var_dict
Beispiel #20
0
class VUNTIM(MATS3DEval):
    """
    Vectorized uncoupled normal tngential interface model
    """
    # -------------------------------------------------------------------------
    # Elasticity
    # -------------------------------------------------------------------------

    E_N = Float(10000, MAT=True)

    E_T = Float(1000, MAT=True)

    gamma_T = Float(100000., MAT=True)

    K_T = Float(10000., MAT=True)

    S_T = Float(0.005, MAT=True)

    r_T = Float(9., MAT=True)

    e_T = Float(12., MAT=True)

    c_T = Float(4.6, MAT=True)

    tau_pi_bar = Float(1.7, MAT=True)

    a = Float(0.003, MAT=True)

    # ------------------------------------------------------------------------------
    # Normal_Tension constitutive law parameters (without cumulative normal strain)
    # ------------------------------------------------------------------------------
    Ad = Float(100.0, MAT=True)

    eps_0 = Float(0.00008, MAT=True)

    # -----------------------------------------------
    # Normal_Compression constitutive law parameters
    # -----------------------------------------------
    K_N = Float(10000., MAT=True)

    gamma_N = Float(5000., MAT=True)

    sig_0 = Float(30., MAT=True)

    ipw_view = View(
        Item('E_N'),
        Item('E_T'),
        Item('Ad'),
        Item('eps_0'),
        Item('K_N'),
        Item('gamma_N'),
        Item('sig_0'),
        Item('gamma_T', latex=r'\gamma_\mathrm{T}', minmax=(10, 100000)),
        Item('K_T', latex=r'K_\mathrm{T}', minmax=(10, 10000)),
        Item('S_T', latex=r'S_\mathrm{T}', minmax=(0.001, 0.01)),
        Item('r_T', latex=r'r_\mathrm{T}', minmax=(1, 3)),
        Item('e_T', latex=r'e_\mathrm{T}', minmax=(1, 40)),
        Item('c_T', latex=r'c_\mathrm{T}', minmax=(1, 10)),
        Item('tau_pi_bar', latex=r'\bar{\sigma}^\pi_{T}', minmax=(1, 10)),
        Item('a', latex=r'a_\mathrm{T}', minmax=(0.001, 3)),
    )

    n_D = 3

    state_var_shapes = dict(
        omega_N=(),  # damage N
        z_N=(),
        alpha_N=(),
        r_N=(),
        eps_N_p=(),
        sig_N=(),
        omega_T=(),
        z_T=(),
        alpha_T_a=(n_D, ),
        eps_T_p_a=(n_D, ),
        sig_T_a=(n_D, ),
    )

    # --------------------------------------------------------------
    # microplane constitutive law (normal behavior CP + TD)
    # --------------------------------------------------------------
    def get_normal_law(self, eps_N, **Eps):
        omega_N, z_N, alpha_N, r_N, eps_N_p = [
            Eps[key]
            for key in ['omega_N', 'z_N', 'alpha_N', 'r_N', 'eps_N_p']
        ]
        E_N = self.E_N

        # When deciding if a microplane is in tensile or compression, we define a strain boundary such that that
        # sigN <= 0 if eps_N < 0, avoiding entering in the quadrant of compressive strains and traction

        sig_trial = E_N * (eps_N - eps_N_p)
        pos1 = [(eps_N < -1e-6) & (sig_trial > 1e-6)
                ]  # looking for microplanes violating strain boundary
        sig_trial[pos1[0]] = 0
        pos = sig_trial > 1e-6  # microplanes under traction
        pos2 = sig_trial < -1e-6  # microplanes under compression
        H = 1.0 * pos
        H2 = 1.0 * pos2

        # thermo forces
        sig_N_tilde = E_N * (eps_N - eps_N_p)
        sig_N_tilde[pos1[0]] = 0  # imposing strain boundary

        Z = self.K_N * z_N
        X = self.gamma_N * alpha_N * H2
        h = (self.sig_0 + Z) * H2

        f_trial = (abs(sig_N_tilde - X) - h) * H2

        # threshold plasticity

        thres_1 = f_trial > 1e-6

        delta_lamda = f_trial / \
                      (E_N / (1 - omega_N) + abs(self.K_N) + self.gamma_N) * thres_1
        eps_N_p = eps_N_p + delta_lamda * \
                      np.sign(sig_N_tilde - X)
        z_N = z_N + delta_lamda
        alpha_N = alpha_N + delta_lamda * \
                      np.sign(sig_N_tilde - X)

        def R_N(r_N):
            return (1.0 / self.Ad) * (-r_N / (1.0 + r_N))

        Y_N = 0.5 * H * E_N * (eps_N - eps_N_p)**2.0
        Y_0 = 0.5 * E_N * self.eps_0**2.0

        f = (Y_N - (Y_0 + R_N(r_N)))

        # threshold damage

        thres_2 = f > 1e-6

        def f_w(Y):
            return 1.0 - 1.0 / (1.0 + self.Ad * (Y - Y_0))

        omega_N[f > 1e-6] = f_w(Y_N)[f > 1e-6]
        r_N[f > 1e-6] = -omega_N[f > 1e-6]

        sig_N = (1.0 - H * omega_N) * E_N * (eps_N - eps_N_p)
        pos1 = [(eps_N < -1e-6) & (sig_trial > 1e-6)
                ]  # looking for microplanes violating strain boundary
        sig_N[pos1[0]] = 0

        return sig_N

    # -------------------------------------------------------------------------
    # microplane constitutive law (Tangential CSD)-(Pressure sensitive cumulative damage)
    # -------------------------------------------------------------------------
    def get_tangential_law(self, eps_T_a, **Eps):

        omega_T, z_T, alpha_T_a, eps_T_p_a, sig_N, = [
            Eps[key] for key in [
                'omega_T',
                'z_T',
                'alpha_T_a',
                'eps_T_p_a',
                'sig_N',
            ]
        ]

        E_T = self.E_T

        # thermodynamic forces
        sig_pi_trial = E_T * (eps_T_a - eps_T_p_a)

        Z = self.K_T * z_T
        X = self.gamma_T * alpha_T_a

        norm_1 = np.sqrt(
            np.einsum('...na,...na->...n', (sig_pi_trial - X),
                      (sig_pi_trial - X)))
        Y = 0.5 * E_T * np.einsum('...na,...na->...n', (eps_T_a - eps_T_p_a),
                                  (eps_T_a - eps_T_p_a))

        # threshold
        f = norm_1 - self.tau_pi_bar - Z + self.a * sig_N

        plas_1 = f > 1e-6
        elas_1 = f < 1e-6

        delta_lamda = f / (E_T /
                           (1.0 - omega_T) + self.gamma_T + self.K_T) * plas_1

        norm_2 = 1.0 * elas_1 + np.sqrt(
            np.einsum('...na,...na->...n', (sig_pi_trial - X),
                      (sig_pi_trial - X))) * plas_1

        eps_T_p_a[..., 0] += plas_1 * delta_lamda * \
                                ((sig_pi_trial[..., 0] - X[..., 0]) /
                                 (1.0 - omega_T)) / norm_2
        eps_T_p_a[..., 1] += plas_1 * delta_lamda * \
                                ((sig_pi_trial[..., 1] - X[..., 1]) /
                                 (1.0 - omega_T)) / norm_2
        eps_T_p_a[..., 2] += plas_1 * delta_lamda * \
                                ((sig_pi_trial[..., 2] - X[..., 2]) /
                                 (1.0 - omega_T)) / norm_2
        omega_T[...] += ((1.0 - omega_T) ** self.c_T) * \
                       (delta_lamda * (Y / self.S_T) ** self.r_T) * \
                       (self.tau_pi_bar / (self.tau_pi_bar - self.a * sig_N)) ** self.e_T
        alpha_T_a[..., 0] += plas_1 * delta_lamda * \
                               (sig_pi_trial[..., 0] - X[..., 0]) / norm_2
        alpha_T_a[..., 1] += plas_1 * delta_lamda * \
                               (sig_pi_trial[..., 1] - X[..., 1]) / norm_2
        alpha_T_a[..., 2] += plas_1 * delta_lamda * \
                               (sig_pi_trial[..., 2] - X[..., 2]) / norm_2
        z_T[...] += delta_lamda

        sig_T_a = np.einsum('...n,...na->...na', (1 - omega_T),
                            E_T * (eps_T_a - eps_T_p_a))

        return sig_T_a

    def get_corr_pred(self, eps_a, t_n1, **Eps):
        eps_a_ = np.einsum('...a->a...', eps_a)
        eps_N_n1 = eps_a_[0, ...]
        eps_T_a_n1 = np.einsum('a...->...a', eps_a_[1:, ...])

        sig_N = self.get_normal_law(eps_N_n1, **Eps)
        sig_T_a = self.get_tangential_law(eps_T_a_n1, **Eps)

        D_ = np.zeros(eps_a.shape + (eps_a.shape[-1], ))
        D_[..., 0, 0] = self.E_N  # * (1 - omega_N)
        D_[..., 1, 1] = self.E_T  # * (1 - omega_T)
        D_[..., 2, 2] = self.E_T  # * (1 - omega_T)
        D_[..., 3, 3] = self.E_T  # * (1 - omega_T)
        sig_a = np.concatenate([sig_N[..., np.newaxis], sig_T_a], axis=-1)
        return sig_a, D_

    def get_eps_NT_p(self, **Eps):
        """Plastic strain tensor
        """
        return Eps['eps_N_p'], Eps['eps_T_p_a']

    def plot_idx(self, ax_sig, ax_d_sig, idx=0):
        eps_max = self.eps_max
        n_eps = self.n_eps
        eps1_range = np.linspace(1e-9, eps_max, n_eps)
        Eps = {
            var: np.zeros((1, ) + shape)
            for var, shape in self.state_var_shapes.items()
        }
        eps_range = np.zeros((n_eps, 4))
        eps_range[:, idx] = eps1_range

        # monotonic load in the normal direction
        sig1_range, d_sig11_range = [], []
        for eps_a in eps_range:
            sig_a, D_range = self.get_corr_pred(eps_a[np.newaxis, ...], 1,
                                                **Eps)
            sig1_range.append(sig_a[0, idx])
            d_sig11_range.append(D_range[0, idx, idx])
        sig1_range = np.array(sig1_range, dtype=np.float_)
        eps1_range = eps1_range[:len(sig1_range)]

        ax_sig.plot(eps1_range, sig1_range, color='blue')
        d_sig11_range = np.array(d_sig11_range, dtype=np.float_)
        ax_d_sig.plot(eps1_range,
                      d_sig11_range,
                      linestyle='dashed',
                      color='gray')
        ax_sig.set_xlabel(r'$\varepsilon_{11}$ [-]')
        ax_sig.set_ylabel(r'$\sigma_{11}$ [MPa]')
        ax_d_sig.set_ylabel(
            r'$\mathrm{d} \sigma_{11} / \mathrm{d} \varepsilon_{11}$ [MPa]')
        ax_d_sig.plot(eps1_range[:-1], (sig1_range[:-1] - sig1_range[1:]) /
                      (eps1_range[:-1] - eps1_range[1:]),
                      color='orange',
                      linestyle='dashed')

    def subplots(self, fig):
        ax_sig_N, ax_sig_T = fig.subplots(1, 2)
        ax_d_sig_N = ax_sig_N.twinx()
        ax_d_sig_T = ax_sig_T.twinx()
        return ax_sig_N, ax_d_sig_N, ax_sig_T, ax_d_sig_T

    def update_plot(self, axes):
        ax_sig_N, ax_d_sig_N, ax_sig_T, ax_d_sig_T = axes
        self.plot_idx(ax_sig_N, ax_d_sig_N, 0)
        self.plot_idx(ax_sig_T, ax_d_sig_T, 1)
Beispiel #21
0
class CyclicLoadingScenario(LoadingScenario):

    number_of_cycles = Int(1, BC=True,
                           enter_set=True, auto_set=False,
                           symbol='n_\mathrm{cycles}',
                           unit='-',
                           desc='for cyclic loading',
                           )
    maximum_loading = Float(1.0, BC=True,
                            enter_set=True, auto_set=False,
                            symbol='\phi_{\max}',
                            desc='load factor at maximum load level',
                            unit='-')
    number_of_increments = Int(20, BC=True,
                               enter_set=True, auto_set=False,
                               symbol='n_{\mathrm{incr}}',
                               unit='-',
                               desc='number of values within a monotonic load branch')
    unloading_ratio = Float(0.5, BC=True,
                            enter_set=True, auto_set=False,
                            symbol='\phi_{\mathrm{unload}}',
                            desc='fraction of maximum load at lowest load level',
                            unit='-')
    amplitude_type = Enum(options=["increasing", "constant"],
                          enter_set=True, auto_set=False,
                          symbol='option',
                          unit='-',
                          desc='possible values: [increasing, constant]',
                          BC=True)
    loading_range = Enum(options=["non-symmetric", "symmetric"],
                         enter_set=True, auto_set=False,
                         symbol='option',
                         unit='-',
                         desc='possible values: [non-symmetric, symmetric]',
                         BC=True)

    ipw_view = bu.View(
        bu.Item('number_of_cycles'),
        bu.Item('maximum_loading'),
        bu.Item('number_of_increments'),
        bu.Item('unloading_ratio'), # , editor=FloatRangeEditor(low=0, high=1)),
        bu.Item('amplitude_type'),
        bu.Item('loading_range'),
    )
    xy_arrays = Property(depends_on="state_changed")
    @cached_property
    def _get_xy_arrays(self):
        if(self.amplitude_type == "increasing" and
                self.loading_range == "symmetric"):
            d_levels = np.linspace(
                0, self.maximum_loading, self.number_of_cycles * 2)
            d_levels.reshape(-1, 2)[:, 0] *= -1
            d_history = d_levels.flatten()
            d_arr = np.hstack([np.linspace(d_history[i], d_history[i + 1],
                                           self.number_of_increments)
                               for i in range(len(d_levels) - 1)])

        if(self.amplitude_type == "increasing" and
                self.loading_range == "non-symmetric"):
            d_levels = np.linspace(
                0, self.maximum_loading, self.number_of_cycles * 2)
            d_levels.reshape(-1, 2)[:, 0] *= 0
            d_history = d_levels.flatten()
            d_arr = np.hstack([np.linspace(d_history[i], d_history[i + 1],
                                           self.number_of_increments)
                               for i in range(len(d_levels) - 1)])

        if(self.amplitude_type == "constant" and
                self.loading_range == "symmetric"):
            d_levels = np.linspace(
                0, self.maximum_loading, self.number_of_cycles * 2)
            d_levels.reshape(-1, 2)[:, 0] = -self.maximum_loading
            d_levels[0] = 0
            d_levels.reshape(-1, 2)[:, 1] = self.maximum_loading
            d_history = d_levels.flatten()
            d_arr = np.hstack([np.linspace(d_history[i], d_history[i + 1], self.number_of_increments)
                               for i in range(len(d_levels) - 1)])

        if(self.amplitude_type == "constant" and
                self.loading_range == "non-symmetric"):
            d_levels = np.linspace(
                0, self.maximum_loading, self.number_of_cycles * 2)
            d_levels.reshape(-1, 2)[:,
                                    0] = self.maximum_loading * self.unloading_ratio
            d_levels[0] = 0
            d_levels.reshape(-1, 2)[:, 1] = self.maximum_loading
            d_history = d_levels.flatten()
            d_arr = np.hstack([np.linspace(d_history[i], d_history[i + 1], self.number_of_increments)
                               for i in range(len(d_levels) - 1)])

        t_arr = np.linspace(0, self.t_max, len(d_arr))
        return t_arr, d_arr
Beispiel #22
0
class ConcreteMaterialModelAdv(ConcreteMatMod, bu.InjectSymbExpr):

    name = 'Concrete behavior'
    node_name = 'material model'

    symb_class = ConcreteMaterialModelAdvExpr

    d_a = Float(16, MAT=True)  ## dia of steel mm
    E_c = Float(28000, MAT=True)  ## tensile strength of Concrete in MPa
    f_t = Float(3, MAT=True)  ## Fracture Energy in N/m
    c_1 = Float(3, MAT=True)
    c_2 = Float(6.93, MAT=True)
    f_c = Float(33.3, MAT=True)
    L_fps = Float(50, MAT=True)
    a = Float(1.038, MAT=True)
    b = Float(0.245, MAT=True)
    interlock_factor = Float(1, MAT=True)

    ipw_view = View(
        Item('d_a', latex=r'd_a'), Item('E_c', latex=r'E_c'),
        Item('f_t', latex=r'f_t'), Item('f_c', latex=r'f_c'),
        Item('c_1', latex=r'c_1'), Item('c_2', latex=r'c_2'),
        Item('L_fps', latex=r'L_{fps}'), Item('a', latex=r'a'),
        Item('b', latex=r'b'),
        Item('interlock_factor',
             latex=r'\gamma_\mathrm{ag}',
             editor=FloatRangeEditor(low=0, high=1)),
        Item('w_cr', latex=r'w_\mathrm{cr}', readonly=True),
        Item('L_c', latex=r'L_\mathrm{c}', readonly=True),
        Item('G_f', latex=r'G_\mathrm{f}', readonly=True))

    # G_f_baz = tr.Property(depends_on='_ITR, _INC, _GEO, _MAT, _DSC')
    # @tr.cached_property
    # def _get_G_f_baz(self):
    #     xi = self.sz_crack_tip_orientation.
    #     return self.symb.G_f_baz

    L_c = tr.Property(Float, depends_on='state_changed')

    @tr.cached_property
    def _get_L_c(self):
        return self.E_c * self.G_f / self.f_t**2

    w_cr = tr.Property(Float, depends_on='state_changed')

    @tr.cached_property
    def _get_w_cr(self):
        return (self.f_t / self.E_c) * self._get_L_c()

    G_f = tr.Property(Float, depends_on='state_changed')

    @tr.cached_property
    def _get_G_f(self):
        '''Calculating fracture energy
        '''
        return (0.028 * self.f_c**0.18 * self.d_a**0.32)

    def get_w_tc(self):
        '''Calculating point of softening curve resulting in 0 stress
        '''
        return (5.14 * self.G_f_baz / self.f_t)

    def get_sig_a(self, u_a):  #w, s
        '''Calculating stresses
        '''
        sig_w = self.get_sig_w(u_a[..., 0], u_a[..., 1])
        tau_s = self.get_tau_s(u_a[..., 0], u_a[..., 1])
        return np.einsum('b...->...b', np.array([sig_w, tau_s],
                                                dtype=np.float_))  #, tau_s

    def get_sig_w(self, w, s):
        return self.symb.get_sig_w(w, s)

    def get_tau_s(self, w, s):
        return self.symb.get_tau_s(w, s) * self.interlock_factor

    w_min_factor = Float(1.2)
    w_max_factor = Float(15)

    def plot3d_sig_w(self, ax3d, vot=1.0):

        w_min = -(self.f_c / self.E_c * self._get_L_c()) * self.w_min_factor
        w_max = self.w_cr * self.w_max_factor
        w_range = np.linspace(w_min, w_max, 100)
        s_max = 3
        s_data = np.linspace(-1.1 * s_max, 1.1 * s_max, 100)
        s_, w_ = np.meshgrid(s_data, w_range)

        sig_w = self.get_sig_w(w_, s_)

        ax3d.plot_surface(w_, s_, sig_w, cmap='viridis', edgecolor='none')
        ax3d.set_xlabel(r'$w\;\;\mathrm{[mm]}$', fontsize=12)
        ax3d.set_ylabel(r'$s\;\;\mathrm{[mm]}$', fontsize=12)
        ax3d.set_zlabel(r'$\sigma_w\;\;\mathrm{[MPa]}$', fontsize=12)
        ax3d.set_title('crack opening law', fontsize=12)

    # def plot_sig_w(self, ax, vot=1.0):
    #         w_min = -(self.f_c / self.E_c * self._get_L_c()) * self.w_min_factor
    #         w_max = self.w_cr * self.w_max_factor
    #         w_range = np.linspace(w_min, w_max, 100)
    #         s_max = 3
    #         s_data = np.linspace(-1.1 * s_max, 1.1 * s_max, 100)
    #         sig_w = self.get_sig_w(w_range, s_data)
    #         ax.plot(w_range, sig_w, lw=2, color='red')
    #         ax.fill_between(w_range, sig_w,
    #                         color='red', alpha=0.2)
    #         ax.set_xlabel(r'$w\;\;\mathrm{[mm]}$', fontsize=12)
    #         ax.set_ylabel(r'$\sigma\;\;\mathrm{[MPa]}$', fontsize=12)
    #         ax.set_title('crack opening law', fontsize=12)

    def plot3d_tau_s(self, ax3d, vot=1.0):
        w_min = 1e-9  #-1
        w_max = 3
        w_data = np.linspace(w_min, w_max, 100)
        s_max = 3
        s_data = np.linspace(-1.1 * s_max, 1.1 * s_max, 100)  #-1.1
        s_, w_ = np.meshgrid(s_data, w_data)
        tau_s = self.get_tau_s(w_, s_)
        ax3d.plot_surface(w_, s_, tau_s, cmap='viridis', edgecolor='none')
        ax3d.set_xlabel(r'$w\;\;\mathrm{[mm]}$', fontsize=12)
        ax3d.set_ylabel(r'$s\;\;\mathrm{[mm]}$', fontsize=12)
        ax3d.set_zlabel(r'$\tau\;\;\mathrm{[MPa]}$', fontsize=12)
        ax3d.set_title('aggregate interlock law', fontsize=12)

    # def subplots(self, fig):
    #     #ax_2d = fig.add_subplot(1, 2, 2)
    #     ax_3d_1 = fig.add_subplot(1, 2, 2, projection='3d')
    #     ax_3d_2 = fig.add_subplot(1, 2, 1, projection='3d')
    #     return ax_3d_1, ax_3d_2
    #
    # def update_plot(self, axes):
    #     '''Plotting function
    #     '''
    #     ax_3d_1, ax_3d_2 = axes
    #     self.plot3d_sig_w(ax_3d_1)
    #     self.plot3d_tau_s(ax_3d_2)

    def get_eps_plot_range(self):
        return np.linspace(1.1 * self.eps_cu, 1.1 * self.eps_tu, 300)

    def get_sig(self, eps):
        return self.factor * self.symb.get_sig_w(eps)
Beispiel #23
0
class MATSXDEval(MATSEval):
    '''Base class for elastic models.
    '''

    n_dims = Constant(Float)
    '''Number of spatial dimensions of an integration 
    cell for the material model
    '''

    E = Float(34e+3,
              label="E",
              desc="Young's Modulus",
              auto_set=False,
              MAT=True)

    nu = Float(0.2,
               label='nu',
               desc="Poison's ratio",
               auto_set=False,
               MAT=True)

    def _get_lame_params(self):
        # First Lame parameter (bulk modulus)
        la = self.E * self.nu / ((1. + self.nu) * (1. - 2. * self.nu))
        # second Lame parameter (shear modulus)
        mu = self.E / (2. + 2. * self.nu)
        return la, mu

    D_abef = Property(Array, depends_on='+input')
    '''Material stiffness - rank 4 tensor
    '''

    @cached_property
    def _get_D_abef(self):
        la, mu = self._get_lame_params()
        delta = np.identity(self.n_dims)
        return (np.einsum(',ij,kl->ijkl', la, delta, delta) +
                np.einsum(',ik,jl->ijkl', mu, delta, delta) +
                np.einsum(',il,jk->ijkl', mu, delta, delta))

    def get_corr_pred(self, eps_Emab, tn1, **Eps):
        '''
        Corrector predictor computation.
        @param eps_Emab input variable - strain tensor
        '''
        sigma_Emab = np.einsum('abcd,...cd->...ab', self.D_abef, eps_Emab)
        Em_len = len(eps_Emab.shape) - 2
        new_shape = tuple([1 for _ in range(Em_len)]) + self.D_abef.shape
        D_abef = self.D_abef.reshape(*new_shape)
        return sigma_Emab, D_abef

    #=========================================================================
    # Response variables
    #=========================================================================
    def get_eps_ab(self, eps_ab, tn1, **Eps):
        return eps_ab

    def get_sig_ab(self, eps_ab, tn1, **Eps):
        '''
        Get the stress tensor
        :param eps_ab: strain tensor with ab indexes
        :param tn1: time - can be used for time dependent properties
        :param Eps: dictionary of state variables corresponding to the
         specification in state_var_shapes
        :return: stress vector with with the shape of input and state variables + ab
         spatial indexes.
        '''
        return self.get_sig(eps_ab, tn1, **Eps)

    def get_state_var(self, var_name, eps_ab, tn1, **Eps):
        '''
        Acess to state variables used for visualization
        :param var_name: string with the name of the state variable
        :param eps_ab: strain tensor (not used)
        :param tn1: time variable (not used)
        :param Eps: dictionary of state variables corresponding to the
         specification in state_var_shapes
        :return: Array with the state variable with the shape corresponding
         to the level of the problem
        '''
        return Eps[var_name]

    var_dict = Property(Dict(Str, Callable))
    '''Dictionary of functions that deliver the response/state variables 
    of a material model
    '''

    @cached_property
    def _get_var_dict(self):
        var_dict = super(MATSXDEval, self)._get_var_dict()
        var_dict.update(eps_ab=self.get_eps_ab, sig_ab=self.get_sig_ab)
        var_dict.update({
            var_name: lambda eps_ab, tn1, **Eps: self.get_state_var(
                var_name, eps_ab, tn1, **Eps)
            for var_name in self.state_var_shapes.keys()
        })
        return var_dict