mttPropagateDomains.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. function model = mttPropagateDomains(model,branch)
  2. is_root_model = (nargin==1) ;
  3. objects = mttGetFieldNames(model,'obj') ;
  4. for i = 1:length(objects)
  5. object_name = objects{i} ;
  6. object = getfield(model,'obj',object_name) ;
  7. if is_root_model
  8. branch = mttDetachText(model.source,'/') ;
  9. end
  10. here = [branch,':',object_name] ;
  11. if ~isempty(object.abg)
  12. for j = 1:mttGetFieldLength(object,'interface')
  13. port_name = object.interface(j).name ;
  14. inbond = object.interface(j).in ;
  15. outbond = object.interface(j).out ;
  16. inmap = object.interface(j).map.in ;
  17. outmap = object.interface(j).map.out ;
  18. [inbond_domain,inbond_domain_item] = mttGetBondDomain(model,inbond) ;
  19. [outbond_domain,outbond_domain_item] = mttGetBondDomain(model,outbond) ;
  20. [inmap_domain,inmap_domain_item] = mttGetBondDomain(object,inmap) ;
  21. [outmap_domain,outmap_domain_item] = mttGetBondDomain(object,outmap) ;
  22. [model,inbond_ok] = mttUpdateBondDomain(model,inbond,inmap_domain,inmap_domain_item) ;
  23. [model,outbond_ok] = mttUpdateBondDomain(model,outbond,outmap_domain,outmap_domain_item) ;
  24. [object,inmap_ok] = mttUpdateBondDomain(object,inmap,inbond_domain,inbond_domain_item) ;
  25. [object,outmap_ok] = mttUpdateBondDomain(object,outmap,outbond_domain,outbond_domain_item) ;
  26. ok = inbond_ok & outbond_ok & inmap_ok & outmap_ok ;
  27. mttAssert(ok,['Domain conflict at port "',port_name,'" in ',here]) ;
  28. end
  29. if is_root_model
  30. branch = object_name ;
  31. else
  32. branch = [branch,'/',object_name] ;
  33. end
  34. object = mttPropagateDomains(object,branch) ;
  35. model = setfield(model,'obj',object_name,object) ;
  36. elseif ~isempty(object.cr)
  37. interface = object.cr.interface ;
  38. port_names = mttGetFieldNames(interface,'port') ;
  39. for j = 1:length(port_names)
  40. port_name = port_names{j} ;
  41. port = getfield(interface,'port',port_name) ;
  42. inbond = port.in ;
  43. outbond = port.out ;
  44. [model,inbond_ok] = mttUpdateBondDomain(model,inbond,port.domain,port.domain_item) ;
  45. [model,outbond_ok] = mttUpdateBondDomain(model,outbond,port.domain,port.domain_item) ;
  46. ok = inbond_ok & outbond_ok ;
  47. mttAssert(ok,['Domain conflict at port "',port_name,'" in ',here]) ;
  48. end
  49. else
  50. number_of_interfaces = mttGetFieldLength(object,'interface') ;
  51. switch object.class
  52. case {'0','1'},
  53. index = 0 ;
  54. finding_domain = 1 ;
  55. while finding_domain
  56. index = index + 1 ;
  57. inbond = object.interface(index).in ;
  58. outbond = object.interface(index).out ;
  59. if isempty(inbond)
  60. bond_number = outbond ;
  61. else
  62. bond_number = inbond ;
  63. end
  64. [existing_domain,existing_domain_item] = mttGetBondDomain(model,bond_number) ;
  65. found_domain = ~isempty(existing_domain) ;
  66. finding_domain = ~found_domain & index<number_of_interfaces ;
  67. end
  68. if found_domain
  69. for j = 1:number_of_interfaces
  70. inbond = object.interface(j).in ;
  71. outbond = object.interface(j).out ;
  72. if isempty(inbond)
  73. bond_number = outbond ;
  74. else
  75. bond_number = inbond ;
  76. end
  77. model = mttUpdateBondDomain(model,bond_number,existing_domain,existing_domain_item) ;
  78. end
  79. end
  80. end
  81. end
  82. end