How to acess the values of a Table

From KratosWiki
Jump to: navigation, search

Tables are stored in the ModelPart. If you want to acces the data of a table, you must know the Id of this table. Then, if you want to acces table 2 from C++ you can do:

ModelPart::Table<double,double>& table_2 = modelpart.GetTable(2);

You can do the same in Python:

table_2 = modelpart.GetTable(2)

If you have a table written in the input file (mdpa file) like this one:

0.0  1.0
1.0  1.5
End Table

accessing its values is simple. Do this in C++:

double temperature_at_time_0_5 = table_2.GetValue(0.5)

or in Python:

temperature_at_time_0_5 = table_2.GetValue(0.5)

The result will be temperature_at_time_0_5 = 1.25, because it's interpolated automatically.

Of course, you can do it all in a single line by doing in C++:

double temperature_at_time_0_5 = modelpart.GetTable(2).GetValue(0.5)

or in Python:

temperature_at_time_0_5 = modelpart.GetTable(2).GetValue(0.5)
Personal tools