Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SCDDS-core
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SPC
SCDDS
SCDDS-core
Commits
1ec58c00
Commit
1ec58c00
authored
4 years ago
by
Federico Felici
Browse files
Options
Downloads
Patches
Plain Diff
Add dynamic generation of data dictionaries
Allows to entirely remove them from SCDliuqe
parent
a10761f8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
algos/SCDliuqe/.gitignore
+1
-0
1 addition, 0 deletions
algos/SCDliuqe/.gitignore
code/classes/SCDclass_algo.m
+73
-40
73 additions, 40 deletions
code/classes/SCDclass_algo.m
code/tests/SCDalgo_test.m
+7
-7
7 additions, 7 deletions
code/tests/SCDalgo_test.m
with
81 additions
and
47 deletions
algos/SCDliuqe/.gitignore
0 → 100644
+
1
−
0
View file @
1ec58c00
*.sldd
This diff is collapsed.
Click to expand it.
code/classes/SCDclass_algo.m
+
73
−
40
View file @
1ec58c00
...
...
@@ -5,14 +5,15 @@ classdef SCDclass_algo
% algorithm
properties
(
Access
=
private
)
modelname
% Name of the model
mdscontainer
% Container class for MDS+ interface objects
taskcontainer
% Container class for init and term tasks
exportedtps
% List of tunable parameters variable to be exported
datadictionary
% Name of the used data dictionary
stdinits
% Standard inits scripts for fixed parameters
timing
% Timing info structure
exportedtpsdefaults
% default tunable parameters defining functions
modelname
% Name of the model
mdscontainer
% Container class for MDS+ interface objects
taskcontainer
% Container class for init and term tasks
exportedtps
% List of tunable parameters variable to be exported
datadictionary
% Name of the used data dictionary
refdatadictionaries
% Cell array of referenced data dictionaries
stdinits
% Standard inits scripts for fixed parameters
timing
% Timing info structure
exportedtpsdefaults
% default tunable parameters defining functions
end
methods
...
...
@@ -28,6 +29,7 @@ classdef SCDclass_algo
obj
.
exportedtpsdefaults
=
{};
obj
.
stdinits
=
{};
obj
.
datadictionary
=
''
;
obj
.
refdatadictionaries
=
{};
obj
.
timing
.
t_start
=
0
;
obj
.
timing
.
t_stop
=
1
;
obj
.
timing
.
dt
=
1e-3
;
...
...
@@ -100,9 +102,8 @@ classdef SCDclass_algo
function
out
=
getinits
(
obj
)
out
=
obj
.
stdinits
;
end
%% Data dictionary setter and getter
function
obj
=
setdatadictionary
(
obj
,
datadict
)
obj
.
datadictionary
=
datadict
;
end
...
...
@@ -116,12 +117,37 @@ classdef SCDclass_algo
dict
=
Simulink
.
data
.
dictionary
.
open
(
ddname
);
out
=
getSection
(
dict
,
'Design Data'
);
end
function
dictionaryObj
=
createdatadictionary
(
obj
,
varargin
)
% create and populate data dictionary with parameter,value pairs
% obj.populatedd('parameter',value);
dd
=
obj
.
getdatadictionary
;
% close open data dictionary
listopendictionaries
=
Simulink
.
data
.
dictionary
.
getOpenDictionaryPaths
;
if
numel
(
listopendictionaries
)
>
0
&&
any
(
contains
(
listopendictionaries
,
dd
))
Simulink
.
data
.
dictionary
.
closeAll
(
dd
,
'-discard'
);
end
if
exist
(
dd
,
'file'
)
% delete the existing data dictionary
delete
(
dd
)
end
% Create
dictionaryObj
=
Simulink
.
data
.
dictionary
.
create
(
dd
);
end
function
obj
=
setreferenceddatadictionaries
(
obj
,
refdd
)
if
ischar
(
refdd
)
&&
~
iscell
(
refdd
);
refdd
=
{
refdd
};
end
% to cell
assert
(
iscell
(
refdd
)
&&
isrow
(
refdd
),
'refdd must be a row cell array of data dictionary names'
)
obj
.
refdatadictionaries
=
refdd
;
end
%% Tunable parameters structures handling functions
function
out
=
getexportedtps
(
obj
)
out
=
obj
.
exportedtps
;
end
end
function
obj
=
addtunparamstruct
(
obj
,
structname
,
varargin
)
% obj = addtunparamstruct(structname, varargin)
...
...
@@ -276,17 +302,7 @@ classdef SCDclass_algo
function
obj
=
cleanwavegens
(
obj
)
obj
.
mdscontainer
=
obj
.
mdscontainer
.
cleanwavegens
;
end
%function obj = bindparameters(obj)
% obj.mdscontainer=obj.mdscontainer.bindparameters(obj.modelname, obj.datadictionary, obj.exportedtps);
%end
% This method has only sense in the expcode context
%function obj = buildworkspacesimstruct(obj)
% obj.mdscontainer=obj.mdscontainer.buildworkspacesimstruct;
%end
%% Task container methods forwarders
function
obj
=
addtask
(
obj
,
task
)
obj
.
taskcontainer
=
obj
.
taskcontainer
.
addtask
(
task
);
...
...
@@ -297,17 +313,6 @@ classdef SCDclass_algo
obj
.
taskcontainer
=
obj
.
taskcontainer
.
printtasks
;
end
%% Wavegen timing structure setters
% function obj = setwavegentimingsources(obj, tstart, dt, tstop)
% assert(ischar(tstart), 'SCDclass_algo.setwavegentimingsources first parameter must be a char array');
% assert(ischar(dt), 'SCDclass_algo.setwavegentimingsources first parameter must be a char array');
% assert(ischar(tstop), 'SCDclass_algo.setwavegentimingsources first parameter must be a char array');
%
% obj.wavegentiming.t_start=tstart;
% obj.wavegentiming.dt=dt;
% obj.wavegentiming.t_stop=tstop;
% end
%% Timing information
function
obj
=
settiming
(
obj
,
t_start
,
dt
,
t_stop
)
obj
.
timing
.
t_start
=
t_start
;
...
...
@@ -321,7 +326,7 @@ classdef SCDclass_algo
targetstruct
=
''
;
end
if
nargin
<
4
targetworkspace
=
'
global'
;
% default: global
workspace (assigninGlobal)
targetworkspace
=
'
datadictionary'
;
% default: data dictionary
workspace (assigninGlobal)
end
if
~
iscell
(
targetstruct
)
&&
~
isempty
(
targetstruct
)
...
...
@@ -353,6 +358,27 @@ classdef SCDclass_algo
end
end
function
initdd
(
obj
)
fprintf
(
'generating data dictionary %s\n'
,
obj
.
getdatadictionary
);
% generate/initialize data dictionary
dictionaryObj
=
obj
.
createdatadictionary
;
% link data dictionary to model and disable access to base
obj
.
load
;
set_param
(
obj
.
getname
,
'DataDictionary'
,
obj
.
getdatadictionary
,
'EnableAccessToBaseWorkspace'
,
'off'
);
% call initialization functions to populate dd
obj
.
callinits
;
% always reference configurations.sldd
dictionaryObj
.
addDataSource
(
'configurations.sldd'
);
% also reference other optional data dictionaries (e.g. used by
% lower-level components of an algorithm)
for
refdd
=
obj
.
refdatadictionaries
dictionaryObj
.
addDataSource
(
refdd
{:});
end
end
function
callinits
(
obj
)
% call initialization functions that set fixed parameters
...
...
@@ -360,13 +386,13 @@ classdef SCDclass_algo
for
ii
=
1
:
numel
(
obj
.
stdinits
)
initfunction
=
obj
.
stdinits
{
ii
}{
1
};
targetnames
=
obj
.
stdinits
{
ii
}{
2
};
workspace
=
obj
.
stdinits
{
ii
}{
3
};
targetnames
=
obj
.
stdinits
{
ii
}{
2
};
workspace
=
obj
.
stdinits
{
ii
}{
3
};
nout
=
numel
(
targetnames
);
fprintf
(
'Calling init function
''
%s
''
, assigning its output to
''
%s
''
...\n'
,
...
char
(
initfunction
),
cell2mat
(
targetnames
));
fprintf
(
'Calling init function
''
%s
''
, assigning its output to
''
%s
''
in %s
...\n'
,
...
char
(
initfunction
),
cell2mat
(
targetnames
)
,
workspace
);
if
ischar
(
initfunction
)
initcmd
=
sprintf
(
'%s(obj);'
,
initfunction
);
...
...
@@ -390,16 +416,19 @@ classdef SCDclass_algo
% cycle over number of output arguments of the function
val
=
value
{
iout
};
target
=
targetnames
{
iout
};
if
strcmp
(
workspace
,
'global'
)
if
strcmp
(
workspace
,
'datadictionary'
)
% assign in associated data dictionary
Simulink
.
data
.
assigninGlobal
(
obj
.
modelname
,
target
,
val
);
elseif
strcmp
(
workspace
,
'base'
)
% assign in base workspace
assignin
(
'base'
,
target
,
val
)
end
end
end
end
end
%% generic operation methods
function
compile
(
obj
)
try
eval
(
sprintf
(
'%s([],[],[],
''
compile
''
)'
,
obj
.
modelname
));
...
...
@@ -433,6 +462,10 @@ classdef SCDclass_algo
function
open
(
obj
)
open
(
obj
.
modelname
)
end
function
load
(
obj
)
load_system
(
obj
.
modelname
);
end
end
end
This diff is collapsed.
Click to expand it.
code/tests/SCDalgo_test.m
+
7
−
7
View file @
1ec58c00
...
...
@@ -5,26 +5,26 @@ classdef SCDalgo_test < matlab.unittest.TestCase
end
methods
(
TestClassSetup
)
function
setup_conf
(
testCase
)
testCase.assertWarningFree
(@()
SCDconf_setSIMconf
);
end
function
setup_algo
(
testCase
)
testCase.assertInstanceOf
(
testCase.algoobj
,'
SCDclass_algo
');
end
end
end
methods
(
Test
)
function
test_
call
init
s
(
testCase
)
testCase.algoobj.
call
init
s
;
%
calls
inits
defining
fixed
parameters
etc
function
test_init
dd
(
testCase
)
testCase.algoobj.init
dd
;
%
init
data
dictionary
end
function
test_setup
(
testCase
)
testCase.algoobj.setup
;
%
calls
possible
tunable
parameters
testCase.algoobj.setup
;
%
setup
tunable
parameters
end
function
test_compile
(
testCase
)
testCase.algoobj.compile
;
testCase.algoobj.compile
;
%
update
model
(
Ctrl-D
)
Simulink
end
function
test_test_harness
(
testCase
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment