コード例 #1
0
    def __Assemble(self, readable_mdpa):
        # TODO Check if this was done before! (same for the submodelparts)
        start_time = time.time()
        global_utils.LogInfo("Assembling Mesh")
        self.__InitializeMesh()
        for smp_name in sorted(self.sub_model_parts.keys()):
            smp = self.sub_model_parts[smp_name]
            smp.Assemble()
            smp_nodes, smp_elements, smp_conditions = smp.GetMesh()
            self.__AddNodes(smp_nodes, readable_mdpa)
            self.__AddElements(smp_elements)
            self.__AddConditions(smp_conditions)

        global_utils.LogTiming("Mesh assembling time", start_time)
コード例 #2
0
    def WriteMesh(self,
                  mdpa_file_path,
                  info_text="",
                  readable_mdpa=False):  # TODO use this
        self.__Assemble(readable_mdpa)  # TODO only do this if sth has changed

        start_time = time.time()
        global_utils.LogInfo("Writing Mesh")

        # Write Header
        if not mdpa_file_path.endswith('.mdpa'):
            mdpa_file_path += ".mdpa"
        with open(mdpa_file_path, "w") as mdpa_file:
            self.__WriteMeshInfo(mdpa_file, info_text)
            mdpa_file.write(
                "\nBegin ModelPartData\n//  VARIABLE_NAME value\nEnd ModelPartData\n\n"
            )
            mdpa_file.write("Begin Properties 0\nEnd Properties\n\n")

            # Write Nodes
            self.__WriteNodes(mdpa_file, readable_mdpa)

            # Write Elements
            self.__WriteElements(mdpa_file, readable_mdpa)

            # Write Conditions
            self.__WriteConditions(mdpa_file, readable_mdpa)

            # Write Nodal Data
            self.__WriteNodalData(mdpa_file, readable_mdpa)

            # Write Elemental Data
            self.__WriteGeometricalEntityData(mdpa_file, readable_mdpa,
                                              self.elements, "Element")

            # Write Conditional Data
            self.__WriteGeometricalEntityData(mdpa_file, readable_mdpa,
                                              self.conditions, "Condition")

            # Write SubModelParts
            for smp_name in sorted(self.sub_model_parts.keys()):
                smp = self.sub_model_parts[smp_name]
                smp.WriteMesh(mdpa_file, readable_mdpa)

            global_utils.LogTiming("Mesh writing time", start_time)

        self.__ClearAfterWriting()

        return True
コード例 #3
0
    def _SaveConverterProject(self, save_as):
        if len(self.tree.get_children()) == 0:
            self.PlotCmdOutput("Nothing to be saved", "red")
        else:
            if (self.save_file_path == "" or save_as):
                input_save_file_path = tk.filedialog.asksaveasfilename(
                    title="Select file",
                    filetypes=[("converter files",
                                "*" + utils.conv_project_file_ending)])

                if input_save_file_path:  # A file path was returned
                    if not input_save_file_path.endswith(
                            utils.conv_project_file_ending):
                        input_save_file_path += utils.conv_project_file_ending

                    self.save_file_path = input_save_file_path

            if self.save_file_path == "":
                self.PlotCmdOutput("File was not saved", "red")
            else:
                start_time = time.time()
                serialized_model_part_dict = self.model_part.Serialize()

                # Add general information to file
                serialized_model_part_dict.update({
                    "general":
                    global_utils.GetGeneralInfoDict(utils.VERSION)
                })

                with open(self.save_file_path, "w") as save_file:
                    if global_utils.GetDebug():
                        # Do this only for debugging, file size is much larger!
                        json.dump(serialized_model_part_dict,
                                  save_file,
                                  sort_keys=True,
                                  indent=4)
                    else:
                        fast_json.dump(serialized_model_part_dict, save_file)

                global_utils.LogTiming("Save Project", start_time)
                self.PlotCmdOutput("Saved the project", "green")
                self.unsaved_changes_exist = False
                global_utils.LogInfo("Saved Project")
コード例 #4
0
    def _OpenConverterProject(self):
        if self._CheckForUnsavedChanges():
            self._ResetGUI()
            file_path, valid_file = utils.GetFilePathOpen(
                utils.conv_project_file_ending)
            utils.BringWindowToFront(self.window)

            if valid_file:
                serialized_model_part_dict = {}
                try:
                    start_time = time.time()
                    with open(file_path, "r") as json_file:
                        serialized_model_part_dict = fast_json.load(json_file)

                    self.model_part.Deserialize(serialized_model_part_dict)
                    self.UpdateMeshTree()
                    global_utils.LogTiming("Open Project", start_time)
                    self.PlotCmdOutput("Opened the project", "green")
                    global_utils.LogInfo("Opened Project")
                except:
                    self.PlotCmdOutput(
                        "Opening project from file \"{}\" failed".format(
                            file_path), "red")