rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
Random.m
1 classdef Random < SnapshotsGenerator.Cached
2  % creates random Dof vectors (for testing purposes only!)
3 
4  properties
5  % min-max vector indicating the range for the random values of the
6  % generated Dof-values.
7  ranges = [0 1];
8  end
9 
10  methods
11  function rdg = Random(dmodel, id, ranges, force_delete, enable_caching)
12  %function rdg = Random(dmodel, id, ranges, force_delete, enable_caching)
13  % constructor for the random detailed generator
14  %
15  % Parameters:
16  % id: an identifier string
17  % force_delete: boolean value indicating whether the cached data
18  % shall be automatically deleted if its inconsistent
19  % with the given 'dmodel'. (Default = 'true')
20  % enable_caching: boolean value indicating whether the generated data
21  % shall be stored in a cache. (Default = 'true')
22  % ranges: min-max vector indicating the range for the random
23  % values of the generated Dof-values. (Default = [0 1])
24  if nargin < 2 || isempty(id)
25  id = 'random';
26  end
27  if nargin < 4
28  force_delete = [];
29  end
30  if nargin < 5
31  enable_caching = [];
32  end
33  rdg = rdg@SnapshotsGenerator.Cached(dmodel, id, force_delete, enable_caching);
34  if nargin >= 3 && ~isempty(ranges)
35  rdg.ranges = ranges;
36  end
37  end
38 
39  end
40 
41  methods (Access = protected)
42  function [U, opt_fields] = generate_impl(this, dmodel, detailed_data, fields)
43  if isa(detailed_data, 'Greedy.DataTree.Detailed.INode')
44  model_data = detailed_data.model_data;
45  else
46  model_data = detailed_data;
47  end
48  nelems = model_data.grid.nelements;
49  hashstring = this.hashcode(dmodel);
50  hash = sscanf(hashstring(1:6), '%x');
51  rand('twister', hash);
52  if isfield(dmodel.descr, 'nt')
53  nt = dmodel.nt;
54  else
55  nt = 0;
56  end
57  if ~isfield(dmodel.descr, 'subfields')
58  U = rand(nelems, nt+1) * (this.ranges(2)-this.ranges(1))+this.ranges(1);
59  else
60  st = dmodel.descr.subfields;
61  for i = 1:length(st)
62  U.(st(i).shortname) = rand(st(i).length, nt+1) ...
63  * (st(i).ranges(2)-st(i).ranges(1)) + st(i).ranges(1);
64  end
65  end
66  opt_fields = [];
67  end
68  end
69 end
Interface for the storage and generation of detailed data that can be used to build reduced basis fun...
Definition: Cached.m:18
Cacheable generators of detailed data snapshots.
Definition: Cached.m:1
Customizable implementation of an abstract greedy algorithm.
Definition: DuneRBLeafNode.m:1