Git Product home page Git Product logo

justachetan / virtualelementmethods Goto Github PK

View Code? Open in Web Editor NEW
15.0 1.0 3.0 925 KB

A Python implementation of the paper "The virtual element method in 50 lines of MATLAB" by Oliver J. Sutton

Home Page: https://link.springer.com/article/10.1007/s11075-016-0235-3

License: MIT License

Python 2.37% Jupyter Notebook 97.63%
python3 numpy matplotlib scipy numerical-methods pde partial-differential-equations virtual-element-method finite-element-methods poisson-equation

virtualelementmethods's Introduction

Virtual Element Methods

This repository contains a Python translation of the code provided in:

The virtual element method in 50 lines of MATLAB. Oliver J. Sutton. Numerical Algorithms

It solves a toy problem, a 2-D poisson equation on generalized polygonal meshes, using the lowest order Virtual Element Method.

Usage

$ python3 vem.py --help
usage: vem.py [-h] [-d D] [-o O] [--save_plot] [--title TITLE] i

This script solves 2-D Poisson Equation on general polygonal meshes using
Virtual Element Method of the lowest order.

positional arguments:
  i              Path to input mesh

optional arguments:
  -h, --help     show this help message and exit
  -d D           Specifies the shape of the 2D domain.
                 Possible values are:
                 - s: Square Domain
                 - l: L-Shaped Domain
  -o O           Path to output file
  --save_plot    Flag for saving the plot
  --title TITLE  Title of plot

The meshes can be downloaded from here (available in the na45 package). A copy of the meshes is also provided in this repository in the meshes directory.

Example Usage

$ # Computing the solution of a 2-D poisson equation on a square mesh and square domain
$ python3 vem.py -d s meshes/square -o solution.npy --save_plot --title plot.png

Some Results

Since this is a translation of the paper, this repository solved the exact toy problem that the paper has taken up, that is,

$$ \begin{align*} -\Delta u &= f \text{ in } \Omega \\ u &= g \text{ in } \partial \Omega \\ \end{align*} $$

Here $f = 15\sin (\pi x) \sin (\pi y)$ and $u = (1 - x) y \sin (\pi x)$ on $\partial \Omega $

The solutions to this problem on different meshes in the square domain are shown below.

Mesh Square Triangle Voronoi Smoothed Voronoi Non-convex
Solution

Custom boundary conditions and RHS

You can customise the code to run it with your own boundary condition and RHS too!

Just take a look at square_domain_boundary_condition and square_domain_rhs, you can write similar boundary condition functions and RHS function definitions.

Basically, the template is as follows:

# for boundary condition
def my_boundary_condition(points):
    # points is a list of 2-lists, containing mesh points
    
    results = do_something(points)
    return results

# for RHS
def my_rhs(point):
    # here we have a single 2-list as input

    result_rhs = do_something_else(point)
    return result_rhs

Now, in vem.py, go to the main function where the vem function is called and change it to:

u = vem(mesh_file, my_rhs, my_boundary_condition)

And voilà! You should be good to go!

Report

My understanding of the paper is documented in a report available here.


This code was written as a part of my course project in MTH598 Numerical Partial Differential Equations with Dr. Kaushik Kalyanaraman at IIIT Delhi during Winter 2019 Semester.

For bugs in the code, please write to: aditya16217 [at] iiitd [dot] ac [dot] in

virtualelementmethods's People

Contributors

dependabot[bot] avatar justachetan avatar

Stargazers

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

Watchers

 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.