Ejemplo n.º 1
0
def test_get_num_nodes_different_per_stage():
    with pytest.raises(NodeError):
        example_dict = {
            "Stages": [
                {
                    "GeoFrewNodes": ["Node1", "Node2"]
                },
                {
                    "GeoFrewNodes": ["Node1", "Node2", "Node3"]
                },
            ]
        }
        get_num_nodes(example_dict)
Ejemplo n.º 2
0
    def get_node_levels(self) -> List[float]:
        """ Method to get the levels of the nodes in a Frew model.

        Returns
        -------
        node_levels : List[float]
            The levels of each node in a Frew model.

        """
        num_nodes = get_num_nodes(self.json_data)
        try:
            node_information = self.json_data["Stages"][0]["GeoFrewNodes"]
        except KeyError:
            raise FrewError("Unable to retreive node information.")
        except IndexError:
            raise FrewError("Unable to retreive node information.")

        if len(node_information) != num_nodes:
            raise FrewError(
                """
                Number of nodes does not equal the length of the node
                information
            """
            )
        return [node_information[node]["Level"] for node in range(num_nodes)]
Ejemplo n.º 3
0
    def get_water_pressures(self) -> Dict[int, Dict[str, dict]]:
        """ Function to get the pore water pressure for each stage and node.

        Returns
        -------
        water_pressures : Dict[int, Dict[str, dict]]
            The pore water pressures along the wall.

        """
        check_results_present(self.json_data)
        num_nodes: int = get_num_nodes(self.json_data)
        num_stages: int = get_num_stages(self.json_data)
        design_cases: List[str] = get_design_case_names(self.json_data)

        water_pressures: Dict[int, Dict[str, dict]] = {}

        for stage in range(num_stages):
            water_pressures[stage] = {
                design_case: {"left": [], "right": [],}
                for design_case in design_cases
            }

        for index, design_case in enumerate(design_cases):
            for stage in range(num_stages):
                node_results = self.json_data["Frew Results"][index][
                    "Stageresults"
                ][stage]["Noderesults"]
                for node in range(num_nodes):
                    water_pressures[stage][design_case]["left"].append(
                        node_results[node]["ULeft"] / 1000
                    )
                    water_pressures[stage][design_case]["right"].append(
                        node_results[node]["URight"] / 1000
                    )
        return water_pressures
Ejemplo n.º 4
0
    def get_envelopes(self) -> Dict[str, dict]:
        """ Method to return the envelopes of max and min shear, bending and
        displacements for each design case.

        Returns
        -------
        envelopes : Dict[str, dict]
            The maximum and minimum shear, bending and displacement for each
            design case for all stages.

        """
        check_results_present(self.json_data)
        num_stages = get_num_stages(self.json_data)
        num_nodes = get_num_nodes(self.json_data)
        design_cases = get_design_case_names(self.json_data)
        wall_results = self.get_results()

        envelopes: Dict[str, dict] = {
            design_case: {
                "maximum": {"shear": [], "bending": [], "disp": []},
                "minimum": {"shear": [], "bending": [], "disp": []},
            }
            for design_case in design_cases
        }

        for design_case in design_cases:
            for node in range(num_nodes):
                shear = []
                bending = []
                disp = []

                for stage in range(num_stages):
                    shear.append(
                        wall_results[stage][design_case]["shear"][node]
                    )
                    bending.append(
                        wall_results[stage][design_case]["bending"][node]
                    )
                    disp.append(
                        wall_results[stage][design_case]["displacement"][node]
                    )

                envelopes[design_case]["maximum"]["shear"].append(max(shear))
                envelopes[design_case]["maximum"]["bending"].append(
                    max(bending)
                )
                envelopes[design_case]["maximum"]["disp"].append(max(disp))
                envelopes[design_case]["minimum"]["shear"].append(min(shear))
                envelopes[design_case]["minimum"]["bending"].append(
                    min(bending)
                )
                envelopes[design_case]["minimum"]["disp"].append(min(disp))
        return envelopes
Ejemplo n.º 5
0
    def get_results(self) -> Dict[int, dict]:
        """ Method to get the shear, bending moment and displacement of the
        wall for each stage, node, and design case.

        Returns
        -------
        wall_results : Dict[int, dict]
            The shear, bending and displacement of the wall.

        """
        num_nodes = get_num_nodes(self.json_data)
        num_stages = get_num_stages(self.json_data)
        check_results_present(self.json_data)

        wall_results: Dict[int, dict] = {}
        for stage in range(num_stages):
            wall_results[stage] = {}
            for result_set in self.json_data["Frew Results"]:
                result_set_name = result_set["GeoPartialFactorSet"]["Name"]
                wall_results[stage][result_set_name] = {
                    "shear": [],
                    "bending": [],
                    "displacement": [],
                }
                for node in range(num_nodes):
                    stage_results = result_set["Stageresults"][stage][
                        "Noderesults"
                    ]
                    wall_results[stage][result_set_name]["shear"].append(
                        stage_results[node]["Shear"] / 1000
                    )
                    wall_results[stage][result_set_name]["bending"].append(
                        stage_results[node]["Bending"] / 1000
                    )
                    wall_results[stage][result_set_name][
                        "displacement"
                    ].append(stage_results[node]["Displacement"] * 1000)
        return wall_results
Ejemplo n.º 6
0
    def get(self, request: str) -> Union[dict, str, int, list]:
        """ Method to get information about the model.

        Parameters
        ----------
        request : str
            Options for request are: 'titles', 'file history', 'file version',
            'frew version', 'num stages', 'stage names', 'num nodes'.

        Returns
        -------
        return_value : Union[dict, str, int, list]
            The information requested about the model.

        Raises
        ------
        FrewError
            If `request` input is not a string or is not one of the options.

        """
        if not isinstance(request, str):
            raise FrewError("Request must be a string.")
        while request == "titles":
            return get_titles(self.json_data)
        while request == "file history":
            return get_file_history(self.json_data)
        while request == "file version":
            return get_file_version(self.json_data)
        while request == "frew version":
            return get_frew_version(self.json_data)
        while request == "num stages":
            return get_num_stages(self.json_data)
        while request == "stage names":
            return get_stage_names(self.json_data)
        while request == "num nodes":
            return get_num_nodes(self.json_data)
        raise FrewError("Please input a valid option.")
Ejemplo n.º 7
0
def test_get_num_nodes_none():
    example_dict = {"Stages": [{}]}
    assert get_num_nodes(example_dict) == 0
Ejemplo n.º 8
0
def test_get_num_nodes(json_data):
    assert get_num_nodes(json_data) == 68
Ejemplo n.º 9
0
    def results_to_excel(self, out_folder: str) -> None:
        """ Method to exports the wall results to an excel file where each
        sheet in the spreadsheet is a design case. The spreadsheet also
        a title sheet and the envelopes.

        Parameters
        ----------
        out_folder : str
            The folder path to save the results at.

        Returns
        -------
        None

        """
        if not os.path.exists(out_folder):
            raise FrewError(f"Path {out_folder} does not exist.")

        num_nodes: int = get_num_nodes(self.json_data)
        num_stages: int = get_num_stages(self.json_data)
        node_levels: List[float] = self.get_node_levels()
        wall_results: Dict[int, dict] = self.get_results()
        design_cases: List[str] = get_design_case_names(self.json_data)
        envelopes: Dict[str, dict] = self.get_envelopes()
        export_envelopes = pd.DataFrame(
            self._format_envelope_data(
                num_nodes, node_levels, envelopes, design_cases
            )
        )
        titles: Dict[str, str] = get_titles(self.json_data)
        export_titles = pd.DataFrame(self._format_titles_data(titles))

        job_title: str = titles["JobTitle"]
        uuid_str: str = str(uuid4()).split("-")[0]
        file_name: str = f"{job_title}_{uuid_str}_results.xlsx"

        export_data: Dict[str, dict] = {}
        for design_case in design_cases:
            export_data[design_case] = {
                "Node #": [],
                "Node levels (m)": [],
                "Stage": [],
                "Bending (kNm/m)": [],
                "Shear (kN/m)": [],
                "Displacement (mm)": [],
            }
            for stage in range(num_stages):
                node_array = list(range(1, num_nodes + 1))
                stage_array = [stage] * num_nodes
                bending_results = wall_results[stage][design_case]["bending"]
                shear_results = wall_results[stage][design_case]["shear"]
                displacement_results = wall_results[stage][design_case][
                    "displacement"
                ]

                export_data[design_case]["Node #"].extend(node_array)
                export_data[design_case]["Node levels (m)"].extend(node_levels)
                export_data[design_case]["Stage"].extend(stage_array)
                export_data[design_case]["Bending (kNm/m)"].extend(
                    bending_results
                )
                export_data[design_case]["Shear (kN/m)"].extend(shear_results)
                export_data[design_case]["Displacement (mm)"].extend(
                    displacement_results
                )
        try:
            with pd.ExcelWriter(os.path.join(out_folder, file_name)) as writer:
                export_titles.to_excel(
                    writer, sheet_name="Titles", index=False, header=False
                )
                export_envelopes.to_excel(
                    writer, sheet_name="Envelopes", index=False,
                )
                for design_case in design_cases:
                    export_data_df = pd.DataFrame(export_data[design_case])
                    export_data_df.to_excel(
                        writer, sheet_name=design_case, index=False,
                    )
        except PermissionError:
            raise FrewError(
                """
                Please make sure you have closed the results spreadsheet.
            """
            )