Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed sign in compositeArea calc (polygons with holes now calc OK) #25

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/+Depomod/+Layout/Site.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,22 @@
end
end

[x, y] = polybool('union', cageStruct(1).x, cageStruct(1).y, cageStruct(1).x, cageStruct(1).y);
%[x, y] = polybool('union', cageStruct(1).x, cageStruct(1).y, cageStruct(1).x, cageStruct(1).y);
A = polyshape(cageStruct(1).x,cageStruct(1).y,'Simplify',false);
[x,y] = boundary(A);


for ss = 2:length(cages)
x1 = x;
y1 = y;
x2 = cageStruct(ss).x;
y2 = cageStruct(ss).y;
[x, y] = polybool('union', x1, y1, x2, y2);
%[x, y] = polybool('union', x1, y1, x2, y2);
B = polyshape(x1,y1,'Simplify',false);
C = polyshape(x2,y2,'Simplify',false);
D = union(B,C);
[x,y] = boundary(D);

end
if plotPerimeter
figure;
Expand Down Expand Up @@ -171,9 +179,9 @@
a = polyarea(x(1:(idx(1)-1)), y(1:(idx(1)-1)));
for pidx = 1:numel(idx)
if pidx == numel(idx)
a = a + polyarea(x((idx(pidx)+1):end), y((idx(pidx)+1):end));
a = a - polyarea(x((idx(pidx)+1):end), y((idx(pidx)+1):end));
else
a = a + polyarea(x((idx(pidx)+1):(idx(pidx+1)-1)), y((idx(pidx)+1):(idx(pidx+1)-1)));
a = a - polyarea(x((idx(pidx)+1):(idx(pidx+1)-1)), y((idx(pidx)+1):(idx(pidx+1)-1)));
end
end
else
Expand Down
31 changes: 24 additions & 7 deletions lib/+Depomod/+Run/Base.m
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,26 @@
% Here we generate x,y vectors covering extent of domain with size matching
% sur.Z value. This seems to fix things.
% Andy used double for loop to populate E,N. But can do it by manipulating meshgrid.
dom=R.project.bathymetry.Domain.spatial;
minX=str2double(dom.minX);
minY=str2double(dom.minY);
maxX=str2double(dom.maxX);
maxY=str2double(dom.maxY);
try
dom=R.project.bathymetry.Domain.spatial;
minX=str2double(dom.minX);
minY=str2double(dom.minY);
maxX=str2double(dom.maxX);
maxY=str2double(dom.maxY);
catch
% dom=R.project.bathymetry.Domain.spatial;
try
minX=str2double(min(R.project.bathymetry.NodeX));
minY=str2double(min(R.project.bathymetry.NodeY));
maxX=str2double(max(R.project.bathymetry.NodeX));
maxY=str2double(max(R.project.bathymetry.NodeY));
catch
print('Cannot define model extent')
end
end
set(gca,'Xlim',[minX,maxX])
set(gca,'Ylim',[minY,maxY])

Nx=length(sur.X)+1;
Ny=length(sur.Y)+1;
X=linspace(minX,maxX,Nx);
Expand Down Expand Up @@ -298,9 +313,9 @@

if ~isempty(legendContours)
if str2num(mv(1:4)) < 2017
leg = legend(legendContours,legendlabels);
leg = legend(legendContours,legendlabels,'color','w');
else
[~,leg] = legend(legendContours,legendlabels, 'AutoUpdate', 'off');
[~,leg] = legend(legendContours,legendlabels, 'AutoUpdate', 'off','color','w');
end

PatchInLegend = findobj(leg, 'type', 'patch');
Expand Down Expand Up @@ -405,6 +420,8 @@
end
end

set(gca,'Xlim',[min(R.project.bathymetry.NodeX),max(R.project.bathymetry.NodeX)])
set(gca,'Ylim',[min(R.project.bathymetry.NodeY),max(R.project.bathymetry.NodeY)])
set(gca,'layer','top');

end
Expand Down
10 changes: 5 additions & 5 deletions lib/+Depomod/Project.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
classdef (Abstract) Project < dynamicprops

properties
name@char;
path@char;
solidsRuns@Depomod.Run.Collection;
EmBZRuns@Depomod.Run.Collection;
TFBZRuns@Depomod.Run.Collection;
name char;
path char;
solidsRuns Depomod.Run.Collection;
EmBZRuns Depomod.Run.Collection;
TFBZRuns Depomod.Run.Collection;
end

methods (Static = true)
Expand Down
36 changes: 20 additions & 16 deletions lib/+NewDepomod/+Run/Base.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@
end

properties
modelFile@NewDepomod.PropertiesFile;
physicalPropertiesFile@NewDepomod.PropertiesFile;
configurationFile@NewDepomod.PropertiesFile;
runtimeFile@NewDepomod.PropertiesFile;
inputsFile@NewDepomod.InputsPropertiesFile;
iterationInputsFile@NewDepomod.InputsPropertiesFile;
exportedTimeSeriesFile@NewDepomod.TimeSeriesFile;
consolidatedTimeSeriesFile@NewDepomod.TimeSeriesFile;
solidsSur@Depomod.Sur.Solids;
carbonSur@Depomod.Sur.Solids;
modelFile NewDepomod.PropertiesFile;
physicalPropertiesFile NewDepomod.PropertiesFile;
configurationFile NewDepomod.PropertiesFile;
runtimeFile NewDepomod.PropertiesFile;
inputsFile NewDepomod.InputsPropertiesFile;
iterationInputsFile NewDepomod.InputsPropertiesFile;
exportedTimeSeriesFile NewDepomod.TimeSeriesFile;
consolidatedTimeSeriesFile NewDepomod.TimeSeriesFile;
solidsSur Depomod.Sur.Solids;
carbonSur Depomod.Sur.Solids;
label; % generalisation of run number
iterationRunNumber = [];
modelFileName = '';
Expand Down Expand Up @@ -672,6 +672,7 @@ function setOutputTimes(R, varargin)

jv = NewDepomod.Java;

runCommand = '"C:\Program Files\depomodruntimecontainer\bin\depomodruntimecontainer"'
commandStringOnly = 0;
singleRunOnly = 1;
showConsoleOutput = 1;
Expand All @@ -680,20 +681,23 @@ function setOutputTimes(R, varargin)

for i = 1:2:length(varargin)
switch varargin{i}
case 'commandStringOnly'
commandStringOnly = varargin{i+1};
case 'runCommand'
runCommand = varargin{i+1}
case 'commandStringOnly'
commandStringOnly = varargin{i+1};
case 'singleRunOnly'
singleRunOnly = varargin{i+1};
singleRunOnly = varargin{i+1};
case 'showConsoleOutput'
showConsoleOutput = varargin{i+1};
showConsoleOutput = varargin{i+1};
case 'noSplash'
noSplash = varargin{i+1};
noSplash = varargin{i+1};
case 'runInBackground'
runInBackground = varargin{i+1};
runInBackground = varargin{i+1};
end
end

cmd = jv.run(...
'runCommand', runCommand, ...
'singleRunOnly', singleRunOnly, ...
'commandStringOnly', commandStringOnly, ...
'modelRunTimeFile', R.runtimePath, ...
Expand Down
29 changes: 22 additions & 7 deletions lib/+NewDepomod/BathymetryMikeMesh.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,17 @@ function fromFile(BMM, filePath)

function h = plot(BMM, varargin)
mesh = 0;

% TPA 08/05/2023
numCElems = 0;

if ~isempty(varargin)
for i = 1:2:size(varargin,2) % only bother with odd arguments, i.e. the labels
switch varargin{i}
case 'mesh'
mesh = varargin{i + 1};
case 'mesh'
mesh = varargin{i + 1};
% TPA 08/05/2023
case 'contour'
numCElems = varargin{i + 1};
end
end
end
Expand All @@ -171,8 +176,13 @@ function fromFile(BMM, filePath)

minDepth = max(BMM.NodeZ);
maxDepth = min(BMM.NodeZ);
numCElems = ceil(minDepth) - floor(maxDepth);

% TPA 08/05/2023: Encase in "if" to allow effective plotting of a contour by
% supplying number of levels as 'bathyContour' argument to main
% plot function
if numCElems == 0 || numCElems == 1
numCElems = ceil(minDepth) - floor(maxDepth);
end

cmap = colormap(flipud(bone(numCElems)));

bathyColour = zeros(numel(BMM.NodeZ),3);
Expand All @@ -189,8 +199,8 @@ function fromFile(BMM, filePath)
end

end
bathyHandle=trisurf(tri,x,y,z,'FaceVertexCData',bathyColour,'FaceColor', 'interp','EdgeColor','none','FaceAlpha',0.7);

bathyHandle=trisurf(tri,x,y,z,'FaceVertexCData',bathyColour,'FaceColor', 'interp','EdgeColor','none','FaceAlpha',1);
hold on;
view(2);

Expand Down Expand Up @@ -221,6 +231,11 @@ function fromFile(BMM, filePath)
xtickformat('%8.f');
ytickformat('%8.f');
end

% TPA 08/05/2023: Note that the above attempt to colour the land green does
% nothing for an irregular mesh. The line below works, at the
% expense of putting extra green around the water boundary too
set(gca,'Color',[0 0.3 0])
end

function boolMatrix = shallowSeabedIndexes(B, depth)
Expand Down
3 changes: 2 additions & 1 deletion lib/+NewDepomod/InputsPropertiesFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function setBiomass(IPF, biomass, varargin) % tonnes
IPF.FeedInputs.stockingDensity = num2str(biomass * 1000.0 / IPF.run.cages.cageVolume);

feedWaterPercentage = 9;
feedWastePercentage = 3;
%feedWastePercentage = 3;
feedWastePercentage = 1;
feedAbsorbedPercentage = 85;
feedCarbonPercentage = 49;
faecesCarbonPercentage = 30;
Expand Down
11 changes: 9 additions & 2 deletions lib/+NewDepomod/Java.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
properties (Constant = true)
versionName = 'newDEPOMOD'
versionNo = 2;
runCommand = '"C:\Program Files\depomodruntimecontainer\bin\depomodruntimecontainer"';
% runCommand = '"C:\Program Files\depomodruntimecontainer\bin\depomodruntimecontainer"';
exportCommand = 'newDEPOMOD\scripts\RunExporter.bat';
end
properties
runCommand = '"C:\Program Files\depomodruntimecontainer\bin\depomodruntimecontainer"';
end

methods (Static = true)
function [newProject, oldProject] = export(run, newProjectPath, varargin)
Expand Down Expand Up @@ -101,13 +104,15 @@
end

function command = run(J, varargin)
command = J.runCommandStringWithOptions(varargin{:});

commandStringOnly = 0;
runInBackground = 1;
verbose = 1;

for i = 1:2:length(varargin) % only bother with odd arguments, i.e. the labels
switch varargin{i}
case 'runCommand'
J.runCommand = varargin{i+1};
case 'commandStringOnly'
commandStringOnly = varargin{i+1};
case 'runInBackground'
Expand All @@ -116,6 +121,8 @@
verbose = varargin{i+1};
end
end

command = J.runCommandStringWithOptions(varargin{:});

if ~commandStringOnly
if verbose
Expand Down
6 changes: 3 additions & 3 deletions lib/+NewDepomod/Project.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
end

properties
location@NewDepomod.PropertiesFile;
bathymetry% @NewDepomod.BathymetryFile
flowmetry@NewDepomod.FlowmetryFile
location NewDepomod.PropertiesFile;
bathymetry% NewDepomod.BathymetryFile
flowmetry NewDepomod.FlowmetryFile
end

methods
Expand Down
20 changes: 20 additions & 0 deletions lib/findRuns.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function Runs=findRuns(project)

Runs=table;
for i=1:length(project.solidsRuns.labels)
Runs.runType(i)={'NONE'};
Runs.Number(i)=project.solidsRuns.numbers(i);
Runs.Label(i)=project.solidsRuns.labels(i);
end
for j=1:length(project.EmBZRuns.labels)
Runs.runType(i+j)={'EmBZ'};
Runs.Number(i+j)=project.EmBZRuns.numbers(j);
Runs.Label(i+j)=project.EmBZRuns.labels(j);
end
for k=1:length(project.TFBZRuns.labels)
Runs.runType(i+j+k)={'TFBZ'};
Runs.Number(i+j+k)=project.TFBZRuns.numbers(k);
Runs.Label(i+j+k)=project.TFBZRuns.labels(k);
end
Runs=sortrows(Runs);
end