Editing Bim package
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
This is a short example on how to use <tt>bim</tt> to solve a DAR problem.<br> | |||
The data for this example can be found in the doc directory inside the | |||
bim installation directory. | |||
This is a short example on how to use <tt>bim</tt> to solve a | |||
We want to solve the equation | We want to solve the equation | ||
<math> -\mathrm{div}\ ( \varepsilon\ \nabla u(x, y) - \nabla \varphi(x,y)\ u(x, y) ) ) + u(x, y) = 1 \qquad | <math> -\mathrm{div}\ ( \varepsilon\ \nabla u(x, y) - \nabla \varphi(x,y)\ u(x, y) ) ) + u(x, y) = 1 \qquad in \Omega</math> | ||
<math> \varphi(x, y)\ =\ x + y </math> | <math> \varphi(x, y)\ =\ x + y </math> | ||
Line 58: | Line 54: | ||
on the mesh structure | on the mesh structure | ||
<pre> | |||
[mesh] = msh2m_gmsh ("fiume","scale",1,"clscale",.1); | [mesh] = msh2m_gmsh("fiume","scale",1,"clscale",.1); | ||
[mesh] = bim2c_mesh_properties (mesh); | [mesh] = bim2c_mesh_properties(mesh); | ||
</ | </pre> | ||
to see the mesh you can use functions from the [[fpl_package|fpl package]] | to see the mesh you can use functions from the [[fpl_package|fpl package]] | ||
<pre> | |||
pdemesh (mesh.p, mesh.e, mesh.t) | pdemesh (mesh.p, mesh.e, mesh.t) | ||
view (2) | view (2) | ||
</ | </pre> | ||
[[File:fiume_msh.png]] | [[File:fiume_msh.png]] | ||
<b> Construct an initial guess</b> | |||
<b> Set the coefficients for the problem:</b> | <b> Set the coefficients for the problem:</b> | ||
Line 77: | Line 74: | ||
Get the node coordinates from the mesh structure | Get the node coordinates from the mesh structure | ||
<pre> | |||
xu = mesh.p(1,:).'; | xu = mesh.p(1,:).'; | ||
yu = mesh.p(2,:).'; | yu = mesh.p(2,:).'; | ||
</ | </pre> | ||
Get the number of elements and nodes in the mesh | Get the number of elements and nodes in the mesh | ||
<pre> | |||
nelems = columns (mesh.t); | nelems = columns(mesh.t); | ||
nnodes = columns (mesh.p); | nnodes = columns(mesh.p); | ||
</ | </pre> | ||
<pre> | |||
epsilon = .1; | epsilon = .1; | ||
phi = xu + yu; | phi = xu + yu; | ||
</ | </pre> | ||
<b> Construct the discretized operators</b> | <b> Construct the discretized operators</b> | ||
<pre> | |||
AdvDiff = bim2a_advection_diffusion (mesh, epsilon | AdvDiff = bim2a_advection_diffusion(mesh, epsilon, 1, phi); | ||
Mass = bim2a_reaction (mesh, | Mass = bim2a_reaction(mesh,delta,zeta); | ||
b = bim2a_rhs (mesh,f,g); | b = bim2a_rhs(mesh,f,g); | ||
A = AdvDiff + Mass; | A = AdvDiff + Mass; | ||
</ | </pre> | ||
<b> To Apply Boundary Conditions, partition LHS and RHS</b> | <b> To Apply Boundary Conditions, partition LHS and RHS</b> | ||
The tags of the sides are assigned by gmsh | The tags of the sides are assigned by gmsh | ||
<pre> | |||
GammaD = bim2c_unknowns_on_side (mesh, [1 2]); | GammaD = bim2c_unknowns_on_side(mesh, [1 2]); ## DIRICHLET NODES LIST | ||
GammaN = bim2c_unknowns_on_side (mesh, [3 4]); | GammaN = bim2c_unknowns_on_side(mesh, [3 4]); ## NEUMANN NODES LIST | ||
GammaN = setdiff ( | Corners = setdiff(GammaD,GammaN); | ||
jn = zeros(length(GammaN),1); ## PRESCRIBED NEUMANN FLUXES | |||
ud = 3*xu; ## DIRICHLET DATUM | |||
Ilist = setdiff(1:length(uin),union(Dlist,Nlist)); ## INTERNAL NODES LIST | |||
</pre> | |||
Add = A( | <pre> | ||
Adn = A( | Add = A(Dlist,Dlist); | ||
Adi = A( | Adn = A(Dlist,Nlist); ## shoud be all zeros hopefully!! | ||
Adi = A(Dlist,Ilist); | |||
And = A( | And = A(Nlist,Dlist); ## shoud be all zeros hopefully!! | ||
Ann = A( | Ann = A(Nlist,Nlist); | ||
Ani = A( | Ani = A(Nlist,Ilist); | ||
Aid = A( | Aid = A(Ilist,Dlist); | ||
Ain = A( | Ain = A(Ilist,Nlist); | ||
Aii = A( | Aii = A(Ilist,Ilist); | ||
bd = b( | bd = b(Dlist); | ||
bn = b( | bn = b(Nlist); | ||
bi = b( | bi = b(Ilist); | ||
ud = uin(Dlist); | |||
un = uin(Nlist); | |||
ui = uin(Ilist); | |||
</pre> | |||
<B> Solve for the | <B> Solve for the displacements</B> | ||
<pre> | |||
temp = [Ann Ani ; Ain Aii ] \ [ | temp = [Ann Ani ; Ain Aii ] \ [ Fn+bn-And*ud ; bi-Aid*ud]; | ||
un = temp(1:length(un)); | |||
ui = temp(length(un)+1:end); | |||
u(Dlist) = ud; | |||
</ | u(Ilist) = ui; | ||
u(Nlist) = un; | |||
</pre> | |||
<b> Compute the fluxes through Dirichlet sides</b><br> | <b> Compute the fluxes through Dirichlet sides</b><br> | ||
<pre> | |||
Fd = Add * ud + Adi * ui + Adn*un - bd; | |||
</pre> | |||
<B> Compute the gradient of the solution </B><BR> | |||
<pre> | |||
[gx, gy] = bim2c_pde_gradient(mesh,u); | |||
</pre> | |||
<B> Compute the | <B> Compute the internal Advection-Diffusion flux</B><BR> | ||
<pre> | |||
[jxglob,jyglob] = bim2c_global_flux(mesh,u,alfa,gamma,eta,beta); | |||
</pre> | |||
<B> Save data for later visualization</B><BR> | |||
<pre> | |||
fpl_dx_write_field("dxdata",mesh,[gx; gy]',"Gradient",1,2,1); | |||
fpl_vtk_write_field ("vtkdata", mesh, {}, {[gx; gy]', "Gradient"}, 1); | |||
<B> | </pre> | ||
</ | |||
</ | |||
[[Category: | [[Category:OctaveForge]] | ||
[[Category:Packages]] |