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

Create an original.wb when running ASPECT with the World Builder #6137

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/modules/changes/20241106_danieldouglas92
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Added: When using the Geodynamic World Builder, ASPECT will create a file
called 'original.wb' in the output directory which contains the exact
worldbuilder file used to run the ASPECT model.
<br>
(Daniel Douglas, 2024/11/06)
14 changes: 14 additions & 0 deletions source/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,20 @@ run_simulator(const std::string &raw_input_as_string,

std::ofstream file(output_directory + "original.prm");
file << raw_input_as_string;

// If using the Geodynamic World Builder, create output/original.wb
// containing the exact file used to create the world:
std::string world_builder_file = prm.get("World builder file");
if (world_builder_file != "")
{
// TODO: We just want to make a copy of the file, but to do this
// platform-independently we need the C++17 filesystem header.
// Update this when we require C++17
std::ifstream wb_source(world_builder_file, std::ios::binary);
std::ofstream wb_destination(output_directory + "original.wb", std::ios::binary);
Comment on lines +628 to +629
Copy link
Member

Choose a reason for hiding this comment

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

why binary? these files are text files or not?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it really matters. My rational was (besides that was what an exampled I find used) that since we need to read it into a stream and directly out into another stream, we don't need it to be converted to text mode by the stream and it can just copy the bites. But am not sure if this is how it really works internally and I don't really think it matters.

From https://en.cppreference.com/w/cpp/io/c/FILE#Binary_and_text_modes:

A binary stream is an ordered sequence of characters that can transparently record internal data. Data read in from a binary stream always equal the data that were earlier written out to that stream, except that an implementation is allowed to append an indeterminate number of null characters to the end of the stream. A wide binary stream doesn't need to end in the initial shift state.

Copy link
Contributor Author

@danieldouglas92 danieldouglas92 Nov 7, 2024

Choose a reason for hiding this comment

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

This was @MFraters suggested edits so he can correct me if I'm wrong, but to my understanding setting std::ios::binary doesn't define the file format, but that you want to copy the world_builder_file as it exists in memory to the output file without modifying the contents of world_builder_file.

This code does work as expected and outputs the contents of the input worldbuilder file exactly as it was input into ASPECT.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I didn't see that you had already replied Menno 😄

Copy link
Member

Choose a reason for hiding this comment

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

I agree that there is no harm in doing it as binary (unmodified) data.


wb_destination << wb_source.rdbuf();
}
}

simulator.run();
Expand Down
5 changes: 5 additions & 0 deletions tests/original_wb.prm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# test that output/original.wb is written correctly

# based on world_builder_simple.prm:
include $ASPECT_SOURCE_DIR/tests/world_builder_simple.prm
set World builder file = $ASPECT_SOURCE_DIR/tests/world_builder_simple.wb
31 changes: 31 additions & 0 deletions tests/original_wb/original.wb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"version":"1.0",
"cross section":[[0,0],[100,0]],
"features":
[
{"model":"oceanic plate", "name":"oceanic plate", "coordinates":[[-1e3,-1e3],[1150e3,-1e3],[1150e3,1e3],[-1e3,1e3]],
"temperature models":[{"model":"plate model", "max depth":95e3, "bottom temperature":1600, "spreading velocity":0.005, "ridge coordinates":[[[100e3,-1e3],[100e3,1e3]]]}],
"composition models":[{"model":"uniform", "compositions":[0], "max depth":10e3},
{"model":"uniform", "compositions":[1], "min depth":10e3, "max depth":95e3}]},

{"model":"continental plate", "name":"continental plate", "coordinates":[[1150e3,-1e3],[2001e3,-1e3],[2001e3,1e3],[1150e3,1e3]],
"temperature models":[{"model":"linear", "max depth":95e3, "bottom temperature":1600}],
"composition models":[{"model":"uniform", "compositions":[2], "max depth":30e3},
{"model":"uniform", "compositions":[3], "min depth":30e3, "max depth":65e3}]},

{"model":"mantle layer", "name":"upper mantle", "min depth":95e3, "max depth":660e3, "coordinates":[[-1e3,-1e3],[2001e3,-1e3],[2001e3,1e3],[-1e3,1e3]],
"temperature models":[{"model":"linear", "min depth":95e3, "max depth":660e3, "top temperature":1600, "bottom temperature":1820}],
"composition models":[{"model":"uniform", "compositions":[4]}]},

{"model":"mantle layer", "name":"lower mantle", "min depth":660e3, "max depth":1160e3, "coordinates":[[-1e3,-1e3],[2001e3,-1e3],[2001e3,1e3],[-1e3,1e3]],
"temperature models":[{"model":"linear", "min depth":660e3, "max depth":1160e3, "top temperature":1820, "bottom temperature":2000}],
"composition models":[{"model":"uniform", "compositions":[5]}]},

{"model":"subducting plate", "name":"Subducting plate", "coordinates":[[1150e3,-1e3],[1150e3,1e3]], "dip point":[2000e3,0],
"segments":[{"length":200e3, "thickness":[95e3], "angle":[0,45]}, {"length":200e3, "thickness":[95e3], "angle":[45]},
{"length":200e3, "thickness":[95e3], "angle":[45,0]}, {"length":100e3, "thickness":[95e3], "angle":[0]}],
"temperature models":[{"model":"plate model", "density":3300, "plate velocity":0.01, "adiabatic heating":false}],
"composition models":[{"model":"uniform", "compositions":[0], "max distance slab top":10e3},
{"model":"uniform", "compositions":[1], "min distance slab top":10e3, "max distance slab top":95e3 }]}
]
}
14 changes: 14 additions & 0 deletions tests/original_wb/statistics
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 1: Time step number
# 2: Time (seconds)
# 3: Time step size (seconds)
# 4: Number of mesh cells
# 5: Number of Stokes degrees of freedom
# 6: Number of temperature degrees of freedom
# 7: Number of degrees of freedom for all compositions
# 8: Iterations for temperature solver
# 9: Iterations for composition solver 1
# 10: Iterations for Stokes solver
# 11: Velocity iterations in Stokes preconditioner
# 12: Schur complement iterations in Stokes preconditioner
# 13: Visualization file name
0 0.000000000000e+00 0.000000000000e+00 1024 9539 4225 4225 0 0 36 38 38 output-original_wb/solution/solution-00000