Mercurial > fem-fenics-eugenio
changeset 158:17358a4eb648
Move the example to their own folder.
author | gedeone-octave <marcovass89@hotmail.it> |
---|---|
date | Thu, 12 Sep 2013 15:19:31 +0200 |
parents | 08dc5547f4d6 |
children | d03d998e64af |
files | example/Advection-Diffusion/AD_time.m example/Biharmonic.m example/Biharmonic.ufl example/Biharmonic/Biharmonic.m example/Biharmonic/Biharmonic.ufl example/Evolution.m example/Evolution.ufl example/Evolution/Evolution.m example/Evolution/Evolution.ufl example/Poisson.m example/Poisson.ufl example/Poisson/Poisson.m example/Poisson/Poisson.ufl |
diffstat | 13 files changed, 142 insertions(+), 142 deletions(-) [+] |
line wrap: on
line diff
--- a/example/Advection-Diffusion/AD_time.m Thu Sep 12 14:58:34 2013 +0200 +++ b/example/Advection-Diffusion/AD_time.m Thu Sep 12 15:19:31 2013 +0200 @@ -5,7 +5,7 @@ pkg load msh fpl fem-fenics problem = 'Advection_Diffusion'; -import_ufl_Problem (problem); +import_ufl_BilinearForm (problem); problem = 'Reaction'; import_ufl_BilinearForm (problem);
--- a/example/Biharmonic.m Thu Sep 12 14:58:34 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -pkg load fem-fenics msh - -problem = 'Biharmonic'; -import_ufl_Problem (problem); - -# Create mesh and define function space -x = y = linspace (0, 1, 33); -mesh = Mesh(msh2m_structured_mesh (x, y, 1, 1:4)); - -V = FunctionSpace(problem, mesh); - -bc = DirichletBC (V, @(x,y) 0, 1:4); - -f = Expression ('f', @(x,y) 4.0*pi^4.*sin(pi.*x).*sin(pi.*y)); -g = Expression ('alpha', @(x,y) 8); - -a = BilinearForm (problem, V, g); -L = LinearForm (problem, V, f); - -[A, b] = assemble_system (a, L, bc); -u = A \ b; - -func = Function ('u', V, u); -plot (func);
--- a/example/Biharmonic.ufl Thu Sep 12 14:58:34 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -# Copyright (C) 2005-2009 Anders Logg - -# Elements -element = FiniteElement("Lagrange", triangle, 2) - -# Trial and test functions -u = TrialFunction(element) -v = TestFunction(element) -f = Coefficient(element) - -# Normal component, mesh size and right-hand side -n = element.cell().n -h = 2.0*triangle.circumradius -h_avg = (h('+') + h('-'))/2 - -# Parameters -alpha = Constant(triangle) - -# Bilinear form -a = inner(div(grad(u)), div(grad(v)))*dx \ - - inner(avg(div(grad(u))), jump(grad(v), n))*dS \ - - inner(jump(grad(u), n), avg(div(grad(v))))*dS \ - + alpha('+')/h_avg*inner(jump(grad(u), n), jump(grad(v),n))*dS - -# Linear form -L = f*v*dx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/Biharmonic/Biharmonic.m Thu Sep 12 15:19:31 2013 +0200 @@ -0,0 +1,24 @@ +pkg load fem-fenics msh + +problem = 'Biharmonic'; +import_ufl_Problem (problem); + +# Create mesh and define function space +x = y = linspace (0, 1, 33); +mesh = Mesh(msh2m_structured_mesh (x, y, 1, 1:4)); + +V = FunctionSpace(problem, mesh); + +bc = DirichletBC (V, @(x,y) 0, 1:4); + +f = Expression ('f', @(x,y) 4.0*pi^4.*sin(pi.*x).*sin(pi.*y)); +g = Expression ('alpha', @(x,y) 8); + +a = BilinearForm (problem, V, g); +L = LinearForm (problem, V, f); + +[A, b] = assemble_system (a, L, bc); +u = A \ b; + +func = Function ('u', V, u); +plot (func);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/Biharmonic/Biharmonic.ufl Thu Sep 12 15:19:31 2013 +0200 @@ -0,0 +1,26 @@ +# Copyright (C) 2005-2009 Anders Logg + +# Elements +element = FiniteElement("Lagrange", triangle, 2) + +# Trial and test functions +u = TrialFunction(element) +v = TestFunction(element) +f = Coefficient(element) + +# Normal component, mesh size and right-hand side +n = element.cell().n +h = 2.0*triangle.circumradius +h_avg = (h('+') + h('-'))/2 + +# Parameters +alpha = Constant(triangle) + +# Bilinear form +a = inner(div(grad(u)), div(grad(v)))*dx \ + - inner(avg(div(grad(u))), jump(grad(v), n))*dS \ + - inner(jump(grad(u), n), avg(div(grad(v))))*dS \ + + alpha('+')/h_avg*inner(jump(grad(u), n), jump(grad(v),n))*dS + +# Linear form +L = f*v*dx
--- a/example/Evolution.m Thu Sep 12 14:58:34 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -pkg load fem-fenics msh - -problem = 'Evolution'; -import_ufl_Problem (problem); - -mesh = Mesh (msh2m_structured_mesh (0:0.05:1, 0:0.05:1, 1, 1:4)); - -V = FunctionSpace(problem, mesh); - -bc = DirichletBC (V, @(x,y) 1, 1:4); - -t = 0; -dt = 0.01; -T = 0.3; - -k = Expression ('dt', @(x,y) dt); - -u0 = Expression ('u0', @(x,y) 10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02)); - -a = BilinearForm (problem, V, k); -L = LinearForm (problem, V, k, u0); - -A = assemble (a, bc); - -# solve the problem for each time step -# We need to update only the lhs -while t < T - t += dt; - - # we can pass u0 to the lhs indifferently as a fem_coeff or - # as a fem_func - L = LinearForm (problem, V, k, u0); - b = assemble (L, bc); - - u = A \ b; - - u0 = Function ('u0', V, u); - - #press Q to make the plot continue - plot (u0); -end
--- a/example/Evolution.ufl Thu Sep 12 14:58:34 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -element = FiniteElement("Lagrange", triangle, 1) - -u = TrialFunction(element) -v = TestFunction(element) - -u0 = Coefficient(element) - -dt = Constant(triangle) - -eq = (1/dt)*(u-u0)*v*dx + inner(grad(u), grad(v))*dx -a = rhs (eq) -L = lhs (eq)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/Evolution/Evolution.m Thu Sep 12 15:19:31 2013 +0200 @@ -0,0 +1,41 @@ +pkg load fem-fenics msh + +problem = 'Evolution'; +import_ufl_Problem (problem); + +mesh = Mesh (msh2m_structured_mesh (0:0.05:1, 0:0.05:1, 1, 1:4)); + +V = FunctionSpace(problem, mesh); + +bc = DirichletBC (V, @(x,y) 1, 1:4); + +t = 0; +dt = 0.01; +T = 0.3; + +k = Expression ('dt', @(x,y) dt); + +u0 = Expression ('u0', @(x,y) 10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02)); + +a = BilinearForm (problem, V, k); +L = LinearForm (problem, V, k, u0); + +A = assemble (a, bc); + +# solve the problem for each time step +# We need to update only the lhs +while t < T + t += dt; + + # we can pass u0 to the lhs indifferently as a fem_coeff or + # as a fem_func + L = LinearForm (problem, V, k, u0); + b = assemble (L, bc); + + u = A \ b; + + u0 = Function ('u0', V, u); + + #press Q to make the plot continue + plot (u0); +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/Evolution/Evolution.ufl Thu Sep 12 15:19:31 2013 +0200 @@ -0,0 +1,12 @@ +element = FiniteElement("Lagrange", triangle, 1) + +u = TrialFunction(element) +v = TestFunction(element) + +u0 = Coefficient(element) + +dt = Constant(triangle) + +eq = (1/dt)*(u-u0)*v*dx + inner(grad(u), grad(v))*dx +a = rhs (eq) +L = lhs (eq)
--- a/example/Poisson.m Thu Sep 12 14:58:34 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -pkg load fem-fenics msh -import_ufl_Problem ('Poisson') - -# Create mesh and define function space -x = y = linspace (0, 1, 33); -mesh = Mesh(msh2m_structured_mesh (x, y, 1, 1:4)); - -V = FunctionSpace('Poisson', mesh); - -# Define boundary condition -bc = DirichletBC(V, @(x, y) 0.0, [2;4]); - -f = Expression ('f', @(x,y) 10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02)); -g = Expression ('g', @(x,y) sin (5.0 * x)); - -a = BilinearForm ('Poisson', V); -L = LinearForm ('Poisson', V, f, g); - -# Compute solution -[A, b] = assemble_system (a, L, bc); -sol = A \ b; -u = Function ('u', V, sol); - -# Save solution in VTK format -save (u, 'poisson') - -# Plot solution -plot (u);
--- a/example/Poisson.ufl Thu Sep 12 14:58:34 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -# Copyright (C) 2005-2009 Anders Logg -element = FiniteElement("Lagrange", triangle, 1) - -u = TrialFunction(element) -v = TestFunction(element) -f = Coefficient(element) -g = Coefficient(element) - -a = inner(grad(u), grad(v))*dx -L = f*v*dx + g*v*ds
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/Poisson/Poisson.m Thu Sep 12 15:19:31 2013 +0200 @@ -0,0 +1,28 @@ +pkg load fem-fenics msh +import_ufl_Problem ('Poisson') + +# Create mesh and define function space +x = y = linspace (0, 1, 33); +mesh = Mesh(msh2m_structured_mesh (x, y, 1, 1:4)); + +V = FunctionSpace('Poisson', mesh); + +# Define boundary condition +bc = DirichletBC(V, @(x, y) 0.0, [2;4]); + +f = Expression ('f', @(x,y) 10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02)); +g = Expression ('g', @(x,y) sin (5.0 * x)); + +a = BilinearForm ('Poisson', V); +L = LinearForm ('Poisson', V, f, g); + +# Compute solution +[A, b] = assemble_system (a, L, bc); +sol = A \ b; +u = Function ('u', V, sol); + +# Save solution in VTK format +save (u, 'poisson') + +# Plot solution +plot (u);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/Poisson/Poisson.ufl Thu Sep 12 15:19:31 2013 +0200 @@ -0,0 +1,10 @@ +# Copyright (C) 2005-2009 Anders Logg +element = FiniteElement("Lagrange", triangle, 1) + +u = TrialFunction(element) +v = TestFunction(element) +f = Coefficient(element) +g = Coefficient(element) + +a = inner(grad(u), grad(v))*dx +L = f*v*dx + g*v*ds