File: SmoothMesh.m

package info (click to toggle)
openems 0.0.35%2Bgit20190103.6a75e98%2Bdfsg.1-3.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,544 kB
  • sloc: cpp: 40,417; python: 2,028; yacc: 580; makefile: 459; lex: 350; sh: 176; ruby: 19
file content (73 lines) | stat: -rw-r--r-- 2,427 bytes parent folder | download | duplicates (3)
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
function [mesh] = SmoothMesh( mesh, max_res, ratio, varargin)
% function [mesh] = SmoothMesh( mesh, max_res, <ratio, varargin>)
%
%   Convienent function to create a smooth mesh in all directions.
%   Generate smooth mesh by choosing an appropriate algorithm in each direction.
%
%   Currently supported smoothing algorithm:
%       SmoothMeshLines, SmoothMeshLines2 and RecursiveSmoothMesh
%
%  arguments:
%   lines:      given fixed lines to create a smooth mesh in between
%   max_res:    scalar or vector of desired max. allowed resolution
%   ratio:      grading ratio: scalar or vector of desired neighboring
%                   line-delta ratio (optional, default is 1.5)
%                   - see also 'allowed_max_ratio' argument
%
%  variable arguments ('keyword',value):
%   algorithm:          define subset of tried algorihm, e.g. [1 3]
%   symmetric:          0/1 force symmetric mesh (default is input symmetry)
%   homogeneous:        0/1 force homogeneous mesh
%   allowed_min_res:    allow a given min resolution only
%   allowed_max_ratio:  allow only a given max. grading ratio
%                           (default --> ratio*1.25)
%   debug:              0/1 off/on
%
% example:
%     mesh.x = [-BoundBox 0 BoundBox];
%     mesh.y = [-BoundBox 0 BoundBox];
%     mesh.z = [0 BoundBox];
%     mesh = SmoothMesh(mesh, lambda/20/unit);
%     CSX = DefineRectGrid(CSX, unit, mesh);
%
% See also AutoSmoothMeshLines, InitCSX, DefineRectGrid, DetectEdges
%
% CSXCAD matlab interface
% -----------------------
% author: Thorsten Liebig (C) 2012

if (nargin<3)
    ratio = 1.5;
end

if (numel(max_res)==1)
    max_res = [max_res max_res max_res];
end
if (numel(ratio)==1)
    ratio = [ratio ratio ratio];
end
if (numel(max_res)~=1)
    max_res = [max_res max_res max_res];
end

if isfield(mesh,'x')
    mesh.x = AutoSmoothMeshLines(mesh.x, max_res(1), ratio(1), varargin{:});
elseif isfield(mesh,'r')
    mesh.r = AutoSmoothMeshLines(mesh.r, max_res(1), ratio(1), varargin{:});
else
    error 'x/(r) direction not found'
end

if isfield(mesh,'y')
    mesh.y = AutoSmoothMeshLines(mesh.y, max_res(2), ratio(2), varargin{:});
elseif isfield(mesh,'a')
    mesh.a = AutoSmoothMeshLines(mesh.a, max_res(2), ratio(2), varargin{:});
else
    error 'y/(a) direction not found'
end

if isfield(mesh,'z')
    mesh.z = AutoSmoothMeshLines(mesh.z, max_res(3), ratio(3), varargin{:});
else
    error 'z direction not found'
end