예제 #1
0
파일: __init__.py 프로젝트: haavahk/adapy
    def visualize(self):
        from ada.core.utils import easy_plotly

        in_data = {
            "Engineering": (self.e, self.S),
            "True": (self.eps, self.sig)
        }
        return easy_plotly(self.title,
                           in_data,
                           xlbl="Strain [-]",
                           ylbl="Stress [Pa]")
예제 #2
0
파일: __init__.py 프로젝트: haavahk/adapy
    def visualize_true(self):
        in_data = dict()
        from ada.core.utils import easy_plotly

        for test in self.test_data:
            in_data[test.title] = (test.eps, test.sig)
        return easy_plotly(
            self.name,
            in_data,
            mode="lines+markers",
            xlbl="True Strain",
            ylbl="True Stress [MPa]",
        )
예제 #3
0
파일: __init__.py 프로젝트: haavahk/adapy
    def visualize_eng(self):
        from ada.core.utils import easy_plotly

        in_data = {}
        for d in self.test_data:
            in_data[f"{d.name} ({d.load_type})"] = (d.e, d.S)
        return easy_plotly(
            self.name,
            in_data,
            mode="lines+markers",
            xlbl="Engineering Strain",
            ylbl="Engineering Stress [MPa]",
        )
예제 #4
0
    def _repr_html_(self):
        from ada.core.utils import easy_plotly

        self._fig = easy_plotly("ADA OpenSim", ([], []), return_widget=True)
        opt_models = list(self._models_d.keys())
        self._selected_models = ["Yeoh"]
        opts_odb = widgets.SelectMultiple(options=opt_models, value=["Yeoh"], disabled=False)
        center = widgets.Button(
            description="plot",
            button_style="",  # 'success', 'info', 'warning', 'danger' or ''
        )
        opts_odb.observe(self._clicked_models, "value")
        center.on_click(self._click_plot)
        # self._clicked_models({'new': 'Yeoh'})
        display(widgets.VBox([widgets.HBox([widgets.VBox([opts_odb, center])]), self._fig]))
예제 #5
0
    def __init__(
        self,
        mat_data,
        num_int=300,
        load_types=None,
        interpolate=True,
        incompressible=True,
    ):
        from ada.core.utils import easy_plotly

        self._mat_data = mat_data
        self._num_int = num_int
        self._load_types = ["uniaxial", "biaxial", "planar"] if load_types is None else load_types
        self._incompressible = incompressible
        self._interpolate = interpolate
        self._params = None
        self._model = None
        self._models_d = dict(Yeoh=dict(model=yeoh, init=[1, 1, 1]), Neo=dict(model=neo_hookean, init=[1]))
        self._selected_models = []
        self._fig = easy_plotly("ADA OpenSim", ([], []), return_widget=True)
예제 #6
0
    def plot(self, model, params, eng_plot=True):
        """

        :param model:
        :param params:
        :param eng_plot: Plot using engineering stress and strain.
        :return:
        """
        model_name = model.__name__
        coeff = [x for x in inspect.getfullargspec(model)[0] if x not in ["strain", "load_type"]]
        name = "".join([f"{c}:{x:>15.4E}<br>" for c, x in zip(coeff, params)])
        annotations = [
            go.layout.Annotation(
                text=f"{model_name} coefficients:<br>{name}",
                align="left",
                showarrow=False,
                xref="paper",
                yref="paper",
                x=0.1,
                y=0.95,
                bordercolor="black",
                borderwidth=1,
            )
        ]
        traces = self._build_test_data(eng_plot)
        traces += self._build_plot(model, params, eng_plot)
        from ada.core.utils import easy_plotly

        return easy_plotly(
            self.mat_data.name + f" ({model_name})",
            ([], []),
            traces=traces,
            mode="lines+markers",
            annotations=annotations,
            xlbl="Engineering Strain",
            ylbl="Engineering Stress [MPa]",
            return_widget=True,
        )
예제 #7
0
파일: __init__.py 프로젝트: haavahk/adapy
    def _repr_html_(self):
        # Create Plotly diagrams for displacement, shear and moment UDL's
        dt_points = 50
        displacements = np.zeros((2, dt_points))
        shear_ = np.zeros((2, dt_points))
        moment_ = np.zeros((2, dt_points))

        # Make sure midpoint is represented in datapoints
        l_half = self._beam.length / 2
        p_half = int(dt_points / 2)
        data_points_1 = np.linspace(0, l_half, p_half, endpoint=True)
        data_points = np.concatenate([
            data_points_1,
            np.linspace(l_half, self._beam.length, p_half, endpoint=True)
        ])
        if len(self._w) > 0:
            for w in self._w:
                # Displacements
                displ_res = [(x,
                              simply_supported(x, w[1], self._beam,
                                               ResType.displ))
                             for x in data_points]
                res_np = np.array(list(zip(*displ_res)))
                displacements += res_np
                # Moment
                moment_res = [(x,
                               simply_supported(x, w[1], self._beam,
                                                ResType.moment))
                              for x in data_points]
                res_np = np.array(list(zip(*moment_res)))
                moment_ += res_np
                # Shear
                shear_res = [(x,
                              simply_supported(x, w[1], self._beam,
                                               ResType.shear))
                             for x in data_points]
                res_np = np.array(list(zip(*shear_res)))
                shear_ += res_np

        l_displ = displacements.tolist()
        l_shear = shear_.tolist()
        l_moment = moment_.tolist()

        plot_displ = easy_plotly(
            "Simply Support Beam (displacements)",
            l_displ,
            xlbl="Beam Length [m]",
            ylbl="Displacement [m]",
            return_widget=True,
        )
        plot_shear = easy_plotly(
            "Simply Support Beam (shear)",
            l_shear,
            xlbl="Beam Length [m]",
            ylbl="Shear [N]",
            return_widget=True,
        )
        plot_moment = easy_plotly(
            "Simply Support Beam (moments)",
            l_moment,
            xlbl="Beam Length [m]",
            ylbl="Moment [Nm]",
            return_widget=True,
        )
        display(VBox([plot_displ, plot_moment, plot_shear]))
        return ""
예제 #8
0
파일: renderer.py 프로젝트: haavahk/adapy
    def display(self, sec):
        """

        :type sec: ada.Section
        """
        from IPython.display import display
        from ipywidgets import HTML, HBox

        from ada.core.utils import easy_plotly
        from ada.sections import SectionCat

        # testb = Button(
        #     description="plot",
        #     button_style="",  # 'success', 'info', 'warning', 'danger' or ''
        # )
        #
        # center = Button(
        #     description="plot",
        #     button_style="",  # 'success', 'info', 'warning', 'danger' or ''
        # )
        html = HTML("<b>Section Properties</b></br></br>")
        outer_curve, inner_curve, disconnected = sec.cross_sec(True)

        def get_data(curve):
            x = []
            y = []
            for edge in curve + [curve[0]]:
                x.append(edge[0])
                y.append(edge[1])
            return x, y

        xrange, yrange = None, None
        plot_data = dict()

        if outer_curve is not None and type(outer_curve) is not float:
            outer = get_data(outer_curve)
            plot_data["outer"] = outer
            max_dim = max(max(outer[0]), max(outer[1]))
            min_dim = min(min(outer[0]), min(outer[1]))
            xrange = [min_dim, max_dim]
            yrange = [min_dim, max_dim]
        if inner_curve is not None:
            inner = get_data(inner_curve)
            plot_data["inner"] = inner

        sp = sec.properties
        sp.calculate()
        for sec_prop in [
            ("Ax", sp.Ax),
            ("Ix", sp.Ix),
            ("Iy", sp.Iy),
            ("Iz", sp.Iz),
            ("Iyz", sp.Iyz),
            ("Wxmin", sp.Wxmin),
            ("Wymin", sp.Wymin),
            ("Wzmin", sp.Wzmin),
            ("Sy", sp.Sy),
            ("Sz", sp.Sz),
            ("Shary", sp.Shary),
            ("Sharz", sp.Sharz),
            ("Shceny", sp.Scheny),
            ("Schenz", sp.Schenz),
        ]:
            res = sec_prop[1]
            if res is not None:
                html.value += f"<b>{sec_prop[0]}:</b> {sec_prop[1]:.4E}<br>"
            else:
                html.value += f"<b>{sec_prop[0]}:</b> Prop calc not defined yet<br>"

        # controls = []
        shapes = None
        if sec.type in SectionCat.circular:
            xrange = [-sec.r * 1.1, sec.r * 1.1]
            yrange = xrange
            shapes = [
                # unfilled circle
                dict(
                    type="circle",
                    xref="x",
                    yref="y",
                    x0=0,
                    y0=0,
                    x1=sec.r,
                    y1=0,
                    line_color="LightSeaGreen",
                )
            ]
        elif sec.type in SectionCat.tubular:
            xrange = [-sec.r * 1.1, sec.r * 1.1]
            yrange = xrange
            shapes = [
                dict(
                    type="circle",
                    xref="x",
                    yref="y",
                    x0=-sec.r,
                    y0=-sec.r,
                    x1=sec.r,
                    y1=sec.r,
                    line_color="LightSeaGreen",
                ),
                dict(
                    type="circle",
                    xref="x",
                    yref="y",
                    x0=-sec.r + sec.wt,
                    y0=-sec.r + sec.wt,
                    x1=sec.r - sec.wt,
                    y1=sec.r - sec.wt,
                    line_color="LightSeaGreen",
                ),
            ]

        fig = easy_plotly(
            f'ADA Section: "{sec.name}", Type: "{sec.type}"',
            plot_data,
            xrange=xrange,
            yrange=yrange,
            shapes=shapes,
            return_widget=True,
        )
        fig["layout"]["yaxis"]["scaleanchor"] = "x"

        display(HBox([fig, html]))