File: tsgGetCandidateConstructionSurplus.m

package info (click to toggle)
tasmanian 8.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,852 kB
  • sloc: cpp: 34,523; python: 7,039; f90: 5,080; makefile: 224; sh: 64; ansic: 8
file content (125 lines) | stat: -rw-r--r-- 4,292 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
function [new_points] = tsgGetCandidateConstructionSurplus(lGrid, fTolerance, sRefinementType, iOut, vLimitLevels, mCorrection)
%
% [new_points] = tsgGetCandidateConstructionSurplus(
%             lGrid, fTolerance, sRefinementType, iOut, vLimitLevels)
%
% returns points for asynchronous (dynamic) construction where
% the "more important" points are sorted first, the sorting is done
% using anisotropic criteria
% see getCandidateConstructionPoints() in the on-line manual
%
% This function works for Local Polynomial and Wavelet grids only
%
% INPUT:
%
% lGrid: a grid list created by tsgMakeXXX(...)
%
% fTolerance: (real non-negative number)
%             refine only in neighborhood of points that satisfy
%             max(point_surplus / max_value) > fTolerance
%             where max(...) is taken over all outputs
%             point_surplus is the hierarchical surplus
%             max_value is the largest loaded value associated with each output
%
%
% sRefinementType: (string indicating the refinement type)
%                  'classic'  'parents'   'direction'   'fds' 'stable'
%                  only for Local Polynomial and Wavelet grids
%
% iOut: (integer giving the output to be used for the refinement)
%       selects which output to use for refinement, must be specified for
%       Global Grids, other grid can omit this or set it to [] to indicate
%       the use of all outputs
%
% vLimitLevels: (optional vector of integers of size iDim)
%               limit the level in each direction, no points beyond the
%               specified limit will be used, e.g., in 2D using
%               localp rule, [1, 99] forces the grid to have
%               at most 3 possible values in the first variable and
%               ~2^99 (practicallyt infinite) number in the second
%               direction.
%
% mCorrection: (optional matrix with size num_points by num_outputs or 1)
%              the surpluses in the refinement procedure will be multiplied
%              by the correction
%              if iOut is -1, then one weight must be given per output and
%              the columns must match the number of outputs
%              if iOut is specified, mCorrection must have one column
%
% OUTPUT:
%
% new_points: (optional) array
%             the new set of sorted needed points
%

[sFiles, sTasGrid] = tsgGetPaths();
[sFileG, sFileX, sFileV, sFileO, sFileW, sFileC, sFileL] = tsgMakeFilenames(lGrid);

sCommand = [sTasGrid,' -getconstructpnts'];

sCommand = [sCommand, ' -gridfile ', sFileG];

sCommand = [sCommand, ' -tolerance ', num2str(fTolerance,17)];

if ((exist('sRefinementType')) && (max(size(sRefinementType)) ~= 0))
    sCommand = [sCommand, ' -reftype ', sRefinementType];
end

if (exist('iOut') && (max(size(iOut)) ~= 0))
    sCommand = [sCommand, ' -refout ', num2str(iOut)];
end

% set level limits
if (exist('vLimitLevels') && (max(size(vLimitLevels)) ~= 0))
    if (min(size(vLimitLevels)) ~= 1)
        error(' vLimitLevels must be a vector, i.e., one row or one column');
    end
    if (max(size(vLimitLevels)) ~= lGrid.iDim)
        error(' vLimitLevels must be a vector of size iDim');
    end
    if (size(vLimitLevels, 1) > size(vLimitLevels, 2))
        tsgWriteMatrix(sFileL, vLimitLevels');
    else
        tsgWriteMatrix(sFileL, vLimitLevels);
    end
    lClean.sFileL = 1;
    sCommand = [sCommand, ' -levellimitsfile ', sFileL];
end

% set correction
if (exist('mCorrection') && (max(size(mCorrection)) ~= 0))
    if (min(size(mCorrection)) ~= 1)
        error(' mCorrection must be a vector, i.e., one row or one column');
    end
    tsgWriteMatrix(sFileV, mCorrection);
    lClean.sFileV = 1;
    sCommand = [sCommand, ' -valsfile ', sFileV];
end

% read the points for the grid
if (nargout == 1)
    sCommand = [sCommand, ' -of ',sFileO];
    lClean.sFileO = 1;
end

[status, cmdout] = system(sCommand);

if (max(size(strfind(cmdout, 'ERROR'))) ~= 0)
    disp(cmdout);
    error('The tasgrid execurable returned an error, see above');
    return;
else
    if (~isempty(cmdout))
        fprintf(1,['WARNING: Command had non-empty output:\n']);
        disp(cmdout);
    end
    if (nargout == 1)
        [new_points] = tsgReadMatrix(sFileO);
    end
end

if (exist('lClean'))
    tsgCleanTempFiles(lGrid, lClean);
end

end