CloudRunner

... share your algorithms as a web service

Algorithm: Solving 1D BVP with Finite Elements (Visualization)

Description:
A function I wrote a while ago to experiment with the finite elements method.
It's solving a 1D boundary value problem on the interval [0,1] with dirichlet conditions f(0)=0 and f(1)=1. The following ODEs are supported: laplace and helmholtz.

As this was mainly for ... (show more)
Tags: BVP FEM
Usage: Algorithm is public.
Viewed 2588 times, called 52 times
Upload:
Empty star Empty star Empty star Empty star Empty star
0 votes
Florian Pfaff
01/27/2013 5:11 p.m. (version #1)

Run Algorithm

: Type
:
: Allow cached result?
Close

Please Wait

Computation is running...

Plots

showing plot # of

Result Value(s)


		

Resource Usage

Execution of the algorithm took seconds.
Peak memory usage for running the algorithm was kilobytes (total usage: kilobytes).

Run ID / Link

ID of this run:
Link:

Result from Cache

Result has been delivered from cache and computed on (UTC).

Matlab log

(show)

		

Error

Using this algorithm in your local MATLAB environment is easy: Click here for instructions!

Usage Instructions for CloudRunner Client

  1. Download the CloudRunner Client by clicking here and place the downloaded file in your MATLAB working directory.

  2. Inside MATLAB, initialize the CloudRunner Client by calling CloudRunner:
    >> CloudRunner

    A login dialog will prompt for your CloudRunner mail address and password. For a start, you can leave the dialog empty and just click "Connect".

    Alternatively, you can provide the login credentials (or empty strings to skip login) as a parameter and hence skip the login dialog. This is useful when using CloudRunner in non-interactive scripts.
    >> CloudRunner('mail@example.com', 'password')

  3. Select this algorithm by its URL. Selecting an algorithm creates the lambda function that proxies calls to the algorithm to the server for execution:
    >> CloudRunnerSelect('http://www.cloudrunner.eu/algorithm/94/solving-1d-bvp-with-finite-elements-visualization/version/1/')

    For the sake of convenience, you can also use the algorithm ID instead of its URL for public algorithms.

  4. Call functions from the algorithm like any regular local function.

Note: You can find further information on the help page.

Source Code

File:

 1 function femTest(type,steps)
 2 % @author Florian Pfaff
 3 % @date 2011
 4     if nargin==0
 5         type='helmholtz';
 6     end
 7     if steps<2
 8         error('Please performe at least two steps');
 9     end
10     figure
11     clf
12     hold on
13     if strcmp(type,'helmholtz')   
14         real=ezplot('exp(1)/(exp(2)-1)*(exp(x)-exp(-x))',[0,1]);
15     elseif strcmp(type,'laplace')
16         real=ezplot('x',[0,1]);
17     end
18     set(real,'Color','r','LineWidth',2)
19     
20     %%
21     
22     syms('xi');
23     p1=1-xi;
24     p1xi=diff(p1,xi);
25     p2=xi;
26     p2xi=diff(p2,xi);
27     
28     for n=2:steps;
29 
30         
31 
32 
33         U=sym('U',[n,1])
34 
35 
36 
37         for i=1:n-1
38             for j=0:1
39                 if strcmp(type,'helmholtz')    
40                     J(i,j+1)=int(1/2*(diff(((n-1)^2*(U(i)*p1xi+U(i+1)*p2xi)^2+(U(i)*p1+U(i+1)*p2)^2)*1/(n-1),U(i+j))),xi,0,1)
41                 elseif strcmp(type,'laplace')
42                     J(i,j+1)=int(1/2*(diff((n-1)*(U(i)*p1xi+U(i+1)*p2xi)^2,U(i+j))),xi,0,1)
43                 end
44             end
45         end
46 
47         big=zeros(n,n)
48         for i=1:n-1
49             big(i,i)=big(i,i)+diff(J(i,1),U(i))
50         end
51 
52         for i=2:n
53             big(i,i)=big(i,i)+diff(J(i-1,2),U(i))
54         end
55 
56         for i=2:n
57             big(i-1,i)=big(i-1,i)+diff(J(i-1,1),U(i))
58         end
59 
60         for i=1:n-1
61             big(i+1,i)=big(i+1,i)+diff(J(i,2),U(i))
62         end
63 
64         big(1,:)=[1,repmat([0],1,n-1)]
65         big(n,:)=[repmat([0],1,n-1),1]
66 
67         y=big\[repmat([0],n-1,1);1]
68 
69         scatter(linspace(0,1,n),y)
70         line(linspace(0,1,n),y)
71         drawnow
72     end
73     
74     
75 
76         
77         
78         
79     %%
80 
81 end
Download algorithm (1 file) as ZIP

Comments

Please login to post a comment.