Code Monkey home page Code Monkey logo

florence's Introduction

Build Status Coverage Status

Florence is a Python-based computational framework for the numerical simulations of multi-physics problems using the finite element methods.

Features

A non-exhaustive list of core features:

  • High order planar and curved finite and boundary elements (line, tri, quad, tet, hex)
  • In-built CAD-conformal curvilinear mesh generator
  • Powerful in-built pre and post processor with the ability to visualise high order curved meshes
  • Poisson, electrostatic and heat transfer solvers
  • Linear, geometrically linearised and fully nonlinear solid/structural mechanics solvers
  • Linear, geometrically linearised and fully nonlinear electromechanics solvers
  • Implicit and explicit dynamic solvers with contact formulation
  • Generic monolithic, staggered and multigrid solvers for coupled multiphysics driven problems
  • Strain gradient and micropolar elasticity and electro-elasticty solvers
  • A suite of advanced hyperelastic, electrostatic and electro-hyperelastic material models
  • Ability to read/write mesh/simulation data to/from gmsh, Salome, GID, Tetgen, obj, FRO, VTK and HDF5
  • Support for heterogeneous computing using SIMD, shared parallelism, cloud-based parallelism and cluster-based parallelism
  • Interfaces to a suite of sparse direct and iterative solvers including MUMPS, Pardiso, Petsc and hypre

In addition, the framework also provides Python interfaces to many low-level numerical subroutines written in C, C++ and Cython.

Platform support

Florence supports all major operating systems including Linux, macOS and Windows (under Cygwin/MinGW) under

  • Python 2.7
  • Python >= 3.5
  • PyPy >= v5.7.0

Dependencies

The following packages are hard dependencies

  • Fastor: Data parallel (SIMD) FEM assembler
  • cython
  • numpy
  • scipy

The following packages are optional (but recommended) dependencies

  • PostMesh: High order curvilinear mesh generator
  • pyevtk
  • matplotlib
  • mayavi
  • scikit-umfpack
  • pyamg
  • psutil
  • h5py

In addition, it is recommended to have an optimised BLAS library such as OpenBLAS or MKL installed and configured on your machine.

Installation

The easy way

using pip

pip install Florence

For pip installation to work you need to have Fastor installed. You can achieve this by

cd ~
git clone https://github.com/romeric/Fastor
mv Fastor/ /usr/local/include/Fastor/

It is also a good practice to set your compilers before pip installing florence

export CC=/path/to/c/compiler
export CXX=/path/to/c++/compiler

Building from source

Have a look at travis.yml file for directions on installing florence's core library. First install cython, numpy and scipy. Download Fastor headers and place them under their default location /usr/local/include/Fastor

cd ~
git clone https://github.com/romeric/Fastor
mv Fastor/ /usr/local/include/Fastor/

Then installation of the core library is as easy as

git clone https://github.com/romeric/florence
cd florence
python setup.py build
export PYTHONPATH="/path/to/florence:$PYTHONPATH"

This builds many low-level cython modules, ahead of time. Options can be given to setup.py for instance

python setup.py build BLAS=mkl CXX=/usr/local/bin/g++ CC=~/LLVM/clang

By default, florence builds in parallel using all the machine's CPU cores. To limit the build process to a specific number of cores, use the np flag for instance, for serial build one can trigger the build process as

python setup.py build np=1

Configuring MUMPS direct sparse solver

Florence can automatically switch to MUMPS sparse direct solver if available. To install MUMPS, the easiest way is to use homebrew on macOS and linuxbrew on linux:

brew install mumps --without-mpi --with-openblas
git clone https://github.com/romeric/MUMPS.py
cd MUMPS.py
python setup.py build
python setup.py install

And whenever MUMPS solver is needed, just open a new terminal window/tab and do (this is the default setting for linuxbrew)

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/linuxbrew/.linuxbrew/lib

Configuring Pardiso direct sparse solver

The direct sparse solver shipped with MKL, Pardiso can be used if MKL is available. Both Anaconda and Intel distribution for python ship these. If MKL is installed, the low-level FEM assembler in florence is also automatically linked to it during compilation, as long as "BLAS=mkl" flag is issued to setup.py.

conda install -c haasad pypardiso

We typically do not recommed adding anaconda/bin to your path. Hence, whenever MKL features or Pardiso solver is needed, just open a new terminal window/tab and type

export PATH="/path/to/anaconda2/bin:$PATH"

Philosophy

Florence follows scipy's philosophy of providing a high level pythonic interface to finite element analysis of partial differential equations. It is a light weight library that depends only on the most ubiquitous python packages namely numpy, scipy and cython. Yet it is aimed to deliver high performance numerical computations on a range modern architectures. It is backend is designed to be configurable for plugging new solvers such as Petsc's and hypre's parallel solvers.

Documentation

Documentation is available under wiki pages. Furthermore, a series of well explained examples are provided in the example folder that cover most of the functionality of florence.

To get a quick taste of Florence, let us consider the Laplacian for example. Setting up and solving the Laplace equation using fourth order hexahedral Lagrange shape functions over a cube is as simple as

import numpy as np
from Florence import *


def simple_laplace():
    """An example of solving the Laplace equation using
        fourth order hexahedral elements on a cube
    """

    # generate a linear hexahedral mesh on a cube
    mesh = Mesh()
    mesh.Cube(element_type="hex", nx=6, ny=6, nz=6)
    # generate the corresponding fourth order mesh
    mesh.GetHighOrderMesh(p=4)

    # set up boundary conditions
    def dirichlet_function(mesh):
        # create boundary flags - nan values would be treated as free boundary
        boundary_data = np.zeros(mesh.nnode)+np.NAN
        # potential at left (Y=0)
        Y_0 = np.isclose(mesh.points[:,1],0)
        boundary_data[Y_0] = 0.
        # potential at right (Y=1)
        Y_1 = np.isclose(mesh.points[:,1],mesh.points[:,1].max())
        boundary_data[Y_1] = 10.

        return boundary_data

    boundary_condition = BoundaryCondition()
    boundary_condition.SetDirichletCriteria(dirichlet_function, mesh)

    # set up material
    material = IdealDielectric(mesh.InferSpatialDimension(), eps=2.35)
    # set up variational form
    formulation = LaplacianFormulation(mesh)
    # set up solver
    fem_solver = FEMSolver(optimise=True)
    # solve
    results = fem_solver.Solve( boundary_condition=boundary_condition,
                                material=material,
                                formulation=formulation,
                                mesh=mesh)

    # write results to vtk file
    results.WriteVTK("laplacian_results")


if __name__ == "__main__":
    simple_laplace()

florence's People

Contributors

dancergraham avatar romeric avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

florence's Issues

No module named 'Florence.FunctionSpace.JacobiPolynomials.JacobiPolynomials'

Hi,

I have successfully installed the florence package (which means no error message showed up during the installation :) )

I tried to import the package and error message showed up:

No module named 'Florence.FunctionSpace.JacobiPolynomials.JacobiPolynomials'

I have checked the installation directory and all files and folders seem to be there,

Under the florence folder:

Base FiniteElements MaterialLibrary PostProcessing Tensor VariationalPrinciple BoundaryCondition FunctionSpace MeshGeneration QuadratureRules TimeIntegrators __init__.py BoundaryElements LegendreTransform ParallelProcessing Solver Utils __pycache__

under the functionsapce folder:

DegenerateMappings.py GetBases.py OneDimensional ThreeDimensional __init__.py FunctionSpace.py JacobiPolynomials PointInversionIsoparametricFEM.py TwoDimensional __pycache__

Under the JacobiPolynomials folder:

JacobiPolynomials.pyx JacobiPolynomials_PurePython.py Makefile NormalisedJacobi_Deprecated.py __init__.py __pycache__

Not sure what cause the issue.

Thanks in advance for checking this out.

ModuleNotFoundError: No module named 'Florence.VariationalPrinciple.DisplacementApproachIndices'

After easy install with pip (All the dependencies have been installed except PostMesh) the execution of " from Florence import * " provides an error:

File "/home/user/anaconda3/lib/python3.7/site-packages/Florence/init.py", line 6, in
from .VariationalPrinciple import *
File "/home/user/anaconda3/lib/python3.7/site-packages/Florence/VariationalPrinciple/init.py", line 1, in
from .VariationalPrinciple import *
File "/home/user/anaconda3/lib/python3.7/site-packages/Florence/VariationalPrinciple/VariationalPrinciple.py", line 5, in
from .DisplacementApproachIndices import FillGeometricB
ModuleNotFoundError: No module named 'Florence.VariationalPrinciple.DisplacementApproachIndices'

Proper error diagnostic for material models

Material models at the moment do not raise any errors when incorrect material parameters are passed to them. This makes it difficult for new users to understand which constants are required for a material model. Specially the low level version of the material crashes with very unhelpful messages.

There are two conceivable ways at the moment for fixing this.

  1. Call the Hessian of the material before the start of the analysis with dummy values to check if it crashes, for instance for most materials this will be of the form:
    F = np.random.rand(1,material.ndim,material.ndim)
    E = np.random.rand(material.ndim)
    material.Hessian(KinematicMeasures(F,analysis_nature),E)

This still gives very unhelpful error message. Alternatively, if we wrap this within a try and catch we lose the info on material constant was exactly missing (in case there are many of them). Or in case something else goes wrong, it is corresponding error will not be shown, perhaps.

  1. Scan the whole content of the candidate material file and find the keyword self.<constant> potentially after filtering unnecessary self attributes. Something like
    with open(material.mtype+".py") as f:
        lines = f.readlines()

    counter = None
    for i, line in enumerate(lines):
        if "def Hessian" in line:
            counter = i
            break
        elif "def Permittivity" in line:
            counter = i
            break

    line_container = []
    for i, line in enumerate(lines):
        if "self." in line and i>counter:
            line_container.append(line)

    parameters_container = []
    for line in line_container:
        line = line.rstrip().split()
        for token in line:
            if "self." in token:
                parameters_container.append(token)

     # process parameters_container further

This technique requires special cases for different formulations as a material may not have methods Hessian or Permittivity defined or use another method where an extra constant is used there. It is an ugly fix and not very programatic.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.