UpdateMesh

PURPOSE ^

UPDATEMESH - update the mesh after a time step

SYNOPSIS ^

function [new_mesh new_velocity_g new_temperature_g new_pressure_g]=UpdateMesh(md,grids,old_mesh,old_velocity_g,old_temperature_g,old_pressure_g,bed,thickness);

DESCRIPTION ^

UPDATEMESH - update the mesh after a time step

   This routine interpolates results onto new mesh

   Usage:
      [new_mesh new_velocity_g new_temperature_g new_pressure_g]=UpdateMesh(md,grids,old_mesh,old_velocity_g,old_temperature_g,old_pressure_g,bed,thickness)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function     [new_mesh new_velocity_g new_temperature_g new_pressure_g]=UpdateMesh(md,grids,old_mesh,old_velocity_g,old_temperature_g,old_pressure_g,bed,thickness);
0002 %UPDATEMESH - update the mesh after a time step
0003 %
0004 %   This routine interpolates results onto new mesh
0005 %
0006 %   Usage:
0007 %      [new_mesh new_velocity_g new_temperature_g new_pressure_g]=UpdateMesh(md,grids,old_mesh,old_velocity_g,old_temperature_g,old_pressure_g,bed,thickness)
0008 
0009 %grids old vertical coordinate
0010 old_z=old_mesh.grids(:,3);
0011 
0012 %initialization
0013 new_z             =old_z;
0014 new_velocity_g    =old_velocity_g;
0015 new_temperature_g =old_temperature_g;
0016 new_pressure_g    =old_pressure_g;
0017 
0018 for i=1:md.numberofgrids2d
0019         for j=1:md.numlayers
0020                 count=(j-1)*md.numberofgrids2d+i;
0021                 new_z(count)=bed(count)+(j-1)/(md.numlayers-1)*(thickness(count));     
0022 
0023         %Linearly interpolate results
0024         if new_z(count)>old_z(count), %The grid is upper
0025             if ~isnan(md.uppergrids(count)) %check that this grid is not already at the top (otherwise: same value)
0026                 old_upper_z=old_z(md.uppergrids(count));
0027                 coeff=(new_z(count)-old_z(count))/(old_upper_z-old_z(count));
0028                 new_velocity_g(grids(count).grid.doflist)=old_velocity_g(grids(count).grid.doflist)+coeff*(old_velocity_g(grids(count).grid.doflist)-old_velocity_g(grids(md.uppergrids(count)).grid.doflist));
0029                 new_temperature_g(grids(count).grid.doflist)=old_temperature_g(grids(count).grid.doflist)+coeff*(old_temperature_g(grids(count).grid.doflist)-old_temperature_g(grids(md.uppergrids(count)).grid.doflist));
0030                 new_pressure_g(grids(count).grid.doflist)=old_pressure_g(grids(count).grid.doflist)+coeff*(old_pressure_g(grids(count).grid.doflist)-old_pressure_g(grids(md.uppergrids(count)).grid.doflist));
0031             end
0032         else                          %The grid is lower
0033             if ~isnan(md.lowergrids(count)) %check that this grid is not already at the bottom (otherwise: same value)
0034                 old_lower_z=old_z(md.lowergrids(count));
0035                 coeff=(new_z(count)-old_z(count))/(old_lower_z-old_z(count));
0036                 new_velocity_g(grids(count).grid.doflist)=old_velocity_g(grids(count).grid.doflist)+coeff*(old_velocity_g(grids(count).grid.doflist)-old_velocity_g(grids(md.lowergrids(count)).grid.doflist));
0037                 new_temperature_g(grids(count).grid.doflist)=old_temperature_g(grids(count).grid.doflist)+coeff*(old_temperature_g(grids(count).grid.doflist)-old_temperature_g(grids(md.lowergrids(count)).grid.doflist));
0038                 new_pressure_g(grids(count).grid.doflist)=old_pressure_g(grids(count).grid.doflist)+coeff*(old_pressure_g(grids(count).grid.doflist)-old_pressure_g(grids(md.lowergrids(count)).grid.doflist));
0039             end
0040         end
0041         end
0042 end
0043 
0044 %Build new mesh
0045 new_mesh.elements=old_mesh.elements;
0046 new_mesh.grids=old_mesh.grids;
0047 new_mesh.grids(:,3)=new_z;

Generated on Sun 29-Mar-2009 20:22:55 by m2html © 2003