Code Monkey home page Code Monkey logo

ameshcoars's Introduction

ameshcoars

Efficient Matlab Implementation of Adaptive Mesh Coarsening in 2D

This project provides an efficient implementation of various adaptive mesh coarsening strategies in two dimensions. We coarsen meshes that are adaptively generated using the following refinement strategies.

alt text

Getting Started

For a use of the coarsening methods download the complete repository /ameshcoars with the test examples and run them on your computer with Matlab. To use it within your own examples you need the repository /refinement and /coarsening. Please see the following instructions for a correct use.

Prerequisites

MATLAB

Running the test examples

/example1: run test_moving_circle.m (refinement along a moving circle)

/example2: run example_P1_irr.m, exampleQ1_irr, and exampleP1Q1.m in the corresponding repositories. Vary the refinement method in exampleP1Q1.m (mesh refinement in the context of the adaptive finite element method for a quasi-stationary partial differential equation)

/example3: run example3.m (triangulation of a GIF)

/example4: run example4.m (local coarsening of a uniformly refined triangulation)

Deployment for your own examples - Data structure

To be able to deploy this package within your framework you need the following data strucure of the mesh:

For triangles you need to define coordinates, elements3, and optionally boundary data dirichlet or neumann. Note, that for coarsening of TrefineR it is important to define the initial triangulation such that the smallest index is stored within an element at position one. In general, we number elements in a counterclockwise order.

alt text

Similarly, for quadrilaterals you need to define coordinates, elements4, and optionally boundary data dirichlet or neumann.

alt text

For meshes with hanging nodes an additional data vector named irregular is needed, where irregular(l,1) and irregular(l,2) are the starting and end point of the lth-irregular edge with hanging node stored in irregular(l,3). If there are no irregular edges, a predefinition irregular = zeros(0,3) is needed. Also note to clear the variables nG and nB before you start running your code as they are persistent variables!

How to call the functions

We abbreviate the data structure as coordinates (C), elements3 (E3), elements4 (E4), irregular (I), dirichlet (D), and neumann (N). Furthermore, marked elements are stored with the corresponding index in the variable marked. N0 is the number of coordinates of the initial mesh.

The different mesh coarsening methods are then called by (remember that D and N are optional arguments)

TcoarsenR

[C,E3,I,D,N] = TcoarsenR(N0,C,E3,I,D,N,marked)

QcoarsenR

[C,E4,I,D,N] = QcoarsenR(N0,C,E4,I,D,N,marked)

TcoarsenNVB

[C,E3,D,N] = TcoarsenNVB(N0,C,E3,D,N,marked)

TcoarsenRGB

[C,E3,D,N] = TcoarsenRGB(N0,C,E3,D,N,marked)

TcoarsenRG

[C,E3,D,N] = TcoarsenRG(N0,C,E3,D,N,marked)

QcoarsenRB

[C,E4,D,N] = QcoarsenRB(N0,C,E4,D,N,marked)

QcoarsenRG

[C,E3,E4,D,N] = Qcoarsen(N0,C,E3,E4,D,N,marked3,marked4)

Minimal example

The used functions are provided in the repository /example1 and /refinement:

addpath('../refinement')
addpath('../coarsening')

%% Define initial mesh
coordinates = [0,0;1,0;1,1;0,1;2,0;2,1];
elements = [3,1,2;1,3,4;2,6,3;6,2,5];
boundary = [1,2;2,5;5,6;6,3;3,4;4,1];
N0 = size(coordinates,1);
c_old = 0;

%% Refine uniformly
while 1
    marked = 1:size(elements,1);
    [coordinates,elements,boundary] ...
        = TrefineRGB(coordinates,elements,boundary,marked);
    if isempty(marked)|| (size(coordinates,1)>1e3)
        break
    end
end

% define discrete points (here a disc)
phi = -pi:pi/50:pi;
r = 0.2:1/50:0.4;
[r,phi] = meshgrid(r,phi);
s = r.*cos(phi);
t = r.*sin(phi);
points = [s(:)+1,t(:)+0.5];

%% Coarsen at discrete points
while 1
    mark3 = point2element(coordinates,elements,points);
    [coordinates,elements,boundary] = TcoarsenRGB(N0,coordinates,elements,boundary,mark3);
    if size(coordinates,1) == c_old
        break
    end
    c_old = size(coordinates,1);
end

% plot results
clf
patch('Faces',elements,'Vertices',coordinates,'Facecolor','none')
axis equal
axis off

Plot your mesh with Matlab

triangular mesh:

patch('Faces',elements3,'Vertices',coordinates,'Facecolor','none')

quadrilateral mesh:

patch('Faces',elements4,'Vertices',coordinates,'Facecolor','none')

Authors

  • Stefan A. Funken - Anja Schmidt Institute for Numerical Mathematics, Ulm University, Germany

If you use TcoarsenRGB in scientific work, please cite:

  • Stefan A. Funken, and Anja Schmidt. "A Coarsening Algorithm on Adaptive Red-Green-Blue Refined Meshes", 2020

License

This project is licensed under the MIT License - see the LICENSE file for details

ameshcoars's People

Contributors

aschmidtuulm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

zorasawyer

ameshcoars's Issues

Octave compatible?

Compatible to free matlab clone octave?
No license is needed for octave.

If yes, please extend your info in Readme with Octave Version. Actual Version of Octave is 7.2.
if unknown, untested with octave, info about this also nice.
if no, it is also ok. Some commands are not compatible in octave.
So you are the expert. Perhaps you can make a fast test run.
Here some last infos about octave.
https://wiki.octave.org/Differences_between_Octave_and_Matlab
https://wiki.octave.org/Release_History
https://octave.org/NEWS-7.html

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.