.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/boundary_conditions/periodic_bc_3d_gyroid_off_axis.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_boundary_conditions_periodic_bc_3d_gyroid_off_axis.py: Off-axis tensile test on a gyroid unit cell with periodic boundary conditions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The periodic mesh of the Gyroid has been generated with microgen. This example shows how to define periodic boundary conditions with :class:`fedoo.constraint.PeriodicBC` and to load the structure with a prescribed mean strain in a local coordinate system rotated by 45° about :math:`z` (``off_axis_rotation``). The mean stress and mean strain are then extracted in the local and global coordinate systems. .. GENERATED FROM PYTHON SOURCE LINES 12-17 .. code-block:: Python import fedoo as fd import numpy as np from scipy.spatial.transform import Rotation .. GENERATED FROM PYTHON SOURCE LINES 18-22 Mesh, material and linear problem --------------------------------- Periodic boundary conditions require a periodic mesh (matching nodes on opposite faces), which is checked here. .. GENERATED FROM PYTHON SOURCE LINES 22-37 .. code-block:: Python fd.ModelingSpace("3D") mesh = fd.Mesh.read("../../util/meshes/gyroid_per_clean.vtk") assert mesh.is_periodic() # Material definition material = fd.constitutivelaw.ElasticIsotrop(1e5, 0.3) wf = fd.weakform.StressEquilibrium(material) # Assembly assembly = fd.Assembly.create(wf, mesh) # Define linear problem pb = fd.problem.Linear(assembly) .. GENERATED FROM PYTHON SOURCE LINES 38-44 Boundary conditions ------------------- The global mean strain components are eliminated from the problem when ``off_axis_rotation`` is given, so they can no longer be prescribed: for instance ``pb.bc.add("Dirichlet", "E_xx", 1)`` would have no effect. The load is applied on the local components ``E_11``, ..., ``E_23`` instead. .. GENERATED FROM PYTHON SOURCE LINES 44-56 .. code-block:: Python # periodic constraint in local frame local_frame = Rotation.from_rotvec([0, 0, np.pi / 4]) bc_periodic = fd.constraint.PeriodicBC("small_strain", off_axis_rotation=local_frame) pb.bc.add(bc_periodic) # block a node near the center to avoid rigid body motion pb.bc.add("Dirichlet", mesh.nearest_node(mesh.bounding_box.center), "Disp", 0) # off axis traction along the local x axis = '1' pb.bc.add("Dirichlet", "E_11", 1) .. rst-class:: sphx-glr-script-out .. code-block:: none Dirichlet boundary condition: var = 'E_11' n_nodes = 1 value = 1 .. GENERATED FROM PYTHON SOURCE LINES 57-71 .. note:: Without ``off_axis_rotation``, the periodic constraint only creates the global mean strain dofs ``MeanStrain`` (``E_xx``, ..., ``E_yz``). The six components can then be prescribed at once in the global frame, for instance a pure shear :math:`\gamma_{yz} = 2 \varepsilon_{yz} = 1`: .. code-block:: python pb.bc.add(fd.constraint.PeriodicBC("small_strain")) # [E_xx, E_yy, E_zz, E_xy, E_xz, E_yz], engineering shear strains pb.bc.add("Dirichlet", "MeanStrain", [0, 0, 0, 0, 0, 1]) pb.solve() pb.get_results(assembly, "Stress").plot("Stress", "YZ") .. GENERATED FROM PYTHON SOURCE LINES 73-84 Solve and print the macroscopic strain and stress tensors --------------------------------------------------------- The mean strain and its reaction can be read from the results (as below) or directly with ``pb.get_dof_solution("LocalMeanStrain")`` and ``pb.get_ext_forces("LocalMeanStrain")``. The reaction to the mean strain dofs is the mean stress times the cell volume (voids included). The mean strain dofs use the Voigt notation ``[11, 22, 33, 12, 13, 23]`` with engineering shear strains :math:`\gamma_{ij} = 2 \varepsilon_{ij}` (see :class:`fedoo.constraint.PeriodicBC`), so the shear terms are divided by 2 to build the strain tensor. The stress tensor shear terms need no correction. .. GENERATED FROM PYTHON SOURCE LINES 84-169 .. code-block:: Python pb.solve() res = pb.get_results( assembly, [ "LocalMeanStrain", "MeanStrain", "Stress", "Disp", "Fext(MeanStrain)", # dual variable associated to strain is: stress * volume "Fext(LocalMeanStrain)", ], ) res.plot("Stress", "XX") np.set_printoptions(3) mean_strain = res["LocalMeanStrain"].ravel() print( "Strain tensor in local frame:\n", np.array( [ [mean_strain[0], mean_strain[3] / 2, mean_strain[4] / 2], [mean_strain[3] / 2, mean_strain[1], mean_strain[5] / 2], [mean_strain[4] / 2, mean_strain[5] / 2, mean_strain[2]], ] ), " \n\n", ) mean_strain = res["MeanStrain"].ravel() print( "Strain tensor in global frame:\n", np.array( [ [mean_strain[0], mean_strain[3] / 2, mean_strain[4] / 2], [mean_strain[3] / 2, mean_strain[1], mean_strain[5] / 2], [mean_strain[4] / 2, mean_strain[5] / 2, mean_strain[2]], ] ), " \n\n", ) volume = mesh.bounding_box.volume # volume of the unit cell, including voids mean_stress = res["Fext(LocalMeanStrain)"].ravel() / volume print( "Stress tensor in local frame:\n", np.array( [ [mean_stress[0], mean_stress[3], mean_stress[4]], [mean_stress[3], mean_stress[1], mean_stress[5]], [mean_stress[4], mean_stress[5], mean_stress[2]], ] ), " \n\n", ) mean_stress = res["Fext(MeanStrain)"].ravel() / volume print( "Stress tensor in global frame:\n", np.array( [ [mean_stress[0], mean_stress[3], mean_stress[4]], [mean_stress[3], mean_stress[1], mean_stress[5]], [mean_stress[4], mean_stress[5], mean_stress[2]], ] ), " \n\n", ) # Compute the mean stress tensor by integration over the domain # The difference with the previous method is due to numerical errors mean_stress = [1 / volume * mesh.integrate_field(res["Stress"][i]) for i in range(6)] print( "Stress tensor using integration:\n", np.array( [ [mean_stress[0], mean_stress[3], mean_stress[4]], [mean_stress[3], mean_stress[1], mean_stress[5]], [mean_stress[4], mean_stress[5], mean_stress[2]], ] ), " \n\n", ) .. image-sg:: /examples/boundary_conditions/images/sphx_glr_periodic_bc_3d_gyroid_off_axis_001.png :alt: periodic bc 3d gyroid off axis :srcset: /examples/boundary_conditions/images/sphx_glr_periodic_bc_3d_gyroid_off_axis_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Strain tensor in local frame: [[ 1.000e+00 -1.222e-03 4.749e-04] [-1.222e-03 -2.415e-01 5.056e-04] [ 4.749e-04 5.056e-04 -3.296e-01]] Strain tensor in global frame: [[ 3.805e-01 6.208e-01 -2.173e-05] [ 6.208e-01 3.780e-01 6.933e-04] [-2.173e-05 6.933e-04 -3.296e-01]] Stress tensor in local frame: [[ 1.336e+04 4.458e-10 1.439e-11] [ 4.458e-10 -3.748e-10 -5.813e-12] [ 1.439e-11 -5.813e-12 -8.573e-10]] Stress tensor in global frame: [[ 6.678e+03 6.678e+03 1.402e-11] [ 6.678e+03 6.678e+03 5.849e-12] [ 1.402e-11 5.849e-12 -8.573e-10]] Stress tensor using integration: [[ 6.678e+03 6.678e+03 1.379e-11] [ 6.678e+03 6.678e+03 1.557e-11] [ 1.379e-11 1.557e-11 -8.750e-10]] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.071 seconds) .. _sphx_glr_download_examples_boundary_conditions_periodic_bc_3d_gyroid_off_axis.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: periodic_bc_3d_gyroid_off_axis.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: periodic_bc_3d_gyroid_off_axis.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: periodic_bc_3d_gyroid_off_axis.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_