mttUpdateBondCausality.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. %function [model,bond_not_failed,diagnostic] = mttUpdateBondCausality(...
  2. % model,bond_number,effort_causality,flow_causality,uni_causality)
  3. function [model,bond_not_failed] = mttUpdateBondCausality(...
  4. model,bond_number,effort_causality,flow_causality,uni_causality)
  5. if isempty(bond_number)
  6. bond_not_failed = 1 ;
  7. % diagnostic = [] ;
  8. else
  9. [model.bond(bond_number).effort,effort_ok] = ...
  10. update_causality(model.bond(bond_number).effort,effort_causality) ;
  11. [model.bond(bond_number).flow,flow_ok] = ...
  12. update_causality(model.bond(bond_number).flow,flow_causality) ;
  13. [model.bond(bond_number).unicausal,unicausal_ok] = ...
  14. update_causality(model.bond(bond_number).unicausal,uni_causality) ;
  15. [model.bond(bond_number),unicausal_checked] = ...
  16. check_unicausal(model.bond(bond_number)) ;
  17. bond_not_failed = effort_ok & flow_ok & unicausal_ok & unicausal_checked ;
  18. % diagnostic = [effort_ok,flow_ok,unicausal_ok,unicausal_checked] ;
  19. end
  20. function [value,ok] = update_causality(value,new_value)
  21. ok = 1 ;
  22. if ~isempty(new_value)
  23. if isempty(value)
  24. value = new_value ;
  25. else
  26. ok = value==new_value ;
  27. end
  28. end
  29. function [bond,ok] = check_unicausal(bond)
  30. unicausal_defined = ~isempty(bond.unicausal) ;
  31. effort_defined = ~isempty(bond.effort) ;
  32. flow_defined = ~isempty(bond.flow) ;
  33. ok = 1 ;
  34. if unicausal_defined
  35. switch bond.unicausal
  36. case 0,
  37. if effort_defined & flow_defined
  38. ok = bond.effort==~bond.flow ;
  39. elseif effort_defined & ~flow_defined
  40. bond.flow = ~bond.effort ;
  41. elseif flow_defined & ~effort_defined
  42. bond.effort = ~bond.flow ;
  43. end
  44. case 1,
  45. if effort_defined & flow_defined
  46. ok = bond.effort==bond.flow ;
  47. elseif effort_defined & ~flow_defined
  48. bond.flow = bond.effort ;
  49. elseif flow_defined & ~effort_defined
  50. bond.effort = bond.flow ;
  51. end
  52. end
  53. end