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

[WIP] Add ReadDensityFromFile capabilities - Test 1 (3D only) #4754

Open
wants to merge 27 commits into
base: development
Choose a base branch
from

Conversation

sevicky
Copy link
Contributor

@sevicky sevicky commented Mar 6, 2024

Adding the capability to read a density from openpmd file to use in particle deposition. The current version has only 3D capabilities and is not quite correct with the indexing, which I am continuing to work on but am putting this version in the pull request. Edited files are InjectorDensity.H, InjectorDensity.cpp, and SpeciesUtils.cpp, with most of the changes in the former two. I have tested it using the uniform_plasma example script to give a rho (density) file which is then read in by another input file.

Close #618
Close #3948

Added by @RemiLehe: TODO:

  • Add automated test: read an openPMD file with multiple MPI ranks ; check that the density of particles corresponds to the expected density.
  • Fix error on GPU
  • Avoid out-of-bounds when reading the array.
  • Handle the case of the moving window, whereby we need to periodically read the file.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@ax3l ax3l self-requested a review March 13, 2024 00:35
@ax3l ax3l marked this pull request as draft March 13, 2024 00:36
@sevicky
Copy link
Contributor Author

sevicky commented Mar 18, 2024

The current version in this pull request works for to read a 3D openpmd file and use the density for another simulation. There is no parallelization and further user input options to be implemented.

@ax3l ax3l added component: openPMD openPMD I/O component: core Core WarpX functionality labels Apr 4, 2024
…nel test matches, but not a more asymmetrical test.
@sevicky
Copy link
Contributor Author

sevicky commented Apr 26, 2024

Linked here are the compilation script, input files, and Jupyter notebook that was used in development.

Compilation script:
compile_script.txt

Files to create the data used in the tests:
plasma_test.txt
plasma_test_gradient.txt

input files run to test the parabolic and asymmetric cases respectively:
file_input.txt
file_asymm.txt

Jupyter Notebook: (actual version is in my Google Drive - 2024-Sarah_Vickers/misc.)
openpmd_read.pdf

@aodhanmci
Copy link

aodhanmci commented Jun 4, 2024

@ax3l @sevicky is it possible to input a density in a PICMI input file using a function? e.g. if I pass the function x, y, z, it will return rho(x, y, z) for the grid? this means I can add complicated density profiles directly in the input file e.g. micro/nanostructures that are limited to the functions which can be parsed by amrex

@ax3l
Copy link
Member

ax3l commented Jun 5, 2024

Hi @aodhanmci,

Yes, this is already possible for the string based parser syntax and does not require the feature in this pull request.

We support loading density profiles with functions following this syntax:

Here is a laser-ion acceleration example that uses this from PICMI, see density_expression_str: https://warpx.readthedocs.io/en/latest/usage/examples/laser_ion/README.html

You can go pretty complex in those expressions as multi-line strings, but you cannot pass Python functions (def ...(...): #3684). (Added in DM: support such as random number generators are not in the AMReX parser functions but needed for Aodhan's workflow.) I'll check with others if they have already done the latter, otherwise once the PR here is ready it could be a good basis to support that.

…lic channel test matches, but not a more asymmetrical test."

This reverts commit 2518b7e.
@RemiLehe
Copy link
Member

RemiLehe commented Jun 25, 2024

It looks like the current code does work (including in cases with multiples boxes), if the openPMD data is C-ordered.

Here are the files that I used to create a C-ordered openPMD file, and then to run the
simulation.

file_asymm.txt
openpmd_create_3d.py.txt

While the simulation produces correct results, it segfaults later on. It does not segfault anymore.
TODO:

  • Understand current SegFault
  • Reuse function ReadExternalField to avoid code duplication

@RemiLehe RemiLehe marked this pull request as ready for review June 25, 2024 11:27
Source/Initialization/InjectorDensity.cpp Fixed Show fixed Hide fixed
Source/Initialization/InjectorDensity.H Fixed Show fixed Hide fixed
Source/Initialization/InjectorDensity.H Fixed Show fixed Hide fixed
{
InjectorDensityFromFile (std::string const& a_species_name);

//~InjectorDensityFromFile() = default;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Source/Initialization/InjectorDensity.cpp Fixed Show fixed Hide fixed
Source/Initialization/InjectorDensity.cpp Fixed Show fixed Hide fixed
@@ -1047,7 +1047,7 @@ public:
* \brief Load field values from a user-specified openPMD file
* for a specific field (specified by `F_name`)
*/
void ReadExternalFieldFromFile (
static void ReadExternalFieldFromFile (
Copy link
Member

Choose a reason for hiding this comment

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

We could make this a free function, and move it to the Utils folder.

int iz = std::floor((z-lo2)/m_cell_size[2]);


return m_rho_array4(ix,iy,iz);
Copy link
Member

Choose a reason for hiding this comment

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

We need to make sure that we are not doing out-of-bound access here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: core Core WarpX functionality component: openPMD openPMD I/O
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alternative method of particle initialisation from a file Initialize plasma density from file
4 participants