Skip to content
Snippets Groups Projects
SCDclass_mdsobjcontainer.m 9.34 KiB
Newer Older
classdef SCDclass_mdsobjcontainer
    % This class is a container class
    % for all MDS objects required for handling
    % a no-nocompile Simulink SCD model
    %
    % Presently it implements methods for handling
    % objects of the following classes:
    % SCDclass_mdsparam (and childrens)
    % SCDclass_mdswavegen (and childrens)
    
    properties
        numparams           % number of configured params objects
        mdsparams           % params objects array
        numwavegens           % number od configured wavegens objects
        mdswavegens         % wavegens objects array
        simstructlist       % list of names of simstructs to be transferred to
                            % base workspace upon expcode setup
    end
    
    methods
        function obj = SCDclass_mdsobjcontainer()
            % contructor, empty container
            obj.numparams=0;
            obj.numwavegens=0;
            
            obj.simstructlist= [ ...
                {'SCDnode01simdata'},...
                {'SCDnode02simdata'},...
                {'SCDnode03simdata'},...
                {'SCDnode06simdata'},...
                {'SCDnode07simdata'},...
                {'SCDnode08simdata'},...
                {'SCDnode0201_simdata'},...
                {'SCDnode0202_simdata'},...
                {'SCDnode0203_simdata'},...
                {'SCDnode0204_simdata'},...
                {'SCDnode0301_simdata'},...
                {'SCDnode0302_simdata'},...
                {'SCDnode0303_simdata'},...
                {'SCDnode0304_simdata'},...
                {'SCDnode0601_simdata'},...
                {'SCDnode0602_simdata'},...
                {'SCDnode0603_simdata'},...
                {'SCDnode0604_simdata'},...
                {'SCDnode0701_simdata'},...
                {'SCDnode0702_simdata'},...
                {'SCDnode0703_simdata'},...
                {'SCDnode0704_simdata'},...
                {'SCDnode0801_simdata'}...
                ];
                        
        end
        
        function obj = addparameter(obj, param)
            % Adds a parameter object
            if obj.numparams==0
                obj.mdsparams=param;
            else
                obj.mdsparams=[obj.mdsparams; param];
            end 
            obj.numparams=obj.numparams+1;
        end
        
        function obj = printparameters(obj)
            % prints the parameters object list
            if obj.numparams>0
               for ii=1:obj.numparams
                  obj.mdsparams(ii).printinfo();
               end
            end
        end
        
        function obj = actualizeparameters(obj, shot)
            % actualize the parameters on the gove data dictionary,
            % naive version with a mds acces for every parameter
            if obj.numparams>0
               for ii=1:obj.numparams
                  obj.mdsparams(ii).actualizedata(shot);
               end
            end
        end

        function obj = bindparameters(obj, modelname, datadictionary, exportedtps)
            if obj.numparams>0   
                for ii=1:obj.numparams
                    obj.mdsparams(ii)=obj.mdsparams(ii).setmodelname(modelname);
                    obj.mdsparams(ii)=obj.mdsparams(ii).setdatadictionary(datadictionary);
                end
                if numel(exportedtps)>0
                    for ii=1:obj.numparams
                        obj.mdsparams(ii)=obj.mdsparams(ii).setparamstructure(exportedtps{end});
                    end
                end        
            end
        end
        
        function obj = bindlastparameter(obj, modelname, datadictionary, exportedtps)
            if obj.numparams>0   
                obj.mdsparams(end)=obj.mdsparams(end).setmodelname(modelname);
                obj.mdsparams(end)=obj.mdsparams(end).setdatadictionary(datadictionary);
                if numel(exportedtps)>0
                    obj.mdsparams(end)=obj.mdsparams(end).setparamstructure(exportedtps{end});
                end        
            end
            
        end
        
        function obj = addwavegen(obj, wavegen)
            % adds a wavegen object
            if obj.numwavegens==0
                obj.mdswavegens=wavegen;
            else
                obj.mdswavegens=[obj.mdswavegens; wavegen];
            end 
            obj.numwavegens=obj.numwavegens+1;
        end
        
        function obj = bindlastwavegen(obj, modelname, datadictionary, timingsrc)
            if obj.numwavegens>0
                obj.mdswavegens(end)=obj.mdswavegens(end).setmodelname(modelname);
                obj.mdswavegens(end)=obj.mdswavegens(end).setdatadictionary(datadictionary);
                obj.mdswavegens(end)=obj.mdswavegens(end).settiminginfo(timingsrc);                
            end    
        end
        
        function obj = setwavegenbasestruct(obj, basestruct)
            if obj.numwavegens>0
                for ii=1:obj.numwavegens
                    obj.mdswavegens(ii)=obj.mdswavegens(ii).setbasestruct(basestruct);
                end
            end    
        end
        
        function obj = printwavegens(obj)
            % prints the wavegen list
            if obj.numwavegens>0
               for ii=1:obj.numwavegens
                  obj.mdswavegens(ii).printinfo();
               end
            end
        end
        
        function obj = actualizewavegens(obj, shot)
            % actualize the wavegen waves timeseries
            % naive version, a mds connection is called for every object
            if obj.numwavegens>0
               for ii=1:obj.numwavegens
                  obj.mdswavegens(ii).actualizedata(shot);
               end
            end
        end
        
        function obj = cleanwavegens(obj)
            % clean wavegens leaving a consistent (with model buses)
            % empty timeseries data structure
            if obj.numwavegens>0
               for ii=1:obj.numwavegens
                  obj.mdswavegens(ii).cleandata;
               end
            end
        end

        function obj = buildworkspacesimstruct(obj)
            % this funtion builds a workspace structure containing
            % a replica of all simulation structures in the data
            % dictionaries, this structure is the one actually used 
            % for loading simulation wavegen data
            % It is better not to use directly data dictionaries structures
            % to avoid flooding dds with big sim data sets (and
            % conseguently the SCD SVN itself
           
            dd=SCDconf_getdatadict('tcv.sldd');
            evalin('base','SCDsimdata=struct();');
            
            for ii=1:numel(obj.simstructlist)
                simstructname=char(obj.simstructlist(ii));
                simstruct=dd.getEntry(simstructname).getValue;
                assignstr=sprintf('SCDsimdata.%s=temp;',simstructname);
                assignin('base','temp',simstruct);
                evalin('base',assignstr);
            end
            
            evalin('base','clear temp;'); 
        end    
            
        function obj = importmdsobjects(obj, source)
            % parameters import

            destparamtargets={};
            if obj.numparams>0             
                for ii=1:obj.numparams
                    destparamtargets{end+1}=obj.mdsparams(ii).gettargetparam;
                end
            end
                           
            numparamstoimport = source.numparams;
            paramstoimport = source.mdsparams;
            
            if numparamstoimport>0
                for ii=1:numparamstoimport
                    if ~ismember(paramstoimport(ii).gettargetparam, destparamtargets)
                        obj=obj.addparameter(paramstoimport(ii));
                    else
                        warning('SCDclass_mdsobjcontainer:importmdsobjects','A mds object driving ''%s'' is already present in the dest. expcode, skipping!',paramstoimport(ii).gettargetparam);
                    end
                end
            end
            
            % wavegens import     
            destwavegentargets={};
            if obj.numwavegens>0             
                for ii=1:obj.numwavegens
                    destwavegentargets{end+1}=obj.mdswavegens(ii).gettargetwavegen;
                end
            end
                           
            numwavegenstoimport = source.numwavegens;
            wavegenstoimport = source.mdswavegens;
            
            if numwavegenstoimport>0
                for ii=1:numwavegenstoimport
                    if ~ismember(wavegenstoimport(ii).gettargetwavegen, destwavegentargets)
                        obj=obj.addwavegen(wavegenstoimport(ii));
                    else
                        warning('SCDclass_mdsobjcontainer:importmdsobjects','A mds object driving ''%s'' is already present in the dest. expcode, skipping!',wavegenstoimport(ii).gettargetwavegen);
                    end
                end
            end
                       
        end
        
        function printMARTe2parconfig(obj, shot)       
           for ii=1:obj.numparams
               str=obj.mdsparams(ii).genMARTe2entry(shot);
               fprintf("   %s\n",str);
           end
        end
        
        function printMARTe2wgconfig(obj, shot)       
           for ii=1:obj.numwavegens
               str=obj.mdswavegens(ii).genMARTe2entry(shot);
               fprintf("   %s\n",str);
           end
        end
        
                
    end
end