Advances in Computational Mathematics

, Volume 45, Issue 4, pp 1897–1921 | Cite as

Multiscale finite element calculations in Python using SfePy

  • Robert CimrmanEmail author
  • Vladimír Lukeš
  • Eduard Rohan


SfePy (simple finite elements in Python) is a software for solving various kinds of problems described by partial differential equations in one, two, or three spatial dimensions by the finite element method. Its source code is mostly (85%) Python and relies on fast vectorized operations provided by the NumPy package. For a particular problem, two interfaces can be used: a declarative application programming interface (API), where problem description/definition files (Python modules) are used to define a calculation, and an imperative API, that can be used for interactive commands, or in scripts and libraries. After outlining the SfePy package development, the paper introduces its implementation, structure, and general features. The components for defining a partial differential equation are described using an example of a simple heat conduction problem. Specifically, the declarative API of SfePy is presented in the example. To illustrate one of SfePy’s main assets, the framework for implementing complex multiscale models based on the theory of homogenization, an example of a two-scale piezoelastic model is presented, showing both the mathematical description of the problem and the corresponding code.


Finite element method Multiscale simulations Piezoelasticity SfePy Python 

Mathematics Subject Classification (2010)

35Qxx 65N30 65M60 65Y05 74S05 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


Funding information

This work was supported by the projects GA17-12925S (the first author) and GA19-04956S (the second author) of the Czech Science Foundation and by the project LO1506 of the Czech Ministry of Education, Youth and Sports (the third author).


  1. 1.
    Abdulle, A., Nonnenmacher, A.: A short and versatile finite element multiscale code for homogenization problems. Comput. Methods Appl. Mech. Eng. 198(37), 2839–2859 (2009). MathSciNetCrossRefzbMATHGoogle Scholar
  2. 2.
    Allaire, G.: Homogenization and two-scale convergence. SIAM J. Math. Anal. 23, 1482–1518 (1992). MathSciNetCrossRefzbMATHGoogle Scholar
  3. 3.
    Alnaes, M.S., Blechta, J., Hake, J., Johansson, A., Kehlet, B., Logg, A., Richardson, C., Ring, J., Rognes, M.E., Wells, G.N.: The FEniCS project version 1.5. Arch. Numer. Softw. 3, 9–23. (2015)
  4. 4.
    Alowayyed, S., Groen, D., Coveney, P.V., Hoekstra, A.G.: Multiscale computing in the exascale era. J. Comput. Sci. 22, 15–25 (2017). CrossRefGoogle Scholar
  5. 5.
    Amaya, M., Morten, J.P., Boman, L.: A low-rank approximation for large-scale 3D controlled-source electromagnetic gauss-newton inversion. Geophysics 81(3), 211–225. (2016)
  6. 6.
    Balay, S., Abhyankar, S., Adams, M., Brown, J., Brune, P., Buschelman, K., Dalcin, L., Dener, A., Eijkhout, V., Gropp, W., Kaushik, D., Knepley, M., May, D., Curfman McInnes, L., Mills, R., Munson, T., Rupp, K., Sanan, P., Smith, B., Zampini, S., Zhang, H., Zhang, H.: PETSc users manual. Tech. Rep. ANL-95/11 - Revision 3.10, Argonne National Laboratory., accessed 25 September 2018 (2018)
  7. 7.
    Balzani, D., Gandhi, A., Klawonn, A., Lanser, M., Rheinbach, O., Schröder, J: One-way and fully-coupled FE2 methods for heterogeneous elasticity and plasticity problems: parallel scalability and an application to thermo-elastoplasticity of dual-phase steels. In: Bungartz, H.J., Neumann, P., Nagel, W.E. (eds.) Software for Exascale Computing - SPPEXA 2013-2015, Springer International Publishing, Lecture Notes in Computational Science and Engineering, pp 91–112 (2016)Google Scholar
  8. 8.
    Borden, M.J., Scott, M.A., Evans, J.A., Hughes, T.J.R.: Isogeometric finite element data structures based on Bezier extraction of NURBS. Int. J. Numer. Meth. Eng. 87, 15–47 (2011). CrossRefzbMATHGoogle Scholar
  9. 9.
    Borgdorff, J., Mamonski, M., Bosak, B., Kurowski, K., Ben Belgacem, M., Chopard, B., Groen, D., Coveney, P.V., Hoekstra, A.G.: Distributed multiscale computing with muscle 2, the multiscale coupling library and environment. J. Comput. Sci. 5(5), 719–731 (2014). CrossRefGoogle Scholar
  10. 10.
    Bradshaw, R., Behnel, S., Seljebotn, D.S., Ewing, G., et al.: The Cython compiler., Accessed 25 September 2018 (2018)
  11. 11.
    Brough, D.B., Wheeler, D., Kalidindi, S.R.: Materials knowledge systems in python—a data science framework for accelerated development of hierarchical materials. Integ. Mater. Manuf. Innov. 6(1), 36–53 (2017). CrossRefGoogle Scholar
  12. 12.
    Chopard, B., Borgdorff, J., Hoekstra, A.G.: A framework for multi-scale modelling. Philos. Trans. R. Soc. A Math. Phys. Eng. Sci. 372(2021), 20130378 (2014). CrossRefGoogle Scholar
  13. 13.
    Cimrman, R.: Enhancing sfepy with isogeometric analysis. arXiv: (2014)
  14. 14.
    Cimrman, R., Lukeš, V.: SfePy 2018.3 sources and heat conduction examples demonstrating declarative and imperative APIs of SfePy. (2018)
  15. 15.
    Cimrman, R., Rohan, E.: On modelling the parallel diffusion flow in deforming porous media. Math. Comput. Simul. 76(1–3), 34–43 (2007). MathSciNetCrossRefzbMATHGoogle Scholar
  16. 16.
    Cimrman, R., Rohan, E.: Two-scale modeling of tissue perfusion problem using homogenization of dual porous media. Int. J. Multiscale. Com. 8(1), 81–102 (2010). CrossRefGoogle Scholar
  17. 17.
    Cimrman, R., Novák, M., Kolman, R., Tůma, M., Plešek, P., Vackář, J.: Convergence study of isogeometric analysis based on Bézier extraction in electronic structure calculations. Appl. Math. Comput. 319, 138–152 (2018a). MathSciNetzbMATHGoogle Scholar
  18. 18.
    Cimrman, R., Novák, M., Kolman, R., Tůma, M., Vackář, J.: Isogeometric analysis in electronic structure calculations. Math. Comput. Simulat. 145, 125–135 (2018b). MathSciNetCrossRefzbMATHGoogle Scholar
  19. 19.
    Cioranescu, D., Donato, P.: An introduction to homogenization. No. 17 in Oxford Lecture Series in mathematics and its applications. Oxford University Press, Oxford (1999)Google Scholar
  20. 20.
    Cioranescu, D., Damlamian, A., Griso, G.: The periodic unfolding method in homogenization. SIAM J. Math. Anal. 40(4), 1585–1620 (2008). MathSciNetCrossRefzbMATHGoogle Scholar
  21. 21.
    Cottrell, J.A., Hughes, T.J.R., Bazilevs, Y.: Isogeometric analysis: toward integration of CAD and FEA. New York, Wiley (2009)CrossRefzbMATHGoogle Scholar
  22. 22.
    Dalcin, L., Paz, R., Kler, P., Cosimo, A.: Parallel distributed computing using Python. Adv. Water Resour. 34(9), 1124–1139 (2011a). CrossRefGoogle Scholar
  23. 23.
    Dalcin, L., Collier, N., Vignal, P., Cortes, A., Calo, V.: Petiga: a framework for high-performance isogeometric analysis. Comput. Method Appl. M, 308(C), 151–181. (2016)
  24. 24.
    Dalcin, L.D., Paz, R.R., Kler, P.A., Cosimo, A.: Parallel distributed computing using Python. Adv. Water Resour. 34(9), 1124–1139 (2011b). CrossRefGoogle Scholar
  25. 25.
    Davis, T.A.: Algorithm 832: UMFPACK, an unsymmetric-pattern multifrontal method. ACM T Math. Softw. 30(2), 196–199 (2004). MathSciNetCrossRefzbMATHGoogle Scholar
  26. 26.
    Falcone, J.L., Chopard, B., Hoekstra, A.: MML: towards a multiscale modeling language. Procedia Comput. Sci. 1(1), 819–826 (2010). CrossRefGoogle Scholar
  27. 27.
    Geers, M.G.D., Kouznetsova, V.G., Matouš, K., Yvonnet, J.: Homogenization Methods and Multiscale Modeling: Nonlinear Problems, Wiley, Ltd, p. 1–34. (2017)
  28. 28.
    Geus, R., Wheeler, D., Orban, D.: Pysparse documentation., Accessed 25 September 2018 (2018)
  29. 29.
    de Geus, T.W.J., Vondřejc, J., Zeman, J., Peerlings, R.H.J., Geers, M.G.D.: Finite strain fft-based non-linear solvers made simple. Comput. Methods Appl. Mech. Eng. 318, 412–430 (2017). MathSciNetCrossRefGoogle Scholar
  30. 30.
    git: The git project web site., Accessed 25 September 2018 (2018)
  31. 31.
    github: Github web site., Accessed 25 September 2018 (2018)
  32. 32.
    Group TH: Hierarchical data format version 5., Accessed 25 September 2018 (2018)
  33. 33.
    Henderson, A.: ParaView guide, a parallel visualization application. Kitware Inc, New York (2007)Google Scholar
  34. 34.
    Hunter, J.D.: Matplotlib: A 2D graphics environment. Comput. Sci. Eng. 9 (3), 90–95 (2007). CrossRefGoogle Scholar
  35. 35.
    Jones, E., Oliphant, T.E., Peterson, P., et al.: SciPy: open source scientific tools for Python., Accessed 25 September 2018 (2018)
  36. 36.
    Kitware, Inc: The Visualization Toolkit User’s Guide. Kitware, Inc. Publishers., iSBN 1-930934-18-1 (2010)Google Scholar
  37. 37.
    Kochová, P., Cimrman, R., Stengl, M., Ošťádal, B., Tonar, Z.: A mathematical model of the carp heart ventricle during the cardiac cycle. J. Theor. Bio. 373, 12–25 (2015). MathSciNetCrossRefzbMATHGoogle Scholar
  38. 38.
    Kondov, I., Surmann, G. (eds.): Multiscale modelling methods for applications in materials science: CECAM tutorial, 16 - 20 September 2013, Forschungszentrum Jülich; lecture notes. Schriften des Forschungszentrums Jülich IAS series, Forschungszentrum, Zentralbibliothek (2013)Google Scholar
  39. 39.
    Logg, A.: Efficient representation of computational meshes. Int. J. Comput. Sci. Eng. 4(4), 283–295 (2009). Google Scholar
  40. 40.
    Matouš, K., Geers, M.G., Kouznetsova, V.G., Gillman, A.: A review of predictive nonlinear theories for multiscale modeling of heterogeneous materials. J. Comput. Phys. 330, 192–220 (2017). MathSciNetCrossRefGoogle Scholar
  41. 41.
    Meurer, A., Smith, C.P., Paprocki, M., Čertík, O., Kirpichev, S.B., Rocklin, M., Kumar, A., Ivanov, S., Moore, J.K., Singh, S., Rathnayake, T., Vig, S., Granger, B.E., Muller, R.P., Bonazzi, F., Gupta, H., Vats, S., Johansson, F., Pedregosa, F., Curry, M.J., Terrel, A.R., Roučka, Š., Saboo, A., Fernando, I., Kulal, S., Cimrman, R., Scopatz, A.: Sympy: symbolic computing in Python. Peer J. Comput. Sci. 3, e103 (2017). CrossRefGoogle Scholar
  42. 42.
    Miller, R.E., Tadmor, E.B.: A unified framework and performance benchmark of fourteen multiscale atomistic/continuum coupling methods. Model. Simul. Mater. Sci. Eng. 17(5), 053001 (2009). CrossRefGoogle Scholar
  43. 43.
    Mosby, M., Matouš, K.: Hierarchically parallel coupled finite strain multiscale solver for modeling heterogeneous layers: hierarchically parallel multiscale solver. Int. J. Numer. Methods Eng. 102(3–4), 748–765 (2015). CrossRefzbMATHGoogle Scholar
  44. 44.
    Moulinec, H., Suquet, P.: A fast numerical method for computing the linear and nonlinear mechanical properties of composites. Comptes Rendus de l’Académie des Sciences 318(11), 1417–1423 (1994). série II, Mécanique, physique, chimie, astronomiezbMATHGoogle Scholar
  45. 45.
    Muntean, A., Chalupecky, V.: Homogenization Method and Multiscale Modeling MI Lecture Note Series, Faculty of Mathematics, Kyushu University (2011)Google Scholar
  46. 46.
    Oliphant, T.E.: Python for scientific computing. Comput. Sci. Eng. 9(3), 10–20 (2007)CrossRefGoogle Scholar
  47. 47.
    Patzák, B., Rypl, D., Kruis, J.: Mupif – a distributed multi-physics integration tool. Adv. Eng. Softw. 60–61, 89–97 (2013). CrossRefGoogle Scholar
  48. 48.
    pytables: Pytables web site., Accessed 25 September 2018 (2018)
  49. 49.
    Ramachandran, P., Varoquaux, G.: Mayavi: 3d visualization of scientific data. Comput. Sci. Eng. 13(2), 40–51 (2011). CrossRefGoogle Scholar
  50. 50.
    Rathgeber, F., Ham, D., Mitchell, L., Lange, M., Luporini, F., Mcrae, A., Bercea, G.T., Markall, G., Kelly, P.: Firedrake: automating the finite element method by composing abstractions. ACM T Math. Softw. 43(3), 24:1–24:27 (2016). MathSciNetCrossRefzbMATHGoogle Scholar
  51. 51.
    Rohan, E., Cimrman, R.: Multiscale FE simulation of diffusion-deformation processes in homogenized dual-porous media. Math Comput. Simul. 82 (10), 1744–1772 (2012). MathSciNetCrossRefzbMATHGoogle Scholar
  52. 52.
    Rohan, E., Lukeš, V.: Homogenization of the vibro–acoustic transmission on perforated plates. arXiv: [physics.comp-ph] (2019)
  53. 53.
    Rohan, E., Lukeš, V.: Homogenization of the acoustic transmission through a perforated layer. J. Comput. Appl. Math 234(6), 1876–1885 (2010). MathSciNetCrossRefzbMATHGoogle Scholar
  54. 54.
    Rohan, E., Lukeš, V.: Homogenization of the fluid-saturated piezoelectric porous media. Int. J. Solids Struct. 147, 110–125 (2018). CrossRefGoogle Scholar
  55. 55.
    Rohan, E., Miara, B.: Band gaps and vibration of strongly heterogeneous Reissner-Mindlin elastic plates. C R Math 349(13–14), 777–781 (2011). MathSciNetCrossRefzbMATHGoogle Scholar
  56. 56.
    Rohan, E., Cimrman, R., Lukeš, V.: Numerical modelling and homogenized constitutive law of large deforming fluid saturated heterogeneous solids. Comput. Struct. 84(17–18), 1095–1114 (2006). MathSciNetCrossRefGoogle Scholar
  57. 57.
    Rohan, E., Cimrman, R., Naili, S., Lemaire, T.: Multiscale modelling of compact bone based on homogenization of double porous medium. In: Computational plasticity x - fundamentals and applications (2009a)Google Scholar
  58. 58.
    Rohan, E., Miara, B., Seifrt, F.: Numerical simulation of acoustic band gaps in homogenized elastic composites. Int. J. Eng. Sci. 47(4), 573–594 (2009b). CrossRefzbMATHGoogle Scholar
  59. 59.
    Rohan, E., Naili, S., Cimrman, R., Lemaire, T.: Hierarchical homogenization of fluid saturated porous solid with multiple porosity scales. C R Mecanique 340(10), 688–694 (2012a). CrossRefGoogle Scholar
  60. 60.
    Rohan, E., Naili, S., Cimrman, R., Lemaire, T.: Multiscale modeling of a fluid saturated medium with double porosity: relevance to the compact bone. J. Mech. Phys. Solids 60(5), 857–881 (2012b). MathSciNetCrossRefGoogle Scholar
  61. 61.
    Schneider, M., Ospald, F., Kabel, M.: Computational homogenization of elasticity on a staggered grid. Int. J. Numer. Methods Eng. 105(9), 693–720 (2016). MathSciNetCrossRefGoogle Scholar
  62. 62.
    scikit-umfpack: skikit-umfpack web site., Accessed 25 September 2018 (2018)
  63. 63.
    sfepy: The SfePy project web site., Accessed 25 September 2018 (2018)
  64. 64.
    Solin, P., Segeth, K., Dolezel, I.: Higher-order finite element methods. CRC Press, Boca Raton (2003)CrossRefGoogle Scholar
  65. 65.
    sphinx: Sphinx web site., Accessed 25 September 2018 (2018)
  66. 66.
    Talebi, H., Silani, M., Bordas, S.P.A., Kerfriden, P., Rabczuk, T.: A computational library for multiscale modeling of material failure. Comput. Mech. 53(5), 1047–1071 (2014). MathSciNetCrossRefGoogle Scholar
  67. 67.
    travis-ci: Travis-ci web site., Accessed 25 September 2018 (2018)
  68. 68.
    Vackář, J., Čertík, O., Cimrman, R., Novák, M., Šipr, O., Plešek, J.: Advances in the Theory of Quantum Systems in Chemistry and Physics. Prog. T. Chem, vol. 22, Springer, chap Finite Element Method in Density Functional Theory Electronic Structure Calculations, pp. 199–217. (2011)
  69. 69.
    Wang, K., Sun, W.: A multiscale multi-permeability poroplasticity model linked by recursive homogenizations and deep learning. Comput. Methods Appl. Mech. Eng. 334, 337–380 (2018). MathSciNetCrossRefGoogle Scholar
  70. 70.
    Weinan, E., Engquist, B.: The heterogeneous multi-scale method for homogenization problems. In: Engquist, B., Runborg, O., Lötstedt, P. (eds.) Multiscale Methods in Science and Engineering, Springer Berlin Heidelberg, Lecture Notes in Computational Science and Engineering, pp 89–110 (2005)Google Scholar
  71. 71.
    Wheeler, D., Brough, D., Fast, T., Kalidindi, S., Reid, A.: PYMKS: materials knowledge system in Python. (2014)
  72. 72.
    Wu, B., Du, X., Tan, H.: A three-dimensional FE nonlinear analysis of membranes. Comput. Struct. 59(4), 601–605 (1996). CrossRefzbMATHGoogle Scholar
  73. 73.
    Zeman, J., de Geus, T.W.J., Vondřejc, J., Peerlings, R.H.J., Geers, M.G.D.: A finite element perspective on nonlinear FFT-based micromechanical simulations. Int. J. Numer. Methods Eng. 111(10), 903–926 (2017). MathSciNetCrossRefGoogle Scholar
  74. 74.
    Zemčík, R., Rolfes, R., Rose, M., Tessmer, J.: High-performance 4-node shell element with piezoelectric coupling. Mech. Adv. Mater Struct. 13 (5), 393–401 (2006). CrossRefzbMATHGoogle Scholar

Copyright information

© Springer Science+Business Media, LLC, part of Springer Nature 2019

Authors and Affiliations

  1. 1.New Technologies - Research CentreUniversity of West BohemiaPilsenCzech Republic
  2. 2.NTIS – New Technologies for the Information Society, Faculty of Applied SciencesUniversity of West BohemiaPilsenCzech Republic

Personalised recommendations