Beispiel #1
0
def test_easy_plotly_simple_graph_to_file(test_dir):
    plot_file_name = "MyEasyPlotlyPlot.png"
    easy_plotly(
        "MyPlot",
        [(0, 0), (1, 0.5), (1.5, 0.8), (2, 1.75)],
        "X label",
        "Y label",
        save_filename=test_dir / plot_file_name,
    )
Beispiel #2
0
 def visualize(self):
     in_data = {
         "Engineering": (self.e, self.S),
         "True": (self.eps, self.sig)
     }
     return easy_plotly(self.title,
                        in_data,
                        xlbl="Strain [-]",
                        ylbl="Stress [Pa]")
Beispiel #3
0
    def visualize_true(self):
        in_data = dict()

        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]",
        )
Beispiel #4
0
    def visualize_eng(self):

        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]",
        )
Beispiel #5
0
 def _repr_html_(self):
     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]))
Beispiel #6
0
    def __init__(
        self,
        mat_data,
        num_int=300,
        load_types=None,
        interpolate=True,
        incompressible=True,
    ):

        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)
Beispiel #7
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)
        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,
        )
Beispiel #8
0
    def build_display(self, sec):
        """

        :type sec: ada.Section
        """

        from ipywidgets import HTML

        from ada.concepts.curves import CurvePoly
        from ada.sections import SectionCat
        from ada.visualize.plots import easy_plotly

        # 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>")
        section_profile = sec.get_section_profile(True)

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

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

        if section_profile.outer_curve is not None and type(
                section_profile.outer_curve) is not float:
            outer = get_data(section_profile.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 section_profile.inner_curve is not None:
            inner = get_data(section_profile.inner_curve)
            plot_data["inner"] = inner

        sp = sec.properties
        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.Shceny),
            ("Shcenz", sp.Shcenz),
        ]:
            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"
        return fig, HTML
Beispiel #9
0
    def _repr_html_(self):
        from ada.config import Settings

        # 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,
        )
        if Settings.silence_display is True:
            display(VBox([plot_displ, plot_moment, plot_shear]))
        return ""