MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
property.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#include "property.h"
8
9#include "UTIL/debug.h"
10#include "UTIL/functions.h"
11#include "UTIL/timer.h"
12
13using namespace std;
14
16
18 TRACE();
19 switch(propertyType) {
20 case MINT: {
21 delete[] intField;
22
23 // Int properties can be requested as float, for which a copy is created. Thus also check the
24 // float field if it was allocated.
25 if(floatField != nullptr) {
26 delete[] floatField;
27 }
28
29 break;
30 }
31 case MFLOAT: {
32 delete[] floatField;
33 break;
34 }
35 case MSTRING: {
36 delete[] stringField;
37 break;
38 }
39 case MBOOL: {
40 delete[] boolField;
41 break;
42 }
43 default: {
44 stringstream errorMessage;
45 errorMessage << "MProperty::clear(): switch variable 'propertyType' with value " << propertyType
46 << " not matching any case." << endl;
47 mTerm(1, AT_, errorMessage.str());
48 }
49 }
50}
51
53 // TRACE();
54 noAccesses = 0;
55 noOldAccesses = 0;
56}
57
59 // TRACE();
61 elements = size;
62 name = propname;
63 noAccesses = 0;
64 noOldAccesses = 0;
66 stringField = new MString[size];
67 for(MInt i = 0; i < size; i++)
68 stringField[i] = value[i];
69}
70
72 // TRACE();
74 elements = size;
75 name = propname;
76 noAccesses = 0;
77 noOldAccesses = 0;
79 floatField = new MFloat[size];
80 for(MInt i = 0; i < size; i++)
81 floatField[i] = value[i];
82}
83
84MProperty::MProperty(MInt size, MString propname, MInt Solver, MInt* value) {
85 // TRACE();
87 elements = size;
88 name = propname;
89 noAccesses = 0;
90 noOldAccesses = 0;
92 intField = new MInt[size];
93 for(MInt i = 0; i < size; i++)
94 intField[i] = value[i];
95}
96
98 // TRACE();
100 elements = size;
101 name = propname;
102 noAccesses = 0;
103 noOldAccesses = 0;
105 boolField = new MBool[size];
106 for(MInt i = 0; i < size; i++)
107 boolField[i] = value[i];
108}
109
111
113
115 if(propertyType != MSTRING) {
116 stringstream errorMessage;
117 errorMessage << "Property " << name << " is requested as a String, but it is a ";
118 switch(propertyType) {
119 case MINT: {
120 errorMessage << "INT!!";
121 break;
122 }
123 case MFLOAT: {
124 errorMessage << "FLOAT!!";
125 break;
126 }
127 case MSTRING: {
128 errorMessage << "STRING!!";
129 break;
130 }
131 case MBOOL: {
132 errorMessage << "BOOL!!";
133 break;
134 }
135 default: {
136 mTerm(1, AT_, "MProperty::asString(): switch variable 'propertyType' not matching any case");
137 }
138 }
139 mTerm(1, AT_, errorMessage.str());
140 }
141 return stringField;
142}
143
145 if(propertyType != MBOOL) {
146 stringstream errorMessage;
147 errorMessage << "Property " << name << " is requested as a Bool, but it is a ";
148 switch(propertyType) {
149 case MINT: {
150 errorMessage << "INT!!";
151 break;
152 }
153 case MFLOAT: {
154 errorMessage << "FLOAT!!";
155 break;
156 }
157 case MSTRING: {
158 errorMessage << "STRING!!";
159 break;
160 }
161 case MBOOL: {
162 errorMessage << "BOOL!!";
163 break;
164 }
165 default: {
166 mTerm(1, AT_, "MProperty::asBool(): switch variable 'propertyType' not matching any case");
167 }
168 }
169 mTerm(1, AT_, errorMessage.str());
170 }
171 return boolField;
172}
173
175 if(propertyType != MINT) {
176 stringstream errorMessage;
177 errorMessage << "Property " << name << " is requested as a Int, but it is a ";
178 switch(propertyType) {
179 case MINT: {
180 errorMessage << "INT!!";
181 break;
182 }
183 case MFLOAT: {
184 errorMessage << "FLOAT!!";
185 break;
186 }
187 case MSTRING: {
188 errorMessage << "STRING!!";
189 break;
190 }
191 case MBOOL: {
192 errorMessage << "BOOL!!";
193 break;
194 }
195 default: {
196 mTerm(1, AT_, "MProperty::asInt(): switch variable 'propertyType' not matching any case");
197 }
198 }
199 mTerm(1, AT_, errorMessage.str());
200 }
201 return intField;
202}
203
205 if(propertyType != MFLOAT && propertyType != MINT) {
206 stringstream errorMessage;
207 errorMessage << "Property " << name << " is requested as a Float, but it is a ";
208 switch(propertyType) {
209 case MINT: {
210 errorMessage << "INT!!";
211 break;
212 }
213 case MFLOAT: {
214 errorMessage << "FLOAT!!";
215 break;
216 }
217 case MSTRING: {
218 errorMessage << "STRING!!";
219 break;
220 }
221 case MBOOL: {
222 errorMessage << "BOOL!!";
223 break;
224 }
225 default: {
226 mTerm(1, AT_, "MProperty::asFloat(): switch variable 'propertyType' not matching any case");
227 }
228 }
229 mTerm(1, AT_, errorMessage.str());
230 }
231
232 // If int property is requested as float, create copy of int properties first
233 if(propertyType == MINT && floatField == nullptr) {
235 copy_n(intField, elements, floatField);
236 }
237
238 return floatField;
239}
240
242 if(propertyType != MSTRING) {
243 stringstream errorMessage;
244 errorMessage << "Property " << name << " is requested as a String, but it is a ";
245 switch(propertyType) {
246 case MINT: {
247 errorMessage << "INT!!";
248 break;
249 }
250 case MFLOAT: {
251 errorMessage << "FLOAT!!";
252 break;
253 }
254 case MSTRING: {
255 errorMessage << "STRING!!";
256 break;
257 }
258 case MBOOL: {
259 errorMessage << "BOOL!!";
260 break;
261 }
262 default: {
263 mTerm(1, AT_, "MProperty::asString(): switch variable 'propertyType' not matching any case");
264 }
265 }
266 mTerm(1, AT_, errorMessage.str());
267 }
268 if(index + 1 > elements) {
269 stringstream errorMessage;
270 errorMessage << " MProperty::asString() for property " << name << " is requested index out of range! It has "
271 << elements << " ,but it is asked for the " << index + 1 << " element! " << endl;
272 mTerm(1, AT_, errorMessage.str());
273 }
274 return (stringField + index);
275}
276
278 if(propertyType != MBOOL) {
279 stringstream errorMessage;
280 errorMessage << "Property " << name << " is requested as a Bool, but it is a ";
281 switch(propertyType) {
282 case MINT: {
283 errorMessage << "INT!!";
284 break;
285 }
286 case MFLOAT: {
287 errorMessage << "FLOAT!!";
288 break;
289 }
290 case MSTRING: {
291 errorMessage << "STRING!!";
292 break;
293 }
294 case MBOOL: {
295 errorMessage << "BOOL!!";
296 break;
297 }
298 default: {
299 mTerm(1, AT_, "MProperty::asBool(): switch variable 'propertyType' not matching any case");
300 }
301 }
302 mTerm(1, AT_, errorMessage.str());
303 }
304 if(index + 1 > elements) {
305 stringstream errorMessage;
306 errorMessage << " MProperty::asBool() for property " << name << " is requested index out of range! It has "
307 << elements << " ,but it is asked for the " << index + 1 << " element! ";
308 mTerm(1, AT_, errorMessage.str());
309 }
310 // cout << " Using int property : " << name << endl;
311 // cout << " 1st value is : " << *(intField+index) << endl;
312 return (boolField + index);
313}
315 if(propertyType != MINT) {
316 stringstream errorMessage;
317 errorMessage << "Property " << name << " is requested as a Int, but it is a ";
318 switch(propertyType) {
319 case MINT: {
320 errorMessage << "INT!!";
321 break;
322 }
323 case MFLOAT: {
324 errorMessage << "FLOAT!!";
325 break;
326 }
327 case MSTRING: {
328 errorMessage << "STRING!!";
329 break;
330 }
331 case MBOOL: {
332 errorMessage << "BOOL!!";
333 break;
334 }
335 default: {
336 mTerm(1, AT_, "MProperty::asInt(): switch variable 'propertyType' not matching any case");
337 }
338 }
339 mTerm(1, AT_, errorMessage.str());
340 }
341 if(index + 1 > elements) {
342 stringstream errorMessage;
343 errorMessage << " MProperty::asInt() for property " << name << " is requested index out of range! It has "
344 << elements << " ,but it is asked for the " << index + 1 << " element! ";
345 mTerm(1, AT_, errorMessage.str());
346 }
347 // cout << " Using int property : " << name << endl;
348 // cout << " 1st value is : " << *(intField+index) << endl;
349 return (intField + index);
350}
351
353 // Check if property really is a float (or int, as getting int properties as floats is allowed)
354 if(propertyType != MFLOAT && propertyType != MINT) {
355 stringstream errorMessage;
356 errorMessage << "Property " << name << " is requested as a float, but it is a ";
357 switch(propertyType) {
358 case MINT: {
359 errorMessage << "INT!!";
360 break;
361 }
362 case MFLOAT: {
363 errorMessage << "FLOAT!!";
364 break;
365 }
366 case MSTRING: {
367 errorMessage << "STRING!!";
368 break;
369 }
370 case MBOOL: {
371 errorMessage << "BOOL!!";
372 break;
373 }
374 default: {
375 mTerm(1, AT_, "MProperty::asInt(): switch variable 'propertyType' not matching any case");
376 }
377 }
378 mTerm(1, AT_, errorMessage.str());
379 }
380
381 // Check if size is OK
382 if(index + 1 > elements) {
383 stringstream errorMessage;
384 errorMessage << " MProperty::asFloat() for property " << name << " is requested index out of range! It has "
385 << elements << " ,but it is asked for the " << index + 1 << " element! ";
386 mTerm(1, AT_, errorMessage.str());
387 }
388
389 // If int property is requested as float, create copy of int properties first
390 if(propertyType == MINT && floatField == nullptr) {
392 copy_n(intField, elements, floatField);
393 }
394
395 return (floatField + index);
396}
VariableType propertyType
Definition: property.h:34
MInt elements
Definition: property.h:35
MFloat * asFloat()
Definition: property.cpp:204
MInt * intField
Definition: property.h:42
MString name
Definition: property.h:36
MInt noAccesses
Definition: property.h:37
VariableType type()
Definition: property.cpp:110
MInt * asInt()
Definition: property.cpp:174
void clear()
Definition: property.cpp:17
MBool * asBool()
Definition: property.cpp:144
MString * stringField
Definition: property.h:40
MInt solverId
Definition: property.h:39
MInt count()
Definition: property.cpp:112
MInt noOldAccesses
Definition: property.h:38
MFloat * floatField
Definition: property.h:41
MString * asString()
Definition: property.cpp:114
MBool * boolField
Definition: property.h:43
~MProperty()
Definition: property.cpp:15
Parent class of all solvers This class is the base for all solvers. I.e. all solver class (e....
Definition: solver.h:29
VariableType
Definition: enums.h:269
@ MINT
Definition: enums.h:269
@ MFLOAT
Definition: enums.h:269
@ MBOOL
Definition: enums.h:269
@ MSTRING
Definition: enums.h:269
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Definition: functions.cpp:29
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
bool MBool
Definition: maiatypes.h:58