-
Notifications
You must be signed in to change notification settings - Fork 36
Refactor Rotated Projection Logic #453
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
Open
mabruzzo
wants to merge
11
commits into
cholla-hydro:dev
Choose a base branch
from
mabruzzo:RotatedProjection
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f51ad0a
Introduce RotatedProjWriter class
mabruzzo 445bbcc
mv init logic for `Rotation` struct to a constructor
mabruzzo b7d58c4
stop tracking `Rotation` within `Grid3D`
mabruzzo ccbcfd5
relocate `Rotation` declaration & put it in `io` namespace
mabruzzo b8c4c69
tweak `Rotation`'s constructor and docstrings
mabruzzo 532e672
directly parse parameters in `Rotation` constructor
mabruzzo 06a4e78
Consolidate Output_Rotated_Projected_Data & RotatedProjWriter::operat…
mabruzzo 44f6302
A little cleanup
mabruzzo 9656311
Merge branch 'dev' into RotatedProjection
evaneschneider 9544d59
Transition to using a switch-statement (per Helena's suggestion)
mabruzzo ac0d66a
Merge branch 'dev' into RotatedProjection
evaneschneider File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| /*! | ||
| * \file | ||
| * Implements the RotatedProjWriter type | ||
| */ | ||
|
|
||
| #include "RotatedProjWriter.h" | ||
|
|
||
| #include <cmath> // M_PI (note: not guaranteed by the C++ standard) | ||
| #ifdef HDF5 | ||
| #include <hdf5.h> | ||
| #endif // HDF5 | ||
|
|
||
| #include "../global/global.h" // Parameters | ||
| #include "../grid/grid3D.h" | ||
| #include "../io/io.h" | ||
| #include "../utils/error_handling.h" | ||
|
|
||
| io::Rotation::Rotation(ParameterMap &pmap) | ||
| { | ||
| // thoughts for the future: | ||
| // do we want to enforce valid domains for arguments? We might require that | ||
| // - nxr & nzr are positive | ||
| // - delta, phi, & theta satisfy 0 <= x < 180 (maybe we want to be more flexible) | ||
| // - Lx & Lz are positive (or at least non-zero) | ||
| // - I think flag_delta should only be 0, 1, or 2 | ||
| // | ||
| // should we make it an error to specify the: | ||
| // - ddelta_dt parameter when flag_delta != 1 | ||
| // - n_delta parameter when flag_delta != 2 | ||
|
|
||
| // x-dir pixels in projection | ||
| this->nx = pmap.value<int>("nxr"); | ||
| // z-dir pixels in projection | ||
| this->nz = pmap.value<int>("nzr"); | ||
| // minimum x location to project | ||
| this->nx_min = 0; | ||
| // minimum z location to project | ||
| this->nz_min = 0; | ||
| // maximum x location to project | ||
| this->nx_max = this->nx; | ||
| // maximum z location to project | ||
| this->nz_max = this->nz; | ||
| // rotation angle about z direction | ||
| this->delta = Real(M_PI * (pmap.value_or("delta", 0.0) / 180.)); // convert to radians | ||
| // rotation angle about x direction | ||
| this->theta = Real(M_PI * (pmap.value_or("theta", 0.0) / 180.)); // convert to radians | ||
| // rotation angle about y direction | ||
| this->phi = Real(M_PI * (pmap.value_or("phi", 0.0) / 180.)); // convert to radians | ||
| // x-dir physical size of projection | ||
| this->Lx = Real(pmap.value<double>("Lx")); | ||
| // z-dir physical size of projection | ||
| this->Lz = Real(pmap.value<double>("Lz")); | ||
| // initialize a counter for rotated outputs | ||
| this->i_delta = 0; | ||
| // number of rotated outputs in a complete revolution | ||
| this->n_delta = pmap.value_or("n_delta", 0); | ||
| CHOLLA_ASSERT(this->n_delta >= 0, "the \"n_delta\" parameter must not be negative"); | ||
| // rate of rotation between outputs, for an actual simulation | ||
| this->ddelta_dt = Real(pmap.value_or("ddelta_dt", 0.0)); | ||
| // are we not rotating about z(0)? | ||
| // are we outputting multiple rotations(1)? or rotating during a | ||
| // simulation(2)? | ||
| this->flag_delta = pmap.value_or("flag_delta", 0); | ||
| } | ||
|
|
||
| void io::RotatedProjWriter::operator()(Grid3D &G, Parameters P, int nfile, const FnameTemplate &fname_template) | ||
| { | ||
| #ifdef HDF5 | ||
| hid_t file_id; | ||
| herr_t status; | ||
|
|
||
| // create the filename | ||
| std::string filename = fname_template.format_fname(nfile, "_rot_proj"); | ||
|
|
||
| // it may be a little more explicit to use a switch statement instead of if/elif/else | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that a switch statement would be clearer if you wanted to change it (but I don't think it's necessary for this PR if you don't feel like it). |
||
| if (this->rot_info_.flag_delta == 1) { | ||
| // if flag_delta==1, then we are just outputting a | ||
| // bunch of rotations of the same snapshot | ||
| char fname[200]; | ||
|
|
||
| for (int i_delta = 0; i_delta < this->rot_info_.n_delta; i_delta++) { | ||
| filename += "." + std::to_string(this->rot_info_.i_delta); | ||
| chprintf("Outputting rotated projection %s.\n", fname); | ||
|
|
||
| // determine delta about z by output index | ||
| this->rot_info_.delta = 2.0 * M_PI * ((double)i_delta) / ((double)this->rot_info_.n_delta); | ||
|
|
||
| // Create a new file | ||
| file_id = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); | ||
|
|
||
| // Write header (file attributes) | ||
| G.Write_Header_Rotated_HDF5(file_id, this->rot_info_); | ||
|
|
||
| // Write the density and temperature projections to the output file | ||
| G.Write_Rotated_Projection_HDF5(file_id, this->rot_info_); | ||
|
|
||
| // Close the file | ||
| status = H5Fclose(file_id); | ||
|
|
||
| CHOLLA_ASSERT(status >= 0, "Rotated Projection: File write failed. ProcID: %d\n", procID); | ||
|
|
||
| // iterate this->rot_info_.i_delta | ||
| this->rot_info_.i_delta++; | ||
| } | ||
|
|
||
| } else if (this->rot_info_.flag_delta == 2) { | ||
| // case 2 -- outputting at a rotating delta | ||
| // rotation rate given in the parameter file | ||
| this->rot_info_.delta = fmod(nfile * this->rot_info_.ddelta_dt * 2.0 * M_PI, (2.0 * M_PI)); | ||
|
|
||
| // Create a new file | ||
| file_id = H5Fcreate(filename.data(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); | ||
|
|
||
| // Write header (file attributes) | ||
| G.Write_Header_Rotated_HDF5(file_id, this->rot_info_); | ||
|
|
||
| // Write the density and temperature projections to the output file | ||
| G.Write_Rotated_Projection_HDF5(file_id, this->rot_info_); | ||
|
|
||
| // Close the file | ||
| status = H5Fclose(file_id); | ||
| } else { | ||
| // case 0 -- just output at the delta given in the parameter file | ||
|
|
||
| // Create a new file | ||
| file_id = H5Fcreate(filename.data(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); | ||
|
|
||
| // Write header (file attributes) | ||
| G.Write_Header_Rotated_HDF5(file_id, this->rot_info_); | ||
|
|
||
| // Write the density and temperature projections to the output file | ||
| G.Write_Rotated_Projection_HDF5(file_id, this->rot_info_); | ||
|
|
||
| // Close the file | ||
| status = H5Fclose(file_id); | ||
| } | ||
|
|
||
| CHOLLA_ASSERT(status >= 0, "Rotated Projection: File write failed. ProcID: %d\n", procID); | ||
|
|
||
| #else | ||
| printf("Output_Rotated_Projected_Data only defined for HDF5 writes.\n"); | ||
| #endif | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think it's a good idea to check that the values of these parameters are valid, at least for the basic things of being positive/nonzero (either in this PR or a future one).
Also, I think it's okay for the
n_delta/ddelta_dtparameters to go unused if they're defined with the wrongflag_deltavalue. But if you're concerned about it being confused, I think printing a warning could also be a good option.