Code Monkey home page Code Monkey logo

ddfenics's Introduction

DDFenics

A (model-free) Data-driven implementation based on fenics (https://github.com/felipefr/ddfenics).

Getting started

Tutorials DDFenics

Aim: Solve a simple 2D bar problem using standard Fenics and DDFenics.

    1. 2D bar (linear elastic) in FEniCs: tutorial/linear/main_bar.ipynb
    1. 2D bar (linear elastic) in DDFenics (Hands-on): tutorial/linear/main_bar_dd_to_fill.ipynb
    • Complete the "missing lines" (commented in the notebook)
    • Plot the convergence (with data) curves
    • Run the sanity-check (last block of notebook) and redo DDCM
    • Change C = some isotropic elastic tensor (hookean) for changed (E', nu') ?
    1. 2D bar (nonlinear elastic) in FEniCs: tutorial/nonlinear/main_bar_nonlinear.ipynb
    1. 2D bar (nonlinear elastic) in DDFenics: tutorial/nonlinear/main_bar_nonlinear_dd.ipynb

Installation

Please run the steps below (subsection Steps) that installs the requirements (listed in subsection Requirements).

Steps:

  • Download the install.sh script
  • Change the initial paths accordingly to your system/preferences
  • run: sh install.sh 1
  • activate the conda environment: conda activate <ddfenics_environment>
  • run: sh install.sh 2
  • launch jupyter: jupyter-lab in the desired parent folder

Obs: You can run step by step the bash script in order to have full control of eventual errors in the installation.

Obs: Note that the script automatically add into the PYTHONPATH the root directory in which you cloned DDFenics. This is done by adding a .pth file (any name) with a list of directories in ~/miniconda3/envs/ddfenics/lib/python3.8/site-packages. You can also add the directories ''by hand'' in spyder (Tools > PYTHONPATH) or sys.path.insert(..., '...folder...') in your source files.

Obs: Command to convert python notebooks to python files (if you prefer not use jupyter-lab): jupyter nbconvert --to script file.ipynb

Requirements

DDFenics relies on the following libraries/packages (some others are installed automatically altogether with the principal ones):

  • library / version
  • python / 3.8 (conda-forge)
  • fenics / 2019.1.0 (conda-forge)
  • scikit-learn / latest or no restriction (conda-forge)
  • matplotlib / latest or no restriction (conda-forge)

Optionally for mesh generation and postprocessing (with Paraview):

  • library / version
  • h5py / 2.10.0 (conda-forge)
  • meshio / 3.3.1 (pypi)
  • pygmsh / 6.0.2 (pypi)
  • gmsh / 4.6.0 (pypi)

Optionally for an interactive run of the tutorial:

  • library / version
  • jupyterlab / latest or no restriction (conda-forge)
  • ipykernel / latest or no restriction (conda-forge)

Obs: the default repository is conda-forge, otherwise pypi from pip. Recommended versions should be understood only as guideline and sometimes the very same version is not indeed mandatory.

Obs: We included in the "external" folder a lite version of fetricks (https://github.com/felipefr/fetricks), that implements some auxiliary routines for computational mechanics using fenics. However, you can decide to use your own functions for this job.

Obs: We recommend the use of miniconda (https://docs.conda.io/en/latest/miniconda.html) or your preferred Anaconda-like variants.

Obs: For Windows users, unfortunately Fenics is not available in the Anaconda repositories for Windows. As alternative, we recommend: i) to use the the Linux (Ubuntu) subsystem (https://learn.microsoft.com/en-us/windows/wsl/install) and use the instructions as below; ii) set some virtual machine (e.g. Virtual Box) or iii) use the Docker version of Fenics (not tested!) (https://fenicsproject.org/download/archive/).

Documentation

  1. Map between Galerkin-like variational approximation and FEniCs objects. FenicsContinuum

  2. Map between FEniCs and the corresponding objects in DDFenics. FenicsDDFenics

  3. Map between (Model-free) Data-driven formulation and the corresponding objects in DDFenics. DDFenics

Basic Usage (a little deprecated)

The usage mimetises the basic framework of fenics by defining Data-driven equivalents of the LinearVariationalProblem and LinearVariationalSolver objects (see https://fenicsproject.org/pub/tutorial/html/._ftut1018.html), respectively DDProblem and DDSolver. Additionally the DDProblem object depends on a Data-driven material, which is defined by an instance of a DDMaterial. The output of the DD solver also contains the mechanical and neighrest projections (in the material database) states, which are instances of DDFunction (just a derived class of the dolfin Function to facilitate some needed domain-specific operations )

Fenics

  1. Definition of standard constitutive equations.
  2. Definition of mesh, FE spaces, boundary conditions, variational forms, etc.
  3. Variational problem definition: problem = LinearVariationalProblem(a, b, uh, bcs)
  4. Solver definition: solver = LinearVariationalSolver(problem, solver_args)
  5. Solve the problem: solver.solve()

DDFenics

  1. Definition of Data-driven constitutive equations : loading of material datasets and definition of an approximative metric ==> ddmat = DDMaterial(DB, Metric)
  2. Definition of mesh, FE spaces, boundary conditions, standard constitutive equations, variational forms, etc. (idem)
  3. Definition of Gauss-Point spaces where the material states live : Sh0 = df.VectorFunctionSpace(Uh.mesh(), 'DG', degree = 0 , dim = 3). Stresses and strains are instances of DDFunction(Sh0).
  4. DD Variational problem definition: problem = DDProblem(a, b, uh, bcs, ddmat, ddmat, state_mech, state_db) (almost idem)
  5. Solver definition: solver = DDProblem(problem, solver_args) (idem)
  6. Solve the problem: solver.solve() (idem)

Citing

Please cite this repository if this library has been useful for you. DOI

ddfenics's People

Contributors

felipefr avatar

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.