mttCountSystemMapping.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. function counter = mttCountSystemMapping(model)
  2. sympars = count_system_sympars(model) ;
  3. inputs = count_system_inputs(model) ;
  4. invars = count_system_invars(model) ;
  5. outvars = count_system_outvars(model) ;
  6. states = count_system_states(model) ;
  7. counter.input = sympars + inputs + invars ;
  8. counter.output = outvars ;
  9. counter.state = states ;
  10. function counter = count_system_sympars(model)
  11. number_of_variables = mttGetFieldLength(model,'sympar') ;
  12. counter = 0 ;
  13. for i = 1:number_of_variables
  14. default_value = model.sympar_default{i} ;
  15. if isempty(default_value)
  16. counter = counter + 1 ;
  17. end
  18. end
  19. function counter = count_system_inputs(model)
  20. number_of_variables = mttGetFieldLength(model,'input') ;
  21. objects = mttGetFieldNames(model,'obj') ;
  22. for i = 1:length(objects)
  23. object_name = objects{i} ;
  24. object = getfield(model,'obj',object_name) ;
  25. additional_variables = 0 ;
  26. if ~isempty(object.abg)
  27. additional_variables = count_system_inputs(object) ;
  28. elseif ~isempty(object.cr)
  29. additional_variables = count_system_inputs(object.cr) ;
  30. end
  31. number_of_variables = number_of_variables + additional_variables ;
  32. end
  33. counter = number_of_variables ;
  34. function counter = count_system_invars(model,root,env)
  35. is_root_model = nargin==1 ;
  36. if is_root_model
  37. root = model ;
  38. env = model.env ;
  39. end
  40. number_of_variables = 0 ;
  41. objects = mttGetFieldNames(model,'obj') ;
  42. for i = 1:length(objects)
  43. object_name = objects{i} ;
  44. object = getfield(model,'obj',object_name) ;
  45. switch object.class
  46. case {'SS','Se','Sf','De','Df'}
  47. inbond_number = object.interface.in ;
  48. outbond_number = object.interface.out ;
  49. inbond = model.bond(inbond_number) ;
  50. outbond = model.bond(outbond_number) ;
  51. if ~isempty(inbond)
  52. covariables = mttGetCovariables(env,inbond.domain,inbond.domain_item) ;
  53. covar = [] ;
  54. if ~inbond.effort
  55. if ~strcmp(object.class,'Df')
  56. covar = covariables.effort ;
  57. end
  58. elseif inbond.flow
  59. if ~strcmp(object.class,'De')
  60. covar = covariables.flow ;
  61. end
  62. end
  63. number_of_variables = number_of_variables + length(covar) ;
  64. end
  65. if ~isempty(outbond)
  66. covariables = mttGetCovariables(env,outbond.domain,outbond.domain_item) ;
  67. covar = [] ;
  68. if outbond.effort
  69. covar = covariables.effort ;
  70. elseif ~outbond.flow
  71. covar = covariables.flow ;
  72. end
  73. number_of_variables = number_of_variables + length(covar) ;
  74. end
  75. end
  76. additional_variables = 0 ;
  77. if ~isempty(object.abg)
  78. additional_variables = count_system_invars(object,root,env) ;
  79. end
  80. number_of_variables = number_of_variables + additional_variables ;
  81. end
  82. counter = number_of_variables ;
  83. function counter = count_system_outvars(model,root,env)
  84. is_root_model = nargin==1 ;
  85. if is_root_model
  86. root = model ;
  87. env = model.env ;
  88. end
  89. number_of_variables = 0 ;
  90. objects = mttGetFieldNames(model,'obj') ;
  91. for i = 1:length(objects)
  92. object_name = objects{i} ;
  93. object = getfield(model,'obj',object_name) ;
  94. switch object.class
  95. case {'SS','Se','Sf','De','Df'}
  96. inbond_number = object.interface.in ;
  97. outbond_number = object.interface.out ;
  98. inbond = model.bond(inbond_number) ;
  99. outbond = model.bond(outbond_number) ;
  100. if ~isempty(inbond)
  101. covariables = mttGetCovariables(env,inbond.domain,inbond.domain_item) ;
  102. covar = [] ;
  103. if inbond.effort
  104. covar = covariables.effort ;
  105. elseif ~inbond.flow
  106. covar = covariables.flow ;
  107. end
  108. number_of_variables = number_of_variables + length(covar) ;
  109. end
  110. if ~isempty(outbond)
  111. covariables = mttGetCovariables(env,outbond.domain,outbond.domain_item) ;
  112. covar = [] ;
  113. if ~outbond.effort
  114. if ~strcmp(object.class,'Sf')
  115. covar = covariables.effort ;
  116. end
  117. elseif outbond.flow
  118. if ~strcmp(object.class,'Se')
  119. covar = covariables.flow ;
  120. end
  121. end
  122. number_of_variables = number_of_variables + length(covar) ;
  123. end
  124. end
  125. additional_variables = 0 ;
  126. if ~isempty(object.abg)
  127. additional_variables = count_system_outvars(object,root,env) ;
  128. end
  129. number_of_variables = number_of_variables + additional_variables ;
  130. end
  131. counter = number_of_variables ;
  132. function counter = count_system_states(model)
  133. number_of_variables = mttGetFieldLength(model,'state') ;
  134. objects = mttGetFieldNames(model,'obj') ;
  135. for i = 1:length(objects)
  136. object_name = objects{i} ;
  137. object = getfield(model,'obj',object_name) ;
  138. additional_variables = 0 ;
  139. if ~isempty(object.abg)
  140. additional_variables = count_system_states(object) ;
  141. elseif ~isempty(object.cr)
  142. additional_variables = count_system_states(object.cr) ;
  143. end
  144. number_of_variables = number_of_variables + additional_variables ;
  145. end
  146. counter = number_of_variables ;