Git Product home page Git Product logo

femhomogenization.jl's Introduction

Build Status

FEMHomogenization.jl

Some basic FEM functionality in Julia.

The goal is to work on homogenization of elliptic PDEs.

Example usage

We refine

using StaticArrays
using FEMHomogenization: Mesh, Tri, assemble_matrix, assemble_rhs, save_file,
           construct_graph_and_find_interior_nodes, refine, checkerboard

# Build a simple mesh from two triangles
nodes = SVector{2,Float64}[(0.0, 0.0), (1.0, -0.1), (1.1, 1.0), (-0.1, 0.9)]
triangles = SVector{3,Int64}[(1, 2, 3), (1, 4, 3)]
mesh = Mesh(Tri, nodes, triangles)
graph, boundary, interior = construct_graph_and_find_interior_nodes(mesh)

# Uniformly refine the grid a couple times
for i = 1 : 9
    mesh = refine(mesh, graph)
    graph, boundary, interior = construct_graph_and_find_interior_nodes(mesh)
end

# Define a bilinear form and a load function
a11 = checkerboard(100)
a22 = checkerboard(100)
bilinear_form = (u, v, x) -> a11(x) * u.∇ϕ[1] * v.∇ϕ[1] + a22(x) * u.∇ϕ[2] * v.∇ϕ[2]
load = x -> x[1] * x[2]

# Build the matrix and the rhs
A = assemble_matrix(mesh, bilinear_form)
b = assemble_rhs(mesh, load)

# For a Dirichlet zero problem we only need the interior nodes
A_int = A[interior, interior]
b_int = b[interior]

# Solve things
x = zeros(b)
x[interior] .= A_int \ b_int

# Save the load function and solution to a Paraview compatible file
save_file("rhs_and_solution", mesh, Dict(
    "x" => x,
    "f" => load.(mesh.nodes),
    "a11" => a11.(mesh.nodes),
    "a22" => a22.(mesh.nodes),
))

Example result:

Plots

Note

This package is a work in progress!

femhomogenization.jl's People

Contributors

haampie avatar

Watchers

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