Skip to main content

Package PyFreeFEM for interfacing Python and FreeFEM.

Project description

PyFreeFEM

PyFreeFEM is a python package interfacing FreeFEM scripts with Python. .edp scripts become small modules that can be used as building blocks of a main python project.

PyFreeFEM is different from the alternative pyFreeFEM module from Olivier Devauchelle, which has been developped rather simultaneously for similar purposes.

Official documentation

Features

PyFreeFEM has the following capabilities:

  • Running FreeFEM .edp scripts that support python input parameters:

    from pyfreefem import FreeFemRunner   
    FreeFemRunner("script.edp").execute({'f':'x+1','N':10, 'THREEDIM':0})
    
  • Executing portions of .edp scripts conditionally to python input parameters by using special preprocessing instructions:

    DEFAULT (THREEDIM,0)    
    
    IF THREEDIM    
    mesh3 Th=cube($N,$N,$N);
    ELSE   
    mesh Th=square($N,$N);
    ENDIF
    
  • Automated imports and exports of data structures (floats, arrays, matrices, meshes) from FreeFEM to Python and vice-versa:

    from pyfreefem import FreeFemRunner   
    
    fem_matrix=""" 
    IMPORT "io.edp"
    mesh Th=square($N,$N); 
    fespace Fh1(Th,P1);    
    varf laplace(u,v)=int2d(Th)(dx(u)*dx(v)+dy(u)*dy(v));  
    matrix A = laplace(Fh1,Fh1,tgv=-2);    
    
    exportMatrix(A);"""    
    
    #Get the sparse matrix (scipy csc_matrix format) A:    
    runner = FreeFemRunner(fem_matrix)
    exports = runner.execute({'N':100}) 
    A = exports['A']
    print('A=\n',A.todense())
    
  • Flexible debugging and capturing of FreeFEM standard output: running the previous script with

    runner = FreeFemRunner(fem_matrix,debug=10)
    exports = runner.execute({'N':100},verbosity=0) 
    

    yields the following output:

    $ python test.py 
    Write /tmp/pyfreefem_xsd1x5dw/run.edp
    Reset directory /tmp/pyfreefem_xsd1x5dw/ffexport
    FreeFem++ /tmp/pyfreefem_xsd1x5dw/run.edp -v 0 -nw
    Saved /tmp/pyfreefem_xsd1x5dw/ffexport/matrix_A
    Finished in (0.06s)
    A=
     [[ 1.  -0.5  0.  ...  0.   0.   0. ]
     [-0.5  2.  -0.5 ...  0.   0.   0. ]
     [ 0.  -0.5  2.  ...  0.   0.   0. ]
     ...
     [ 0.   0.   0.  ...  2.  -0.5  0. ]
     [ 0.   0.   0.  ... -0.5  2.  -0.5]
     [ 0.   0.   0.  ...  0.  -0.5  1. ]]
    

Contribute and support

If I am not responding on the issue tracker, feel free to send me an email to florian.feppon[at]kuleuven.be

Citation

Please cite the following reference when using this package:

FEPPON, Florian. Shape and topology optimization of multiphysics systems. 2019. Université Paris-Saclay. Thèse préparée à l'École polytechnique.

@phdthesis{feppon2020,
   author = {Feppon, Florian},
   title =  {Shape and topology optimization of multiphysics systems},
   school = {Th\`{e}se de doctorat de l'Universit'{e} Paris-Saclay pr'{e}par'{e}e
      \`a l''{E}cole polytechnique},
   year = {2019}
}

Licence

PyFreeFEM is a free software distributed under the terms of the GNU General Public Licence GPL3.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfreefem-1.1.3.tar.gz (42.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfreefem-1.1.3-py3-none-any.whl (53.7 kB view details)

Uploaded Python 3

File details

Details for the file pyfreefem-1.1.3.tar.gz.

File metadata

  • Download URL: pyfreefem-1.1.3.tar.gz
  • Upload date:
  • Size: 42.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pyfreefem-1.1.3.tar.gz
Algorithm Hash digest
SHA256 df3048ff5e8258929c8849a49c26f2317a092b8fdcb78bb8e7e61dca8957db0b
MD5 e3d6940aeac2491fda6116604c2defa6
BLAKE2b-256 bf4e813f6ea8317642010b82a3a06dab03912c3890f078fe42a50e9080961214

See more details on using hashes here.

File details

Details for the file pyfreefem-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: pyfreefem-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 53.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pyfreefem-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 88525cf2e6a2858c791dcf00a70c745d1bf820622c6364c60ccdd4399e1dfe7e
MD5 d062bbfb07f80f1543b421f2d66ca7a0
BLAKE2b-256 db61c1834d298e1a7284d79ae48183bc50d918bbbed87bf95e2286be72ef744c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page