| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | __title__ = "FreeCAD FEM solver Mystran tasks" |
| | __author__ = "Bernd Hahnebach" |
| | __url__ = "https://www.freecad.org" |
| |
|
| | |
| | |
| |
|
| | import os |
| | import os.path |
| | import subprocess |
| |
|
| | import FreeCAD |
| |
|
| |
|
| | try: |
| | import hfcMystranNeuIn |
| |
|
| | result_reading = True |
| | except Exception: |
| | FreeCAD.Console.PrintWarning("Module to read results not found.\n") |
| | result_reading = False |
| |
|
| |
|
| | from . import writer |
| | from .. import run |
| | from .. import settings |
| | from femmesh import meshsetsgetter |
| | from femtools import femutils |
| | from femtools import membertools |
| |
|
| |
|
| | _inputFileName = None |
| |
|
| |
|
| | class Check(run.Check): |
| |
|
| | def run(self): |
| | self.pushStatus("Checking analysis member...\n") |
| | self.check_mesh_exists() |
| | self.check_material_exists() |
| | self.check_material_single() |
| | self.check_geos_beamsection_single() |
| | self.check_geos_shellthickness_single() |
| | self.check_geos_beamsection_and_shellthickness() |
| |
|
| |
|
| | class Prepare(run.Prepare): |
| |
|
| | def run(self): |
| | global _inputFileName |
| | self.pushStatus("Preparing solver input...\n") |
| |
|
| | |
| | |
| | mesh_obj = membertools.get_mesh_to_solve(self.analysis)[0] |
| | meshdatagetter = meshsetsgetter.MeshSetsGetter( |
| | self.analysis, |
| | self.solver, |
| | mesh_obj, |
| | membertools.AnalysisMember(self.analysis), |
| | ) |
| | meshdatagetter.get_mesh_sets() |
| |
|
| | |
| | w = writer.FemInputWriterMystran( |
| | self.analysis, |
| | self.solver, |
| | mesh_obj, |
| | meshdatagetter.member, |
| | self.directory, |
| | ) |
| | path = w.write_solver_input() |
| | |
| | if path != "": |
| | self.pushStatus("Writing solver input completed.") |
| | else: |
| | self.pushStatus("Writing solver input failed.") |
| | self.fail() |
| | _inputFileName = os.path.splitext(os.path.basename(path))[0] |
| |
|
| |
|
| | class Solve(run.Solve): |
| |
|
| | def run(self): |
| | self.pushStatus("Executing solver...\n") |
| |
|
| | infile = _inputFileName + ".bdf" |
| |
|
| | |
| | self.pushStatus("Get solver binary...\n") |
| | binary = settings.get_binary("Mystran") |
| | if binary is None: |
| | self.fail() |
| |
|
| | |
| | self.pushStatus("Executing solver...\n") |
| | self._process = subprocess.Popen( |
| | args=[binary, infile], |
| | cwd=self.directory, |
| | stdout=subprocess.PIPE, |
| | stderr=subprocess.PIPE, |
| | ) |
| | self.signalAbort.add(self._process.terminate) |
| | self._process.communicate() |
| | self.signalAbort.remove(self._process.terminate) |
| |
|
| | |
| |
|
| |
|
| | class Results(run.Results): |
| |
|
| | def run(self): |
| | prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/General") |
| | if not prefs.GetBool("KeepResultsOnReRun", False): |
| | self.purge_results() |
| | if result_reading is True: |
| | self.load_results() |
| |
|
| | def purge_results(self): |
| | self.pushStatus("Purge existing results...\n") |
| | |
| | for m in membertools.get_member(self.analysis, "Fem::FemResultObject"): |
| | if femutils.is_of_type(m.Mesh, "Fem::MeshResult"): |
| | self.analysis.Document.removeObject(m.Mesh.Name) |
| | self.analysis.Document.removeObject(m.Name) |
| | self.analysis.Document.recompute() |
| |
|
| | def load_results(self): |
| | self.pushStatus("Import new results...\n") |
| | neu_result_file = os.path.join(self.directory, _inputFileName + ".NEU") |
| | if os.path.isfile(neu_result_file): |
| | hfcMystranNeuIn.import_neu(neu_result_file) |
| | |
| | for o in self.analysis.Document.Objects: |
| | if o.Name == "Displacement0": |
| | self.analysis.addObject(o) |
| | break |
| | else: |
| | |
| | FreeCAD.Console.PrintError(f"FEM: No results found at {neu_result_file}!\n") |
| | self.fail() |
| |
|
| |
|
| | |
| |
|