MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / getAutosizedValue

Method getAutosizedValue

src/model/ModelObject.cpp:290–337  ·  view source on GitHub ↗

Gets the autosized component value from the sql file **/

Source from the content-addressed store, hash-verified

288
289 /** Gets the autosized component value from the sql file **/
290 boost::optional<double> ModelObject_Impl::getAutosizedValue(const std::string& valueName, const std::string& units,
291 std::string overrideCompType) const {
292
293 // Get the object name
294 if (!name()) {
295 LOG(Warn, "This object does not have a name, cannot retrieve the autosized value '" + valueName + "'.");
296 return boost::none;
297 }
298
299 // Check that the model has a sql file
300 if (!model().sqlFile()) {
301 LOG(Warn, "This model has no sql file, cannot retrieve the autosized value '" + valueName + "'.");
302 return boost::none;
303 }
304
305 // Get the object name and transform to the way it is recorded
306 // in the sql file
307 std::string sqlName = name().get();
308 boost::to_upper(sqlName);
309
310 // Get the object type and transform to the way it is recorded in the sql file
311 if (overrideCompType.empty()) {
312 overrideCompType = iddObject().type().valueDescription();
313 boost::replace_all(overrideCompType, "OS:", "");
314 }
315
316 const std::string directQuery = R"sql(
317 SELECT Value FROM ComponentSizes
318 WHERE CompType = ?
319 AND CompName = ?
320 AND Description = ?
321 AND Units = ?;
322 )sql";
323 boost::optional<double> val = model().sqlFile().get().execAndReturnFirstDouble(directQuery,
324 // bindArgs
325 overrideCompType, sqlName, valueName, units);
326 if (!val) {
327 LOG(Debug, fmt::format(R"sql(The direct query failed:
328SELECT Value FROM ComponentSizes
329 WHERE CompType = '{}'
330 AND CompName = '{}'
331 AND Description = '{}'
332 AND Units = '{}';)sql",
333 overrideCompType, sqlName, valueName, units));
334 }
335
336 return val;
337 }
338
339 //void ModelObject_Impl::connect(unsigned outletPort, ModelObject target, unsigned inletPort)
340 //{

Calls 7

nameClass · 0.85
sqlFileMethod · 0.80
valueDescriptionMethod · 0.80
getMethod · 0.45
emptyMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected