Exemple #1
0
def make_prlc_rand():
    md_RLC_rand = (
        gr.Model("RLC with component tolerances") >> gr.cp_vec_function(
            fun=lambda df: gr.df_make(
                Rr=df.R * (1 + df.dR),
                Lr=df.L * (1 + df.dL),
                Cr=df.C * (1 + df.dC),
            ),
            var=["R", "dR", "L", "dL", "C", "dC"],
            out=["Rr", "Lr", "Cr"],
        ) >> gr.cp_vec_function(
            fun=lambda df: gr.df_make(omega0=np.sqrt(1 / df.Lr / df.Cr)),
            var=["Lr", "Cr"],
            out=["omega0"],
        ) >> gr.cp_vec_function(
            fun=lambda df: gr.df_make(Q=df.omega0 * df.Rr * df.Cr),
            name="parallel RLC",
            var=["omega0", "Rr", "Cr"],
            out=["Q"]) >> gr.cp_bounds(
                R=(1e-3, 1e0),
                L=(1e-9, 1e-3),
                C=(1e-3, 100),
            ) >> gr.cp_marginals(
                dR=dict(dist="uniform",
                        loc=R_percent_lo,
                        scale=R_percent_up - R_percent_lo),
                dL=dict(dist="uniform",
                        loc=L_percent_lo,
                        scale=L_percent_up - L_percent_lo),
                dC=dict(dist="uniform",
                        loc=C_percent_lo,
                        scale=C_percent_up - C_percent_lo),
            ) >> gr.cp_copula_independence())

    return md_RLC_rand
Exemple #2
0
def make_test():
    md = Model() >> \
         cp_function(fun=fun, var=3, out=1) >> \
         cp_bounds(x0=(-1,+1), x1=(-1,+1), x2=(-1,+1)) >> \
         cp_marginals(
             x0={"dist": "uniform", "loc": -1, "scale": 2},
             x1={"dist": "uniform", "loc": -1, "scale": 2}
         ) >> \
         cp_copula_independence()

    return md
Exemple #3
0
def make_trajectory_linear():
    ## Assemble model
    md_trajectory = (
        Model("Trajectory Model")
        >> cp_vec_function(fun=fun_x, var=var_list, out=["x"], name="x_trajectory",)
        >> cp_vec_function(fun=fun_y, var=var_list, out=["y"], name="y_trajectory",)
        >> cp_bounds(
            u0=[0.1, Inf], v0=[0.1, Inf], tau=[0.05, Inf], t=[0, 600]
        )
    )

    return md_trajectory
Exemple #4
0
def make_plate_buckle():
    r"""Initialize a buckling plate model

    Variables (deterministic):
        w (in): Plate width
        h (in): Plate height
        t (in): Plate thickness
        m (-): Wavenumber
        L (kips): Applied (compressive) load;
            uniformly applied along top and bottom edges

    Variables (random):
        E (kips/in^2): Elasticity
        mu (-): Poisson's ratio

    Outputs:
        k_cr (-): Prefactor for buckling stress
        g_buckle (kips/in^2): Buckling limit state:
            critical stress - applied stress
    """
    md = (
        Model("Plate Buckling")
        >> cp_vec_function(
            fun=lambda df: df_make(
                k_cr=(df.m*df.h/df.w + df.w/df.m/df.h)**2
            ),
            var=["w", "h", "m"],
            out=["k_cr"],
        )
        >> cp_vec_function(
            fun=lambda df: df_make(
                g_buckle=df.k_cr * pi**2/12 * df.E / (1 - df.mu**2) * (df.t/df.h)**2
                - df.L / df.t / df.w
            ),
            var=["k_cr", "t", "h", "w", "E", "mu", "L"],
            out=["g_buckle"],
            name="limit state",
        )
        >> cp_bounds(
            t=(0.5 * THICKNESS, 2 * THICKNESS),
            h=(6, 18),
            w=(6, 18),
            m=(1, 5),
            L=(LOAD / 2, LOAD * 2),
        )
        >> cp_marginals(
            E=marg_fit("norm", df_stang.E),
            mu=marg_fit("beta", df_stang.mu),
        )
        >> cp_copula_gaussian(df_data=df_stang)
    )

    return md
Exemple #5
0
def make_ishigami():
    """Ishigami function

    The Ishigami function is commonly used as a test case for estimating Sobol'
    indices.

    Model definition:

        y0 = sin(x1) + a sin(x2)^2 + b x3^4 sin(x1)

        x1 ~ U[-pi, +pi]

        x2 ~ U[-pi, +pi]

        x3 ~ U[-pi, +pi]

    Sobol' index data:

        V[y0] = a^2/8 + b pi^4/5 + b^2 pi^8/18 + 0.5

        T1 = 0.5(1 + b pi^4/5)^2

        T2 = a^2/8

        T3 = 0

        Tt1 = 0.5(1 + b pi^4/5)^2 + 8 b^2 pi^8/225

        Tt2 = a^2/8

        Tt3 = 8 b^2 pi^8/225

    References:
        T. Ishigami and T. Homma, “An importance quantification technique in uncertainty analysis for computer models,” In the First International Symposium on Uncertainty Modeling and Analysis, Maryland, USA, Dec. 3–5, 1990. DOI:10.1109/SUMA.1990.151285
    """

    md = gr.Model(name = "Ishigami Function") >> \
        gr.cp_function(
            fun=fun,
            var=["a", "b", "x1", "x2", "x3"],
            out=1
        ) >> \
        gr.cp_bounds(a=(6.0, 8.0), b=(0, 0.2)) >> \
        gr.cp_marginals(
            x1={"dist": "uniform", "loc": -np.pi, "scale": 2 * np.pi},
            x2={"dist": "uniform", "loc": -np.pi, "scale": 2 * np.pi},
            x3={"dist": "uniform", "loc": -np.pi, "scale": 2 * np.pi}
        ) >> \
        gr.cp_copula_independence()

    return md
Exemple #6
0
def make_channel_nondim():
    r"""Make 1d channel model; dimensionless form

    Instantiates a model for particle and fluid temperature rise; particles are suspended in a fluid with bulk velocity along a square cross-section channel. The walls of said channel are transparent, and radiation heats the particles as they travel down the channel.

    References:
        Banko, A.J. "RADIATION ABSORPTION BY INERTIAL PARTICLES IN A TURBULENT SQUARE DUCT FLOW" (2018) PhD Thesis, Stanford University, Chapter 2

    """
    md = (
        Model("1d Particle-laden Channel with Radiation; Dimensionless Form")
        >> cp_vec_function(
            fun=lambda df: df_make(beta=120 * (1 + df.Phi_M * df.chi)),
            var=["Phi_M", "chi"],
            out=["beta"],
        ) >> cp_vec_function(
            fun=lambda df: df_make(
                T_f=(df.Phi_M * df.chi) / (1 + df.Phi_M * df.chi) *
                (df.I * df.xst - df.beta**(-1) * df.I *
                 (1 - exp(-df.beta * df.xst))),
                T_p=1 / (1 + df.Phi_M * df.chi) *
                (df.Phi_M * df.chi * df.I * df.xst + df.beta**(-1) * df.I *
                 (1 - exp(-df.beta * df.xst))),
            ),
            var=["xst", "Phi_M", "chi", "I", "beta"],
            out=["T_f", "T_p"],
        ) >> cp_bounds(
            ## Dimensionless axial location (-)
            xst=(0, 5), ) >> cp_marginals(
                ## Mass loading ratio (-)
                Phi_M={
                    "dist": "uniform",
                    "loc": 0,
                    "scale": 1
                },
                ## Particle-fluid heat capacity ratio (-)
                chi={
                    "dist": "uniform",
                    "loc": 0.1,
                    "scale": 0.9
                },
                ## Normalized radiative intensity (-)
                I={
                    "dist": "uniform",
                    "loc": 0.1,
                    "scale": 0.9
                },
            ) >> cp_copula_independence())

    return md
Exemple #7
0
def make_prlc():
    md_RLC_det = (gr.Model("RLC Circuit") >> gr.cp_vec_function(
        fun=lambda df: gr.df_make(np.sqrt(1 / df.L / df.C)),
        var=["L", "C"],
        out=["omega0"],
    ) >> gr.cp_function(fun=lambda df: gr.df_make(Q=df.omega0 * df.R * df.C),
                        name="parallel RLC",
                        var=["omega0", "R", "C"],
                        out=["Q"]) >> gr.cp_bounds(
                            R=(1e-3, 1e0),
                            L=(1e-9, 1e-3),
                            C=(1e-3, 100),
                        ))

    return md_RLC_det
Exemple #8
0
def make_plate_buckle():
    md = (gr.Model("Plate Buckling") >> gr.cp_function(
        fun=function_buckle_state,
        var=["t", "h", "w", "E", "mu", "L"],
        out=["g_buckle"],
        name="limit state",
    ) >> gr.cp_bounds(
        t=(0.5 * THICKNESS, 2 * THICKNESS),
        h=(6, 18),
        w=(6, 18),
        L=(LOAD / 2, LOAD * 2),
    ) >> gr.cp_marginals(E=gr.marg_named(df_stang.E, "norm"),
                         mu=gr.marg_named(df_stang.mu, "beta")) >>
          gr.cp_copula_gaussian(df_data=df_stang))

    return md
Exemple #9
0
def make_sir(rtol=1e-4):
    r"""Make an SIR model

    Instantiates a Susceptible, Infected, Removed (SIR) model for disease transmission.

    Args:
        rtol (float): Relative tolerance for IVP solver

    Returns:
        grama Model: SIR model

    References:
        "Compartmental models in epidemiology," Wikipedia, url: https://en.wikipedia.org/wiki/Compartmental_models_in_epidemiology

    """

    md_sir = (
        gr.Model("SIR Model") >> gr.cp_vec_function(
            fun=lambda df: gr.df_make(
                # Assume no recovered people at virus onset
                R0=0,
                # Assume total population of N=100
                S0=df.N - df.I0,
            ),
            var=["I0", "N"],
            out=["S0", "R0"],
            name="Population setup",
        ) >> gr.cp_vec_function(
            fun=fun_sir(rtol=rtol),
            var=["t", "S0", "I0", "R0", "beta", "gamma"],
            out=["S", "I", "R"],
            name="ODE solver & interpolation",
        ) >> gr.cp_bounds(
            N=(100, 100),  # Fixed population size
            I0=(1, 10),
            beta=(0.1, 0.5),
            gamma=(0.1, 0.5),
            t=(0, 100),
        ))

    return md_sir
Exemple #10
0
def make_cantilever_beam():
    """Cantilever beam

    A standard reliability test-case, often used for benchmarking reliability
    analysis and design algorithms.

    Generally used in the following optimization problem:

        min_{w,t} c_area

        s.t.      P[g_stress <= 0] <= 1.35e-3

                  P[g_disp <= 0] <= 1.35e-3

                  1 <= w, t <= 4

    Deterministic Variables:
        w: Beam width
        t: Beam thickness
    Random Variables:
        H: Horizontal applied force
        V: Vertical applied force
        E: Elastic modulus
        Y: Yield stress
    Outputs:
        c_area: Cost; beam cross-sectional area
        g_stress: Limit state; stress
        g_disp: Limit state; tip displacement

    References:
        Wu, Y.-T., Shin, Y., Sues, R., and Cesare, M., "Safety-factor based approach for probability-based design optimization," American Institute of Aeronautics and Astronautics, Seattle, Washington, April 2001.
        Sues, R., Aminpour, M., and Shin, Y., "Reliability-based Multi-Disciplinary Optimiation for Aerospace Systems," American Institute of Aeronautics and Astronautics, Seattle, Washington, April 2001.

    """

    md = Model(name = "Cantilever Beam") >> \
         cp_vec_function(
             fun=function_area,
             var=["w", "t"],
             out=["c_area"],
             name="cross-sectional area",
             runtime=1.717e-7
         ) >> \
         cp_vec_function(
             fun=function_stress,
             var=["w", "t", "H", "V", "E", "Y"],
             out=["g_stress"],
             name="limit state: stress",
             runtime=8.88e-7
         ) >> \
         cp_vec_function(
             fun=function_displacement,
             var=["w", "t", "H", "V", "E", "Y"],
             out=["g_disp"],
             name="limit state: displacement",
             runtime=3.97e-6
         ) >> \
         cp_bounds(
             w=(2, 4),
             t=(2, 4)
         ) >> \
         cp_marginals(
             H={"dist": "norm", "loc": MU_H, "scale": TAU_H, "sign": +1},
             V={"dist": "norm", "loc": MU_V, "scale": TAU_V, "sign": +1},
             E={"dist": "norm", "loc": MU_E, "scale": TAU_E, "sign":  0},
             Y={"dist": "norm", "loc": MU_Y, "scale": TAU_Y, "sign": -1}
         ) >> \
         cp_copula_independence()

    return md
Exemple #11
0
def make_channel():
    r"""Make 1d channel model; dimensional form

    Instantiates a model for particle and fluid temperature rise; particles are suspended in a fluid with bulk velocity along a square cross-section channel. The walls of said channel are transparent, and radiation heats the particles as they travel down the channel.

    Note that this takes the same inputs as the builtin dataset `df_channel`.

    References:
        Banko, A.J. "RADIATION ABSORPTION BY INERTIAL PARTICLES IN A TURBULENT SQUARE DUCT FLOW" (2018) PhD Thesis, Stanford University, Chapter 2

    Examples:

    >>> import grama as gr
    >>> from grama.data import df_channel
    >>> from grama.models import make_channel
    >>> md_channel = make_channel()

    >>> (
    >>>     df_channel
    >>>     >> gr.tf_md(md_channel)

    >>>     >> gr.ggplot(gr.aes("T_f", "T_norm"))
    >>>     + gr.geom_abline(slope=1, intercept=0, linetype="dashed")
    >>>     + gr.geom_point()
    >>>     + gr.labs(x="1D Model", y="3D DNS")
    >>> )

    """
    md = (
        Model("1d Particle-laden Channel with Radiation; Dimensional Form") >>
        cp_vec_function(
            fun=lambda df: df_make(
                Re=df.U * df.H / df.nu_f,
                chi=df.cp_p / df.cp_f,
                Pr=df.nu_f / df.alpha_f,
                Phi_M=df.rho_p * 0.524 * df.d_p**3 * df.n / df.rho_f,
                tau_flow=df.L / df.U,
                tau_pt=(df.rho_p * df.cp_p * 0.318 * df.d_p) / df.h_p,
                tau_rad=(df.rho_p * df.cp_p * 0.667 * df.d_p * df.T_0) /
                (df.Q_abs * 0.78 * df.I_0),
            ),
            var=[
                "U",  # Fluid bulk velocity
                "H",  # Channel width
                "nu_f",  # Fluid kinematic viscosity
                "cp_p",  # Particle isobaric heat capacity
                "cp_f",  # Fluid isobaric heat capacity
                "alpha_f",  # Fluid thermal diffusivity
                "rho_p",  # Particle density
                "rho_f",  # Fluid density
                "d_p",  # Particle diameter
                "n",  # Particle number density
                "h_p",  # Particle-to-gas convection coefficient
                "T_0",  # Initial temperature
                "Q_abs",  # Particle radiation absorption coefficient
                "I_0",  # Incident radiation
            ],
            out=[
                "Re",  # Reynolds number
                "Pr",  # Prandtl number
                "chi",  # Particle-fluid heat capacity ratio
                "Phi_M",  # Mass Loading Ratio
                "tau_flow",  # Fluid residence time
                "tau_pt",  # Particle thermal time constant
                "tau_rad",  # Particle temperature doubling time (approximate)
            ],
            name="Dimensionless Numbers",
        ) >> cp_vec_function(
            fun=lambda df: df_make(
                ## Let xi = x / L
                xst=(df.xi * df.L) / df.H / df.Re / df.Pr,
                ## Assume an optically-thin scenario; I/I_0 = 1
                Is=df.Re * df.Pr * (df.H / df.L) *
                (df.tau_flow / df.tau_rad) * 1,
                beta=df.Re * df.Pr * (df.H / df.L) *
                (df.tau_flow / df.tau_pt) * (1 + df.Phi_M * df.chi),
            ),
            var=[
                "xi", "chi", "H", "L", "Phi_M", "tau_flow", "tau_rad", "tau_pt"
            ],
            out=[
                "xst",  # Flow-normalized channel axial location
                "Is",  # Normalized heat flux
                "beta",  # Spatial development coefficient
            ],
            name="Intermediate Dimensionless Numbers",
        ) >> cp_vec_function(
            fun=lambda df: df_make(
                T_f=(df.Phi_M * df.chi) / (1 + df.Phi_M * df.chi) *
                (df.Is * df.xst - df.Is / df.beta *
                 (1 - exp(-df.beta * df.xst))),
                T_p=1 / (1 + df.Phi_M * df.chi) *
                (df.Phi_M * df.chi * df.Is * df.xst + df.Is / df.beta *
                 (1 - exp(-df.beta * df.xst))),
            ),
            var=["xst", "Phi_M", "chi", "Is", "beta"],
            out=["T_f", "T_p"],
        ) >> cp_bounds(
            ## Normalized axial location; xi = x/L (-)
            xi=(0, 1), ) >> cp_marginals(
                ## Channel width (m)
                H={
                    "dist": "uniform",
                    "loc": 0.038,
                    "scale": 0.004
                },
                ## Channel length (m)
                L={
                    "dist": "uniform",
                    "loc": 0.152,
                    "scale": 0.016
                },
                ## Fluid bulk velocity (m/s)
                U={
                    "dist": "uniform",
                    "loc": 1,
                    "scale": 2.5
                },
                ## Fluid kinematic viscosity (m^2/s)
                nu_f={
                    "dist": "uniform",
                    "loc": 1.4e-5,
                    "scale": 0.1e-5
                },
                ## Particle isobaric heat capacity (J/(kg K))
                cp_p={
                    "dist": "uniform",
                    "loc": 100,
                    "scale": 900
                },
                ## Fluid isobaric heat capacity (J/(kg K))
                cp_f={
                    "dist": "uniform",
                    "loc": 1000,
                    "scale": 1000
                },
                ## Fluid thermal diffusivity (m^2/s)
                alpha_f={
                    "dist": "uniform",
                    "loc": 50e-6,
                    "scale": 50e-6
                },
                ## Particle density (kg / m^3)
                rho_p={
                    "dist": "uniform",
                    "loc": 1e3,
                    "scale": 9e3
                },
                ## Fluid density (kg / m^3)
                rho_f={
                    "dist": "uniform",
                    "loc": 0.5,
                    "scale": 1.0
                },
                ## Particle diameter (m)
                d_p={
                    "dist": "uniform",
                    "loc": 1e-6,
                    "scale": 9e-6
                },
                ## Particle number density (1 / m^3)
                n={
                    "dist": "uniform",
                    "loc": 9.5e9,
                    "scale": 1.0e9
                },
                ## Particle-to-gas convection coefficient (W / (m^2 K))
                h_p={
                    "dist": "uniform",
                    "loc": 1e3,
                    "scale": 9e3
                },
                ## Initial temperature (K)
                T_0={
                    "dist": "uniform",
                    "loc": 285,
                    "scale": 30
                },
                ## Particle radiation absorption coefficient (-)
                Q_abs={
                    "dist": "uniform",
                    "loc": 0.25,
                    "scale": 0.50
                },
                ## Incident radiation (W/m^2)
                I_0={
                    "dist": "uniform",
                    "loc": 9.5e6,
                    "scale": 1.0e6
                },
            ) >> cp_copula_independence())

    return md
Exemple #12
0

var_applied = ["L", "w", "t"]
out_applied = ["sig_app"]


def fun_limit(x):
    sig_cr, sig_app = x
    return sig_cr - sig_app


var_limit = ["sig_cr", "sig_app"]
out_limit = ["safety"]

## Build model
md_plate = (
    gr.Model("Plate under buckling load") >> gr.cp_function(
        fun=fun_critical, var=var_critical, out=out_critical, name="Critical")
    >> gr.cp_function(
        fun=fun_applied, var=var_applied, out=out_applied, name="Applied") >>
    gr.cp_function(fun=fun_limit, var=var_limit, out=out_limit,
                   name="Safety") >> gr.cp_bounds(  # Deterministic variables
                       t=(0.03, 0.12),  # Thickness
                       w=(6, 18),  # Width
                       h=(6, 18),  # Height
                       L=(2.5e-1, 4.0e-1),  # Load
                   ) >> gr.cp_marginals(  # Random variables
                       E=gr.marg_gkde(df_stang.E),
                       mu=gr.marg_gkde(df_stang.mu)) >>
    gr.cp_copula_gaussian(df_data=df_stang))  # Dependence