From ca018c3445bf64646527ae885b2f6faa3031a5e2 Mon Sep 17 00:00:00 2001 From: krande Date: Thu, 29 Apr 2021 21:18:42 +0200 Subject: [PATCH] CodeAster. Add actual control of boundary conditions (not only ENCASTRE). --- README.md | 14 ++++++++++---- src/ada/fem/io/code_aster/writer.py | 17 ++++++++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e8dac06ec..128648102 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ creates an IFC with the following hierarchy (as shown in the figure below taken ![Beam Visualized in BlenderBIM](docs/_static/figures/my_beam.png) -### Create and execute a FEM analysis in Calculix and Abaqus +### Create and execute a FEM analysis in Calculix, Code Aster and Abaqus This example uses a function `beam_ex1` from [here](src/ada/param_models/fem_models.py) that returns an Assembly object ready to be written to FEM. @@ -85,6 +85,7 @@ a = beam_ex1() a.to_fem("MyCantilever_abaqus", "abaqus", overwrite=True, execute=True, run_ext=True) a.to_fem("MyCantilever_calculix", "calculix", overwrite=True, execute=True) +a.to_fem("MyCantilever_code_aster", "code_aster", overwrite=True, execute=True) ``` after the execution is finished you can look at the results (in Paraview or Abaqus CAE for the results from @@ -104,9 +105,14 @@ import meshio vtu = Settings.scratch_dir / "MyCantilever_calculix" / "MyCantilever_calculix.vtu" mesh = meshio.read(vtu) -# Von Mises stresses and displacement at a point @ index=0 -print(mesh.point_data['S'][0]) -print(mesh.point_data['U'][0]) +# Displacements in [X, Y, Z] at point @ index=-1 +print('Calculix:',mesh.point_data['U'][-1]) + +rmed = Settings.scratch_dir / "MyCantilever_code_aster" / "MyCantilever_code_aster.rmed" +ca_mesh = meshio.read(rmed, 'med') + +# Displacements in [X, Y, Z] at point @ index=-1 +print('Code Aster:',ca_mesh.point_data['DISP[10] - 1'][-1][:3]) ``` In short `beam_ex1` creates a `Beam` object which it uses to create a shell element `FEM` mesh using diff --git a/src/ada/fem/io/code_aster/writer.py b/src/ada/fem/io/code_aster/writer.py index 9c23b27ba..dc54e10c9 100644 --- a/src/ada/fem/io/code_aster/writer.py +++ b/src/ada/fem/io/code_aster/writer.py @@ -235,10 +235,21 @@ def write_boundary_condition(bc): :rtype: str """ set_name = bc.fem_set.name - - return f"""{bc.name}_bc = AFFE_CHAR_MECA( - MODELE=model, DDL_IMPO=_F(GROUP_NO="{set_name}", LIAISON="ENCASTRE") + bc_str = "" + for i, n in enumerate(["DX", "DY", "DZ", "DRX", "DRY", "DRZ"], start=1): + if i in bc.dofs: + bc_str += f"{n}=0, " + dofs_str = f"""dofs = dict( + GROUP_NO="{set_name}", + {bc_str} +)\n""" + + return ( + dofs_str + + f"""{bc.name}_bc = AFFE_CHAR_MECA( + MODELE=model, DDL_IMPO=_F(**dofs) )""" + ) def write_load(load):