-
Notifications
You must be signed in to change notification settings - Fork 18
/
LocalSize.m
78 lines (75 loc) · 2.4 KB
/
LocalSize.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
classdef LocalSize
%LOCALSIZE helps defining local sizes and local size gradients in
%specific grains. The constructed object is intended to be passed to
%the 'LocalSize' argument of the MESH command from gmshGeo class.
%
% See also gmshGeo/mesh
properties
grainID=[];
sizeAtBoundaries=[];
slope=[];
end
methods
function obj=LocalSize(id,def_size,varargin)
%LOCALSIZE Object contructor for class LocalSize.
% LOCALSIZE(A, S) sets the element size to S in grains with IDs
% A. S can be a single value or an array of the same size as A.
%
% LOCALSIZE(A, S, q) sets the size at grain boundaries to S and
% prescribes a size gradient with slope q. Again, q can be a
% single value of an array of the same size as A.
%
%
% Examples:
% ls=LOCALSIZE(5, 0.1) sets the element size to 0.1 in grain
% labelled 5.
%
% ls=LOCALSIZE([5 10], 0.1) sets the element size to 0.1 in
% grain labelled 5 and 10.
%
% ls=LOCALSIZE([5 10], [0.1 0.2]) sets the element size to
% 0.1 in grain labelled 5, and 0.2 in grain labelled 10.
%
% ls=LOCALSIZE(5, 0.1, 0.5) sets the element in grain 5 to
% follow a size gradient with increasing distance from grain
% boundary with slope 0.5, starting from 0.1.
%
% ls=LOCALSIZE([5 10], 0.1, [0.5 0.7]) does the same as
% before, plus it sets the slope in grain labelled 10 to 0.7.
%
% See also gmshGeo/mesh
if nargin
n=length(id);
if numel(def_size)==1
def_size=repmat(def_size,n,1);
elseif length(def_size)~=n
error('The sizes at boundaries must be either a unique value or an array of the same length as the grain IDs.')
end
if nargin==3
slope=varargin{1};
else
slope=0.0;
end
if numel(slope)==1
slope=repmat(slope,n,1);
elseif length(slope)~=n
error('The size of the slopes must be either a unique value or an array of the same length as the grain IDs.')
end
obj(n)=obj;
for i=1:n
obj(i).grainID=id(i);
obj(i).sizeAtBoundaries=def_size(i);
obj(i).slope=slope(i);
end
end
end
function disp(obj)
t=table([obj(:).grainID]', [obj(:).sizeAtBoundaries]', [obj(:).slope]', 'VariableNames', {'GrainID', 'SizeAtBoundaries', 'Slope'});
if isempty(t)
disp('Empty set for local element sizes')
else
disp(t);
end
end
end
end