.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/boundary_conditions/periodic_bc_mean_disp_constraint.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_mean_disp_constraint.py: Periodic BC without node pinning: mean displacement constraint ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Periodic boundary conditions only constrain the difference of displacement between opposite faces: the rigid body translation remains free and must be removed. The usual way is to block the displacement of an arbitrary node (generally the node nearest to the center of the RVE). This example shows an alternative that avoids choosing a specific node: the mean displacement over all the nodes is constrained to zero with Lagrange multipliers (one per displacement component), using :py:class:`fedoo.constraint.MeanValueConstraint`. The solution is then independent of any node choice, and the reaction is distributed over all the nodes instead of being concentrated on the pinned node. .. GENERATED FROM PYTHON SOURCE LINES 17-22 .. code-block:: Python import numpy as np import fedoo as fd .. GENERATED FROM PYTHON SOURCE LINES 23-25 Geometry and material --------------------- .. GENERATED FROM PYTHON SOURCE LINES 25-33 .. code-block:: Python fd.ModelingSpace("2Dstress") mesh = fd.mesh.hole_plate_mesh(nr=11, nt=11, length=100, height=100, radius=20) material = fd.constitutivelaw.ElasticIsotrop(1e5, 0.3) wf = fd.weakform.StressEquilibrium(material) assemb = fd.Assembly.create(wf, mesh) .. GENERATED FROM PYTHON SOURCE LINES 34-40 Problem: solid assembly + mean displacement constraint ------------------------------------------------------ The MeanValueConstraint is an assembly object summed with the solid assembly. It enforces :math:`\sum_i w_i u_d^{(i)} = 0` for each displacement component :math:`d`, with one Lagrange multiplier per component (saddle-point system: a direct solver is required). .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python constraint = fd.constraint.MeanValueConstraint(mesh, "Disp") pb = fd.problem.Linear(assemb + constraint) .. GENERATED FROM PYTHON SOURCE LINES 45-47 Boundary conditions: periodicity + macroscopic strain ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 47-56 .. code-block:: Python E = [0.1, 0, 0] # macroscopic strain tensor [EXX, EYY, EXY] pb.bc.add(fd.constraint.PeriodicBC(periodicity_type="small_strain")) # No node pinning needed: the rigid body translation is removed by the # mean displacement constraint. pb.bc.add("Dirichlet", "MeanStrain", E) # apply specified macro strain .. rst-class:: sphx-glr-script-out .. code-block:: none List of boundary conditions: number of bc = 3 0: Dirichlet -> 'E_xx' for 1 nodes set to 0.1 1: Dirichlet -> 'E_yy' for 1 nodes set to 0 2: Dirichlet -> 'E_xy' for 1 nodes set to 0 .. GENERATED FROM PYTHON SOURCE LINES 57-59 Solve and post-treatment ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 59-79 .. code-block:: Python pb.solve() volume = mesh.bounding_box.volume mean_stress = pb.get_ext_forces("MeanStrain") / volume print("Mean stress, Voigt vector ([Sxx, Syy, Sxy]): ", mean_stress) # The mean displacement is zero (this is the enforced constraint): disp = pb.get_disp() print("Mean displacement: ", disp.mean(axis=1)) assert np.allclose(disp.mean(axis=1), 0, atol=1e-10) # The Lagrange multipliers are close to zero (no resultant force is needed # to maintain the constraint on a self-equilibrated periodic solution): print( "Lagrange multipliers: ", [pb.get_dof_solution(name)[0] for name in ("MeanValue_DispX", "MeanValue_DispY")], ) pb.get_results(assemb, ["Stress", "Disp"]).plot("Stress", "XX") .. image-sg:: /examples/boundary_conditions/images/sphx_glr_periodic_bc_mean_disp_constraint_001.png :alt: periodic bc mean disp constraint :srcset: /examples/boundary_conditions/images/sphx_glr_periodic_bc_mean_disp_constraint_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Mean stress, Voigt vector ([Sxx, Syy, Sxy]): [[ 7.888e+03] [ 2.253e+03] [-1.061e-13]] Mean displacement: [-1.292e-16 0.000e+00] Lagrange multipliers: [np.float64(-1.4527895721721947e-09), np.float64(1.8364084269405725e-09)] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.332 seconds) .. _sphx_glr_download_examples_boundary_conditions_periodic_bc_mean_disp_constraint.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_mean_disp_constraint.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: periodic_bc_mean_disp_constraint.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: periodic_bc_mean_disp_constraint.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_