MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
Context Class Reference

#include <context.h>

Collaboration diagram for Context:
[legend]

Static Public Member Functions

static void readPropertyFile (FileType, const MString &fileName)
 
static MInt propertyLength (const MString &name, MInt solverId=m_noSolvers)
 Returns the number of elements of a property. More...
 
static void assertPropertyLength (const MString &name, const MInt length, const MInt solverId=m_noSolvers)
 Assert that the length of a property matches the given length. More...
 
static MInt propertySolverId (const MString &name, MInt solverId=m_noSolvers)
 Returns the number of elements of a property. More...
 
static MBool propertyExists (const MString &name, MInt solver=m_noSolvers)
 This function checks if a property exists in general. More...
 
static MBool solverPropertyExists (const MString &name, MInt solver)
 Checks existence of a solver property details This function returns true, if the solver property with the requested name exists for the requested solver. More...
 
static void clear ()
 
static void init ()
 This intializes the property Map. More...
 
static void addProperty (MProperty *)
 This method adds properties. More...
 
static void writeProperties (char *fileName)
 
static void writePropertiesHumanReadable ()
 Write the properties into a text file. More...
 
static void initializationProcessFinished ()
 Sets flag to forbide property access. More...
 
static void communicateProperties ()
 Communicates properties to check if default falues match. More...
 
static std::list< MProperty * > * receiveProperties (MInt rank)
 Receives a property list from another cpu. More...
 
static void sendProperties (MInt rank)
 Sends the property list to another cpu. More...
 
static void checkPropertyViolation (MInt partnerrank, std::list< MProperty * > *prop)
 Checks if local properties differ from received properties. More...
 
static MString propertyFileName ()
 Return name of most recently read property file. More...
 
static MString propertyFileText ()
 Return unprocessed content of most recently read property file. More...
 
static void dump (const MString &fileName)
 Dump all properties to text file. More...
 
template<typename T >
static T getBasicProperty (const MString name, const MString &nameOfCallingFunction, const T *default_value, MInt pos=0)
 
template<typename T >
static T getBasicProperty (const MString name, const MString &nameOfCallingFunction, MInt pos=0)
 
template<typename T >
static T getSolverProperty (const MString name, const MInt solverId, const MString &nameOfCallingFunction, const T *default_value, MInt pos=0)
 
template<typename T >
static T getSolverProperty (const MString name, const MInt solverId, const MString &nameOfCallingFunction, MInt pos=0)
 

Static Private Member Functions

template<typename T , typename F >
static T getBasicPropertyImplicit (const MString &nameOfCallingFunction, const MString &name, MBool has_default, const T *defaultValue, MInt position, F &&f)
 Returns the value of the requested basic level property (implicit). More...
 
static MInt getBasicPropertyOverloaded (const MString &nameOfCallingFunction, const MString &name, MBool has_default, const MInt *default_value, MInt pos)
 
static MFloat getBasicPropertyOverloaded (const MString &nameOfCallingFunction, const MString &name, MBool has_default, const MFloat *default_value, MInt pos)
 
static MString getBasicPropertyOverloaded (const MString &nameOfCallingFunction, const MString &name, MBool has_default, const MString *default_value, MInt pos)
 Returns the value of the requested basic property. overloaded. More...
 
static MBool getBasicPropertyOverloaded (const MString &nameOfCallingFunction, const MString &name, MBool has_default, const MBool *default_value, MInt pos)
 
template<typename T , typename F >
static T getSolverPropertyImplicit (const MString &nameOfCallingFunction, const MString &name, const MInt solverId, MBool has_default, const T *defaultValue, MInt position, F &&f)
 Returns the value of the requested solver property (implicit). More...
 
static MInt getSolverPropertyOverloaded (const MString &nameOfCallingFunction, const MString &name, const MInt solverId, MBool has_default, const MInt *default_value, MInt pos)
 
static MFloat getSolverPropertyOverloaded (const MString &nameOfCallingFunction, const MString &name, const MInt solverId, MBool has_default, const MFloat *default_value, MInt pos)
 
static MString getSolverPropertyOverloaded (const MString &nameOfCallingFunction, const MString &name, const MInt solverId, MBool has_default, const MString *default_value, MInt pos)
 Returns the value of the requested solver property. overloaded. More...
 
static MBool getSolverPropertyOverloaded (const MString &nameOfCallingFunction, const MString &name, const MInt solverId, MBool has_default, const MBool *default_value, MInt pos)
 
static MBool isSameValue (const MFloat v1, const MFloat v2)
 
static MBool isSameValue (const MBool v1, const MBool v2)
 
static MBool isSameValue (const MInt v1, const MInt v2)
 
static MBool isSameValue (const MString v1, const MString v2)
 

Static Private Attributes

static IONetcdfm_IONetcdf
 
static IOTomlm_IOToml
 
static MString m_name
 
static MInt m_noSolvers
 
static propertyMapm_propertyMap
 
static propertyMapm_propertyMapLowercase
 
static zoneMapm_zoneMap
 
static assemblym_assembly
 
static std::pair< propertyMap::iterator, propertyMap::iterator > m_pair
 
static MString m_propertyFileOutputName
 
static MString m_propertyFileText
 
static MInt m_fileType
 
static MBool m_checkingProperties
 

Detailed Description

This class manages the properties that are used in the MAIA. The functions and members are statical so that you can acces the properties from every where within the program. The class only stores the pointers to the property structs, and not the structs themselves. For storing those pointers a STL multimap is used with the names of the properties as keys. The class has two template functions for a more convienient useage. To get a basic property, simply call the getBasicProperty() function, with the property name. Furthermore, you can specify a default value and a the position, in case the property is an array. To get a solver specific property, simply call the getSolverProperty() function, with the property name and the solverId. Furthermore, you can specify a default value and a the position, in case the property is an array.

Definition at line 80 of file context.h.

Member Function Documentation

◆ addProperty()

void Context::addProperty ( MProperty p)
static

Definition at line 453 of file context.cpp.

453 {
454 // TRACE();
455
456 const pair<const MString, MProperty*> mp(p->name, p);
457
458 // produce the lowercase variant of the name to warn if property exists with different case
459 MString nameL = p->name;
460 std::transform(nameL.begin(), nameL.end(), nameL.begin(), [](unsigned char c) { return std::tolower(c); });
461
462 const pair<const MString, MProperty*> mpL(nameL, p);
463
464 // check if the lowercase variant of this property already exists but no regular-case variant
465 if(!(m_propertyMapLowercase->find(nameL) == m_propertyMapLowercase->end())
466 && (m_propertyMap->find(p->name) == m_propertyMap->end())) {
467 mTerm(1, AT_,
468 "There are multiple occurrences of the property " + p->name
469 + " with different cases. This should not happen!");
470 }
471 m_propertyMap->insert(mp);
472 m_propertyMapLowercase->insert(mpL);
473}
static propertyMap * m_propertyMapLowercase
Definition: context.h:135
static propertyMap * m_propertyMap
Definition: context.h:134
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Definition: functions.cpp:29
std::basic_string< char > MString
Definition: maiatypes.h:55
constexpr std::underlying_type< FcCell >::type p(const FcCell property)
Converts property name to underlying integer value.

◆ assertPropertyLength()

void Context::assertPropertyLength ( const MString name,
const MInt  length,
const MInt  solverId = m_noSolvers 
)
static

Check the length of a given property, terminate if it does not match the given length.

Definition at line 559 of file context.cpp.

559 {
560 const MInt propLength = propertyLength(name, solverId);
561 if(propLength != length) {
562 const MString isSolver = (solverId != m_noSolvers) ? " for solver #" + std::to_string(solverId) : "";
563 TERMM(1, "Property '" + name + "'" + isSolver + " has the wrong length, it is of length "
564 + std::to_string(Context::propertyLength(name)) + " but there should be " + std::to_string(length)
565 + " values!");
566 }
567}
static MInt propertyLength(const MString &name, MInt solverId=m_noSolvers)
Returns the number of elements of a property.
Definition: context.cpp:538
static MInt m_noSolvers
Definition: context.h:133
int32_t MInt
Definition: maiatypes.h:62

◆ checkPropertyViolation()

void Context::checkPropertyViolation ( MInt  partnerrank,
std::list< MProperty * > *  prop 
)
static
Author
Andreas Lintermann
Date
9.12.2010
Parameters
[in]therank the partner cpu
[in]theproperty list of the other cpu

This function checks if local properties differ from the properties received from the children and stops the program if values differ.

Definition at line 1256 of file context.cpp.

1256 {
1257 TRACE();
1258
1259 MInt defaultInt = -1;
1260 MFloat defaultFloat = -1.0;
1261 MBool defaultBool = false;
1262 MString defaultString = " ";
1263
1264 MInt rank = globalDomainId();
1265
1266 // Set flag to indicate that property accesses should not be counted here
1267 m_checkingProperties = true;
1268
1269 // Check local with other
1270 for(auto& it : *prop) {
1271 if(propertyExists(it->name)) {
1272 switch(it->type()) {
1273 case MINT: {
1274 for(MInt j = 0; j < it->elements; j++) {
1275 if(*(it->asInt(j)) != getSolverProperty<MInt>(it->name, it->solverId, AT_, &defaultInt, j)
1276 || it->solverId != propertySolverId(it->name, it->solverId)) {
1277 stringstream errorMessage;
1278 // auto p = getProperty((*it)->name,(*it)->solverId, AT_, (MInt*) nullptr);
1279 errorMessage << "Poperty violation for '" << it->name << "' on CPUs: " << rank << "," << partnerrank;
1280 // << endl
1281 // << "received: name='" << (*it)->name << "', value='" << *((*it)->asInt(j))
1282 // << "', solverId='" << (*it)->solverId << "'" << endl
1283 // << "local: name = '" << p->name << "', value='" << *(p->asInt(j))
1284 // << "', solverId='" << p->solverId << "'";
1285 mTerm(1, AT_, errorMessage.str());
1286 }
1287 }
1288 break;
1289 }
1290 case MBOOL: {
1291 for(MInt j = 0; j < it->elements; j++) {
1292 if(*(it->asBool(j)) != getSolverProperty<MBool>(it->name, it->solverId, AT_, &defaultBool, j)
1293 || it->solverId != propertySolverId(it->name, it->solverId)) {
1294 stringstream errorMessage;
1295 errorMessage << "Poperty violation for '" << it->name << "' on CPUs: " << rank << "," << partnerrank;
1296 mTerm(1, AT_, errorMessage.str());
1297 }
1298 }
1299 break;
1300 }
1301 case MFLOAT: {
1302 for(MInt j = 0; j < it->elements; j++) {
1303 if(!approx(*(it->asFloat(j)), getSolverProperty<MFloat>(it->name, it->solverId, AT_, &defaultFloat, j),
1304 MFloatEps)
1305 || it->solverId != propertySolverId(it->name, it->solverId)) {
1306 stringstream errorMessage;
1307 errorMessage << "Poperty violation for '" << it->name << "' on CPUs: " << rank << "," << partnerrank;
1308 mTerm(1, AT_, errorMessage.str());
1309 }
1310 }
1311 break;
1312 }
1313 case MSTRING: {
1314 for(MInt j = 0; j < it->elements; j++) {
1315 if(*(it->asString(j)) != getSolverProperty<MString>(it->name, it->solverId, AT_, &defaultString, j)
1316 || it->solverId != propertySolverId(it->name, it->solverId)) {
1317 stringstream errorMessage;
1318 errorMessage << "Poperty violation for '" << it->name << "' on CPUs: " << rank << "," << partnerrank;
1319 mTerm(1, AT_, errorMessage.str());
1320 }
1321 }
1322 break;
1323 }
1324 default: {
1325 mTerm(1, AT_, "Context::CheckPropertyViolation(): switch variable '(*it)->type' not matching any case");
1326 }
1327 }
1328 } else {
1329 MProperty* a;
1330 switch(it->type()) {
1331 case MINT: {
1332 a = new MProperty(it->elements, it->name, it->solverId, it->intField);
1333 break;
1334 }
1335 case MBOOL: {
1336 a = new MProperty(it->elements, it->name, it->solverId, it->boolField);
1337 break;
1338 }
1339 case MFLOAT: {
1340 a = new MProperty(it->elements, it->name, it->solverId, it->floatField);
1341 break;
1342 }
1343 case MSTRING: {
1344 a = new MProperty(it->elements, it->name, it->solverId, it->stringField);
1345 break;
1346 }
1347 default:
1348 a = new MProperty();
1349 }
1350 addProperty(a);
1351 }
1352 }
1353
1354 // Reset flag after checking properties
1355 m_checkingProperties = false;
1356
1357 // Clean up
1358 prop->clear();
1359}
static MBool m_checkingProperties
Definition: context.h:142
static MInt propertySolverId(const MString &name, MInt solverId=m_noSolvers)
Returns the number of elements of a property.
Definition: context.cpp:576
static void addProperty(MProperty *)
This method adds properties.
Definition: context.cpp:453
static MBool propertyExists(const MString &name, MInt solver=m_noSolvers)
This function checks if a property exists in general.
Definition: context.cpp:494
@ MINT
Definition: enums.h:269
@ MFLOAT
Definition: enums.h:269
@ MBOOL
Definition: enums.h:269
@ MSTRING
Definition: enums.h:269
MBool approx(const T &, const U &, const T)
Definition: functions.h:272
MInt globalDomainId()
Return global domain id.
double MFloat
Definition: maiatypes.h:52
bool MBool
Definition: maiatypes.h:58
Definition: contexttypes.h:19

◆ clear()

void Context::clear ( )
static

This method deletes the property structs. It runs over all elements of the propertyMap and zoneMap and deletes the individual structs. Finally the zoneMap and propertyMap are deleted.

Definition at line 418 of file context.cpp.

418 {
419 TRACE();
420 for(propertyIterator i = m_propertyMap->begin(); i != m_propertyMap->end(); i++) {
421 DEBUG("MProperty::clear: name " << i->second->name, MAIA_DEBUG_IO);
422 DEBUG("MProperty::clear: solverId " << i->second->solverId, MAIA_DEBUG_IO);
423 i->second->clear(); // remove the pointers of property
424 }
425 m_propertyMap->clear();
426
427 for(propertyIterator i = m_propertyMapLowercase->begin(); i != m_propertyMapLowercase->end(); i++) {
428 DEBUG("MProperty::clear: name " << i->second->name, MAIA_DEBUG_IO);
429 DEBUG("MProperty::clear: solverId " << i->second->solverId, MAIA_DEBUG_IO);
430 i->second->clear(); // remove the pointers of property
431 }
432 m_propertyMapLowercase->clear();
433
434 for(zoneIterator i = m_zoneMap->begin(); i != m_zoneMap->end(); i++) {
435 DEBUG("MProperty::clear() name : " << i->second->name, MAIA_DEBUG_IO);
436 DEBUG("MProperty::clear() noSolvers : " << i->second->noSolvers, MAIA_DEBUG_IO);
437 delete[] i->second->solvers;
438 }
439#ifdef MAIA_PRINT_PROPERTIES
440 propsFromFile.close();
441 propsDefault.close();
442#endif
443}
static zoneMap * m_zoneMap
Definition: context.h:136
zoneMap::const_iterator zoneIterator
Definition: contexttypes.h:18
propertyMap::const_iterator propertyIterator
Definition: contexttypes.h:16

◆ communicateProperties()

void Context::communicateProperties ( )
static
Author
Andreas Lintermann
Date
06.12.2010

This function communicates properties available in the property map in a tree-like structure and is called in environment->run().

  1. A binary tree is built to accelerate communication
  2. Starting at the leafs, properties are merged at father-nodes 2.1 Check if properties from leafs do not violate equality restrictions
  3. Finish at root node (processor with id 0)

Definition at line 773 of file context.cpp.

773 {
774 TRACE();
775
776 NEW_TIMER_GROUP_STATIC(m_timerGroupId, "Context");
777 NEW_TIMER(timerpcheck, "Property Validity Check", m_timerGroupId);
778 RECORD_TIMER_START(timerpcheck);
779
780 m_log << "==============================================================" << endl;
781 m_log << " Checking property validity... ";
782#ifdef MAIA_WRITE_ACCESS_PROPERTIES_FILE
783 maia_properties << "==============================================================" << endl;
784 maia_properties << " Checking property validity... ";
785#endif
786
787 // TEST
788 /*
789 MInt rank = MPI_COMM_WORLD.Get_rank();
790 if(rank==1)
791 {
792 MInt* b = new MInt();
793 *b=1;
794 MProperty* a = new MProperty(1,"AAA",1,b);
795 addProperty(a);
796 }
797 else
798 {
799 MInt* b = new MInt();
800 *b=2;
801 MProperty* a = new MProperty(1,"AAA",1,b);
802 addProperty(a);
803 }
804 */
805
806 MInt noDomains = globalNoDomains();
807 BinaryPropertyMPITree tree(noDomains);
808 // if(rank==0)
809 // tree.printTree();
810
811 MInt comm_partner = 0;
812
813 list<MProperty*>* left = nullptr;
814 list<MProperty*>* right = nullptr;
815
816 // We need to receive something from below
817 if(tree.getMyLeftMPISender() != nullptr || tree.getMyRightMPISender() != nullptr) {
818 if(tree.getMyLeftMPISender() != nullptr) {
819 comm_partner = *(tree.getMyLeftMPISender()->getObject());
820 left = receiveProperties(comm_partner);
821 checkPropertyViolation(comm_partner, left);
822 }
823 if(tree.getMyRightMPISender() != nullptr) {
824 comm_partner = *(tree.getMyRightMPISender()->getObject());
825 right = receiveProperties(comm_partner);
826 checkPropertyViolation(comm_partner, right);
827 }
828 }
829
830 // Send if we are not the almighty father of the tree
831 if(tree.getMyMPIReceiver() != nullptr) {
832 comm_partner = *(tree.getMyMPIReceiver()->getObject());
833 sendProperties(comm_partner);
834 }
835
836 m_log << " ---> EVERYTHING IS FINE!!!!" << endl;
837 m_log << "==============================================================" << endl;
838#ifdef MAIA_WRITE_ACCESS_PROPERTIES_FILE
839 maia_properties << " ---> EVERYTHING IS FINE!!!!" << endl;
840 maia_properties << "==============================================================" << endl;
841#endif
842 RECORD_TIMER_STOP(timerpcheck);
843}
static void sendProperties(MInt rank)
Sends the property list to another cpu.
Definition: context.cpp:1052
static void checkPropertyViolation(MInt partnerrank, std::list< MProperty * > *prop)
Checks if local properties differ from received properties.
Definition: context.cpp:1256
static std::list< MProperty * > * receiveProperties(MInt rank)
Receives a property list from another cpu.
Definition: context.cpp:866
MInt globalNoDomains()
Return global number of domains.
InfoOutFile m_log

◆ dump()

void Context::dump ( const MString fileName)
static

Definition at line 1362 of file context.cpp.

1362 {
1363 ofstream os(fileName);
1364 for(auto&& pm : *m_propertyMap) {
1365 const auto name = pm.first;
1366 const auto prop = pm.second;
1367 os << name << " (";
1368 switch(prop->propertyType) {
1369 case MINT:
1370 os << "MINT";
1371 break;
1372 case MFLOAT:
1373 os << "MFLOAT";
1374 break;
1375 case MSTRING:
1376 os << "MSTRING";
1377 break;
1378 case MBOOL:
1379 os << "MBOOL";
1380 break;
1381 default:
1382 TERMM(1, "Bad type");
1383 }
1384 os << "): ";
1385 for(MInt i = 0; i < prop->count(); i++) {
1386 if(i != 0) {
1387 os << ", ";
1388 }
1389 switch(prop->propertyType) {
1390 case MINT:
1391 os << prop->intField[i];
1392 break;
1393 case MFLOAT:
1394 os << prop->floatField[i];
1395 break;
1396 case MSTRING:
1397 os << prop->stringField[i];
1398 break;
1399 case MBOOL:
1400 os << prop->boolField[i];
1401 break;
1402 default:
1403 TERMM(1, "Bad type");
1404 }
1405 }
1406 os << std::endl;
1407 }
1408}

◆ getBasicProperty() [1/2]

template<typename T >
static T Context::getBasicProperty ( const MString  name,
const MString nameOfCallingFunction,
const T *  default_value,
MInt  pos = 0 
)
inlinestatic

Definition at line 149 of file context.h.

150 {
151 const MBool hasDefault = (default_value != nullptr);
152 return getBasicPropertyOverloaded(nameOfCallingFunction, name, hasDefault, default_value, pos);
153 }
static MInt getBasicPropertyOverloaded(const MString &nameOfCallingFunction, const MString &name, MBool has_default, const MInt *default_value, MInt pos)
Definition: context.cpp:197

◆ getBasicProperty() [2/2]

template<typename T >
static T Context::getBasicProperty ( const MString  name,
const MString nameOfCallingFunction,
MInt  pos = 0 
)
inlinestatic

Definition at line 159 of file context.h.

159 {
160 T* defaultValue = nullptr;
161 return getBasicPropertyOverloaded(nameOfCallingFunction, name, false, defaultValue, pos);
162 }

◆ getBasicPropertyImplicit()

template<typename T , typename F >
T Context::getBasicPropertyImplicit ( const MString nameOfCallingFunction,
const MString name,
MBool  has_default,
const T *  defaultValue,
MInt  position,
F &&  f 
)
staticprivate

This template function searchs for a certain property given as an argument (name). If the property exists, it will be returned. If the property does not exist, the default value will be returned (if one is given). If there is also no defaultValue, the code exits with an error.

Author
Moritz Waldmann
Date
12.2018

Definition at line 126 of file context.cpp.

127 {
128 if(propertyExists(name)) {
129 // lookup all properties with the requested key
130 m_pair = m_propertyMap->equal_range(name);
131 for(propertyIterator i = m_pair.first; i != m_pair.second; i++) {
132 if(i->second->solverId == m_noSolvers) {
133#ifdef MAIA_WRITE_ACCESS_PROPERTIES_FILE
134 if(!m_checkingProperties) { // Count number of accesses (if not during property checking)
135 i->second->noAccesses++;
136 }
137#endif
138
139 const T pValue = f(i->second, position);
140
141#ifdef MAIA_WRITE_ACCESS_PROPERTIES_FILE
142 // Check for default property values specified in the property file
143 if(has_default && !m_checkingProperties) {
144 const T dValue = *defaultValue;
145 const MBool isDefault = isSameValue(dValue, pValue);
146 if(!isDefault) {
147 // TODO labels:IO could be used to count properties with/without default values
148 /* i->second->noOldAccesses++; */
149 } else {
150 std::cerr << "Property default value specified: " << name << " solverId=" << -1 << " pos=" << position
151 << " value=" << pValue << " default=" << *defaultValue << " " << nameOfCallingFunction
152 << std::endl;
153 }
154 }
155#endif
156
157 return pValue;
158 }
159 }
160 }
161 stringstream errormessage;
162 errormessage << " The solver property '" << name << "' is required for the simulation"
163 << ", but was not set in the toml file!!!!";
164
165 if(!has_default) {
166 mTerm(1, nameOfCallingFunction, errormessage.str());
167 } else {
168 return *defaultValue;
169 }
170}
static std::pair< propertyMap::iterator, propertyMap::iterator > m_pair
Definition: context.h:138
static MBool isSameValue(const MFloat v1, const MFloat v2)
Definition: context.h:221

◆ getBasicPropertyOverloaded() [1/4]

MBool Context::getBasicPropertyOverloaded ( const MString nameOfCallingFunction,
const MString name,
MBool  has_default,
const MBool default_value,
MInt  pos 
)
staticprivate

Definition at line 227 of file context.cpp.

228 {
229 MBool propertyValue;
230 if(m_fileType == TOML) {
231 propertyValue = getBasicPropertyImplicit(nameOfCallingFunction, name, has_default, default_value, pos,
232 [](MProperty* i, MInt p) { return (*(i)->asBool(p)); });
233 } else {
234 // handle the case that we have a netcdf property file
235 MInt tmpDef = 0; // false
236 if(has_default) {
237 tmpDef = static_cast<MInt>(*default_value);
238 }
239 MInt tmp = getBasicPropertyImplicit(nameOfCallingFunction, name, has_default, &tmpDef, pos,
240 [](MProperty* i, MInt p) { return (*(i)->asInt(p)); });
241 propertyValue = (tmp == 1);
242 }
243#ifdef MAIA_PRINT_PROPERTIES
244 if(propertyExists(name))
245 propsFromFile << name << " = " << propertyValue << ", basic Property (MBool)" << endl;
246 else
247 propsDefault << name << " = " << propertyValue << ", basic Property (MBool)" << endl;
248#endif
249
250 return propertyValue;
251}
static T getBasicPropertyImplicit(const MString &nameOfCallingFunction, const MString &name, MBool has_default, const T *defaultValue, MInt position, F &&f)
Returns the value of the requested basic level property (implicit).
Definition: context.cpp:126
static MInt m_fileType
Definition: context.h:141
@ TOML
Definition: enums.h:18

◆ getBasicPropertyOverloaded() [2/4]

MFloat Context::getBasicPropertyOverloaded ( const MString nameOfCallingFunction,
const MString name,
MBool  has_default,
const MFloat default_value,
MInt  pos 
)
staticprivate

Definition at line 212 of file context.cpp.

213 {
214 MFloat propertyValue;
215 propertyValue = getBasicPropertyImplicit(nameOfCallingFunction, name, has_default, default_value, pos,
216 [](MProperty* i, MInt p) { return (*(i)->asFloat(p)); });
217#ifdef MAIA_PRINT_PROPERTIES
218 if(propertyExists(name))
219 propsFromFile << name << " = " << propertyValue << ", basic Property (MFloat)" << endl;
220 else
221 propsDefault << name << " = " << propertyValue << ", basic Property (MFloat)" << endl;
222#endif
223
224 return propertyValue;
225}

◆ getBasicPropertyOverloaded() [3/4]

MInt Context::getBasicPropertyOverloaded ( const MString nameOfCallingFunction,
const MString name,
MBool  has_default,
const MInt default_value,
MInt  pos 
)
staticprivate

Definition at line 197 of file context.cpp.

198 {
199 MInt propertyValue;
200 propertyValue = getBasicPropertyImplicit(nameOfCallingFunction, name, has_default, default_value, pos,
201 [](MProperty* i, MInt p) { return (*(i)->asInt(p)); });
202#ifdef MAIA_PRINT_PROPERTIES
203 if(propertyExists(name))
204 propsFromFile << name << " = " << propertyValue << ", basic Property (MInt)" << endl;
205 else
206 propsDefault << name << " = " << propertyValue << ", basic Property (MInt)" << endl;
207#endif
208
209 return propertyValue;
210}

◆ getBasicPropertyOverloaded() [4/4]

MString Context::getBasicPropertyOverloaded ( const MString nameOfCallingFunction,
const MString name,
MBool  has_default,
const MString default_value,
MInt  pos 
)
staticprivate

The following 4 (one for MInt, MFloat, MString, MBool) functions provide a value for the template funtion getBasicProperty. They receive their value from the implicite function getBasicPropertyImplicit. For debugging 'MAIA_PRINT_PROPERTIES' can be defined in config.h. Each of the overloaded functions will than print the property name and corresponding value or default value to a file. This can extend the simulation time.

Author
Moritz Waldmann
Date
12.2018

Definition at line 183 of file context.cpp.

184 {
185 MString propertyValue;
186 propertyValue = getBasicPropertyImplicit(nameOfCallingFunction, name, has_default, default_value, pos,
187 [](MProperty* i, MInt p) { return (*(i)->asString(p)); });
188#ifdef MAIA_PRINT_PROPERTIES
189 if(propertyExists(name))
190 propsFromFile << name << " = " << propertyValue << ", basic Property (MString)" << endl;
191 else
192 propsDefault << name << " = " << propertyValue << ", basic Property (MString)" << endl;
193#endif
194 return propertyValue;
195}

◆ getSolverProperty() [1/2]

template<typename T >
static T Context::getSolverProperty ( const MString  name,
const MInt  solverId,
const MString nameOfCallingFunction,
const T *  default_value,
MInt  pos = 0 
)
inlinestatic

Definition at line 168 of file context.h.

169 {
170 return getSolverPropertyOverloaded(nameOfCallingFunction, name, solverId, true, default_value, pos);
171 }
static MInt getSolverPropertyOverloaded(const MString &nameOfCallingFunction, const MString &name, const MInt solverId, MBool has_default, const MInt *default_value, MInt pos)
Definition: context.cpp:343

◆ getSolverProperty() [2/2]

template<typename T >
static T Context::getSolverProperty ( const MString  name,
const MInt  solverId,
const MString nameOfCallingFunction,
MInt  pos = 0 
)
inlinestatic

Definition at line 178 of file context.h.

179 {
180 T* defaultValue = nullptr;
181 return getSolverPropertyOverloaded(nameOfCallingFunction, name, solverId, false, defaultValue, pos);
182 }

◆ getSolverPropertyImplicit()

template<typename T , typename F >
T Context::getSolverPropertyImplicit ( const MString nameOfCallingFunction,
const MString name,
const MInt  solverId,
MBool  has_default,
const T *  defaultValue,
MInt  position,
F &&  f 
)
staticprivate

This template function searchs for a certain property of a certain solver given as an argument (name, solverId). If the property exists, it will be returned. If the property does not exist, the basic property will be returned. If also the basic property does not exist, the default value will be returned (if one is given). If there is also no defaultValue, the code exits with an error.

Author
Moritz Waldmann
Date
12.2018

Definition at line 265 of file context.cpp.

266 {
267 if(solverPropertyExists(name, solverId)) {
268 // lookup all properties with the requested key
269 m_pair = m_propertyMap->equal_range(name);
270 for(propertyIterator i = m_pair.first; i != m_pair.second; i++) {
271 if(i->second->solverId == solverId) {
272#ifdef MAIA_WRITE_ACCESS_PROPERTIES_FILE
273 if(!m_checkingProperties) { // Count number of accesses (if not during property checking)
274 i->second->noAccesses++;
275 }
276#endif
277
278 const T pValue = f(i->second, position);
279
280#ifdef MAIA_WRITE_ACCESS_PROPERTIES_FILE
281 // Check for default property values specified in the property file
282 if(has_default && !m_checkingProperties) {
283 const T dValue = *defaultValue;
284 const MBool isDefault = isSameValue(dValue, pValue);
285 if(!isDefault) {
286 // TODO labels:IO could be used to count properties with/without default values
287 /* i->second->noOldAccesses++; */
288 } else {
289 std::cerr << "Property default value specified: " << name << " solverId=" << solverId << " pos=" << position
290 << " value=" << pValue << " default=" << *defaultValue << " " << nameOfCallingFunction
291 << std::endl;
292 }
293 }
294#endif
295
296 return pValue;
297 }
298 }
299 } else if(propertyExists(name)) {
300 return getBasicPropertyImplicit(nameOfCallingFunction, name, has_default, defaultValue, position, f);
301 }
302
303 stringstream errormessage;
304 errormessage << " The solver property '" << name << "' is required for the simulation"
305 << ", but was not set in the toml file!!!!";
306 if(!has_default) {
307 mTerm(1, nameOfCallingFunction, errormessage.str());
308 } else {
309 return *defaultValue;
310 }
311}
static MBool solverPropertyExists(const MString &name, MInt solver)
Checks existence of a solver property details This function returns true, if the solver property with...
Definition: context.cpp:519

◆ getSolverPropertyOverloaded() [1/4]

MBool Context::getSolverPropertyOverloaded ( const MString nameOfCallingFunction,
const MString name,
const MInt  solverId,
MBool  has_default,
const MBool default_value,
MInt  pos 
)
staticprivate

Definition at line 380 of file context.cpp.

382 {
383 MBool propertyValue;
384 if(m_fileType == TOML) {
385 propertyValue = getSolverPropertyImplicit(nameOfCallingFunction, name, solverId, has_default, default_value, pos,
386 [](MProperty* i, MInt p) { return (*(i)->asBool(p)); });
387 } else {
388 // handle the case that we have a netcdf property file
389 MInt tmpDef = 0; // false
390 if(has_default) {
391 tmpDef = static_cast<MInt>(*default_value);
392 }
393 MInt tmp = getBasicPropertyImplicit(nameOfCallingFunction, name, has_default, &tmpDef, pos,
394 [](MProperty* i, MInt p) { return (*(i)->asInt(p)); });
395 propertyValue = (tmp == 1);
396 }
397
398#ifdef MAIA_PRINT_PROPERTIES
399 if(solverId != m_noSolvers) {
400 if(propertyExists(name, solverId))
401 propsFromFile << name << " = " << propertyValue << ", solver Property (solverId = " << solverId
402 << ", type = MBool)" << endl;
403 else
404 propsDefault << name << " = " << propertyValue << ", solver Property (solverId = " << solverId
405 << ", type = MBool)" << endl;
406 }
407#endif
408 return propertyValue;
409}
static T getSolverPropertyImplicit(const MString &nameOfCallingFunction, const MString &name, const MInt solverId, MBool has_default, const T *defaultValue, MInt position, F &&f)
Returns the value of the requested solver property (implicit).
Definition: context.cpp:265

◆ getSolverPropertyOverloaded() [2/4]

MFloat Context::getSolverPropertyOverloaded ( const MString nameOfCallingFunction,
const MString name,
const MInt  solverId,
MBool  has_default,
const MFloat default_value,
MInt  pos 
)
staticprivate

Definition at line 361 of file context.cpp.

363 {
364 MFloat propertyValue;
365 propertyValue = getSolverPropertyImplicit(nameOfCallingFunction, name, solverId, has_default, default_value, pos,
366 [](MProperty* i, MInt p) { return (*(i)->asFloat(p)); });
367#ifdef MAIA_PRINT_PROPERTIES
368 if(solverId != m_noSolvers) {
369 if(propertyExists(name, solverId))
370 propsFromFile << name << " = " << propertyValue << ", solver Property (solverId = " << solverId
371 << ", type = MFloat)" << endl;
372 else
373 propsDefault << name << " = " << propertyValue << ", solver Property (solverId = " << solverId
374 << ", type = MFloat)" << endl;
375 }
376#endif
377 return propertyValue;
378}

◆ getSolverPropertyOverloaded() [3/4]

MInt Context::getSolverPropertyOverloaded ( const MString nameOfCallingFunction,
const MString name,
const MInt  solverId,
MBool  has_default,
const MInt default_value,
MInt  pos 
)
staticprivate

Definition at line 343 of file context.cpp.

344 {
345 MInt propertyValue;
346 propertyValue = getSolverPropertyImplicit(nameOfCallingFunction, name, solverId, has_default, default_value, pos,
347 [](MProperty* i, MInt p) { return (*(i)->asInt(p)); });
348#ifdef MAIA_PRINT_PROPERTIES
349 if(solverId != m_noSolvers) {
350 if(propertyExists(name, solverId))
351 propsFromFile << name << " = " << propertyValue << ", solver Property (solverId = " << solverId
352 << ", type = MInt)" << endl;
353 else
354 propsDefault << name << " = " << propertyValue << ", solver Property (solverId = " << solverId << ", type = MInt)"
355 << endl;
356 }
357#endif
358 return propertyValue;
359}

◆ getSolverPropertyOverloaded() [4/4]

MString Context::getSolverPropertyOverloaded ( const MString nameOfCallingFunction,
const MString name,
const MInt  solverId,
MBool  has_default,
const MString default_value,
MInt  pos 
)
staticprivate

The following 4 (one for MInt, MFloat, MString, MBool) functions provide a value for the template funtion getSolverProperty. They receive their value from the implicite function getSolverPropertyImplicit

Author
Moritz Waldmann For debugging 'MAIA_PRINT_PROPERTIES' can be defined in config.h. Each of the overloaded functions will than print the property name, the solverId and the corresponding value or default value to a file. This can extend the simulation time.
Date
12.2018

Definition at line 324 of file context.cpp.

326 {
327 MString propertyValue;
328 propertyValue = getSolverPropertyImplicit(nameOfCallingFunction, name, solverId, has_default, default_value, pos,
329 [](MProperty* i, MInt p) { return (*(i)->asString(p)); });
330#ifdef MAIA_PRINT_PROPERTIES
331 if(solverId != m_noSolvers) {
332 if(propertyExists(name, solverId))
333 propsFromFile << name << " = " << propertyValue << ", solver Property (solverId = " << solverId
334 << ", type = MString)" << endl;
335 else
336 propsDefault << name << " = " << propertyValue << ", solver Property (solverId = " << solverId
337 << ", type = MString)" << endl;
338 }
339#endif
340 return propertyValue;
341}

◆ init()

void Context::init ( )
static

Use ts function if you want to create a new property list. If you want to load properties from file use the function readPropertyFile.

Definition at line 482 of file context.cpp.

482 {
483 // TRACE();
484
487}
std::multimap< MString, MProperty * > propertyMap
Definition: contexttypes.h:15

◆ initializationProcessFinished()

void Context::initializationProcessFinished ( )
static

not yet activate, remove the comment

Author
Christoph Siewert
Date
10.2010

Definition at line 745 of file context.cpp.

745 {
746 // TRACE();
747
748#ifdef MAIA_WRITE_ACCESS_PROPERTIES_FILE
749 maia_properties << endl << "--------------------------initialization process finshed--------------------------";
750 maia_properties << endl
751 << "--------------------------property access not allowed anymore--------------------------" << endl
752 << endl;
753#endif
754 // chrs should be commented in, if properties regrouping is finished
755 // writePropertiesHumanReadable();
756}

◆ isSameValue() [1/4]

static MBool Context::isSameValue ( const MBool  v1,
const MBool  v2 
)
inlinestaticprivate

Definition at line 222 of file context.h.

222{ return (v1 == v2); }

◆ isSameValue() [2/4]

static MBool Context::isSameValue ( const MFloat  v1,
const MFloat  v2 
)
inlinestaticprivate

Definition at line 221 of file context.h.

221{ return approx(v1, v2, MFloatEps); }

◆ isSameValue() [3/4]

static MBool Context::isSameValue ( const MInt  v1,
const MInt  v2 
)
inlinestaticprivate

Definition at line 223 of file context.h.

223{ return (v1 == v2); }

◆ isSameValue() [4/4]

static MBool Context::isSameValue ( const MString  v1,
const MString  v2 
)
inlinestaticprivate

Definition at line 224 of file context.h.

224{ return (v1 == v2); }

◆ propertyExists()

MBool Context::propertyExists ( const MString name,
MInt  solver = m_noSolvers 
)
static

Definition at line 494 of file context.cpp.

494 {
495 const MBool exists = !(m_propertyMap->find(name) == m_propertyMap->end());
496 if(!exists) {
497 // produce lowercase name to check for case-insensitive matches
498 MString nameL = name;
499 std::transform(nameL.begin(), nameL.end(), nameL.begin(), [](unsigned char c) { return std::tolower(c); });
500 if(nameL == "postprocessing") { // delete this, when the two different spellings of postprocessing are delted!
501 return exists;
502 }
503 const MBool existsCaseInsensitive = !(m_propertyMapLowercase->find(nameL) == m_propertyMapLowercase->end());
504 if(existsCaseInsensitive) {
505 mTerm(1, AT_,
506 "Property " + name
507 + " not found, but there was a case-insensitive match. Are you sure you spelled it correctly?");
508 }
509 }
510 return exists;
511}

◆ propertyFileName()

static MString Context::propertyFileName ( )
inlinestatic

Definition at line 122 of file context.h.

122{ return m_name; }
static MString m_name
Definition: context.h:132

◆ propertyFileText()

static MString Context::propertyFileText ( )
inlinestatic

Definition at line 125 of file context.h.

125{ return m_propertyFileText; }
static MString m_propertyFileText
Definition: context.h:140

◆ propertyLength()

MInt Context::propertyLength ( const MString name,
MInt  solverId = m_noSolvers 
)
static

This function returns the number of elements of a property. If the property exists, it returns the value given by the function count(), which is implemented in property.cpp

Author
Moritz Waldmann
Date
12.2018

Definition at line 538 of file context.cpp.

538 {
539 if(solverPropertyExists(name, solverId)) {
540 m_pair = m_propertyMap->equal_range(name); // lookup all properties with the requested key
541 for(propertyIterator i = m_pair.first; i != m_pair.second; i++) { // search for the solverId
542 if(i->second->solverId == solverId) { // look for the requested solverId
543 return i->second->count();
544 }
545 }
546 } else if(propertyExists(name)) {
547 m_pair = m_propertyMap->equal_range(name); // lookup all properties with the requested key
548 for(propertyIterator i = m_pair.first; i != m_pair.second; i++) { // search for the solverId
549 if(i->second->solverId == m_noSolvers) { // look for the requested solverId
550 return i->second->count();
551 }
552 }
553 }
554 return 0;
555}

◆ propertySolverId()

MInt Context::propertySolverId ( const MString name,
MInt  solverId = m_noSolvers 
)
static

This function returns the number of elements of a property. If the property exists, it returns its solverId

Author
Moritz Waldmann
Date
12.2018

Definition at line 576 of file context.cpp.

576 {
577 if(solverPropertyExists(name, solverId)) {
578 m_pair = m_propertyMap->equal_range(name); // lookup all properties with the requested key
579 for(propertyIterator i = m_pair.first; i != m_pair.second; i++) { // search for the solverId
580 if(i->second->solverId == solverId) { // look for the requested solverId
581 return i->second->solverId;
582 }
583 }
584 } else if(propertyExists(name)) {
585 m_pair = m_propertyMap->equal_range(name); // lookup all properties with the requested key
586 for(propertyIterator i = m_pair.first; i != m_pair.second; i++) { // search for the solverId
587 if(i->second->solverId == m_noSolvers) { // look for the requested solverId
588 return i->second->solverId;
589 }
590 }
591 }
592 return 0;
593}

◆ readPropertyFile()

static void Context::readPropertyFile ( FileType  ,
const MString fileName 
)
static

◆ receiveProperties()

list< MProperty * > * Context::receiveProperties ( MInt  rank)
static
Author
Andreas Lintermann
Date
9.12.2010
Parameters
[in]therank of the processor to commuicate with
Returns
returning a list containing all properties from the sending cpu

This function receives the properties from a given cpu in the following order

  1. the sizes of all arrays
  2. all integer values of the properties
  3. all float (double) values of the properties
  4. all string values of the properties
  5. all names of the properties
  6. all solverIds of the properties
  7. all offsets of the properties, required to find the right values for the associated property

At the end a list of of received properties is built and returned for further investigations.

Definition at line 866 of file context.cpp.

866 {
867 TRACE();
868 // cerr << "Processor " << MPI_COMM_WORLD.Get_rank() << " is receiving from: " << rank << endl;
869
870 MInt tag = 0;
871 MPI_Status status;
872
873 MInt listSizes[10];
874
875 // Receive list sizes
876 MPI_Recv(listSizes, 10, MPI_INT, rank, tag, MPI_COMM_WORLD, &status, AT_, "listSizes");
877
878 // Receive integer array
879 auto* int_ar = new MInt[listSizes[0]];
880 MPI_Recv(int_ar, listSizes[0], MPI_INT, rank, tag, MPI_COMM_WORLD, &status, AT_, "int_ar");
881
882 // Receive MBool array
883 auto* bool_ar = new MBool[listSizes[1]];
884 MPI_Recv(bool_ar, listSizes[1], MPI_C_BOOL, rank, tag, MPI_COMM_WORLD, &status, AT_, "bool_ar");
885
886 // Receive float array
887 auto* float_ar = new MFloat[listSizes[2]];
888 MPI_Recv(float_ar, listSizes[2], MPI_DOUBLE, rank, tag, MPI_COMM_WORLD, &status, AT_, "float_ar");
889
890 // Receive string array
891 MChar* char_ar = new MChar[listSizes[3]];
892 MPI_Recv(char_ar, listSizes[3], MPI_CHAR, rank, tag, MPI_COMM_WORLD, &status, AT_, "char_ar");
893
894 // Receive name array
895 MChar* char_ar2 = new MChar[listSizes[4]];
896 MPI_Recv(char_ar2, listSizes[4], MPI_CHAR, rank, tag, MPI_COMM_WORLD, &status, AT_, "char_ar2");
897
898 // Receive offset array
899 MInt offset_sizes = listSizes[5] + listSizes[6] + listSizes[7] + listSizes[8] + listSizes[9];
900 auto* offset = new MInt[offset_sizes];
901 MPI_Recv(offset, offset_sizes, MPI_INT, rank, tag, MPI_COMM_WORLD, &status, AT_, "offset");
902
903 // Receive offset array
904 auto* solverIds = new MInt[listSizes[9]];
905 MPI_Recv(solverIds, listSizes[9], MPI_INT, rank, tag, MPI_COMM_WORLD, &status, AT_, "solverIds");
906
907 // Build something we can give back and handle in the comparison
908 auto* proplist = new list<MProperty*>();
909
910 MInt boolOffset = listSizes[5];
911 MInt floatOffset = listSizes[5] + listSizes[6];
912 MInt stringOffset = listSizes[5] + listSizes[6] + listSizes[7];
913 MInt nameOffset = listSizes[5] + listSizes[6] + listSizes[7] + listSizes[8];
914
915 // Run over all elements
916 MInt i = 0;
917 for(; i < boolOffset; i++) {
918 MInt low_off = 0;
919 MInt low_off_name = 0;
920 if(i > 0) {
921 low_off = offset[i - 1];
922 low_off_name = offset[nameOffset + i - 1];
923 }
924
925 auto* a = new MInt[offset[i] - low_off];
926 for(MInt j = low_off, l = 0; j < offset[i]; j++, l++) {
927 a[l] = int_ar[j];
928 }
929
930 MString name;
931 for(MInt j = low_off_name; j < offset[nameOffset + i]; j++) {
932 name += char_ar2[j];
933 }
934
935 MProperty* prop = new MProperty(offset[i] - low_off, name, solverIds[i], a);
936 proplist->push_back(prop);
937
938 delete[] a;
939 }
940
941 for(; i < floatOffset; i++) {
942 MInt low_off = 0;
943 MInt low_off_name = offset[nameOffset + i - 1];
944 if(i > boolOffset) {
945 low_off = offset[i - 1];
946 }
947
948 // cerr << offset[i]<< " " << low_off << endl;
949 auto* a = new MBool[offset[i] - low_off];
950 for(MInt j = low_off, l = 0; j < offset[i]; j++, l++) {
951 a[l] = bool_ar[j];
952 }
953
954 MString name;
955 for(MInt j = low_off_name; j < offset[nameOffset + i]; j++) {
956 name += char_ar2[j];
957 }
958
959 MProperty* prop = new MProperty(offset[i] - low_off, name, solverIds[i], a);
960 proplist->push_back(prop);
961
962 delete[] a;
963 }
964
965 for(; i < stringOffset; i++) {
966 MInt low_off = 0;
967 MInt low_off_name = offset[nameOffset + i - 1];
968 if(i > floatOffset) low_off = offset[i - 1];
969
970 // cerr << offset[i]<< " " << low_off << endl;
971 auto* a = new MFloat[offset[i] - low_off];
972 for(MInt j = low_off, l = 0; j < offset[i]; j++, l++) {
973 a[l] = float_ar[j];
974 }
975
976 MString name;
977 for(MInt j = low_off_name; j < offset[nameOffset + i]; j++)
978 name += char_ar2[j];
979
980 MProperty* prop = new MProperty(offset[i] - low_off, name, solverIds[i], a);
981 proplist->push_back(prop);
982
983 delete[] a;
984 }
985
986 for(; i < nameOffset; i++) {
987 MInt low_off = 0;
988 MInt low_off_name = offset[nameOffset + i - 1];
989 if(i > stringOffset) low_off = offset[i - 1];
990
991 MString a;
992 for(MInt j = low_off, l = 0; j < offset[i]; j++, l++)
993 a += char_ar[j];
994
995 MString name;
996 for(MInt j = low_off_name; j < offset[nameOffset + i]; j++)
997 name += char_ar2[j];
998
999 MProperty* prop = new MProperty(1, name, solverIds[i], &a);
1000 proplist->push_back(prop);
1001 }
1002
1003 // Check all properties
1004 // FOR DEBUG
1005 /*
1006 MInt l=0;
1007 for (list<MProperty*>::iterator it = proplist->begin(); it!=proplist->end();it++,l++)
1008 {
1009 cerr << (*it)->name << " " << (*it)->solverId << ": " ;
1010 for (MInt j=0; j<(*it)->elements;j++)
1011 {
1012 if(l<floatOffset)
1013 cerr << *((*it)->asInt(j)) << " ";
1014 else if(l<stringOffset)
1015 cerr << *((*it)->asFloat(j)) << " ";
1016 else if(l<nameOffset)
1017 cerr << *((*it)->asString(j)) << " ";
1018 }
1019 cerr << endl;
1020 }
1021 */
1022 delete[] offset;
1023 delete[] solverIds;
1024 delete[] int_ar;
1025 delete[] float_ar;
1026 delete[] bool_ar;
1027 delete[] char_ar;
1028 delete[] char_ar2;
1029
1030
1031 return proplist;
1032}
char MChar
Definition: maiatypes.h:56
int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status, const MString &name, const MString &varname)
same as MPI_Recv

◆ sendProperties()

void Context::sendProperties ( MInt  rank)
static
Author
Andreas Lintermann
Date
9.12.2010
Parameters
[in]therank of the processor to commuicate with

This function sends the own properties to a cpu given by rank. The properties are sent in the following order

  1. the sizes of all arrays
  2. all integer values of the properties
  3. all float (double) values of the properties
  4. all string values of the properties
  5. all names of the properties
  6. all solverIds of the properties
  7. all offsets of the properties, required to find the right values for the associated property

Definition at line 1052 of file context.cpp.

1052 {
1053 TRACE();
1054
1055 MInt tag = 0;
1056
1057 // cerr << "Processor " << MPI_COMM_WORLD.Get_rank() << " is sending to: " << rank << endl;
1058 MInt listSizes[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1059
1060 list<MProperty*> intProperties;
1061 list<MProperty*> floatProperties;
1062 list<MProperty*> stringProperties;
1063 list<MProperty*> boolProperties;
1064
1065 for(auto& i : *m_propertyMap) {
1066 switch(i.second->type()) {
1067 case MINT: {
1068 intProperties.push_back(i.second);
1069 listSizes[0] += (i.second->elements);
1070 listSizes[5]++;
1071 break;
1072 }
1073 case MBOOL: {
1074 boolProperties.push_back(i.second);
1075 listSizes[1] += (i.second->elements);
1076 listSizes[6]++;
1077 break;
1078 }
1079 case MFLOAT: {
1080 floatProperties.push_back(i.second);
1081 listSizes[2] += (i.second->elements);
1082 listSizes[7]++;
1083 break;
1084 }
1085 case MSTRING: {
1086 stringProperties.push_back(i.second);
1087 listSizes[3] += (i.second->stringField->size());
1088 listSizes[8]++;
1089 break;
1090 }
1091 default: {
1092 mTerm(1, AT_, "Context::sendProperties(): switch variable 'i->second->type' not matching any case");
1093 }
1094 }
1095 listSizes[4] += (i.second->name.size());
1096 listSizes[9]++;
1097 }
1098
1099 MInt offset_sizes = listSizes[5] + listSizes[6] + listSizes[7] + listSizes[8] + listSizes[9];
1100 // cerr << offset_sizes << endl;
1101 auto* offset = new MInt[offset_sizes];
1102 auto* solverIds = new MInt[listSizes[9]];
1103 /*
1104 cerr << "Number of INT properties: " << intProperties.size() << ", size = " << listSizes[0] << endl;
1105 cerr << "Number of FLOAT properties: " << floatProperties.size() << ", size = " << listSizes[1] << endl;
1106 cerr << "Number of STRING properties: " << stringProperties.size() << ", size = " << listSizes[2] << endl;
1107 cerr << "Number of NAMES: " << listSizes[7] << ", size = " << listSizes[3] << endl;
1108 */
1109
1110 // Build integer array and fill sizes for offsets
1111 auto* int_ar = new MInt[listSizes[0]];
1112 MInt k = 0, m = 0, n = 0;
1113 for(auto& intPropertie : intProperties) {
1114 for(MInt j = 0; j < intPropertie->elements; j++) {
1115 int_ar[k] = intPropertie->intField[j];
1116 k++;
1117 }
1118 offset[m] = k;
1119 solverIds[m] = intPropertie->solverId;
1120 m++;
1121 }
1122
1123 // Build float array
1124 auto* bool_ar = new MBool[listSizes[1]];
1125 k = 0;
1126 for(auto& boolPropertie : boolProperties) {
1127 for(MInt j = 0; j < boolPropertie->elements; j++) {
1128 bool_ar[k] = boolPropertie->boolField[j];
1129 k++;
1130 }
1131
1132
1133 offset[m] = k;
1134 solverIds[m] = boolPropertie->solverId;
1135 m++;
1136 }
1137
1138 // Build MBool array and fill sizes for offsets
1139 auto* float_ar = new MFloat[listSizes[2]];
1140 k = 0;
1141 for(auto& floatPropertie : floatProperties) {
1142 for(MInt j = 0; j < floatPropertie->elements; j++) {
1143 float_ar[k] = floatPropertie->floatField[j];
1144 k++;
1145 }
1146
1147 offset[m] = k;
1148 solverIds[m] = floatPropertie->solverId;
1149 m++;
1150 }
1151
1152 // Build string array
1153 MChar* char_ar = new MChar[listSizes[3]];
1154 k = 0;
1155 for(auto& stringPropertie : stringProperties) {
1156 MString a = *(stringPropertie->asString());
1157 for(MInt j = 0; j < (MInt)a.size(); j++) {
1158 char_ar[k] = a[j];
1159 k++;
1160 }
1161 offset[m] = k;
1162 solverIds[m] = stringPropertie->solverId;
1163 m++;
1164 }
1165
1166 // Build name array
1167 MChar* char_ar2 = new MChar[listSizes[4]];
1168 k = 0;
1169 for(auto& intPropertie : intProperties) {
1170 MString a = intPropertie->name;
1171 for(MChar j : a) {
1172 char_ar2[k] = j;
1173 k++;
1174 }
1175 offset[m] = k;
1176 m++;
1177 }
1178 for(auto& boolPropertie : boolProperties) {
1179 MString a = boolPropertie->name;
1180 for(MChar j : a) {
1181 char_ar2[k] = j;
1182 k++;
1183 }
1184 offset[m] = k;
1185 m++;
1186 }
1187 for(auto& floatPropertie : floatProperties) {
1188 MString a = floatPropertie->name;
1189 for(MChar j : a) {
1190 char_ar2[k] = j;
1191 k++;
1192 }
1193 offset[m] = k;
1194 m++;
1195 }
1196 for(auto& stringPropertie : stringProperties) {
1197 MString a = stringPropertie->name;
1198 for(MChar j : a) {
1199 char_ar2[k] = j;
1200 k++;
1201 }
1202 offset[m] = k;
1203 m++;
1204 n++;
1205 }
1206
1207 // Send information about arrays
1208 MPI_Send(listSizes, 10, MPI_INT, rank, tag, MPI_COMM_WORLD, AT_, "listSizes");
1209
1210 // Send integer array
1211 MPI_Send(int_ar, listSizes[0], MPI_INT, rank, tag, MPI_COMM_WORLD, AT_, "int_ar");
1212
1213 // Send float array
1214 MPI_Send(bool_ar, listSizes[1], MPI_C_BOOL, rank, tag, MPI_COMM_WORLD, AT_, "bool_ar");
1215
1216 // Send MBool array
1217 MPI_Send(float_ar, listSizes[2], MPI_DOUBLE, rank, tag, MPI_COMM_WORLD, AT_, "float_ar");
1218
1219 // Send string array
1220 MPI_Send(char_ar, listSizes[3], MPI_CHAR, rank, tag, MPI_COMM_WORLD, AT_, "char_ar");
1221
1222 // Send name array
1223 MPI_Send(char_ar2, listSizes[4], MPI_CHAR, rank, tag, MPI_COMM_WORLD, AT_, "char_ar2");
1224
1225 // Send offset information
1226 MPI_Send(offset, offset_sizes, MPI_INT, rank, tag, MPI_COMM_WORLD, AT_, "offset");
1227
1228 // Send solverIds
1229 MPI_Send(solverIds, listSizes[9], MPI_INT, rank, tag, MPI_COMM_WORLD, AT_, "solverIds");
1230
1231 // Clean up
1232 delete[] offset;
1233 delete[] solverIds;
1234 delete[] int_ar;
1235 delete[] float_ar;
1236 delete[] bool_ar;
1237 delete[] char_ar;
1238 delete[] char_ar2;
1239 intProperties.clear();
1240 floatProperties.clear();
1241 stringProperties.clear();
1242 boolProperties.clear();
1243}
int MPI_Send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, const MString &name, const MString &varname)
same as MPI_Send

◆ solverPropertyExists()

MBool Context::solverPropertyExists ( const MString name,
MInt  solverId 
)
static
Author
Moritz Waldmann
Date
12.2018

Definition at line 519 of file context.cpp.

519 {
520 if(propertyExists(name)) {
521 m_pair = m_propertyMap->equal_range(name); // lookup all properties with the requested key
522 for(propertyIterator i = m_pair.first; i != m_pair.second; i++) { // search for the solverId
523 if(i->second->solverId == solverId) { // look for the requested solverId
524 return true;
525 }
526 }
527 }
528 return false;
529}

◆ writeProperties()

static void Context::writeProperties ( char *  fileName)
static

◆ writePropertiesHumanReadable()

void Context::writePropertiesHumanReadable ( )
static

This function closes the properties stream and writes all properties in the propertyMap to the same file including extra information like the number of accesses

Author
Christoph Siewert
Date
10.2010

Definition at line 600 of file context.cpp.

600 {
601 TRACE();
602
603 // All domains write their own property access file
604 {
605 std::cerr << "rank " << globalDomainId() << " writing property access file. " << m_propertyFileOutputName
606 << std::endl;
607#ifdef MAIA_WRITE_ACCESS_PROPERTIES_FILE
608 maia_properties.close();
609#endif
610 FILE* datei;
611 datei = fopen(m_propertyFileOutputName.c_str(), "a+");
612 MString tester;
613 MChar buffer[100];
614 MInt maxNameLength, maxElementLength;
615 maxNameLength = maxElementLength = 0;
616 fprintf(datei, "\n\n--------------------------property table--------------------------\n");
617 for(auto& i : *m_propertyMap) {
618 if(maxNameLength < ((MInt)i.first.length())) {
619 maxNameLength = i.first.length();
620 }
621 for(MInt j = 0; j < i.second->count(); j++) {
622 switch(i.second->type()) {
623 case MBOOL: {
624 sprintf(buffer, "%i", *i.second->asBool(j));
625 tester.append(buffer);
626 break;
627 }
628 case MINT: {
629 sprintf(buffer, "%i", *i.second->asInt(j));
630 tester.append(buffer);
631 break;
632 }
633 case MFLOAT: {
634 sprintf(buffer, "%G", *i.second->asFloat(j));
635 tester.append(buffer);
636 break;
637 }
638 case MSTRING: {
639 tester.append(*i.second->asString(j));
640 tester.append(" ");
641 break;
642 }
643 default: {
644 mTerm(1, AT_, "writePropertiesHumanReadable(): switch variable 'i->second->type' not matching any case");
645 }
646 }
647 tester.append("; ");
648 }
649 if(maxElementLength < ((MInt)tester.length())) {
650 maxElementLength = tester.length();
651 }
652 tester.clear();
653 }
654 maxNameLength = maxNameLength + 1;
655
656 for(auto& i : *m_propertyMap) {
657 switch(i.second->type()) {
658 case MBOOL: {
659 fprintf(datei, "%s ", "bool");
660 fprintf(datei, "%s", i.first.c_str());
661 for(MInt j = 0; j < ((MInt)(maxNameLength - i.first.length())); j++)
662 fprintf(datei, " ");
663 fprintf(datei, "= ");
664 for(MInt j = 0; j < i.second->count(); j++) {
665 sprintf(buffer, "%i; ", *i.second->asBool(j));
666 tester.append(buffer);
667 fprintf(datei, "%i; ", i.second->boolField[j]);
668 }
669 for(MInt k = 0; k < ((MInt)(maxElementLength - tester.length())); k++)
670 fprintf(datei, " ");
671 break;
672 }
673 case MINT: {
674 fprintf(datei, "%s ", "int");
675 fprintf(datei, "%s", i.first.c_str());
676 for(MInt j = 0; j < ((MInt)(maxNameLength - i.first.length())); j++)
677 fprintf(datei, " ");
678 fprintf(datei, "= ");
679 for(MInt j = 0; j < i.second->count(); j++) {
680 sprintf(buffer, "%i; ", *i.second->asInt(j));
681 tester.append(buffer);
682 fprintf(datei, "%i; ", i.second->intField[j]);
683 }
684 for(MInt k = 0; k < ((MInt)(maxElementLength - tester.length())); k++)
685 fprintf(datei, " ");
686 break;
687 }
688 case MFLOAT: {
689 fprintf(datei, "%s ", "double");
690 fprintf(datei, "%s", i.first.c_str());
691 for(MInt j = 0; j < ((MInt)(maxNameLength - i.first.length())); j++)
692 fprintf(datei, " ");
693 fprintf(datei, "= ");
694 for(MInt j = 0; j < i.second->count(); j++) {
695 sprintf(buffer, "%G; ", *i.second->asFloat(j));
696 tester.append(buffer);
697 fprintf(datei, "%G; ", i.second->floatField[j]);
698 }
699 for(MInt k = 0; k < ((MInt)(maxElementLength - tester.length())); k++)
700 fprintf(datei, " ");
701 break;
702 }
703 case MSTRING: {
704 fprintf(datei, "%s ", "char");
705 fprintf(datei, "%s", i.first.c_str());
706 for(MInt j = 0; j < ((MInt)(maxNameLength - i.first.length())); j++)
707 fprintf(datei, " ");
708 fprintf(datei, "= ");
709 for(MInt j = 0; j < i.second->count(); j++) {
710 tester.append(*i.second->asString(j));
711 fprintf(datei, "\"%s\"; ", i.second->asString(j)->c_str());
712 }
713 for(MInt k = 0; k < ((MInt)(maxElementLength - tester.length() - 4)); k++)
714 fprintf(datei, " ");
715 break;
716 }
717
718 default: {
719 fprintf(datei, "--------------ERROR--------------");
720 fprintf(datei, "\n");
721 fprintf(datei, "Undefined type of Property: ");
722 fprintf(datei, "%s =", i.first.c_str());
723 fprintf(datei, "\n");
724 break;
725 }
726 }
727 const MInt solverId = (i.second->solverId < m_noSolvers) ? i.second->solverId : -1;
728 fprintf(datei, "SolverId %2i", solverId);
729 fprintf(datei, " Accesses %i", i.second->noAccesses);
730 fprintf(datei, " OldAccesses %i",
731 i.second->noOldAccesses); // TODO labels:IO,totest,toremove not useful (anymore)?
732 fprintf(datei, "\n");
733 tester.clear();
734 }
735 fclose(datei);
736 }
737}
static MString m_propertyFileOutputName
Definition: context.h:139

Member Data Documentation

◆ m_assembly

assembly * Context::m_assembly
staticprivate

Definition at line 137 of file context.h.

◆ m_checkingProperties

MBool Context::m_checkingProperties
staticprivate

Definition at line 142 of file context.h.

◆ m_fileType

MInt Context::m_fileType
staticprivate

Definition at line 141 of file context.h.

◆ m_IONetcdf

IONetcdf * Context::m_IONetcdf
staticprivate

Definition at line 130 of file context.h.

◆ m_IOToml

IOToml * Context::m_IOToml
staticprivate

Definition at line 131 of file context.h.

◆ m_name

MString Context::m_name
staticprivate

Definition at line 132 of file context.h.

◆ m_noSolvers

MInt Context::m_noSolvers
staticprivate

Definition at line 133 of file context.h.

◆ m_pair

pair< propertyMap::iterator, propertyMap::iterator > Context::m_pair
staticprivate

Definition at line 138 of file context.h.

◆ m_propertyFileOutputName

MString Context::m_propertyFileOutputName
staticprivate

Definition at line 139 of file context.h.

◆ m_propertyFileText

MString Context::m_propertyFileText
staticprivate

Definition at line 140 of file context.h.

◆ m_propertyMap

propertyMap * Context::m_propertyMap
staticprivate

Definition at line 134 of file context.h.

◆ m_propertyMapLowercase

propertyMap * Context::m_propertyMapLowercase
staticprivate

Definition at line 135 of file context.h.

◆ m_zoneMap

zoneMap * Context::m_zoneMap
staticprivate

Definition at line 136 of file context.h.


The documentation for this class was generated from the following files: