Home > utilities > distance_to_coast.m

distance_to_coast

PURPOSE ^

Calculates the distance from the coast in all mesh nodes

SYNOPSIS ^

function Mobj=distance_to_coast(Mobj,conf)

DESCRIPTION ^

 Calculates the distance from the coast in all mesh nodes

 Mobj=distance_to_coast(Mobj,conf)

 DESCRIPTION:
    Calculates distance from coast within the domain mesh and
    stores it in a matlab mesh object

 INPUT 
   Mobj                   = Mesh object structure variable
   conf                   = configuration structure variable with the
   directory where the HJB_Solver_Package is installed

 OUTPUT:
    Mobj = matlab structure containing distance data

 EXAMPLE USAGE
     Mobj=distance_to_coast(Mobj,conf)
 This function needs the HJB_solver package by Shawn Walker and can be downloaded from Matlab central 
 http://www.mathworks.com/matlabcentral/fileexchange/24827-hamilton-jacobi-solver-on-unstructured-triangular-grids

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Mobj=distance_to_coast(Mobj,conf)
0002 % Calculates the distance from the coast in all mesh nodes
0003 %
0004 % Mobj=distance_to_coast(Mobj,conf)
0005 %
0006 % DESCRIPTION:
0007 %    Calculates distance from coast within the domain mesh and
0008 %    stores it in a matlab mesh object
0009 %
0010 % INPUT
0011 %   Mobj                   = Mesh object structure variable
0012 %   conf                   = configuration structure variable with the
0013 %   directory where the HJB_Solver_Package is installed
0014 %
0015 % OUTPUT:
0016 %    Mobj = matlab structure containing distance data
0017 %
0018 % EXAMPLE USAGE
0019 %     Mobj=distance_to_coast(Mobj,conf)
0020 % This function needs the HJB_solver package by Shawn Walker and can be downloaded from Matlab central
0021 % http://www.mathworks.com/matlabcentral/fileexchange/24827-hamilton-jacobi-solver-on-unstructured-triangular-grids
0022 
0023 % Author(s):
0024 %    Ricardo Torres  (Plymouth Marine Laboratory)
0025 %
0026 % Revision history
0027 %
0028 %   2015-11-20 First version
0029 %
0030 %==============================================================================
0031 dump = dbstack;
0032 subname = dump.name;
0033 clear dump
0034 global ftbverbose;
0035 if ftbverbose
0036     fprintf('\nbegin : %s \n', subname)
0037 end
0038 
0039 CD=pwd;
0040 % setup HPJ solver to calculate the distance function for the SMS mesh
0041  [~,~,~,bnd] = connectivity([Mobj.x,Mobj.y],Mobj.tri);
0042 % remove nodestring from coast.
0043     
0044 BCnodes=[Mobj.read_obc_nodes{:}];
0045 
0046 bnd(BCnodes)=0;
0047 coast_ind=find(bnd);
0048 
0049  % % calculate distance function
0050 myParam.Max_Tri_per_Star = 20;
0051 myParam.NumGaussSeidel = 40;
0052 myParam.INF_VAL = 1000000;
0053 myParam.TOL = 1e-12;
0054 % in this case, we will assume the standard Euclidean metric
0055 myMetric = [];
0056 myTM.Vtx=[Mobj.x(:),Mobj.y(:)];
0057 myTM.DoFmap=[Mobj.tri];
0058 myTM.NegMask=false(size(bnd));
0059 myBdy.Nodes=coast_ind(:);
0060 myBdy.Data=zeros(size(myBdy.Nodes));
0061 %
0062 cd (conf.HJB_Solver_Package)
0063 %
0064 %
0065 SEmex  = SolveEikonalmex(myTM,myBdy,myParam,myMetric);
0066 tic
0067 Mobj.dist  =SEmex.Compute_Soln;
0068 cd(CD)
0069 if ftbverbose
0070     fprintf('end   : %s \n', subname)
0071 end
0072 
0073 return

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005