Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add temperature models that reads from ascii data file #830

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jdannberg
Copy link
Contributor

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:
Screenshot from 2025-01-24 21-48-37
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.

Copy link
Member

@MFraters MFraters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/"}]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The working directory is tests, so I think the following should work.

Suggested change
"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]]]}],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this snake_case?

Suggested change
double temperature = interpolateTemperature (age_depth_table, age, depth);
double temperature = interpolate_temperature (age_depth_table, age, depth);



bool
AsciiData::readDataFromFile(const std::string &filename,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AsciiData::readDataFromFile(const std::string &filename,
AsciiData::read_data_from_file(const std::string &filename,



double
AsciiData::interpolateTemperature(const TableData &table,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!readDataFromFile(data_directory + data_file_name, age_depth_table))
if (!read_data_from_file(data_directory + data_file_name, age_depth_table))

@jdannberg
Copy link
Contributor Author

Great, thank you! I've addressed your comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants