New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEM CalculiX 2D mechanical analyses (plane stress, plane strain and axisymmetric) #12562
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works correctly.
Just some comments about duplicate code.
In my opinion, it would be enough to remove the duplicate code in write_femelement_geometry.py
; The other functions can remain as they are, in any case, in the future I plan to extend the C++ writing function to avoid systematic editing of the already written file.
src/Mod/Fem/femmesh/meshtools.py
Outdated
f.truncate() | ||
f.close() | ||
def plane_stress( | ||
fileName | ||
): | ||
# replace shell elements with plane stress elements | ||
f = open(fileName, "r+") | ||
lines = f.readlines() | ||
f.seek(0) | ||
for line in lines: | ||
if line.find("S3") != -1: | ||
line = line.replace("S3", "CPS3") | ||
if line.find("S6") != -1: | ||
line = line.replace("S6", "CPS6") | ||
if line.find("S4") != -1: | ||
line = line.replace("S4", "CPS4") | ||
f.write(line) | ||
|
||
f.truncate() | ||
f.close() | ||
def plane_strain( | ||
fileName | ||
): | ||
# replace shell elements with plane strain elements | ||
f = open(fileName, "r+") | ||
lines = f.readlines() | ||
f.seek(0) | ||
for line in lines: | ||
if line.find("S3") != -1: | ||
line = line.replace("S3", "CPE3") | ||
if line.find("S6") != -1: | ||
line = line.replace("S6", "CPE6") | ||
if line.find("S4") != -1: | ||
line = line.replace("S4", "CPE4") | ||
f.write(line) | ||
|
||
f.truncate() | ||
f.close() | ||
def axisymmetric( | ||
fileName | ||
): | ||
# replace shell elements with axisymmetric elements | ||
f = open(fileName, "r+") | ||
lines = f.readlines() | ||
f.seek(0) | ||
for line in lines: | ||
if line.find("S3") != -1: | ||
line = line.replace("S3", "CAX3") | ||
if line.find("S6") != -1: | ||
line = line.replace("S6", "CAX6") | ||
if line.find("S4") != -1: | ||
line = line.replace("S4", "CAX4") | ||
f.write(line) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These functions plus beam_reduced_integration
could be compacted into a single function that takes the appropriate parameters or use a base function that does the replacement and then called inside the others.
if ccxwriter.solver_obj.ModelSpace == "3D": | ||
shellth_obj = matgeoset["shellthickness_obj"] | ||
section_def = "*SHELL SECTION, {}{}\n".format(elsetdef, material) | ||
thickness = shellth_obj.Thickness.getValueAs("mm").Value | ||
section_geo = "{:.13G}\n".format(thickness) | ||
f.write(section_def) | ||
f.write(section_geo) | ||
else: | ||
shellth_obj = matgeoset["shellthickness_obj"] | ||
section_def = "*SOLID SECTION, {}{}\n".format(elsetdef, material) | ||
thickness = shellth_obj.Thickness.getValueAs("mm").Value | ||
section_geo = "{:.13G}\n".format(thickness) | ||
f.write(section_def) | ||
f.write(section_geo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better not to repeat code in the if-else block. Move duplicate code out of conditional block.
|
||
# Use 2D elements if model space is not set to 3D | ||
if ccxwriter.solver_obj.ModelSpace == "plane stress": | ||
meshtools.plane_stress(ccxwriter.femmesh_file) | ||
if ccxwriter.solver_obj.ModelSpace == "plane strain": | ||
meshtools.plane_strain(ccxwriter.femmesh_file) | ||
if ccxwriter.solver_obj.ModelSpace == "axisymmetric": | ||
meshtools.axisymmetric(ccxwriter.femmesh_file) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that by properly adapting the functions in meshtools.py, these conditionals could be replaced by a call to a single function.
# Use 2D elements if model space is not set to 3D | ||
if ccxwriter.solver_obj.ModelSpace == "plane stress": | ||
meshtools.plane_stress(ccxwriter.femmesh_file) | ||
if ccxwriter.solver_obj.ModelSpace == "plane strain": | ||
meshtools.plane_strain(ccxwriter.femmesh_file) | ||
if ccxwriter.solver_obj.ModelSpace == "axisymmetric": | ||
meshtools.axisymmetric(ccxwriter.femmesh_file) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
Ok, done. Thank you for reviewing. So it can be merged ? |
@chennes Can you merge it ? |
@chennes The required tests passed. Some other tests failed but apparently because of Part Design Helix:
So it shouldn't be related to the PR. |
use the wires of the computed face instead of the selected ones.
resolves #10864
This PR implements 2D mechanical analyses (plane stress, plane strain and axisymmetric) with CalculiX.
Usage:
@marioalexis84 and @chennes