Add temperature models that reads from ascii data file#830
Add temperature models that reads from ascii data file#830jdannberg wants to merge 2 commits intoGeodynamicWorldBuilder:mainfrom
Conversation
MFraters
left a comment
There was a problem hiding this comment.
Thanks for contributing this! I think the contrib folder makes sense for now, give that @Minerallo is also placing his python scripts there. I think the folder name can be a bit more specific though than python. Maybe 1D-diffusion-table, or something like that?
I have a few small suggestions to make the testers happy and to change camel case into snake case for functions. I think we should also separate out the ascii data functionality into a generic utilities function, but we can do that later.
| "features": | ||
| [ | ||
| {"model":"oceanic plate", "name":"oceanic plate", "coordinates":[[-1e3,-1e3],[2100e3,-1e3],[2100e3,1e3],[-1e3,1e3]], | ||
| "temperature models":[{"model":"ascii data", "max depth":500e3, "spreading velocity":0.01, "ridge coordinates":[[[0,-1e3],[0,1e3]]], "data file name":"test_data.txt", "data directory":"../data/"}]} |
There was a problem hiding this comment.
The working directory is tests, so I think the following should work.
| "temperature models":[{"model":"ascii data", "max depth":500e3, "spreading velocity":0.01, "ridge coordinates":[[[0,-1e3],[0,1e3]]], "data file name":"test_data.txt", "data directory":"../data/"}]} | |
| "temperature models":[{"model":"ascii data", "max depth":500e3, "spreading velocity":0.01, "ridge coordinates":[[[0,-1e3],[0,1e3]]], "data file name":"test_data.txt", "data directory":"data/"}]} |
| "composition models":[{"model":"uniform", "compositions":[4]}]}, | ||
|
|
||
| {"model":"oceanic plate", "name":"oceanic plate", "coordinates":[[-1e3,-1e3],[1150e3,-1e3],[1150e3,1e3],[-1e3,1e3]], | ||
| "temperature models":[{"model":"ascii data", "max depth":300e3, "spreading velocity":0.01, "ridge coordinates":[[[100e3,-1e3],[100e3,1e3]]]}], |
There was a problem hiding this comment.
The working directory for the cookbooks is /home/runner/work/WorldBuilder/WorldBuilder/tests/cookbooks/, so the data directory has to be 2d_cartesian_plate_ascii. Another option would be to make the working directory the actual cookbook directory in cmake.
| "temperature models":[{"model":"ascii data", "max depth":300e3, "spreading velocity":0.01, "ridge coordinates":[[[100e3,-1e3],[100e3,1e3]]]}], | |
| "temperature models":[{"model":"ascii data", "data directory":"2d_cartesian_plate_ascii/", "max depth":300e3, "spreading velocity":0.01, "ridge coordinates":[[[100e3,-1e3],[100e3,1e3]]]}], |
| const double age = ridge_parameters[1] / (ridge_parameters[0] * seconds_in_year); | ||
|
|
||
| // Get temperature from ascii data file. | ||
| double temperature = interpolateTemperature (age_depth_table, age, depth); |
There was a problem hiding this comment.
Could you make this snake_case?
| double temperature = interpolateTemperature (age_depth_table, age, depth); | |
| double temperature = interpolate_temperature (age_depth_table, age, depth); |
|
|
||
|
|
||
| bool | ||
| AsciiData::readDataFromFile(const std::string &filename, |
There was a problem hiding this comment.
| AsciiData::readDataFromFile(const std::string &filename, | |
| AsciiData::read_data_from_file(const std::string &filename, |
|
|
||
|
|
||
| double | ||
| AsciiData::interpolateTemperature(const TableData &table, |
There was a problem hiding this comment.
| AsciiData::interpolateTemperature(const TableData &table, | |
| AsciiData::interpolate_temperature(const TableData &table, |
| * the temperature distribution in dependence of age and depth | ||
| * and returns it as TableData. | ||
| */ | ||
| bool readDataFromFile(const std::string &filename, |
There was a problem hiding this comment.
| bool readDataFromFile(const std::string &filename, | |
| bool read_data_from_file(const std::string &filename, |
| * by linearly interpolating between the closest entries for depth | ||
| * and age. | ||
| */ | ||
| double interpolateTemperature(const TableData &table, |
There was a problem hiding this comment.
| double interpolateTemperature(const TableData &table, | |
| double interpolate_temperature(const TableData &table, |
| } | ||
|
|
||
| // Read in the data table | ||
| if (!readDataFromFile(data_directory + data_file_name, age_depth_table)) |
There was a problem hiding this comment.
| if (!readDataFromFile(data_directory + data_file_name, age_depth_table)) | |
| if (!read_data_from_file(data_directory + data_file_name, age_depth_table)) |
|
Great, thank you! I've addressed your comments. |
I added a temperature model for oceanic plates that can read from an ascii data file, and I also made a test and a cookbook.
Not sure when you'll get to reviewing this, but I just wanted to upload the state I got to. The cookbook does not have any text or images, but other than that, everything should work.
This is how the cookbook output looks like:

I obviously can't exactly match the edges of the plate (which uses a T-dependent conductivity) and the slab (which uses mass-conserving, and therefore a constant conductivity), but I tried to make it close.
For now I've simply added the python script into a contrib folder, but let me know if you want that somewhere else.