| 46 | } |
| 47 | |
| 48 | ScheduleTypeLimits ScheduleTypeRegistry::getOrCreateScheduleTypeLimits(const ScheduleType& scheduleType, Model& model) const { |
| 49 | std::string defaultName = getDefaultName(scheduleType); |
| 50 | |
| 51 | // DLM: I do not understand why both upper and lower limit have to be set to reuse this? |
| 52 | //// if fully specified, try to retrieve |
| 53 | //if (scheduleType.lowerLimitValue && scheduleType.upperLimitValue) { |
| 54 | ScheduleTypeLimitsVector candidates = model.getConcreteModelObjectsByName<ScheduleTypeLimits>(defaultName); |
| 55 | for (const ScheduleTypeLimits& candidate : candidates) { |
| 56 | // Pass isStringent = true, so we don't return for eg a Dimensionless schedule with limits [0.5, 0.7] when our object accepts any number |
| 57 | if (isCompatible(scheduleType, candidate, true)) { |
| 58 | return candidate; |
| 59 | } |
| 60 | } |
| 61 | //} |
| 62 | |
| 63 | // otherwise, or if not there, create and return |
| 64 | ScheduleTypeLimits scheduleTypeLimits(model); |
| 65 | |
| 66 | scheduleTypeLimits.setName(defaultName); |
| 67 | |
| 68 | if (scheduleType.lowerLimitValue) { |
| 69 | scheduleTypeLimits.setLowerLimitValue(scheduleType.lowerLimitValue.get()); |
| 70 | } |
| 71 | if (scheduleType.upperLimitValue) { |
| 72 | scheduleTypeLimits.setUpperLimitValue(scheduleType.upperLimitValue.get()); |
| 73 | } |
| 74 | if (scheduleType.isContinuous) { |
| 75 | scheduleTypeLimits.setNumericType("Continuous"); |
| 76 | } else { |
| 77 | scheduleTypeLimits.setNumericType("Discrete"); |
| 78 | } |
| 79 | if (!scheduleType.unitType.empty()) { |
| 80 | scheduleTypeLimits.setUnitType(scheduleType.unitType); |
| 81 | } |
| 82 | |
| 83 | return scheduleTypeLimits; |
| 84 | } |
| 85 | |
| 86 | ScheduleTypeRegistry& ScheduleTypeRegistry::instance() { |
| 87 | static ScheduleTypeRegistry instance; |