From 9fa444c1138c729e1e55b4bb1edc08e2dbcb225f Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Mon, 12 Jul 2021 22:33:13 +0200 Subject: [PATCH] FEM: calculix writer, move write mesh in separate module --- src/Mod/Fem/CMakeLists.txt | 1 + src/Mod/Fem/femsolver/calculix/write_mesh.py | 76 ++++++++++++++++++++ src/Mod/Fem/femsolver/calculix/writer.py | 50 +------------ 3 files changed, 79 insertions(+), 48 deletions(-) create mode 100644 src/Mod/Fem/femsolver/calculix/write_mesh.py diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index 75ba0c05ab..97d78f4c44 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -203,6 +203,7 @@ SET(FemSolverCalculix_SRCS femsolver/calculix/write_constraint_tie.py femsolver/calculix/write_constraint_transform.py femsolver/calculix/write_footer.py + femsolver/calculix/write_mesh.py femsolver/calculix/write_step_equation.py femsolver/calculix/write_step_output.py femsolver/calculix/writer.py diff --git a/src/Mod/Fem/femsolver/calculix/write_mesh.py b/src/Mod/Fem/femsolver/calculix/write_mesh.py new file mode 100644 index 0000000000..86b14a6721 --- /dev/null +++ b/src/Mod/Fem/femsolver/calculix/write_mesh.py @@ -0,0 +1,76 @@ +# *************************************************************************** +# * Copyright (c) 2021 Bernd Hahnebach * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "FreeCAD FEM calculix write inpfile mesh" +__author__ = "Bernd Hahnebach" +__url__ = "https://www.freecadweb.org" + + +import codecs +from os.path import join + +from femmesh import meshtools + + +def write_mesh(ccxwriter): + + element_param = 1 # highest element order only + group_param = False # do not write mesh group data + if ccxwriter.split_inpfile is True: + write_name = "femesh" + file_name_split = ccxwriter.mesh_name + "_" + write_name + ".inp" + ccxwriter.femmesh_file = join(ccxwriter.dir_name, file_name_split) + + ccxwriter.femmesh.writeABAQUS( + ccxwriter.femmesh_file, + element_param, + group_param + ) + + # Check to see if fluid sections are in analysis and use D network element type + if ccxwriter.fluidsection_objects: + meshtools.write_D_network_element_to_inputfile(ccxwriter.femmesh_file) + + inpfile = codecs.open(ccxwriter.file_name, "w", encoding="utf-8") + inpfile.write("{}\n".format(59 * "*")) + inpfile.write("** {}\n".format(write_name)) + inpfile.write("*INCLUDE,INPUT={}\n".format(file_name_split)) + + else: + ccxwriter.femmesh_file = ccxwriter.file_name + ccxwriter.femmesh.writeABAQUS( + ccxwriter.femmesh_file, + element_param, + group_param + ) + + # Check to see if fluid sections are in analysis and use D network element type + if ccxwriter.fluidsection_objects: + # inpfile is closed + meshtools.write_D_network_element_to_inputfile(ccxwriter.femmesh_file) + + # reopen file with "append" to add all the rest + inpfile = codecs.open(ccxwriter.femmesh_file, "a", encoding="utf-8") + inpfile.write("\n\n") + + return inpfile diff --git a/src/Mod/Fem/femsolver/calculix/writer.py b/src/Mod/Fem/femsolver/calculix/writer.py index 48e0b484ee..e0e32f31b3 100644 --- a/src/Mod/Fem/femsolver/calculix/writer.py +++ b/src/Mod/Fem/femsolver/calculix/writer.py @@ -29,7 +29,6 @@ __url__ = "https://www.freecadweb.org" ## \addtogroup FEM # @{ -import codecs import six import time from os.path import join @@ -53,10 +52,10 @@ from . import write_constraint_temperature as con_temperature from . import write_constraint_tie as con_tie from . import write_constraint_transform as con_transform from . import write_footer +from . import write_mesh from . import write_step_equation from . import write_step_output from .. import writerbase -from femmesh import meshtools from femtools import constants @@ -159,7 +158,7 @@ class FemInputWriterCcx(writerbase.FemInputWriter): self.split_inpfile = False # mesh - inpfile = self.write_mesh() + inpfile = write_mesh.write_mesh(self) # element sets for materials and element geometry # self.write_element_sets_material_and_femelement_geometry(inpfile) @@ -219,51 +218,6 @@ class FemInputWriterCcx(writerbase.FemInputWriter): write_footer.write_footer(inpfile, self) inpfile.close() - # ******************************************************************************************** - # mesh - def write_mesh(self): - # write mesh to file - element_param = 1 # highest element order only - group_param = False # do not write mesh group data - if self.split_inpfile is True: - write_name = "femesh" - file_name_split = self.mesh_name + "_" + write_name + ".inp" - self.femmesh_file = join(self.dir_name, file_name_split) - - self.femmesh.writeABAQUS( - self.femmesh_file, - element_param, - group_param - ) - - # Check to see if fluid sections are in analysis and use D network element type - if self.fluidsection_objects: - meshtools.write_D_network_element_to_inputfile(self.femmesh_file) - - inpfile = codecs.open(self.file_name, "w", encoding="utf-8") - inpfile.write("***********************************************************\n") - inpfile.write("** {}\n".format(write_name)) - inpfile.write("*INCLUDE,INPUT={}\n".format(file_name_split)) - - else: - self.femmesh_file = self.file_name - self.femmesh.writeABAQUS( - self.femmesh_file, - element_param, - group_param - ) - - # Check to see if fluid sections are in analysis and use D network element type - if self.fluidsection_objects: - # inpfile is closed - meshtools.write_D_network_element_to_inputfile(self.femmesh_file) - - # reopen file with "append" to add all the rest - inpfile = codecs.open(self.femmesh_file, "a", encoding="utf-8") - inpfile.write("\n\n") - - return inpfile - # ******************************************************************************************** # write constraint node sets, constraint face sets, constraint element sets def write_constraints_sets(