123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- function counter = mttCountSystemMapping(model)
- sympars = count_system_sympars(model) ;
- inputs = count_system_inputs(model) ;
- invars = count_system_invars(model) ;
- outvars = count_system_outvars(model) ;
- states = count_system_states(model) ;
- counter.input = sympars + inputs + invars ;
- counter.output = outvars ;
- counter.state = states ;
- function counter = count_system_sympars(model)
- number_of_variables = mttGetFieldLength(model,'sympar') ;
- counter = 0 ;
-
- for i = 1:number_of_variables
- default_value = model.sympar_default{i} ;
- if isempty(default_value)
- counter = counter + 1 ;
- end
- end
-
-
- function counter = count_system_inputs(model)
- number_of_variables = mttGetFieldLength(model,'input') ;
-
- objects = mttGetFieldNames(model,'obj') ;
- for i = 1:length(objects)
- object_name = objects{i} ;
- object = getfield(model,'obj',object_name) ;
-
- additional_variables = 0 ;
- if ~isempty(object.abg)
- additional_variables = count_system_inputs(object) ;
- elseif ~isempty(object.cr)
- additional_variables = count_system_inputs(object.cr) ;
- end
-
- number_of_variables = number_of_variables + additional_variables ;
- end
-
- counter = number_of_variables ;
-
-
- function counter = count_system_invars(model,root,env)
- is_root_model = nargin==1 ;
-
- if is_root_model
- root = model ;
- env = model.env ;
- end
-
- number_of_variables = 0 ;
-
- objects = mttGetFieldNames(model,'obj') ;
- for i = 1:length(objects)
- object_name = objects{i} ;
- object = getfield(model,'obj',object_name) ;
-
- switch object.class
- case {'SS','Se','Sf','De','Df'}
- inbond_number = object.interface.in ;
- outbond_number = object.interface.out ;
-
- inbond = model.bond(inbond_number) ;
- outbond = model.bond(outbond_number) ;
-
- if ~isempty(inbond)
- covariables = mttGetCovariables(env,inbond.domain,inbond.domain_item) ;
- covar = [] ;
-
- if ~inbond.effort
- if ~strcmp(object.class,'Df')
- covar = covariables.effort ;
- end
- elseif inbond.flow
- if ~strcmp(object.class,'De')
- covar = covariables.flow ;
- end
- end
-
- number_of_variables = number_of_variables + length(covar) ;
- end
-
- if ~isempty(outbond)
- covariables = mttGetCovariables(env,outbond.domain,outbond.domain_item) ;
- covar = [] ;
-
- if outbond.effort
- covar = covariables.effort ;
- elseif ~outbond.flow
- covar = covariables.flow ;
- end
-
- number_of_variables = number_of_variables + length(covar) ;
- end
- end
-
- additional_variables = 0 ;
- if ~isempty(object.abg)
- additional_variables = count_system_invars(object,root,env) ;
- end
-
- number_of_variables = number_of_variables + additional_variables ;
- end
-
- counter = number_of_variables ;
-
-
- function counter = count_system_outvars(model,root,env)
- is_root_model = nargin==1 ;
-
- if is_root_model
- root = model ;
- env = model.env ;
- end
- number_of_variables = 0 ;
-
- objects = mttGetFieldNames(model,'obj') ;
- for i = 1:length(objects)
- object_name = objects{i} ;
- object = getfield(model,'obj',object_name) ;
-
- switch object.class
- case {'SS','Se','Sf','De','Df'}
- inbond_number = object.interface.in ;
- outbond_number = object.interface.out ;
-
- inbond = model.bond(inbond_number) ;
- outbond = model.bond(outbond_number) ;
-
- if ~isempty(inbond)
- covariables = mttGetCovariables(env,inbond.domain,inbond.domain_item) ;
- covar = [] ;
-
- if inbond.effort
- covar = covariables.effort ;
- elseif ~inbond.flow
- covar = covariables.flow ;
- end
-
- number_of_variables = number_of_variables + length(covar) ;
- end
-
- if ~isempty(outbond)
- covariables = mttGetCovariables(env,outbond.domain,outbond.domain_item) ;
- covar = [] ;
-
- if ~outbond.effort
- if ~strcmp(object.class,'Sf')
- covar = covariables.effort ;
- end
- elseif outbond.flow
- if ~strcmp(object.class,'Se')
- covar = covariables.flow ;
- end
- end
-
- number_of_variables = number_of_variables + length(covar) ;
- end
- end
-
- additional_variables = 0 ;
- if ~isempty(object.abg)
- additional_variables = count_system_outvars(object,root,env) ;
- end
-
- number_of_variables = number_of_variables + additional_variables ;
- end
-
- counter = number_of_variables ;
-
-
- function counter = count_system_states(model)
- number_of_variables = mttGetFieldLength(model,'state') ;
-
- objects = mttGetFieldNames(model,'obj') ;
- for i = 1:length(objects)
- object_name = objects{i} ;
- object = getfield(model,'obj',object_name) ;
-
- additional_variables = 0 ;
- if ~isempty(object.abg)
- additional_variables = count_system_states(object) ;
- elseif ~isempty(object.cr)
- additional_variables = count_system_states(object.cr) ;
- end
-
- number_of_variables = number_of_variables + additional_variables ;
- end
-
- counter = number_of_variables ;
|