use of org.osate.contribution.sei.sei.Sei in project osate2 by osate.
the class PropertyTotals method calcWeight.
private static Result calcWeight(ComponentInstance ci, boolean needWeight) {
Result result = ResultFactory.eINSTANCE.createResult();
result.setModelElement(ci);
final boolean getWeight = hasWeight.contains(ci.getCategory());
final double net = getWeight ? PropertyUtils.getScaled(Sei::getNetweight, ci, Weightunits.KG).orElse(0.0) : 0.0;
double weight = 0.0;
final double gross = getWeight ? PropertyUtils.getScaled(Sei::getGrossweight, ci, Weightunits.KG).orElse(0.0) : 0.0;
double sublimit = 0.0;
EList<ComponentInstance> cil = ci.getComponentInstances();
for (ComponentInstance subi : cil) {
ComponentCategory subcat = subi.getCategory();
if (!(subcat.equals(ComponentCategory.PROCESS) || subcat.equals(ComponentCategory.VIRTUAL_BUS) || subcat.equals(ComponentCategory.VIRTUAL_PROCESSOR))) {
Result subresult = calcWeight(subi, (needWeight && (gross == 0.0 || net > 0.0)));
result.getSubResults().add(subresult);
double subweight = ResultUtil.getReal(subresult, 0);
weight += subweight;
sublimit += hasWeight.contains(subi.getCategory()) ? PropertyUtils.getScaled(Sei::getWeightlimit, subi, Weightunits.KG).orElse(0.0) : 0.0;
}
}
EList<ConnectionInstance> connl = ci.getConnectionInstances();
for (ConnectionInstance connectionInstance : connl) {
ConnectionInstanceEnd source = connectionInstance.getSource();
ConnectionInstanceEnd destination = connectionInstance.getDestination();
if ((source instanceof FeatureInstance && ((FeatureInstance) source).getCategory() == FeatureCategory.BUS_ACCESS) || (destination instanceof FeatureInstance && ((FeatureInstance) destination).getCategory() == FeatureCategory.BUS_ACCESS)) {
double netconn = PropertyUtils.getScaled(Sei::getNetweight, connectionInstance, Weightunits.KG).orElse(0.0);
double grossconn = PropertyUtils.getScaled(Sei::getGrossweight, connectionInstance, Weightunits.KG).orElse(0.0);
weight += netconn > 0 ? netconn : grossconn;
if (netconn > 0 || grossconn > 0) {
String ResultMsg = String.format(connectionInstance.getName() + ": Weight of access connection is %.3f kg", netconn > 0 ? netconn : grossconn);
result.getDiagnostics().add(ResultUtil.createInfoDiagnostic(ResultMsg, connectionInstance));
}
sublimit += connectionInstance.getKind() == ConnectionKind.ACCESS_CONNECTION ? PropertyUtils.getScaled(Sei::getWeightlimit, connectionInstance, Weightunits.KG).orElse(0.0) : 0.0;
}
}
if (weight == 0.0 && cil.isEmpty()) {
if (gross == 0 && net > 0) {
weight = net;
} else {
weight = gross;
}
} else {
weight += net;
}
if (gross > 0.0) {
if (weight > gross) {
// problem
result.getDiagnostics().add(ResultUtil.createWarningDiagnostic(String.format("[G] Sum of weights (%.3f kg) exceeds gross weight of %.3f kg", weight, gross), ci));
// Set gross weight
} else if (weight > 0 && weight < gross) {
// problem
result.getDiagnostics().add(ResultUtil.createWarningDiagnostic(String.format("[G] Sum of weights (%.3f kg) less than gross weight of %.3f kg (using gross weight)", weight, gross), ci));
weight = gross;
}
if (weight == 0.0) {
weight = gross;
}
}
final double limit = getWeight ? PropertyUtils.getScaled(Sei::getWeightlimit, ci, Weightunits.KG).orElse(0.0) : 0.0;
if (limit > 0.0) {
if (weight > limit) {
// problem
String ResultMsg = String.format("[A] Sum of weights (%.3f kg) exceeds weight limit of %.3f kg", weight, limit);
result.getDiagnostics().add(ResultUtil.createErrorDiagnostic(ResultMsg, ci));
} else {
if (sublimit > limit) {
// problem
result.getDiagnostics().add(ResultUtil.createWarningDiagnostic(String.format("[L] Sum of subcomponent weight limits (%.3f kg) exceeds weight limit of %.3f kg", sublimit, limit), ci));
}
if (weight < limit) {
String ResultMsg = String.format("[A] Sum of weights (%.3f kg) is below weight limit of %.3f kg (%.1f %% Weight slack)", weight, limit, (limit - weight) / limit * 100);
result.getDiagnostics().add(ResultUtil.createInfoDiagnostic(ResultMsg, ci));
}
}
} else {
if (weight > 0.0) {
String ResultMsg = String.format("[L] Sum of weights / gross weight is %.3f kg (no limit specified)", weight);
result.getDiagnostics().add(ResultUtil.createInfoDiagnostic(ResultMsg, ci));
} else if (needWeight) {
String ResultMsg = "[L] No net weight plus subcomponent weight or no gross weight";
result.getDiagnostics().add(ResultUtil.createWarningDiagnostic(ResultMsg, ci));
}
}
ResultUtil.addRealValue(result, weight, "kg");
ResultUtil.addRealValue(result, gross, "kg");
ResultUtil.addRealValue(result, net, "kg");
ResultUtil.addRealValue(result, limit, "kg");
return result;
}
use of org.osate.contribution.sei.sei.Sei in project osate2 by osate.
the class BoundResourceAnalysis method checkProcessorLoad.
/**
* check the load from components bound to the given processor The
* components can be threads or higher level components.
*
* @param curProcessor Component Instance of processor
*/
private void checkProcessorLoad(ComponentInstance curProcessor, final SystemOperationMode som) {
if (!curProcessor.isActive(som)) {
return;
}
double MIPScapacity = getMIPSCapacityInMIPS(curProcessor, 0.0);
if (MIPScapacity == 0 && InstanceModelUtil.isVirtualProcessor(curProcessor)) {
MIPScapacity = PropertyUtils.getScaled(Sei::getMipsbudget, curProcessor, ProcessorSpeedUnits.MIPS).orElse(0.0);
}
EList<ComponentInstance> boundComponents = InstanceModelUtil.getBoundSWComponents(curProcessor);
if (boundComponents.size() == 0 && MIPScapacity > 0) {
errManager.infoSummary(curProcessor, som.getName(), "No application components bound to " + curProcessor.getComponentInstancePath() + " with MIPS capacity " + toStringScaled(MIPScapacity, ProcessorSpeedUnits.MIPS));
return;
}
if (MIPScapacity == 0 && InstanceModelUtil.isVirtualProcessor(curProcessor)) {
errManager.warningSummary(curProcessor, som.getName(), "Virtual processor " + curProcessor.getComponentInstancePath() + " has no MIPS capacity or budget.");
return;
}
if (MIPScapacity == 0 && InstanceModelUtil.isProcessor(curProcessor)) {
errManager.errorSummary(curProcessor, som.getName(), "Processor " + curProcessor.getComponentInstancePath() + " has no MIPS capacity but has bound components.");
}
if (InstanceModelUtil.isVirtualProcessor(curProcessor)) {
logHeader("\n\nDetailed Workload Report: " + Aadl2Util.getPrintableSOMName(som) + " for Virtual Processor " + curProcessor.getComponentInstancePath() + " with Capacity " + toStringScaled(MIPScapacity, ProcessorSpeedUnits.MIPS) + "\n\nComponent,Budget,Actual");
} else {
logHeader("\n\nDetailed Workload Report: " + Aadl2Util.getPrintableSOMName(som) + " for Processor " + curProcessor.getComponentInstancePath() + " with Capacity " + toStringScaled(MIPScapacity, ProcessorSpeedUnits.MIPS) + "\n\nComponent,Budget,Actual");
}
double totalMIPS = 0.0;
for (Iterator<ComponentInstance> it = boundComponents.iterator(); it.hasNext(); ) {
ComponentInstance bci = it.next();
double actualmips = sumBudgets(bci, ResourceKind.MIPS, som, "");
if (actualmips > 0) {
totalMIPS += actualmips;
}
}
logHeader("Total,," + toStringScaled(totalMIPS, ProcessorSpeedUnits.MIPS));
if (totalMIPS > MIPScapacity) {
errManager.errorSummary(curProcessor, null, " Processor " + curProcessor.getComponentInstancePath() + ": Total MIPS " + toStringScaled(totalMIPS, ProcessorSpeedUnits.MIPS) + " of bound tasks exceeds MIPS capacity " + toStringScaled(MIPScapacity, ProcessorSpeedUnits.MIPS));
} else if (totalMIPS == 0.0) {
errManager.warningSummary(curProcessor, null, " Processor " + curProcessor.getComponentInstancePath() + ": Bound app's have no MIPS budget.");
} else {
errManager.infoSummary(curProcessor, null, " Processor " + curProcessor.getComponentInstancePath() + ": Total MIPS " + toStringScaled(totalMIPS, ProcessorSpeedUnits.MIPS) + " of bound tasks within " + "MIPS capacity " + toStringScaled(MIPScapacity, ProcessorSpeedUnits.MIPS) + " of " + curProcessor.getComponentInstancePath());
}
}
Aggregations