Bim package: Difference between revisions

Jump to navigation Jump to search
939 bytes added ,  20 July 2012
no edit summary
No edit summary
Line 65: Line 65:
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>
{{Code|Plot mesh in the 2D problem|<syntaxhighlight lang="octave" style="font-size:13px">
pdemesh (mesh.p, mesh.e, mesh.t)
pdemesh (mesh.p, mesh.e, mesh.t)
view (2)
view (2)
</pre>  
</syntaxhighlight>}}


[[File:fiume_msh.png]]
[[File:fiume_msh.png]]
Line 77: Line 77:
Get the node coordinates from the mesh structure
Get the node coordinates from the mesh structure


<pre>
{{Code|Get mesh coordinates in the 2D problem|<syntaxhighlight lang="octave" style="font-size:13px">
xu    = mesh.p(1,:).';
xu    = mesh.p(1,:).';
yu    = mesh.p(2,:).';
yu    = mesh.p(2,:).';
</pre>
</syntaxhighlight>}}




Get the number of elements and nodes in the mesh
Get the number of elements and nodes in the mesh


<pre>
{{Code|Get number of elements in the 2D problem|<syntaxhighlight lang="octave" style="font-size:13px">
nelems = columns (mesh.t);
nelems = columns (mesh.t);
nnodes = columns (mesh.p);
nnodes = columns (mesh.p);
</pre>
</syntaxhighlight>}}


<pre>
<pre>
Line 97: Line 97:
<b> Construct the discretized operators</b>
<b> Construct the discretized operators</b>


<pre>
{{Code|Discretized operators for the 2D problem|<syntaxhighlight lang="octave" style="font-size:13px">  
AdvDiff = bim2a_advection_diffusion (mesh, epsilon, 1, 1, phi);
AdvDiff = bim2a_advection_diffusion (mesh, epsilon, 1, 1, phi);
Mass    = bim2a_reaction (mesh, 1, 1);
Mass    = bim2a_reaction (mesh, 1, 1);
b      = bim2a_rhs (mesh,f,g);
b      = bim2a_rhs (mesh,f,g);
A      = AdvDiff + Mass;
A      = AdvDiff + Mass;
</pre>
</syntaxhighlight>}}


<b> To Apply Boundary Conditions, partition LHS and RHS</b>
<b> To Apply Boundary Conditions, partition LHS and RHS</b>
Line 109: Line 109:
and <math> \Gamma_D </math> be the rest of the boundary
and <math> \Gamma_D </math> be the rest of the boundary


<pre>
{{Code|Boundary conditions for the 2D problem|<syntaxhighlight lang="octave" style="font-size:13px">  
GammaD = bim2c_unknowns_on_side (mesh, [1 2]);     ## DIRICHLET NODES LIST
GammaD = bim2c_unknowns_on_side (mesh, [1 2]);     ## DIRICHLET NODES LIST
GammaN = bim2c_unknowns_on_side (mesh, [3 4]);     ## NEUMANN NODES LIST
GammaN = bim2c_unknowns_on_side (mesh, [3 4]);     ## NEUMANN NODES LIST
Line 117: Line 117:
ud    = 3*xu;                                      ## DIRICHLET DATUM
ud    = 3*xu;                                      ## DIRICHLET DATUM
Omega = setdiff (1:nnodes, union (GammaD, GammaN)); ## INTERIOR NODES LIST
Omega = setdiff (1:nnodes, union (GammaD, GammaN)); ## INTERIOR NODES LIST
</pre>


<pre>
Add = A(GammaD, GammaD);
Add = A(GammaD, GammaD);
Adn = A(GammaD, GammaN); ## shoud be all zeros hopefully!!
Adn = A(GammaD, GammaN); ## shoud be all zeros hopefully!!
Line 136: Line 133:
bn = b(GammaN);  
bn = b(GammaN);  
bi = b(Omega);  
bi = b(Omega);  
</pre>
</syntaxhighlight>}}
 


<B> Solve for the displacements</B>
<B> Solve for the displacements</B>


<pre>
{{Code|Displacement in the 2D problem|<syntaxhighlight lang="octave" style="font-size:13px">  
temp = [Ann Ani ; Ain Aii ] \ [ jn+bn-And*ud(GammaD) ; bi-Aid*ud(GammaD)];
temp = [Ann Ani ; Ain Aii ] \ [ jn+bn-And*ud(GammaD) ; bi-Aid*ud(GammaD)];
u = ud;
u = ud;
u(GammaN)  = temp(1:numel (GammaN));
u(GammaN)  = temp(1:numel (GammaN));
u(Omega)  = temp(length(GammaN)+1:end);
u(Omega)  = temp(length(GammaN)+1:end);
</pre>
</syntaxhighlight>}}


<b> Compute the fluxes through Dirichlet sides</b><br>
<b> Compute the fluxes through Dirichlet sides</b><br>


<pre>
{{Code|Fluxes at sides in the 2D problem|<syntaxhighlight lang="octave" style="font-size:13px">  
jd = [Add Adi Adn] * u([GammaD; Omega; GammaN]) - bd;
jd = [Add Adi Adn] * u([GammaD; Omega; GammaN]) - bd;
</pre>
</syntaxhighlight>}}




<B> Compute the gradient of the solution </B>
<B> Compute the gradient of the solution </B>


<pre>
{{Code|Gradient of solution in the 2D problem|<syntaxhighlight lang="octave" style="font-size:13px">  
[gx, gy] = bim2c_pde_gradient (mesh, u);
[gx, gy] = bim2c_pde_gradient (mesh, u);
</pre>
</syntaxhighlight>}}


<B> Compute the internal Advection-Diffusion flux</B>
<B> Compute the internal Advection-Diffusion flux</B>
Line 203: Line 201:
<math> u = \exp (- \left(\frac{x-.2}{.2}\right)^2 - \left(\frac{y-.2}{.2}\right)^2 - \left(\frac{z-.2}{.2}\right)^2)</math>
<math> u = \exp (- \left(\frac{x-.2}{.2}\right)^2 - \left(\frac{y-.2}{.2}\right)^2 - \left(\frac{z-.2}{.2}\right)^2)</math>


<pre>
{{Code|Define the 3D problem|<syntaxhighlight lang="octave" style="font-size:13px">  
pkg load bim
pkg load bim


Line 238: Line 236:
   fpl_vtk_write_field (name, msh, {U(ii,:)', 'u'}, {}, 1);
   fpl_vtk_write_field (name, msh, {U(ii,:)', 'u'}, {}, 1);
endfor
endfor
</pre>
</syntaxhighlight>}}


[http://youtu.be/2E6Z_AcV8CQ This is a video] showing the .3 isosurface of the solution.
[http://youtu.be/2E6Z_AcV8CQ This is a video] showing the .3 isosurface of the solution.
657

edits

Navigation menu