13#include <forward_list>
84 virtual std::string
strOption(
const char * i_key,
const std::string & i_default =
"") const noexcept = 0;
87 virtual
bool boolOption(const
char * i_key) const noexcept = 0;
98 virtual
int intOption(const
char * i_key,
int i_default) const noexcept = 0;
101 virtual
long long longOption(const
char * i_key,
long long i_default) const noexcept = 0;
104 virtual
double doubleOption(const
char * i_key,
double i_default) const noexcept = 0;
107 virtual std::vector<std::pair<std::
string, std::
string>>
allOptions(
void) const noexcept = 0;
131 virtual void readParameter(
const char * i_name,
int i_subId,
const std::type_info & i_type,
size_t i_size,
void * io_valueArr) = 0;
137 virtual ~IModel(
void)
noexcept = 0;
158 virtual void writeOutputTable(
const char * i_name,
size_t i_size, std::forward_list<std::unique_ptr<
double[]> > & io_accValues) = 0;
169 virtual void writeDbMicrodata(
int i_entityKind, uint64_t i_microdataKey,
const void * i_entityThis) = 0;
179 virtual void writeCsvMicrodata(
int i_entityKind, uint64_t i_microdataKey,
int i_eventId,
bool i_isSameEntity,
const void * i_entityThis) = 0;
226 static int byName(
const char * i_entityName,
const char * i_attrName);
253 static const char * byId(
int i_eventId);
265 #define OM_USE_MICRODATA_EVENTS (EVENT_ID_NAME_ARR_LEN > 1)
288 std::vector<TVal> valueVec(selfCount);
290 bool isStr =
typeid(TVal) ==
typeid(std::string);
293 for (
int nSub = 0; nSub < allCount; nSub++) {
295 void * pData = &extraVal;
297 extraVal = std::numeric_limits<TVal>::quiet_NaN();
299 i_runBase->
readParameter(i_name, nSub,
typeid(TVal), 1, pData);
302 valueVec[0] = extraVal;
308 catch (std::exception & ex) {
309 throw ModelException(
"Failed to read input parameter: %s sub-value [%d]. %s", i_name, nSub, ex.what());
316 template<
typename TVal> std::vector<std::unique_ptr<TVal[]>>
read_om_parameter(
IRunBase *
const i_runBase,
const char * i_name,
size_t i_size)
322 if (i_size <= 0)
throw ModelException(
"invalid size: %zd of parameter %s", i_size, i_name);
325 std::vector<std::unique_ptr<TVal[]>> valueVec(selfCount);
326 for (
auto & p : valueVec) {
327 p.reset(
new TVal[i_size]);
330 std::unique_ptr<TVal> extraVal;
332 extraVal.reset(
new TVal[i_size]);
334 bool isStr =
typeid(TVal) ==
typeid(std::string);
337 for (
int nSub = 0; nSub < allCount; nSub++) {
339 void * pData = valueVec[0].get();
348 std::fill(
static_cast<TVal *
>(pData), &(
static_cast<TVal *
>(pData))[i_size], std::numeric_limits<TVal>::quiet_NaN());
350 i_runBase->
readParameter(i_name, nSub,
typeid(TVal), i_size, pData);
352 catch (std::exception & ex) {
353 throw ModelException(
"Failed to read input parameter: %s sub-value [%d]. %s", i_name, nSub, ex.what());
374int main(
int argc,
char ** argv);
openM++ exceptions
Definition: omError.h:19
openM++ namespace
Definition: log.h:32
OpenmException< 4000, modelUnknownErrorMessage > ModelException
modeling library exception
Definition: omModel.h:271
const ParameterNameSizeItem parameterNameSizeArr[]
model input parameters name, type and size
const EventIdNameItem EventIdNameArr[]
list of events id, name
const char modelUnknownErrorMessage[]
default error message: "unknown model error"
Definition: modelBase.cpp:14
std::vector< TVal > read_om_parameter(IRunBase *const i_runBase, const char *i_name)
read scalar parameter value or all sub-values for the current process
Definition: omModel.h:280
const size_t EVENT_ID_NAME_ARR_LEN
size of event list: all events in all entities
const size_t PARAMETER_NAME_ARR_LEN
size of parameters list: number of model input parameters
const size_t ENTITY_NAME_SIZE_ARR_LEN
size of entity attributes list: all attributes of all entities
const char simulationUnknownErrorMessage[]
simulation exception default error message: "unknown error in simulation"
Definition: modelBase.cpp:17
OpenmException< 4000, simulationUnknownErrorMessage > SimulationException
simulation exception
Definition: omModel.h:277
const EntityNameSizeItem EntityNameSizeArr[]
list of entity attributes name, type, size and member offset
OpenM++: public interface for errors and exceptions.
OpenM++: public interface for log and trace support.
const char * OM_MODEL_NAME
model name
openm::IModelRunState * theModelRunState
public interface of process-wide model run state: status, progress, update times
Definition: modelRunState.cpp:33
void(* OM_STARTUP_HANDLER)(openm::IModel *const i_model)
model startup method: initialize sub-value
Definition: omModel.h:385
OM_SHUTDOWN_HANDLER ModelShutdownHandler
model shutdown method: save output results
Definition: main.cpp:64
int main(int argc, char **argv)
main entry point
Definition: main.cpp:82
OM_STARTUP_HANDLER ModelStartupHandler
model startup method: initialize sub-value
Definition: main.cpp:58
OM_RUN_ONCE_HANDLER RunOnceHandler
model one-time initialization
Definition: main.cpp:52
void(* OM_EVENT_LOOP_HANDLER)(openm::IModel *const i_model)
model event loop: user code entry point
Definition: omModel.h:389
OM_RUN_SHUTDOWN_HANDLER RunShutdownHandler
process shutdown: last entry point from user code before process exit
Definition: main.cpp:67
void(* OM_RUN_SHUTDOWN_HANDLER)(bool i_isError, openm::IRunBase *const i_runBase)
process shutdown: last entry point from user code before process exit
Definition: omModel.h:397
OM_RUN_INIT_HANDLER RunInitHandler
model run initialization: read input parameters
Definition: main.cpp:55
void(* OM_RUN_ONCE_HANDLER)(openm::IRunBase *const i_runBase)
model one-time initialization
Definition: omModel.h:377
void(* OM_SHUTDOWN_HANDLER)(openm::IModel *const i_model)
model shutdown method: save output results
Definition: omModel.h:393
OM_EVENT_LOOP_HANDLER RunModelHandler
model event loop: user code entry point
Definition: main.cpp:61
const char * OM_MODEL_DIGEST
model metadata digest: unique model key
void(* OM_RUN_INIT_HANDLER)(openm::IRunBase *const i_runBase)
model run initialization: read input parameters
Definition: omModel.h:381
OpenM++ modeling library: model run state public interface.
model entity attributes name, type, size and member offset
Definition: omModel.h:203
const ptrdiff_t offset
attribute value offset in entity this
Definition: omModel.h:223
const char * attribute
attribute name
Definition: omModel.h:214
int entityId
entity metadata id in database
Definition: omModel.h:205
int attributeId
attribute metadata id in database
Definition: omModel.h:211
const char * entity
entity name
Definition: omModel.h:208
const std::type_info & typeOf
attribute value type
Definition: omModel.h:217
const size_t size
attribute value bytes size
Definition: omModel.h:220
model events id, name
Definition: omModel.h:245
int eventId
event id
Definition: omModel.h:247
const char * eventName
event name
Definition: omModel.h:250
static bool checkId(int i_eventId)
return true if event id valid
Definition: omModel.h:256
model sub-value run public interface
Definition: omModel.h:136
virtual void updateProgress(int i_count, double i_value=0.0)=0
set modeling progress count and value
virtual void writeCsvMicrodata(int i_entityKind, uint64_t i_microdataKey, int i_eventId, bool i_isSameEntity, const void *i_entityThis)=0
write microdata into CSV file or into trace.
virtual int subValueCount(void) const noexcept=0
number of sub-values
virtual int tableIdByName(const char *i_name) const =0
return id of output table by name
virtual int parameterSubValueIndex(const char *i_name) const =0
return index of parameter sub-value in the storage array for current modeling thread
virtual int subValueId(void) const noexcept=0
sub-value index of current modeling thread
virtual void writeOutputTable(const char *i_name, size_t i_size, std::forward_list< std::unique_ptr< double[]> > &io_accValues)=0
write output result table: sub values
virtual bool isSuppressed(const char *i_name) const =0
check by name if output table suppressed.
virtual void writeDbMicrodata(int i_entityKind, uint64_t i_microdataKey, const void *i_entityThis)=0
write microdata into the database.
virtual const RunOptions * runOptions(void) const =0
return basic model run options
model run state public interface: thread safe
Definition: omModelRunState.h:139
public interface to initialize model run and input parameters
Definition: omModel.h:112
virtual int parameterSubValueIndex(int i_paramId, int i_subId) const =0
return index of parameter sub-value in the storage array of sub-values
virtual void readParameter(const char *i_name, int i_subId, const std::type_info &i_type, size_t i_size, void *io_valueArr)=0
read model parameter
virtual int parameterSelfSubCount(int i_paramId) const =0
number of parameter sub-values for current process
virtual int parameterSubCount(int i_paramId) const =0
number of parameter sub-values
virtual bool isUseSubValue(int i_subId) const =0
return true if sub-value used by current process
virtual int parameterIdByName(const char *i_name) const =0
return id of parameter by name
public interface to get model run options
Definition: omModel.h:77
virtual bool isOptionExist(const char *i_key) const noexcept=0
return true if run option found by i_key in run_option table for the current run id.
virtual int boolOptionToInt(const char *i_key) const noexcept=0
search for boolean value of run option by i_key and return one of: return 1 if key found and value i...
virtual double doubleOption(const char *i_key, double i_default) const noexcept=0
return double value of run option by i_key or default if not found or can not be converted to double.
virtual long long longOption(const char *i_key, long long i_default) const noexcept=0
return long value of run option by i_key or default if not found or can not be converted to long.
virtual std::vector< std::pair< std::string, std::string > > allOptions(void) const noexcept=0
return a copy of all run options as [key, value] pairs, ordered by key.
virtual std::string strOption(const char *i_key, const std::string &i_default="") const noexcept=0
return string value of run option by i_key or default value if not found.
virtual int intOption(const char *i_key, int i_default) const noexcept=0
return int value of run option by i_key or default if not found or can not be converted to int.
virtual bool boolOption(const char *i_key) const noexcept=0
return boolean value of run option by i_key or false if not found or value is not "yes",...
model input parameter name, type and size
Definition: omModel.h:184
const size_t size
parameter size (number of parameter values)
Definition: omModel.h:192
const std::type_info & typeOf
value type
Definition: omModel.h:189
const char * name
input parameter name
Definition: omModel.h:186
basic model run options
Definition: omModel.h:26
bool isMicrodata(void) const
retrun true if any microdata output enabled
Definition: omModel.h:69
bool isTraceMicrodata
if true then model run is writing microdata into trace output
Definition: omModel.h:46
double progressStep
if positive then used for simulation progress reporting, ex: every 1000 cases or every 0....
Definition: omModel.h:52
bool isTextMicrodata(void) const
retrun true if microdata output to text enabled: output to CSV or to trace
Definition: omModel.h:72
bool useSparse
OBSOLETE, for backward compatibility only.
Definition: omModel.h:34
int progressPercent
if positive then used for simulation progress reporting, ex: every 10%
Definition: omModel.h:49
bool isCsvMicrodata
if true then model run is writing microdata into CSV
Definition: omModel.h:43
int subValueId
sub-value index for current modeling thread
Definition: omModel.h:31
bool isDbMicrodata
if true then model run is storing microdata in database
Definition: omModel.h:40
int subValueCount
number of sub-values
Definition: omModel.h:28
double nullValue
OBSOLETE, for backward compatibility only.
Definition: omModel.h:37
RunOptions(void)
init run options with default values
Definition: omModel.h:55