GithubHelp home page GithubHelp logo

xianqichen / adfem.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kailaix/adfem.jl

0.0 1.0 0.0 249.43 MB

Innovative, efficient, and computational-graph-based finite element simulator for inverse modeling

License: MIT License

Julia 99.52% Python 0.48%

adfem.jl's Introduction

Documentation

Documentation

AdFem is a finite element method open source library for inverse modeling in computational and mathematical engineering. It provides a set of reusable, flexible, and differentiable operators for building scalable and efficient simulators for partial differential equations.

AdFem is built on ADCME, an automatic differentiation library for computational and mathematical engineering. It was originally developed for prototyping inverse modeling algorithms using structured meshes but later evolved into a general and powerful tool with a scalable FEM backend MFEM.

Ad in AdFem stands for "automatic differentiation" or "adjoint".

Install Guide

using Pkg
Pkg.add("AdFem")

Forward Computation in AdFem

As an example, we consider solving the Poisson's equation in AdFem

Here

The weak form for the Poisson's equation is to solve a variational equation

The problem is easily translated in AdFem:

using AdFem
using PyPlot 

# forward computation
mmesh = Mesh(joinpath(PDATA, "twoholes_large.stl"))
xy = gauss_nodes(mmesh)
κ = @. sin(xy[:,1]) * (1+xy[:,2]^2) + 1.0
f = 1e5 * @. xy[:,1] + xy[:,2]
K = compute_fem_laplace_matrix1(κ, mmesh)
F = compute_fem_source_term1(f, mmesh)
bdnode = bcnode(mmesh)
K, F = impose_Dirichlet_boundary_conditions(K, F, bdnode, zeros(length(bdnode)))
sol = K\F

The above code shows how to use a linear finite element space to approximate the state variable on a given mesh, define boundary conditions, and construct the linear system.

Inverse Modeling

Most functions of AdFem, such as compute_fem_laplace_matrix1, compute_fem_source_term1, and impose_Dirichlet_boundary_conditions, are AD-capable, meaning that you can back-propagate gradients from their outputs to inputs. This enables you to conduct inverse modeling without writing extra substantial effort once the forward computation codes are implemented. AdFem constructs a static computational graph for finite element simulators: the computational graph is optimized before executation, and all computations are delegated to efficient C++ kernels.

Here we use a deep neural network to approximate κ(x) (fc is an ADCME function and stands for fully-connected):

nn_κ = squeeze(fc(xy, [20,20,20,1])) + 1
K = compute_fem_laplace_matrix1(nn_κ, mmesh)
F = compute_fem_source_term1(f, mmesh)
bdnode = bcnode(mmesh)
K, F = impose_Dirichlet_boundary_conditions(K, F, bdnode, zeros(length(bdnode)))
nn_sol = K\F
loss = sum((nn_sol - sol)^2)

sess = Session(); init(sess)
BFGS!(sess, loss)

Installation

AdFem is tested on Unix platform (Linux and Mac). To install the stable release:

using Pkg
Pkg.add("ADCME") # dependency
Pkg.add("AdFem")

To install the latest version:

using Pkg 
Pkg.add(PackageSpec(url="https://github.com/kailaix/AdFem.jl", rev="master")) 

To install with docker, here is the built docker image provided by @Ricahrd-Li, and please see docker install guide.

Research

AdFem is an open-source package that accompanies ADCME.jl for solving inverse problems involving partial differential equations (PDEs). AdFem provides users a rich collection of operators, which users can use to quickly build finite element/volumn codes for forward computation. More importantly, these operators can back-propagate gradients, and therefore users can calculate the gradients using the ideas of adjoint methods and reverse-mode automatic differention (these two concepts overlap). The advanced physics constrained learning (PCL) approach enables users to back-propagate gradients through iterative and nonlinear solvers efficiently. AdFem offers a flexible interface for experienced researchers to develop their own operators.

Some related research works can be found here:

  1. Physics constrained learning for data-driven inverse modeling from sparse observations
  2. Solving Inverse Problems in Steady State Navier-Stokes Equations using Deep Neural Networks
  3. Inverse Modeling of Viscoelasticity Materials using Physics Constrained Learning

License

AdFem is licensed under MIT License. See LICENSE for details.

adfem.jl's People

Contributors

kailaix avatar tifffan avatar wayneweiqiang avatar zhehaoli1999 avatar

Watchers

James Cloos 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.