From 32a3bc496accfb34cb20c819be928c263beab254 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Thu, 3 Aug 2023 18:24:09 -0700 Subject: [PATCH 001/100] WarpX: Rule-of-Five (#4155) Explicitly declares the copy and move constructors for the `WarpX` class. https://en.cppreference.com/w/cpp/language/rule_of_three --- Source/WarpX.H | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/WarpX.H b/Source/WarpX.H index ae8f7dfcae1..eeb71f042bd 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -92,8 +92,19 @@ public: */ static void Finalize(); + /** Destructor */ ~WarpX (); + /** Copy constructor */ + WarpX ( WarpX const &) = delete; + /** Copy operator */ + WarpX& operator= ( WarpX const & ) = delete; + + /** Move constructor */ + WarpX ( WarpX && ) = default; + /** Move operator */ + WarpX& operator= ( WarpX && ) = default; + static std::string Version (); //!< Version of WarpX executable static std::string PicsarVersion (); //!< Version of PICSAR dependency @@ -1544,7 +1555,7 @@ private: bool is_synchronized = true; // Synchronization of nodal points - const bool sync_nodal_points = true; + static constexpr bool sync_nodal_points = true; guardCellManager guard_cells; From 310f33221d968d2baade946a37ee147ea3802791 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 4 Aug 2023 15:19:15 +0200 Subject: [PATCH 002/100] move function from .H file to .cpp file (#4159) --- Source/Particles/ParticleBoundaryBuffer.H | 11 +---------- Source/Particles/ParticleBoundaryBuffer.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Source/Particles/ParticleBoundaryBuffer.H b/Source/Particles/ParticleBoundaryBuffer.H index 784b5c8df6c..04885f960f0 100644 --- a/Source/Particles/ParticleBoundaryBuffer.H +++ b/Source/Particles/ParticleBoundaryBuffer.H @@ -23,16 +23,7 @@ public: int numSpecies() const { return getSpeciesNames().size(); } - const std::vector& getSpeciesNames() const { - static bool initialized = false; - if (!initialized) - { - const amrex::ParmParse pp_particles("particles"); - pp_particles.queryarr("species_names", m_species_names); - initialized = true; - } - return m_species_names; - } + const std::vector& getSpeciesNames() const; void gatherParticles (MultiParticleContainer& mypc, const amrex::Vector& distance_to_eb); diff --git a/Source/Particles/ParticleBoundaryBuffer.cpp b/Source/Particles/ParticleBoundaryBuffer.cpp index e66f1415b04..70c9459df5e 100644 --- a/Source/Particles/ParticleBoundaryBuffer.cpp +++ b/Source/Particles/ParticleBoundaryBuffer.cpp @@ -186,6 +186,18 @@ void ParticleBoundaryBuffer::redistribute () { } } +const std::vector& ParticleBoundaryBuffer::getSpeciesNames() const +{ + static bool initialized = false; + if (!initialized) + { + const amrex::ParmParse pp_particles("particles"); + pp_particles.queryarr("species_names", m_species_names); + initialized = true; + } + return m_species_names; +} + void ParticleBoundaryBuffer::clearParticles () { for (int i = 0; i < numBoundaries(); ++i) { From 241b3f4392b9217898dad6840c5f1cee561c4946 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Sat, 5 Aug 2023 01:44:59 +0200 Subject: [PATCH 003/100] remove WarpX::GetInstance from WarpX::InitFromCheckpoint () (#4160) --- Source/Diagnostics/WarpXIO.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Diagnostics/WarpXIO.cpp b/Source/Diagnostics/WarpXIO.cpp index abc5c4f4548..2ae990851e2 100644 --- a/Source/Diagnostics/WarpXIO.cpp +++ b/Source/Diagnostics/WarpXIO.cpp @@ -223,13 +223,11 @@ WarpX::InitFromCheckpoint () is >> time_of_last_gal_shift; ablastr::utils::text::goto_next_line(is); - - auto & warpx = WarpX::GetInstance(); - for (int idiag = 0; idiag < warpx.GetMultiDiags().GetTotalDiags(); ++idiag) + for (int idiag = 0; idiag < multi_diags->GetTotalDiags(); ++idiag) { - if( warpx.GetMultiDiags().diagstypes(idiag) == DiagTypes::BackTransformed ) + if( multi_diags->diagstypes(idiag) == DiagTypes::BackTransformed ) { - auto& diag = warpx.GetMultiDiags().GetDiag(idiag); + auto& diag = multi_diags->GetDiag(idiag); if (diag.getnumbuffers() > 0) { diag.InitDataBeforeRestart(); for (int i_buffer=0; i_bufferGetDiag(idiag).InitData(); } } } From a9a171e60da01a85a71b5f3aea4106f245d5b78b Mon Sep 17 00:00:00 2001 From: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com> Date: Mon, 7 Aug 2023 00:52:24 -0700 Subject: [PATCH 004/100] Add a few abbreviations and terms to the glossary (#4143) * add several abbreviations and terms to the glossary * Apply suggestions from code review Co-authored-by: Luca Fedeli --------- Co-authored-by: Luca Fedeli --- Docs/source/glossary.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Docs/source/glossary.rst b/Docs/source/glossary.rst index 2f00198e42c..cb376af481f 100644 --- a/Docs/source/glossary.rst +++ b/Docs/source/glossary.rst @@ -22,12 +22,14 @@ Abbreviations * **CI:** continuous integration, automated tests that we perform before a proposed code-change is accepted; see PR * **CPU:** `central processing unit `__, we usual mean a socket or generally the host-side of a computer (compared to the accelerator, e.g. GPU) * **DOE:** `The United States Department of Energy `__, the largest sponsor of national laboratory research in the United States of America +* **DSMC:** `Direct Simulation Monte Carlo `__, a method to capture collisions between kinetic particles * **ECP:** `Exascale Computing Project `__, a :ref:`U.S. DOE funding source ` that supports WarpX development * **ECT:** `Enlarged Cell Technique `__, an electromagnetic solver with accurate resolution of perfectly conducting embedded boundaries * **EB:** embedded boundary, boundary conditions inside the simulation box, e.g. following material surfaces * **EM:** electromagnetic, e.g. EM PIC * **ES:** electrostatic, e.g. ES PIC * **FDTD:** `Finite-difference time-domain or Yee's method `__, a class of grid-based finite-difference field solvers +* **FRC:** `Field Reversed Configuration `__, an approach of magnetic confinement fusion * **GPU:** originally graphics processing unit, now used for fast `general purpose computing (GPGPU) `__; also called (hardware) accelerator * **IO:** input/output, usually files and/or data * **IPO:** `interprocedural optimization `__, a collection of compiler optimization techniques that analyze the whole code to avoid duplicate calculations and optimize performance @@ -36,7 +38,9 @@ Abbreviations * **LPI:** laser-plasma interaction (often for laser-solid physics) *or* laser-plasma instability (often in fusion physics), depending on context * **LTO:** `link-time optimization `__, program optimizations for file-by-file compilation that optimize object files before linking them together to an executable * **LWFA:** laser-wakefield acceleration (of electrons/leptons) +* **MCC:** Monte-Carlo collisions wherein a kinetic species collides with a fluid species, for example used in glow discharge simulations * **MR:** mesh-refinement +* **MS:** magnetostatic, e.g. MS PIC * **MVA:** magnetic-vortex acceleration (of protons/ions) * **NERSC:** `National Energy Research Scientific Computing Center `__, a supercomputing center located in Berkeley, CA (USA) * **NSF:** the `National Science Foundation `__, a large public agency in the United States of America, supporting research and education @@ -65,8 +69,11 @@ Terms * **evolve:** this is a generic term to advance a quantity (same nomenclature in AMReX). For instance, ``WarpX::EvolveE(dt)`` advances the electric field for duration ``dt``, ``PhysicalParticleContainer::Evolve(...)`` does field gather + particle push + current deposition for all particles in ``PhysicalParticleContainer``, and ``WarpX::EvolveEM`` is the central ``WarpX`` function that performs 1 PIC iteration. * **Frontier:** an `Exascale supercomputer at OLCF `__ +* **hybrid-PIC:** a plasma simulation scheme that combines fluid and kinetic approaches, with (usually) the electrons treated as a fluid and the ions as kinetic particles (see :ref:`theory-kinetic-fluid-hybrid-model`) * **laser:** most of the time, we mean a `laser pulse `__ -* **openPMD**: `Open Standard for Particle-Mesh Data Files `__, a community meta-data project for scientific data +* **openPMD:** `Open Standard for Particle-Mesh Data Files `__, a community meta-data project for scientific data +* **Ohm's law solver:** the logic that solves for the electric-field when using the hybrid-PIC algorithm * **Perlmutter:** a Berkeley Lab nobel laureate and a `Pre-Exascale supercomputer at NERSC `__ -* **plotfiles**: the internal binary format for data files in *AMReX* +* **plotfiles:** the internal binary format for data files in *AMReX* * **Python:** a popular scripted `programming language `__ +* **scraping:** a term often used to refer to the process of removing particles that have crossed into an embedded boundary or pass an absorbing domain boundary from the simulation From f785c0d3c45f75cc9835c219b0e56e049c367b2a Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Mon, 7 Aug 2023 13:54:55 -0700 Subject: [PATCH 005/100] Release 23.08 (#4165) * AMReX: 23.08 * PICSAR: 23.08 * WarpX: 23.08 --- .github/workflows/cuda.yml | 2 +- CMakeLists.txt | 2 +- Docs/source/conf.py | 4 ++-- LICENSE.txt | 2 +- Python/setup.py | 2 +- Regression/WarpX-GPU-tests.ini | 2 +- Regression/WarpX-tests.ini | 2 +- cmake/dependencies/AMReX.cmake | 4 ++-- cmake/dependencies/PICSAR.cmake | 2 +- run_test.sh | 2 +- setup.py | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/cuda.yml b/.github/workflows/cuda.yml index 176b87ddd6a..0b7c094649c 100644 --- a/.github/workflows/cuda.yml +++ b/.github/workflows/cuda.yml @@ -110,7 +110,7 @@ jobs: which nvcc || echo "nvcc not in PATH!" git clone https://github.com/AMReX-Codes/amrex.git ../amrex - cd ../amrex && git checkout --detach cf8d9f8e233be2ac68aeb65a95e992adfb483939 && cd - + cd ../amrex && git checkout --detach 23.08 && cd - make COMP=gcc QED=FALSE USE_MPI=TRUE USE_GPU=TRUE USE_OMP=FALSE USE_PSATD=TRUE USE_CCACHE=TRUE -j 2 build_nvhpc21-11-nvcc: diff --git a/CMakeLists.txt b/CMakeLists.txt index 705c6511db4..c3587942184 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # Preamble #################################################################### # cmake_minimum_required(VERSION 3.20.0) -project(WarpX VERSION 23.07) +project(WarpX VERSION 23.08) include(${WarpX_SOURCE_DIR}/cmake/WarpXFunctions.cmake) diff --git a/Docs/source/conf.py b/Docs/source/conf.py index a84fef29fb6..534cfd1e6b5 100644 --- a/Docs/source/conf.py +++ b/Docs/source/conf.py @@ -79,9 +79,9 @@ # built documents. # # The short X.Y version. -version = u'23.07' +version = u'23.08' # The full version, including alpha/beta/rc tags. -release = u'23.07' +release = u'23.08' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/LICENSE.txt b/LICENSE.txt index 0ef22913505..c8c1f925ea4 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -WarpX v23.07 Copyright (c) 2018-2023, The Regents of the University of California, through Lawrence Berkeley National Laboratory, and Lawrence Livermore National Security, LLC, for the operation of Lawrence Livermore National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved. +WarpX v23.08 Copyright (c) 2018-2023, The Regents of the University of California, through Lawrence Berkeley National Laboratory, and Lawrence Livermore National Security, LLC, for the operation of Lawrence Livermore National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/Python/setup.py b/Python/setup.py index 7f52f7a4699..1dcfcc4d35e 100644 --- a/Python/setup.py +++ b/Python/setup.py @@ -54,7 +54,7 @@ package_data = {} setup(name = 'pywarpx', - version = '23.07', + version = '23.08', packages = ['pywarpx'], package_dir = {'pywarpx': 'pywarpx'}, description = """Wrapper of WarpX""", diff --git a/Regression/WarpX-GPU-tests.ini b/Regression/WarpX-GPU-tests.ini index 0123a6691c5..6633050fd39 100644 --- a/Regression/WarpX-GPU-tests.ini +++ b/Regression/WarpX-GPU-tests.ini @@ -60,7 +60,7 @@ emailBody = Check https://ccse.lbl.gov/pub/GpuRegressionTesting/WarpX/ for more [AMReX] dir = /home/regtester/git/amrex/ -branch = cf8d9f8e233be2ac68aeb65a95e992adfb483939 +branch = 23.08 [source] dir = /home/regtester/git/WarpX diff --git a/Regression/WarpX-tests.ini b/Regression/WarpX-tests.ini index ed1cbaf8ee2..28ca031f028 100644 --- a/Regression/WarpX-tests.ini +++ b/Regression/WarpX-tests.ini @@ -59,7 +59,7 @@ emailBody = Check https://ccse.lbl.gov/pub/RegressionTesting/WarpX/ for more det [AMReX] dir = /home/regtester/AMReX_RegTesting/amrex/ -branch = cf8d9f8e233be2ac68aeb65a95e992adfb483939 +branch = 23.08 [source] dir = /home/regtester/AMReX_RegTesting/warpx diff --git a/cmake/dependencies/AMReX.cmake b/cmake/dependencies/AMReX.cmake index e3151870447..400a11d3aa0 100644 --- a/cmake/dependencies/AMReX.cmake +++ b/cmake/dependencies/AMReX.cmake @@ -229,7 +229,7 @@ macro(find_amrex) endif() set(COMPONENT_PRECISION ${WarpX_PRECISION} P${WarpX_PARTICLE_PRECISION}) - find_package(AMReX 23.07 CONFIG REQUIRED COMPONENTS ${COMPONENT_ASCENT} ${COMPONENT_DIMS} ${COMPONENT_EB} PARTICLES ${COMPONENT_PIC} ${COMPONENT_PRECISION} ${COMPONENT_SENSEI} TINYP LSOLVERS) + find_package(AMReX 23.08 CONFIG REQUIRED COMPONENTS ${COMPONENT_ASCENT} ${COMPONENT_DIMS} ${COMPONENT_EB} PARTICLES ${COMPONENT_PIC} ${COMPONENT_PRECISION} ${COMPONENT_SENSEI} TINYP LSOLVERS) message(STATUS "AMReX: Found version '${AMReX_VERSION}'") endif() endmacro() @@ -243,7 +243,7 @@ set(WarpX_amrex_src "" set(WarpX_amrex_repo "https://github.com/AMReX-Codes/amrex.git" CACHE STRING "Repository URI to pull and build AMReX from if(WarpX_amrex_internal)") -set(WarpX_amrex_branch "cf8d9f8e233be2ac68aeb65a95e992adfb483939" +set(WarpX_amrex_branch "23.08" CACHE STRING "Repository branch for WarpX_amrex_repo if(WarpX_amrex_internal)") diff --git a/cmake/dependencies/PICSAR.cmake b/cmake/dependencies/PICSAR.cmake index 47373a88bc1..536fe0e92cc 100644 --- a/cmake/dependencies/PICSAR.cmake +++ b/cmake/dependencies/PICSAR.cmake @@ -82,7 +82,7 @@ function(find_picsar) #message(STATUS "PICSAR: Using version '${PICSAR_VERSION}'") else() # not supported by PICSAR (yet) - #find_package(PICSAR 23.07 CONFIG REQUIRED QED) + #find_package(PICSAR 23.08 CONFIG REQUIRED QED) #message(STATUS "PICSAR: Found version '${PICSAR_VERSION}'") message(FATAL_ERROR "PICSAR: Cannot be used as externally installed " "library yet. " diff --git a/run_test.sh b/run_test.sh index 7e6ba830ec9..353767c65b0 100755 --- a/run_test.sh +++ b/run_test.sh @@ -71,7 +71,7 @@ python3 -m pip install --upgrade -r warpx/Regression/requirements.txt # Clone AMReX and warpx-data git clone https://github.com/AMReX-Codes/amrex.git -cd amrex && git checkout --detach cf8d9f8e233be2ac68aeb65a95e992adfb483939 && cd - +cd amrex && git checkout --detach 23.08 && cd - # warpx-data contains various required data sets git clone --depth 1 https://github.com/ECP-WarpX/warpx-data.git # openPMD-example-datasets contains various required data sets diff --git a/setup.py b/setup.py index c9116da12a7..2f60300a43e 100644 --- a/setup.py +++ b/setup.py @@ -272,7 +272,7 @@ def build_extension(self, ext): setup( name='pywarpx', # note PEP-440 syntax: x.y.zaN but x.y.z.devN - version = '23.07', + version = '23.08', packages = ['pywarpx'], package_dir = {'pywarpx': 'Python/pywarpx'}, author='Jean-Luc Vay, David P. Grote, Maxence Thévenet, Rémi Lehe, Andrew Myers, Weiqun Zhang, Axel Huebl, et al.', From fb33708501b986922066f332afa76ea8610ba31a Mon Sep 17 00:00:00 2001 From: Grant Johnson <69021085+johnson452@users.noreply.github.com> Date: Mon, 7 Aug 2023 16:48:43 -0700 Subject: [PATCH 006/100] Show compiler warnings with appleclang (#4166) --- cmake/WarpXFunctions.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/WarpXFunctions.cmake b/cmake/WarpXFunctions.cmake index d7520fcc3af..fee934a04d0 100644 --- a/cmake/WarpXFunctions.cmake +++ b/cmake/WarpXFunctions.cmake @@ -133,6 +133,8 @@ macro(set_cxx_warnings) #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wunreachable-code") elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") From fa5dc424956cae58ec910bee49e1b9118fc1feb0 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 8 Aug 2023 01:55:13 +0200 Subject: [PATCH 007/100] Clang-tidy CI test: add 4 new readability checks (#4163) --- .clang-tidy | 4 ++++ Source/Diagnostics/Diagnostics.cpp | 4 ++-- Source/Diagnostics/ParticleDiag/ParticleDiag.cpp | 2 +- Source/Diagnostics/ReducedDiags/ChargeOnEB.cpp | 2 +- .../Diagnostics/ReducedDiags/FieldReduction.cpp | 2 +- .../ReducedDiags/ParticleHistogram.cpp | 4 ++-- .../ReducedDiags/ParticleHistogram2D.H | 8 ++++---- Source/Diagnostics/ReducedDiags/ReducedDiags.cpp | 2 +- Source/Evolve/WarpXEvolve.cpp | 16 ++++++++-------- Source/Initialization/PlasmaInjector.cpp | 10 +++++----- Source/Initialization/TemperatureProperties.cpp | 2 +- Source/Utils/Parser/ParserUtils.cpp | 2 +- Source/WarpX.cpp | 4 ++-- 13 files changed, 33 insertions(+), 29 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 8bc92cefb4f..a84816b3255 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -42,6 +42,10 @@ Checks: '-*, performance-move-const-arg, performance-move-constructor-init, readability-non-const-parameter, + readability-redundant-preprocessor, + readability-redundant-smartptr-get, + readability-redundant-string-cstr, + readability-redundant-string-init, readability-simplify-boolean-expr, readability-simplify-subscript-expr, readability-static-accessed-through-instance, diff --git a/Source/Diagnostics/Diagnostics.cpp b/Source/Diagnostics/Diagnostics.cpp index 62c802483d2..a0e6db68d1e 100644 --- a/Source/Diagnostics/Diagnostics.cpp +++ b/Source/Diagnostics/Diagnostics.cpp @@ -124,14 +124,14 @@ Diagnostics::BaseReadParameters () // Get parser strings for particle fields and generate map of parsers std::string parser_str; - std::string filter_parser_str = ""; + std::string filter_parser_str; const amrex::ParmParse pp_diag_pfield(m_diag_name + ".particle_fields"); for (const auto& var : m_pfield_varnames) { bool do_average = true; pp_diag_pfield.query((var + ".do_average").c_str(), do_average); m_pfield_do_average.push_back(do_average); utils::parser::Store_parserString( - pp_diag_pfield, (var + "(x,y,z,ux,uy,uz)").c_str(), parser_str); + pp_diag_pfield, (var + "(x,y,z,ux,uy,uz)"), parser_str); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( parser_str != "", diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp index 6622fd9bdcf..18fbb4f593b 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp @@ -60,7 +60,7 @@ ParticleDiag::ParticleDiag(std::string diag_name, std::string name, WarpXParticl buf); if (m_do_parser_filter) { - std::string function_string = ""; + std::string function_string; utils::parser::Store_parserString( pp_diag_name_species_name,"plot_filter_function(t,x,y,z,ux,uy,uz)", function_string); m_particle_filter_parser = std::make_unique( diff --git a/Source/Diagnostics/ReducedDiags/ChargeOnEB.cpp b/Source/Diagnostics/ReducedDiags/ChargeOnEB.cpp index c9ce3523f0b..c6f75e4a712 100644 --- a/Source/Diagnostics/ReducedDiags/ChargeOnEB.cpp +++ b/Source/Diagnostics/ReducedDiags/ChargeOnEB.cpp @@ -50,7 +50,7 @@ ChargeOnEB::ChargeOnEB (std::string rd_name) const amrex::ParmParse pp_rd_name(rd_name); m_do_parser_weighting = pp_rd_name.query("weighting_function(x,y,z)", buf); if (m_do_parser_weighting) { - std::string weighting_string = ""; + std::string weighting_string; utils::parser::Store_parserString( pp_rd_name,"weighting_function(x,y,z)", weighting_string); m_parser_weighting = std::make_unique( diff --git a/Source/Diagnostics/ReducedDiags/FieldReduction.cpp b/Source/Diagnostics/ReducedDiags/FieldReduction.cpp index 32c8c96539a..a0a7af0a83c 100644 --- a/Source/Diagnostics/ReducedDiags/FieldReduction.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldReduction.cpp @@ -49,7 +49,7 @@ FieldReduction::FieldReduction (std::string rd_name) const amrex::ParmParse pp_rd_name(rd_name); // read reduced function with parser - std::string parser_string = ""; + std::string parser_string; utils::parser::Store_parserString(pp_rd_name,"reduced_function(x,y,z,Ex,Ey,Ez,Bx,By,Bz,jx,jy,jz)", parser_string); m_parser = std::make_unique( diff --git a/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp b/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp index 1b34c1c7aad..242659236d6 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp @@ -66,7 +66,7 @@ ParticleHistogram::ParticleHistogram (std::string rd_name) m_bin_size = (m_bin_max - m_bin_min) / m_bin_num; // read histogram function - std::string function_string = ""; + std::string function_string; utils::parser::Store_parserString(pp_rd_name,"histogram_function(t,x,y,z,ux,uy,uz)", function_string); m_parser = std::make_unique( @@ -111,7 +111,7 @@ ParticleHistogram::ParticleHistogram (std::string rd_name) std::string buf; m_do_parser_filter = pp_rd_name.query("filter_function(t,x,y,z,ux,uy,uz)", buf); if (m_do_parser_filter) { - std::string filter_string = ""; + std::string filter_string; utils::parser::Store_parserString( pp_rd_name,"filter_function(t,x,y,z,ux,uy,uz)", filter_string); m_parser_filter = std::make_unique( diff --git a/Source/Diagnostics/ReducedDiags/ParticleHistogram2D.H b/Source/Diagnostics/ReducedDiags/ParticleHistogram2D.H index cefe32dd42f..6b82514567d 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleHistogram2D.H +++ b/Source/Diagnostics/ReducedDiags/ParticleHistogram2D.H @@ -56,10 +56,10 @@ public: amrex::Real m_bin_size_ord; /// functions - std::string function_string_abs = ""; - std::string function_string_ord = ""; - std::string filter_string = ""; - std::string value_string = ""; + std::string function_string_abs; + std::string function_string_ord; + std::string filter_string; + std::string value_string; /// Parser to read expression for particle quantity from the input file. /// 7 elements are t, x, y, z, ux, uy, uz, w diff --git a/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp b/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp index 38da1feff83..77377c7d5ed 100644 --- a/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp +++ b/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp @@ -38,7 +38,7 @@ ReducedDiags::ReducedDiags (std::string rd_name) pp_rd_name.query("extension", m_extension); // check if it is a restart run - std::string restart_chkfile = ""; + std::string restart_chkfile; const ParmParse pp_amr("amr"); pp_amr.query("restart", restart_chkfile); bool IsNotRestart = restart_chkfile.empty(); diff --git a/Source/Evolve/WarpXEvolve.cpp b/Source/Evolve/WarpXEvolve.cpp index 37023c8dde4..40df059adce 100644 --- a/Source/Evolve/WarpXEvolve.cpp +++ b/Source/Evolve/WarpXEvolve.cpp @@ -564,7 +564,7 @@ void WarpX::SyncCurrentAndRho () // Reflect charge and current density over PEC boundaries, if needed. for (int lev = 0; lev <= finest_level; ++lev) { - if (rho_fp[lev].get()) { + if (rho_fp[lev]) { ApplyRhofieldBoundary(lev, rho_fp[lev].get(), PatchType::fine); } ApplyJfieldBoundary( @@ -572,7 +572,7 @@ void WarpX::SyncCurrentAndRho () current_fp[lev][2].get(), PatchType::fine ); if (lev > 0) { - if (rho_cp[lev].get()) { + if (rho_cp[lev]) { ApplyRhofieldBoundary(lev, rho_cp[lev].get(), PatchType::coarse); } ApplyJfieldBoundary( @@ -1016,9 +1016,9 @@ WarpX::PushParticlesandDepose (int lev, amrex::Real cur_time, DtType a_dt_type, if (current_buf[lev][0].get()) { ApplyInverseVolumeScalingToCurrentDensity(current_buf[lev][0].get(), current_buf[lev][1].get(), current_buf[lev][2].get(), lev-1); } - if (rho_fp[lev].get()) { + if (rho_fp[lev]) { ApplyInverseVolumeScalingToChargeDensity(rho_fp[lev].get(), lev); - if (charge_buf[lev].get()) { + if (charge_buf[lev]) { ApplyInverseVolumeScalingToChargeDensity(charge_buf[lev].get(), lev-1); } } @@ -1079,8 +1079,8 @@ WarpX::applyMirrors(Real time) NullifyMF(Bz, lev, z_min, z_max); // If div(E)/div(B) cleaning are used, set F/G field to zero - if (F_fp[lev]) NullifyMF(*F_fp[lev].get(), lev, z_min, z_max); - if (G_fp[lev]) NullifyMF(*G_fp[lev].get(), lev, z_min, z_max); + if (F_fp[lev]) NullifyMF(*F_fp[lev], lev, z_min, z_max); + if (G_fp[lev]) NullifyMF(*G_fp[lev], lev, z_min, z_max); if (lev>0) { @@ -1101,8 +1101,8 @@ WarpX::applyMirrors(Real time) NullifyMF(cBz, lev, z_min, z_max); // If div(E)/div(B) cleaning are used, set F/G field to zero - if (F_cp[lev]) NullifyMF(*F_cp[lev].get(), lev, z_min, z_max); - if (G_cp[lev]) NullifyMF(*G_cp[lev].get(), lev, z_min, z_max); + if (F_cp[lev]) NullifyMF(*F_cp[lev], lev, z_min, z_max); + if (G_cp[lev]) NullifyMF(*G_cp[lev], lev, z_min, z_max); } } } diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp index 115fbfca132..03cee4c5eee 100644 --- a/Source/Initialization/PlasmaInjector.cpp +++ b/Source/Initialization/PlasmaInjector.cpp @@ -50,7 +50,7 @@ namespace { std::string string; stringstream << var << " string '" << name << "' not recognized."; string = stringstream.str(); - WARPX_ABORT_WITH_MESSAGE(string.c_str()); + WARPX_ABORT_WITH_MESSAGE(string); } } @@ -688,16 +688,16 @@ void PlasmaInjector::parseMomentum (const amrex::ParmParse& pp) ux_min, uy_min, uz_min, ux_max, uy_max, uz_max)); } else if (mom_dist_s == "maxwell_boltzmann"){ h_mom_temp = std::make_unique(pp); - const GetTemperature getTemp(*h_mom_temp.get()); + const GetTemperature getTemp(*h_mom_temp); h_mom_vel = std::make_unique(pp); - const GetVelocity getVel(*h_mom_vel.get()); + const GetVelocity getVel(*h_mom_vel); // Construct InjectorMomentum with InjectorMomentumBoltzmann. h_inj_mom.reset(new InjectorMomentum((InjectorMomentumBoltzmann*)nullptr, getTemp, getVel)); } else if (mom_dist_s == "maxwell_juttner"){ h_mom_temp = std::make_unique(pp); - const GetTemperature getTemp(*h_mom_temp.get()); + const GetTemperature getTemp(*h_mom_temp); h_mom_vel = std::make_unique(pp); - const GetVelocity getVel(*h_mom_vel.get()); + const GetVelocity getVel(*h_mom_vel); // Construct InjectorMomentum with InjectorMomentumJuttner. h_inj_mom.reset(new InjectorMomentum((InjectorMomentumJuttner*)nullptr, getTemp, getVel)); } else if (mom_dist_s == "radial_expansion") { diff --git a/Source/Initialization/TemperatureProperties.cpp b/Source/Initialization/TemperatureProperties.cpp index 52af6637e79..34e1d2b5fcc 100644 --- a/Source/Initialization/TemperatureProperties.cpp +++ b/Source/Initialization/TemperatureProperties.cpp @@ -69,6 +69,6 @@ TemperatureProperties::TemperatureProperties (const amrex::ParmParse& pp) { std::string string; stringstream << "Temperature distribution type '" << temp_dist_s << "' not recognized."; string = stringstream.str(); - WARPX_ABORT_WITH_MESSAGE(string.c_str()); + WARPX_ABORT_WITH_MESSAGE(string); } } diff --git a/Source/Utils/Parser/ParserUtils.cpp b/Source/Utils/Parser/ParserUtils.cpp index de4723241a9..0add95df1ae 100644 --- a/Source/Utils/Parser/ParserUtils.cpp +++ b/Source/Utils/Parser/ParserUtils.cpp @@ -87,7 +87,7 @@ amrex::Parser utils::parser::makeParser ( parser.registerVariables(varnames); std::set symbols = parser.symbols(); - for (auto const& v : varnames) symbols.erase(v.c_str()); + for (auto const& v : varnames) symbols.erase(v); // User can provide inputs under this name, through which expressions // can be provided for arbitrary variables. PICMI inputs are aware of diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 24e3ceb303f..8d4e9846239 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -86,7 +86,7 @@ using namespace amrex; Vector WarpX::E_external_grid(3, 0.0); Vector WarpX::B_external_grid(3, 0.0); -std::string WarpX::authors = ""; +std::string WarpX::authors; std::string WarpX::B_ext_grid_s = "default"; std::string WarpX::E_ext_grid_s = "default"; bool WarpX::add_external_E_field = false; @@ -546,7 +546,7 @@ WarpX::ReadParameters () ablastr::warn_manager::GetWMInstance().SetAlwaysWarnImmediately(always_warn_immediately); // Set the WarnPriority threshold to decide if WarpX has to abort when a warning is recorded - if(std::string str_abort_on_warning_threshold = ""; + if(std::string str_abort_on_warning_threshold; pp_warpx.query("abort_on_warning_threshold", str_abort_on_warning_threshold)){ std::optional abort_on_warning_threshold = std::nullopt; if (str_abort_on_warning_threshold == "high") From 51f4395060f9c98542bfaa91c91f94543bf7b52f Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 8 Aug 2023 01:59:39 +0200 Subject: [PATCH 008/100] add back printing of warning messages at the end of the simulation (#4154) --- Source/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/main.cpp b/Source/main.cpp index 3051539d87e..f98674d2ac7 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -39,7 +39,8 @@ int main(int argc, char* argv[]) warpx.Evolve(); //Print warning messages at the end of the simulation - ablastr::warn_manager::GetWMInstance().PrintGlobalWarnings("THE END"); + amrex::Print() << + ablastr::warn_manager::GetWMInstance().PrintGlobalWarnings("THE END"); timer.record_stop_time(); if (warpx.Verbose()) { From f27fe24a35d5990345501fede09235f4c55ecc02 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 8 Aug 2023 11:35:58 +0200 Subject: [PATCH 009/100] Clang tidy CI test: add 4 more readability-* checks to clang-tidy CI test (#4164) * clang-tidy CI test: add new readability checks * address issues found with clang-tidy --- .clang-tidy | 4 ++++ Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp | 4 ++-- Source/Particles/MultiParticleContainer.H | 4 +--- Source/Particles/PhysicalParticleContainer.cpp | 2 -- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index a84816b3255..dd36c538200 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -42,6 +42,10 @@ Checks: '-*, performance-move-const-arg, performance-move-constructor-init, readability-non-const-parameter, + readability-redundant-control-flow, + readability-redundant-declaration, + readability-redundant-function-ptr-dereference, + readability-redundant-member-init, readability-redundant-preprocessor, readability-redundant-smartptr-get, readability-redundant-string-cstr, diff --git a/Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp b/Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp index fb510b6dd4b..060c0e4a5e9 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp @@ -8,13 +8,13 @@ #endif FlushFormatSensei::FlushFormatSensei () : - m_insitu_config(), m_insitu_pin_mesh(0), m_insitu_bridge(nullptr), + m_insitu_pin_mesh(0), m_insitu_bridge(nullptr), m_amr_mesh(nullptr) {} FlushFormatSensei::FlushFormatSensei (amrex::AmrMesh *amr_mesh, std::string diag_name) : - m_insitu_config(), m_insitu_pin_mesh(0), m_insitu_bridge(nullptr), + m_insitu_pin_mesh(0), m_insitu_bridge(nullptr), m_amr_mesh(amr_mesh) { #ifndef AMREX_USE_SENSEI_INSITU diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 3eb4cfba8d9..4b6f2b5845d 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -488,9 +488,7 @@ private: bool m_do_back_transformed_particles = false; void MFItInfoCheckTiling(const WarpXParticleContainer& /*pc_src*/) const noexcept - { - return; - } + {} template void MFItInfoCheckTiling(const WarpXParticleContainer& pc_src, diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 56fdbc378d5..ded222ce80a 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -667,8 +667,6 @@ PhysicalParticleContainer::AddPlasmaFromFile(ParticleReal q_tot, #endif // WARPX_USE_OPENPMD ignore_unused(q_tot, z_shift); - - return; } void From b64681e9d5673a7623fc16d0a6322ff8692bbeb5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 8 Aug 2023 12:53:29 +0200 Subject: [PATCH 010/100] [pre-commit.ci] pre-commit autoupdate (#4167) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/Lucas-C/pre-commit-hooks: v1.5.1 → v1.5.3](https://github.com/Lucas-C/pre-commit-hooks/compare/v1.5.1...v1.5.3) - [github.com/hadialqattan/pycln: v2.2.0 → v2.2.1](https://github.com/hadialqattan/pycln/compare/v2.2.0...v2.2.1) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b441fe3861c..7188af2df42 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,7 +49,7 @@ repos: # Changes tabs to spaces - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.5.1 + rev: v1.5.3 hooks: - id: remove-tabs exclude: 'Make.WarpX|Make.package|Makefile|GNUmake' @@ -68,7 +68,7 @@ repos: # Autoremoves unused Python imports - repo: https://github.com/hadialqattan/pycln - rev: v2.2.0 + rev: v2.2.1 hooks: - id: pycln name: pycln (python) From 4078eae6f9894072cf5d4c3020671a87c13ab92b Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 9 Aug 2023 01:06:43 +0200 Subject: [PATCH 011/100] Clang-tidy CI test: add two performance checks (#4158) --- .clang-tidy | 2 ++ Source/Diagnostics/WarpXOpenPMD.cpp | 12 ++++++------ Source/Particles/MultiParticleContainer.cpp | 4 ++-- Source/ablastr/utils/Serialization.H | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index dd36c538200..8c323c9f3a6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -41,6 +41,8 @@ Checks: '-*, performance-inefficient-vector-operation, performance-move-const-arg, performance-move-constructor-init, + performance-no-automatic-move, + performance-no-int-to-ptr, readability-non-const-parameter, readability-redundant-control-flow, readability-redundant-declaration, diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index a3fc4864dd1..e32c1e3d37b 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -218,9 +218,9 @@ namespace detail { using vs = std::vector< std::string >; #if defined(WARPX_DIM_1D_Z) - vs const positionComponents{"z"}; + vs positionComponents{"z"}; #elif defined(WARPX_DIM_XZ) - vs const positionComponents{"x", "z"}; + vs positionComponents{"x", "z"}; #elif defined(WARPX_DIM_RZ) // note: although we internally store particle positions // for AMReX in r,z and a theta attribute, we @@ -228,9 +228,9 @@ namespace detail // and I/O in Cartesian. // Other attributes like momentum are consequently // stored in x,y,z internally. - vs const positionComponents{"x", "y", "z"}; + vs positionComponents{"x", "y", "z"}; #elif defined(WARPX_DIM_3D) - vs const positionComponents{"x", "y", "z"}; + vs positionComponents{"x", "y", "z"}; #else # error Unknown WarpX dimensionality. #endif @@ -282,12 +282,12 @@ namespace detail using vs = std::vector< std::string >; if (var_in_theta_mode) { // if we write individual modes - vs const fieldComponents{"r", "t", "z"}; + vs fieldComponents{"r", "t", "z"}; return fieldComponents; } else { // if we just write reconstructed fields at theta=0 or are Cartesian // note: 1D3V and 2D3V simulations still have 3 components for the fields - vs const fieldComponents{"x", "y", "z"}; + vs fieldComponents{"x", "y", "z"}; return fieldComponents; } } diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 529a78c8ec0..8da078dc8af 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -672,7 +672,7 @@ MultiParticleContainer::GetZeroParticlesInGrid (const int lev) const { const WarpX& warpx = WarpX::GetInstance(); const int num_boxes = warpx.boxArray(lev).size(); - const Vector r(num_boxes, 0); + Vector r(num_boxes, 0); return r; } @@ -681,7 +681,7 @@ MultiParticleContainer::NumberOfParticlesInGrid (int lev) const { if (allcontainers.empty()) { - const Vector r = GetZeroParticlesInGrid(lev); + Vector r = GetZeroParticlesInGrid(lev); return r; } else diff --git a/Source/ablastr/utils/Serialization.H b/Source/ablastr/utils/Serialization.H index 5db3e9968b4..29173a8eeec 100644 --- a/Source/ablastr/utils/Serialization.H +++ b/Source/ablastr/utils/Serialization.H @@ -94,7 +94,7 @@ namespace ablastr::utils::serialization if constexpr (std::is_same()) { const auto length = get_out(it); - const auto str = std::string{it, it + length}; + auto str = std::string{it, it + length}; it += length; return str; From 0be669ef64def8343e3d66c6ebdf3f1ca5911c92 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 9 Aug 2023 01:10:10 +0200 Subject: [PATCH 012/100] Fix typo in parameters.rst (#4152) --- Docs/source/usage/parameters.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index 0ad5d03e595..af45080ee59 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -1275,7 +1275,7 @@ Laser initialization E(\boldsymbol{x},t) \propto \exp\left( -\frac{(t-t_{peak})^2}{\tau^2} \right) - Note that :math:`\tau` relates to the full width at half maximum (FWHM) of *intensity*, which is closer to pulse length measurements in experiments, as :math:`\tau = \mathrm{FWHM}_I / \sqrt{2\ln(2)}` :math:`\approx \mathrm{FWHM}_I / 1.174`. + Note that :math:`\tau` relates to the full width at half maximum (FWHM) of *intensity*, which is closer to pulse length measurements in experiments, as :math:`\tau = \mathrm{FWHM}_I / \sqrt{2\ln(2)}` :math:`\approx \mathrm{FWHM}_I / 1.1774`. When running a **boosted-frame simulation**, provide the value of ``.profile_duration`` in the laboratory frame, and use ``warpx.gamma_boost`` From 11bc55d3aca193fca7a61772f041971e2cf08a89 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 9 Aug 2023 01:11:06 +0200 Subject: [PATCH 013/100] remove unused function (#4151) --- Source/Diagnostics/WarpXOpenPMD.H | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Source/Diagnostics/WarpXOpenPMD.H b/Source/Diagnostics/WarpXOpenPMD.H index 7cc5eda903c..c8511553c04 100644 --- a/Source/Diagnostics/WarpXOpenPMD.H +++ b/Source/Diagnostics/WarpXOpenPMD.H @@ -10,7 +10,6 @@ #include "Particles/WarpXParticleContainer.H" #include "Diagnostics/FlushFormats/FlushFormat.H" -#include "Utils/TextMsg.H" #include "Diagnostics/ParticleDiag/ParticleDiag_fwd.H" @@ -36,26 +35,6 @@ #include #include -// -// helper class -// -class Timer -{ -public: - Timer (const char* tag) {m_Tag = tag; m_Start = amrex::second();} - ~Timer () { - m_End = amrex::second(); - amrex::ParallelDescriptor::ReduceRealMax(m_End, amrex::ParallelDescriptor::IOProcessorNumber()); - amrex::Print() << Utils::TextMsg::Info( - m_Tag + " took: "+ std::to_string(m_End - m_Start) + " seconds"); - } -private: - amrex::Real m_Start; - amrex::Real m_End; - std::string m_Tag; -}; - - // // class WarpXParticleCounter From 94fdb3c49a7055130bfe2f75d584ca6a448ec28e Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 9 Aug 2023 01:13:29 +0200 Subject: [PATCH 014/100] Clang tidy CI test: add some misc-* checks (#4150) * Clang-tidy CI test: add few misc checks * fix issue --- .clang-tidy | 3 +++ Source/Initialization/WarpXAMReXInit.H | 2 +- Source/Initialization/WarpXAMReXInit.cpp | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 8c323c9f3a6..cee8274c8a6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -15,6 +15,9 @@ Checks: '-*, -cppcoreguidelines-owning-memory, misc-const-correctness, misc-misleading-bidirectional, + misc-misleading-identifier, + misc-misplaced-const, + -misc-definitions-in-headers, modernize-avoid-bind, modernize-concat-nested-namespaces, modernize-deprecated-headers, diff --git a/Source/Initialization/WarpXAMReXInit.H b/Source/Initialization/WarpXAMReXInit.H index 06c31e35872..620e06350c5 100644 --- a/Source/Initialization/WarpXAMReXInit.H +++ b/Source/Initialization/WarpXAMReXInit.H @@ -31,7 +31,7 @@ namespace warpx::initialization int& argc, char**& argv, bool const build_parm_parse = true, - MPI_Comm const mpi_comm = MPI_COMM_WORLD + MPI_Comm mpi_comm = MPI_COMM_WORLD ); } diff --git a/Source/Initialization/WarpXAMReXInit.cpp b/Source/Initialization/WarpXAMReXInit.cpp index 33bc1a78998..1904a30d217 100644 --- a/Source/Initialization/WarpXAMReXInit.cpp +++ b/Source/Initialization/WarpXAMReXInit.cpp @@ -61,7 +61,7 @@ namespace warpx::initialization { amrex::AMReX* - amrex_init (int& argc, char**& argv, bool const build_parm_parse, MPI_Comm const mpi_comm) + amrex_init (int& argc, char**& argv, bool const build_parm_parse, MPI_Comm mpi_comm) { return amrex::Initialize( argc, From 66058aaeb9850b53cf6431294e4163feab2f8ff9 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 9 Aug 2023 03:35:33 -0700 Subject: [PATCH 015/100] Doc: Gitter -> Discussions (#4168) As discussed last week, we have a hard time tracking the Gitter chat and organizing threads in it. GitHub discussions should simplify that. --- Docs/source/index.rst | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Docs/source/index.rst b/Docs/source/index.rst index afcde99ca7f..2209b360e26 100644 --- a/Docs/source/index.rst +++ b/Docs/source/index.rst @@ -22,7 +22,7 @@ In addition, WarpX is also a *multi-platform code* and runs on Linux, macOS and Contact us ^^^^^^^^^^ -If you are starting using WarpX, or if you have a user question, please pop in our `Gitter chat room `__ and get in touch with the community. +If you are starting using WarpX, or if you have a user question, please pop in our `discussions page `__ and get in touch with the community. The `WarpX GitHub repo `__ is the main communication platform. Have a look at the action icons on the top right of the web page: feel free to watch the repo if you want to receive updates, or to star the repo to support the project. diff --git a/README.md b/README.md index a16d47de796..95b6f16dfa7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Documentation Status](https://readthedocs.org/projects/warpx/badge/?version=latest)](https://warpx.readthedocs.io/en/latest/?badge=latest) [![Spack Version](https://img.shields.io/spack/v/warpx)](https://spack.readthedocs.io/en/latest/package_list.html#warpx) [![Conda Version](https://img.shields.io/conda/vn/conda-forge/warpx)](https://anaconda.org/conda-forge/warpx) -[![Gitter](https://badges.gitter.im/ECP-WarpX/community.svg)](https://gitter.im/ECP-WarpX/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +[![Discussions](https://img.shields.io/badge/chat-discussions-turquoise.svg)](https://github.com/ECP-WarpX/WarpX/discussions) [![Supported Platforms](https://img.shields.io/badge/platforms-linux%20|%20osx%20|%20win-blue)](https://warpx.readthedocs.io/en/latest/install/users.html) [![GitHub commits since last release](https://img.shields.io/github/commits-since/ECP-WarpX/WarpX/latest/development.svg)](https://github.com/ECP-WarpX/WarpX/compare/development) [![Exascale Computing Project](https://img.shields.io/badge/supported%20by-ECP-orange)](https://www.exascaleproject.org/research/) @@ -32,7 +32,7 @@ WarpX scales to the world's largest supercomputers and was awarded the [2022 ACM In order to learn how to install and run the code, please see the online documentation: https://warpx.readthedocs.io -To contact the developers, feel free to open an issue on this repo, or visit our Gitter room at https://gitter.im/ECP-WarpX/community +To contact the developers, feel free to open an issue on this repo, or visit our discussions page at https://github.com/ECP-WarpX/WarpX/discussions ## Contributing From 5313c5d93ce652451097a2990dcc34d8ffcc112f Mon Sep 17 00:00:00 2001 From: David Grote Date: Wed, 9 Aug 2023 03:36:17 -0700 Subject: [PATCH 016/100] Add write_diagonstics_on_restart input option (#4091) * Add write_diagonstics_on_restart input option * Add doc to new variable Co-authored-by: Axel Huebl * Use correct time step --------- Co-authored-by: Axel Huebl --- Docs/source/usage/parameters.rst | 3 +++ Source/Initialization/WarpXInitData.cpp | 8 +++++--- Source/WarpX.H | 3 +++ Source/WarpX.cpp | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index af45080ee59..87c2ca16f7a 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -3129,6 +3129,9 @@ The checkpoint capability can be turned with regular diagnostics: ``. Name of the checkpoint file to restart from. Returns an error if the folder does not exist or if it is not properly formatted. +* ``warpx.write_diagonstics_on_restart`` (`bool`) optional (default `false`) + When `true`, write the diagnostics after restart at the time of the restart. + Intervals parser ---------------- diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 0e1bb4aa785..233d03a0c58 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -483,15 +483,17 @@ WarpX::InitData () // looks at field values will see the composite of the field // solution and any external field AddExternalFields(); + } + if (restart_chkfile.empty() || write_diagonstics_on_restart) { // Write full diagnostics before the first iteration. - multi_diags->FilterComputePackFlush( -1 ); + multi_diags->FilterComputePackFlush(istep[0] - 1); // Write reduced diagnostics before the first iteration. if (reduced_diags->m_plot_rd != 0) { - reduced_diags->ComputeDiags(-1); - reduced_diags->WriteToFile(-1); + reduced_diags->ComputeDiags(istep[0] - 1); + reduced_diags->WriteToFile(istep[0] - 1); } } diff --git a/Source/WarpX.H b/Source/WarpX.H index eeb71f042bd..3a740d1b000 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -1540,6 +1540,9 @@ private: std::string restart_chkfile; + /** When `true`, write the diagnostics after restart at the time of the restart. */ + bool write_diagonstics_on_restart = false; + amrex::VisMF::Header::Version plotfile_headerversion = amrex::VisMF::Header::Version_v1; amrex::VisMF::Header::Version slice_plotfile_headerversion = amrex::VisMF::Header::Version_v1; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 8d4e9846239..27d463c12f0 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -617,6 +617,8 @@ WarpX::ReadParameters () } } + pp_warpx.query("write_diagonstics_on_restart", write_diagonstics_on_restart); + pp_warpx.queryarr("checkpoint_signals", signals_in); #if defined(__linux__) || defined(__APPLE__) for (const std::string &str : signals_in) { From cbe63b6d454a2f91191f5ff60e6896a5bb496a8e Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 9 Aug 2023 15:13:16 -0700 Subject: [PATCH 017/100] Doc: Update License Notice (#4171) - We do not need to cover year ranges (just the starting range). - Update to exact wording of current notice texts. --- LICENSE.txt | 2 +- README.md | 7 ++++--- Tools/Release/newVersion.sh | 14 -------------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index c8c1f925ea4..9d9b939f342 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -WarpX v23.08 Copyright (c) 2018-2023, The Regents of the University of California, through Lawrence Berkeley National Laboratory, and Lawrence Livermore National Security, LLC, for the operation of Lawrence Livermore National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved. +WarpX Copyright (c) 2018, The Regents of the University of California, through Lawrence Berkeley National Laboratory, and Lawrence Livermore National Security, LLC, for the operation of Lawrence Livermore National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index 95b6f16dfa7..ef0551405a0 100644 --- a/README.md +++ b/README.md @@ -46,9 +46,9 @@ To contact the developers, feel free to open an issue on this repo, or visit our Our workflow is described in [CONTRIBUTING.rst](CONTRIBUTING.rst). -## License +## Copyright Notice -WarpX Copyright (c) 2018-2023, The Regents of the University of California, +WarpX Copyright (c) 2018, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved. @@ -64,4 +64,5 @@ Software to reproduce, distribute copies to the public, prepare derivative works, and perform publicly and display publicly, and to permit other to do so. -License for WarpX can be found at [LICENSE.txt](LICENSE.txt). +Please see the full license agreement in [LICENSE.txt](LICENSE.txt). +The SPDX license identifier is `BSD-3-Clause-LBNL`. diff --git a/Tools/Release/newVersion.sh b/Tools/Release/newVersion.sh index 3523c37305f..b1d2a6aad27 100755 --- a/Tools/Release/newVersion.sh +++ b/Tools/Release/newVersion.sh @@ -125,20 +125,6 @@ sed -i "s/"\ "release = u'${VERSION_STR}'/g" \ ${REPO_DIR}/Docs/source/conf.py -# LICENSE -# LICENSE.txt: WarpX vYY.MM Copyright (c) 20YY, The Regents of ... -sed -i -E "s/"\ -"(WarpX v)(.*)([[:blank:]]+Copyright \(c\) 2018-)(.*)(, The Regents of.*)/"\ -"\1${VERSION_STR_NOSUFFIX}\3$(date +%Y)\5/g" \ - ${REPO_DIR}/LICENSE.txt - -# README.md -# README.md: WarpX Copyright (c) 2018-2021, The Regents of ... -sed -i -E "s/"\ -"(WarpX Copyright \(c\) 2018-)(.*)(, The Regents of.*)/"\ -"\1$(date +%Y)\3/g" \ - ${REPO_DIR}/README.md - # Epilog ###################################################################### From 45e1b7262a7fab54ed062e514fd2768e762d51f2 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Thu, 10 Aug 2023 10:08:00 -0700 Subject: [PATCH 018/100] AMReX: Weekly Update (#4172) --- .github/workflows/cuda.yml | 2 +- Regression/WarpX-GPU-tests.ini | 2 +- Regression/WarpX-tests.ini | 2 +- cmake/dependencies/AMReX.cmake | 2 +- run_test.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cuda.yml b/.github/workflows/cuda.yml index 0b7c094649c..3f11e108ba5 100644 --- a/.github/workflows/cuda.yml +++ b/.github/workflows/cuda.yml @@ -110,7 +110,7 @@ jobs: which nvcc || echo "nvcc not in PATH!" git clone https://github.com/AMReX-Codes/amrex.git ../amrex - cd ../amrex && git checkout --detach 23.08 && cd - + cd ../amrex && git checkout --detach d92232a0c17b846ac85851ca5c950d1cd916e3e3 && cd - make COMP=gcc QED=FALSE USE_MPI=TRUE USE_GPU=TRUE USE_OMP=FALSE USE_PSATD=TRUE USE_CCACHE=TRUE -j 2 build_nvhpc21-11-nvcc: diff --git a/Regression/WarpX-GPU-tests.ini b/Regression/WarpX-GPU-tests.ini index 6633050fd39..546c9fab58a 100644 --- a/Regression/WarpX-GPU-tests.ini +++ b/Regression/WarpX-GPU-tests.ini @@ -60,7 +60,7 @@ emailBody = Check https://ccse.lbl.gov/pub/GpuRegressionTesting/WarpX/ for more [AMReX] dir = /home/regtester/git/amrex/ -branch = 23.08 +branch = d92232a0c17b846ac85851ca5c950d1cd916e3e3 [source] dir = /home/regtester/git/WarpX diff --git a/Regression/WarpX-tests.ini b/Regression/WarpX-tests.ini index 28ca031f028..77556d08cd9 100644 --- a/Regression/WarpX-tests.ini +++ b/Regression/WarpX-tests.ini @@ -59,7 +59,7 @@ emailBody = Check https://ccse.lbl.gov/pub/RegressionTesting/WarpX/ for more det [AMReX] dir = /home/regtester/AMReX_RegTesting/amrex/ -branch = 23.08 +branch = d92232a0c17b846ac85851ca5c950d1cd916e3e3 [source] dir = /home/regtester/AMReX_RegTesting/warpx diff --git a/cmake/dependencies/AMReX.cmake b/cmake/dependencies/AMReX.cmake index 400a11d3aa0..54db01d16a8 100644 --- a/cmake/dependencies/AMReX.cmake +++ b/cmake/dependencies/AMReX.cmake @@ -243,7 +243,7 @@ set(WarpX_amrex_src "" set(WarpX_amrex_repo "https://github.com/AMReX-Codes/amrex.git" CACHE STRING "Repository URI to pull and build AMReX from if(WarpX_amrex_internal)") -set(WarpX_amrex_branch "23.08" +set(WarpX_amrex_branch "d92232a0c17b846ac85851ca5c950d1cd916e3e3" CACHE STRING "Repository branch for WarpX_amrex_repo if(WarpX_amrex_internal)") diff --git a/run_test.sh b/run_test.sh index 353767c65b0..811205bb3b4 100755 --- a/run_test.sh +++ b/run_test.sh @@ -71,7 +71,7 @@ python3 -m pip install --upgrade -r warpx/Regression/requirements.txt # Clone AMReX and warpx-data git clone https://github.com/AMReX-Codes/amrex.git -cd amrex && git checkout --detach 23.08 && cd - +cd amrex && git checkout --detach d92232a0c17b846ac85851ca5c950d1cd916e3e3 && cd - # warpx-data contains various required data sets git clone --depth 1 https://github.com/ECP-WarpX/warpx-data.git # openPMD-example-datasets contains various required data sets From 6ea18be7120684e2f704fd6753f2f2fc8e77ce35 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Thu, 10 Aug 2023 16:22:52 -0700 Subject: [PATCH 019/100] Fix Python test due to recent openPMD-viewer update (#4177) --- Examples/Tests/scraping/analysis_rz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Tests/scraping/analysis_rz.py b/Examples/Tests/scraping/analysis_rz.py index 8f82e01bff0..0390eed580e 100755 --- a/Examples/Tests/scraping/analysis_rz.py +++ b/Examples/Tests/scraping/analysis_rz.py @@ -53,7 +53,7 @@ def n_remaining_particles( iteration ): w, = ts_full.get_particle(['w'], iteration=iteration) return len(w) def n_scraped_particles( iteration ): - timestamp = ts_scraping.get_particle( ['timestamp'] ) + timestamp = ts_scraping.get_particle( ['timestamp'], iteration=ts_scraping.iterations[0] ) return (timestamp <= iteration).sum() n_remaining = np.array([ n_remaining_particles(iteration) for iteration in ts_full.iterations ]) n_scraped = np.array([ n_scraped_particles(iteration) for iteration in ts_full.iterations ]) From 0d998613b311a87e7da496ef7368c3b7649a779c Mon Sep 17 00:00:00 2001 From: Edoardo Zoni <59625522+EZoni@users.noreply.github.com> Date: Thu, 10 Aug 2023 16:24:45 -0700 Subject: [PATCH 020/100] Fix continuous injection of lasers (#4112) * Fix continuous injection of lasers - define new member functions nLasers and nContainers; - loop over all containers, not just over all "species". * Fix update of injection position for lasers * Fix CodeQL issues * Fix style * Rename `ispecies` as `index` * Rename functions to update injection and antenna positions --- Source/Particles/LaserParticleContainer.H | 8 ++- Source/Particles/LaserParticleContainer.cpp | 6 +- Source/Particles/MultiParticleContainer.H | 25 +++++--- Source/Particles/MultiParticleContainer.cpp | 9 +-- Source/Particles/WarpXParticleContainer.H | 9 ++- Source/Utils/WarpXMovingWindow.cpp | 63 +++++++++++---------- Source/WarpX.H | 8 ++- Source/WarpX.cpp | 7 ++- 8 files changed, 76 insertions(+), 59 deletions(-) diff --git a/Source/Particles/LaserParticleContainer.H b/Source/Particles/LaserParticleContainer.H index 5e1debf5ed7..f2ec1739f80 100644 --- a/Source/Particles/LaserParticleContainer.H +++ b/Source/Particles/LaserParticleContainer.H @@ -129,8 +129,12 @@ private: // Inject the laser antenna during the simulation, if it started // outside of the simulation domain and enters it. void ContinuousInjection(const amrex::RealBox& injection_box) override; - // Update position of the antenna - void UpdateContinuousInjectionPosition(amrex::Real dt) override; + + /** + * \brief Update antenna position for continuous injection of lasers + * in a boosted frame + */ + void UpdateAntennaPosition (const amrex::Real dt) override; // Unique (smart) pointer to the laser profile std::unique_ptr m_up_laser_profile; diff --git a/Source/Particles/LaserParticleContainer.cpp b/Source/Particles/LaserParticleContainer.cpp index 6fb8aa97456..0f0259438c6 100644 --- a/Source/Particles/LaserParticleContainer.cpp +++ b/Source/Particles/LaserParticleContainer.cpp @@ -319,12 +319,8 @@ LaserParticleContainer::ContinuousInjection (const RealBox& injection_box) } } -/* \brief update position of the antenna if running in boosted frame. - * \param dt time step (level 0). - * The up-to-date antenna position is stored in updated_position. - */ void -LaserParticleContainer::UpdateContinuousInjectionPosition (Real dt) +LaserParticleContainer::UpdateAntennaPosition (const amrex::Real dt) { if (!m_enabled) return; diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 4b6f2b5845d..86d96fac250 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -71,21 +71,21 @@ public: ~MultiParticleContainer() {} WarpXParticleContainer& - GetParticleContainer (int ispecies) const {return *allcontainers[ispecies];} + GetParticleContainer (int index) const {return *allcontainers[index];} WarpXParticleContainer* - GetParticleContainerPtr (int ispecies) const {return allcontainers[ispecies].get();} + GetParticleContainerPtr (int index) const {return allcontainers[index].get();} WarpXParticleContainer& GetParticleContainerFromName (const std::string& name) const; #ifdef WARPX_USE_OPENPMD - std::unique_ptr& GetUniqueContainer(int ispecies) { - return allcontainers[ispecies]; + std::unique_ptr& GetUniqueContainer(int index) { + return allcontainers[index]; } #endif - std::array meanParticleVelocity(int ispecies) { - return allcontainers[ispecies]->meanParticleVelocity(); + std::array meanParticleVelocity(int index) { + return allcontainers[index]->meanParticleVelocity(); } void AllocData (); @@ -234,7 +234,9 @@ public: void SetParticleBoxArray (int lev, amrex::BoxArray& new_ba); void SetParticleDistributionMap (int lev, amrex::DistributionMapping& new_dm); - int nSpecies() const {return species_names.size();} + int nSpecies () const {return species_names.size();} + int nLasers () const {return lasers_names.size();} + int nContainers () const {return allcontainers.size();} /** Whether back-transformed diagnostics need to be performed for any plasma species. * @@ -264,8 +266,13 @@ public: // simulation domain after some iterations, due to flowing plasma and/or // moving window). void ContinuousInjection(const amrex::RealBox& injection_box) const; - // Update injection position for continuously-injected species. - void UpdateContinuousInjectionPosition(amrex::Real dt) const; + + /** + * \brief Update antenna position for continuous injection of lasers + * in a boosted frame. Empty function for containers other than lasers. + */ + void UpdateAntennaPosition(const amrex::Real dt) const; + int doContinuousInjection() const; // Inject particles from a surface during the simulation diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 8da078dc8af..1a02cabb816 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -738,17 +738,12 @@ MultiParticleContainer::ContinuousInjection (const RealBox& injection_box) const } } -/* \brief Update position of continuous injection parameters. - * \param dt: simulation time step (level 0) - * All classes inherited from WarpXParticleContainer do not have - * a position to update (PhysicalParticleContainer does not do anything). - */ void -MultiParticleContainer::UpdateContinuousInjectionPosition (Real dt) const +MultiParticleContainer::UpdateAntennaPosition (const amrex::Real dt) const { for (auto& pc : allcontainers){ if (pc->do_continuous_injection){ - pc->UpdateContinuousInjectionPosition(dt); + pc->UpdateAntennaPosition(dt); } } } diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 6169ae540b5..2cc528447a6 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -250,8 +250,13 @@ public: // LaserParticleContainer: implemented. // RigidInjectedParticleContainer: not implemented. virtual void ContinuousInjection(const amrex::RealBox& /*injection_box*/) {} - // Update optional sub-class-specific injection location. - virtual void UpdateContinuousInjectionPosition(amrex::Real /*dt*/) {} + + /** + * \brief Update antenna position for continuous injection of lasers + * in a boosted frame. Empty function for containers other than lasers. + */ + virtual void UpdateAntennaPosition(const amrex::Real /*dt*/) {} + bool doContinuousInjection() const {return do_continuous_injection;} // Inject a continuous flux of particles from a defined plane diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index f62453f63b9..f968af81c13 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -53,22 +53,19 @@ using namespace amrex; void -WarpX::UpdatePlasmaInjectionPosition (amrex::Real a_dt) +WarpX::UpdateInjectionPosition (const amrex::Real a_dt) { const int dir = moving_window_dir; - // Loop over species - const int n_species = mypc->nSpecies(); - for (int i=0; inContainers(); + for (int i=0; iGetParticleContainer(i); // Continuously inject plasma in new cells (by default only on level 0) if (pc.doContinuousInjection()) { - PlasmaInjector* plasma_injector = pc.GetPlasmaInjector(); - if (plasma_injector == nullptr) continue; - // Get bulk momentum and velocity of plasma // 1D: dir=0 is z // 2D: dir=0 is x, dir=1 is z @@ -81,17 +78,25 @@ WarpX::UpdatePlasmaInjectionPosition (amrex::Real a_dt) #else // 3D current_injection_position[dir] = pc.m_current_injection_position; #endif - amrex::XDim3 u_bulk = plasma_injector->getInjectorMomentumHost()->getBulkMomentum(current_injection_position[0], - current_injection_position[1], - current_injection_position[2]); + + PlasmaInjector* plasma_injector = pc.GetPlasmaInjector(); + + amrex::Real v_shift = 0._rt; + if (plasma_injector != nullptr) + { + amrex::XDim3 u_bulk = plasma_injector->getInjectorMomentumHost()->getBulkMomentum( + current_injection_position[0], + current_injection_position[1], + current_injection_position[2]); #if defined(WARPX_DIM_1D_Z) - amrex::Vector u_bulk_vec = {u_bulk.z}; + amrex::Vector u_bulk_vec = {u_bulk.z}; #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::Vector u_bulk_vec = {u_bulk.x, u_bulk.z}; + amrex::Vector u_bulk_vec = {u_bulk.x, u_bulk.z}; #else // 3D - amrex::Vector u_bulk_vec = {u_bulk.x, u_bulk.y, u_bulk.z}; + amrex::Vector u_bulk_vec = {u_bulk.x, u_bulk.y, u_bulk.z}; #endif - amrex::Real v_bulk = PhysConst::c * u_bulk_vec[dir] / std::sqrt(1._rt + u_bulk_vec[dir]*u_bulk_vec[dir]); + v_shift = PhysConst::c * u_bulk_vec[dir] / std::sqrt(1._rt + u_bulk_vec[dir]*u_bulk_vec[dir]); + } // In boosted-frame simulations, the plasma has moved since the last // call to this function, and injection position needs to be updated. @@ -100,26 +105,26 @@ WarpX::UpdatePlasmaInjectionPosition (amrex::Real a_dt) // v' = (v-c*beta)/(1-v*beta/c) if (WarpX::gamma_boost > 1._rt) { - v_bulk = (v_bulk - PhysConst::c*WarpX::beta_boost) - / (1._rt - v_bulk*WarpX::beta_boost/PhysConst::c); + v_shift = (v_shift - PhysConst::c*WarpX::beta_boost) + / (1._rt - v_shift*WarpX::beta_boost/PhysConst::c); #if defined(WARPX_DIM_3D) - v_bulk *= WarpX::boost_direction[dir]; + v_shift *= WarpX::boost_direction[dir]; #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) // In 2D, dir=0 corresponds to x and dir=1 corresponds to z. // This needs to be converted to access boost_direction, // which has always 3 components. - v_bulk *= WarpX::boost_direction[2*dir]; + v_shift *= WarpX::boost_direction[2*dir]; #elif defined(WARPX_DIM_1D_Z) // In 1D, dir=0 corresponds to z. // This needs to be converted to access boost_direction, // which has always 3 components. - v_bulk *= WarpX::boost_direction[2]; + v_shift *= WarpX::boost_direction[2]; amrex::ignore_unused(dir); #endif } // Update current injection position - pc.m_current_injection_position += v_bulk * a_dt; + pc.m_current_injection_position += v_shift * a_dt; } } } @@ -142,13 +147,11 @@ WarpX::MoveWindow (const int step, bool move_j) moving_window_x += (moving_window_v - WarpX::beta_boost * PhysConst::c)/(1 - moving_window_v * WarpX::beta_boost / PhysConst::c) * dt[0]; const int dir = moving_window_dir; - // Update warpx.current_injection_position, - // PhysicalParticleContainer uses this injection position - UpdatePlasmaInjectionPosition( dt[0] ); - // Update injection position for WarpXParticleContainer in mypc, - // nothing to do for PhysicalParticleContainer, - // need to update the antenna position for LaserParticleContainer. - mypc->UpdateContinuousInjectionPosition( dt[0] ); + // Update current injection position for all containers + UpdateInjectionPosition(dt[0]); + // Update antenna position for all lasers + // TODO Make this specific to lasers only + mypc->UpdateAntennaPosition(dt[0]); // compute the number of cells to shift on the base level amrex::Real new_lo[AMREX_SPACEDIM]; @@ -356,9 +359,9 @@ WarpX::MoveWindow (const int step, bool move_j) } } - // Loop over species - const int n_species = mypc->nSpecies(); - for (int i=0; inContainers(); + for (int i=0; iGetParticleContainer(i); diff --git a/Source/WarpX.H b/Source/WarpX.H index 3a740d1b000..8fe6db1813e 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -602,7 +602,13 @@ public: * In doding so, only positions attributes are changed while fields remain unchanged. */ void ShiftGalileanBoundary (); - void UpdatePlasmaInjectionPosition (amrex::Real dt); + + /** + * \brief Update injection position for continuous injection of + * particles and lasers (loops over species and lasers). + */ + void UpdateInjectionPosition (const amrex::Real dt); + void ResetProbDomain (const amrex::RealBox& rb); void EvolveE ( amrex::Real dt); void EvolveE (int lev, amrex::Real dt); diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 27d463c12f0..86f61beb4e2 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -299,10 +299,11 @@ WarpX::WarpX () t_old.resize(nlevs_max, std::numeric_limits::lowest()); dt.resize(nlevs_max, std::numeric_limits::max()); - // Loop over species and set current injection position per species + // Loop over species (particles and lasers) + // and set current injection position per species mypc = std::make_unique(this); - const int n_species = mypc->nSpecies(); - for (int i=0; inContainers(); + for (int i=0; iGetParticleContainer(i); From 1d67cba10d34a65542294efaed6f02f6c3284ab0 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Thu, 10 Aug 2023 21:43:57 -0700 Subject: [PATCH 021/100] Add Python wrapper to set the lens strength (#3748) * Add Python wrapper to set the lens strength * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Correct missing `c_real` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add assert message --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- Python/pywarpx/_libwarpx.py | 22 ++++++++++++++++++++++ Source/Python/WarpXWrappers.H | 2 ++ Source/Python/WarpXWrappers.cpp | 15 +++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py index ebd18e5ee96..2a297b90880 100755 --- a/Python/pywarpx/_libwarpx.py +++ b/Python/pywarpx/_libwarpx.py @@ -311,6 +311,7 @@ class Particle(ctypes.Structure): self.libwarpx_so.warpx_sett_new.argtypes = [ctypes.c_int, c_real] self.libwarpx_so.warpx_getdt.argtypes = [ctypes.c_int] self.libwarpx_so.warpx_setPotentialEB.argtypes = [ctypes.c_char_p] + self.libwarpx_so.warpx_setPlasmaLensStrength.argtypes = [ctypes.c_int, c_real, c_real] def _get_boundary_number(self, boundary): ''' @@ -1231,6 +1232,27 @@ def set_potential_EB(self, potential): """ self.libwarpx_so.warpx_setPotentialEB(ctypes.c_char_p(potential.encode('utf-8'))) + def set_plasma_lens_strength( self, i_lens, strength_E, strength_B ): + """ + Set the strength of the `i_lens`-th lens + + Parameters + ---------- + i_lens: int + Index of the lens to be modified + + strength_E, strength_B: floats + The electric and magnetic focusing strength of the lens + """ + if self._numpy_real_dtype == 'f8': + c_real = ctypes.c_double + else: + c_real = ctypes.c_float + + self.libwarpx_so.warpx_setPlasmaLensStrength( + ctypes.c_int(i_lens), c_real(strength_E), c_real(strength_B) ) + + def _get_mesh_field_list(self, warpx_func, level, direction, include_ghosts): """ Generic routine to fetch the list of field data arrays. diff --git a/Source/Python/WarpXWrappers.H b/Source/Python/WarpXWrappers.H index 65e2b796abd..cd1e41cf444 100644 --- a/Source/Python/WarpXWrappers.H +++ b/Source/Python/WarpXWrappers.H @@ -159,6 +159,8 @@ extern "C" { void warpx_setPotentialEB (const char * char_potential); + void warpx_setPlasmaLensStrength (const int i_lens, const amrex::Real strength_E, const amrex::Real strength_B); + void mypc_Redistribute (); amrex::Real** warpx_getEfield (int lev, int direction, int *return_size, int *ncomps, int **ngrowvect, int **shapes); diff --git a/Source/Python/WarpXWrappers.cpp b/Source/Python/WarpXWrappers.cpp index 8d3be68be4d..02cee52e035 100644 --- a/Source/Python/WarpXWrappers.cpp +++ b/Source/Python/WarpXWrappers.cpp @@ -773,6 +773,21 @@ namespace warpx.m_poisson_boundary_handler.setPotentialEB(potential); } + void warpx_setPlasmaLensStrength (const int i_lens, const amrex::Real strength_E, const amrex::Real strength_B ) { + auto & mypc = WarpX::GetInstance().GetPartContainer(); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( i_lens >= mypc.h_repeated_plasma_lens_strengths_E.size(), + "i_lens is larger than the number of plasma lenses."); + mypc.h_repeated_plasma_lens_strengths_E[i_lens] = strength_E; + mypc.h_repeated_plasma_lens_strengths_B[i_lens] = strength_B; + amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, + mypc.h_repeated_plasma_lens_strengths_E.begin(), mypc.h_repeated_plasma_lens_strengths_E.end(), + mypc.d_repeated_plasma_lens_strengths_E.begin()); + amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, + mypc.h_repeated_plasma_lens_strengths_B.begin(), mypc.h_repeated_plasma_lens_strengths_B.end(), + mypc.d_repeated_plasma_lens_strengths_B.begin()); + amrex::Gpu::synchronize(); + } + void mypc_Redistribute () { auto & mypc = WarpX::GetInstance().GetPartContainer(); mypc.Redistribute(); From 7293f20939ca6e45e29d995408825ecd86dd6421 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 11 Aug 2023 06:19:38 -0700 Subject: [PATCH 022/100] Fix compilation issue with single-precision particles (#4174) --- Source/Particles/Filter/FilterFunctors.H | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Particles/Filter/FilterFunctors.H b/Source/Particles/Filter/FilterFunctors.H index e80b0be7d51..a7b894ce336 100644 --- a/Source/Particles/Filter/FilterFunctors.H +++ b/Source/Particles/Filter/FilterFunctors.H @@ -93,7 +93,7 @@ struct ParserFilter * \param time simulation time on the coarsest level */ ParserFilter(bool a_is_active, amrex::ParserExecutor<7> const& a_filter_parser, - const amrex::Real a_mass, const amrex::Real time): + const amrex::ParticleReal a_mass, const amrex::Real time): m_is_active{a_is_active}, m_function_partparser{a_filter_parser}, m_mass{a_mass}, @@ -139,7 +139,7 @@ public: /** Mass of particle species */ amrex::ParticleReal m_mass; /** Store physical time on the coarsest level. */ - amrex::ParticleReal m_t; + amrex::Real m_t; /** keep track of momentum units particles will come in with **/ InputUnits m_units; }; From b10502843780f16b02f247c05af8d52b153c2475 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 11 Aug 2023 06:20:14 -0700 Subject: [PATCH 023/100] Use more consistent particle type in pusher (#4175) --- Source/Particles/PhysicalParticleContainer.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index ded222ce80a..c5c44f9b6da 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -2497,8 +2497,8 @@ PhysicalParticleContainer::PushP (int lev, Real dt, } // Loop over the particles and update their momentum - const amrex::Real q = this->charge; - const amrex::Real m = this-> mass; + const amrex::ParticleReal q = this->charge; + const amrex::ParticleReal m = this-> mass; const auto pusher_algo = WarpX::particle_pusher_algo; const auto do_crr = do_classical_radiation_reaction; @@ -2535,25 +2535,25 @@ PhysicalParticleContainer::PushP (int lev, Real dt, } if (do_crr) { - amrex::Real qp = q; + amrex::ParticleReal qp = q; if (ion_lev) { qp *= ion_lev[ip]; } UpdateMomentumBorisWithRadiationReaction(ux[ip], uy[ip], uz[ip], Exp, Eyp, Ezp, Bxp, Byp, Bzp, qp, m, dt); } else if (pusher_algo == ParticlePusherAlgo::Boris) { - amrex::Real qp = q; + amrex::ParticleReal qp = q; if (ion_lev) { qp *= ion_lev[ip]; } UpdateMomentumBoris( ux[ip], uy[ip], uz[ip], Exp, Eyp, Ezp, Bxp, Byp, Bzp, qp, m, dt); } else if (pusher_algo == ParticlePusherAlgo::Vay) { - amrex::Real qp = q; + amrex::ParticleReal qp = q; if (ion_lev){ qp *= ion_lev[ip]; } UpdateMomentumVay( ux[ip], uy[ip], uz[ip], Exp, Eyp, Ezp, Bxp, Byp, Bzp, qp, m, dt); } else if (pusher_algo == ParticlePusherAlgo::HigueraCary) { - amrex::Real qp = q; + amrex::ParticleReal qp = q; if (ion_lev){ qp *= ion_lev[ip]; } UpdateMomentumHigueraCary( ux[ip], uy[ip], uz[ip], Exp, Eyp, Ezp, Bxp, From e28c61385362542647ad00cb83b75525720cee99 Mon Sep 17 00:00:00 2001 From: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:02:20 -0700 Subject: [PATCH 024/100] Enable `divE` field diagnostic with Ohm's law solver (#4178) * use same finite difference algo as for Yee with hybrid-PIC to calculate divE * add `divE` and `divB` to field diagnostic in picmi.py --- Python/pywarpx/picmi.py | 2 +- Source/FieldSolver/FiniteDifferenceSolver/ComputeDivE.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Python/pywarpx/picmi.py b/Python/pywarpx/picmi.py index a607010c766..768310a518c 100644 --- a/Python/pywarpx/picmi.py +++ b/Python/pywarpx/picmi.py @@ -1991,7 +1991,7 @@ def initialize_inputs(self): fields_to_plot.add(dataname) elif dataname in A_fields_list: fields_to_plot.add(dataname) - elif dataname in ['rho', 'phi', 'F', 'proc_number', 'part_per_cell']: + elif dataname in ['rho', 'phi', 'F', 'divE', 'divB', 'proc_number', 'part_per_cell']: fields_to_plot.add(dataname) elif dataname in J_fields_list: fields_to_plot.add(dataname.lower()) diff --git a/Source/FieldSolver/FiniteDifferenceSolver/ComputeDivE.cpp b/Source/FieldSolver/FiniteDifferenceSolver/ComputeDivE.cpp index 7f4016450ae..163792a2737 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/ComputeDivE.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/ComputeDivE.cpp @@ -46,7 +46,8 @@ void FiniteDifferenceSolver::ComputeDivE ( // Select algorithm (The choice of algorithm is a runtime option, // but we compile code for each algorithm, using templates) #ifdef WARPX_DIM_RZ - if (m_fdtd_algo == ElectromagneticSolverAlgo::Yee){ + if (m_fdtd_algo == ElectromagneticSolverAlgo::Yee || + m_fdtd_algo == ElectromagneticSolverAlgo::HybridPIC){ ComputeDivECylindrical ( Efield, divEfield ); @@ -55,7 +56,8 @@ void FiniteDifferenceSolver::ComputeDivE ( ComputeDivECartesian ( Efield, divEfield ); - } else if (m_fdtd_algo == ElectromagneticSolverAlgo::Yee) { + } else if (m_fdtd_algo == ElectromagneticSolverAlgo::Yee || + m_fdtd_algo == ElectromagneticSolverAlgo::HybridPIC) { ComputeDivECartesian ( Efield, divEfield ); From b0afc82a687ef3f5b9c76c9eb72d12a0ee900041 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 11 Aug 2023 10:38:58 -0700 Subject: [PATCH 025/100] Update PICMI interface for Gaussian flux (#4084) * Update PICMI interface for Gaussian flux * Update version of picmistandard --- Docs/requirements.txt | 2 +- Python/pywarpx/picmi.py | 2 +- Python/setup.py | 2 +- requirements.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Docs/requirements.txt b/Docs/requirements.txt index 760a38e0cf8..10656e29bce 100644 --- a/Docs/requirements.txt +++ b/Docs/requirements.txt @@ -11,7 +11,7 @@ docutils>=0.17.1 # PICMI API docs # note: keep in sync with version in ../requirements.txt -picmistandard==0.25.0 +picmistandard==0.26.0 # for development against an unreleased PICMI version, use: # picmistandard @ git+https://github.com/picmi-standard/picmi.git#subdirectory=PICMI_Python diff --git a/Python/pywarpx/picmi.py b/Python/pywarpx/picmi.py index 768310a518c..941e3d1ff55 100644 --- a/Python/pywarpx/picmi.py +++ b/Python/pywarpx/picmi.py @@ -414,7 +414,7 @@ def initialize_inputs(self, species_number, layout, species, density_scale): # --- Use specific attributes for flux injection species.injection_style = "nfluxpercell" assert (isinstance(layout, PseudoRandomLayout)), Exception('UniformFluxDistribution only supports the PseudoRandomLayout in WarpX') - if species.momentum_distribution_type == "gaussian": + if self.gaussian_flux_momentum_distribution: species.momentum_distribution_type = "gaussianflux" diff --git a/Python/setup.py b/Python/setup.py index 1dcfcc4d35e..2a35516dba1 100644 --- a/Python/setup.py +++ b/Python/setup.py @@ -59,7 +59,7 @@ package_dir = {'pywarpx': 'pywarpx'}, description = """Wrapper of WarpX""", package_data = package_data, - install_requires = ['numpy', 'picmistandard==0.25.0', 'periodictable'], + install_requires = ['numpy', 'picmistandard==0.26.0', 'periodictable'], python_requires = '>=3.7', zip_safe=False ) diff --git a/requirements.txt b/requirements.txt index c7189a292ad..7d2aa5376ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ periodictable~=1.5 # PICMI # note: don't forget to update the version in Docs/requirements.txt, too -picmistandard==0.25.0 +picmistandard==0.26.0 # for development against an unreleased PICMI version, use: #picmistandard @ git+https://github.com/picmi-standard/picmi.git#subdirectory=PICMI_Python From 49ba4fd2788e1c13899a5ae92219a018570ff5f0 Mon Sep 17 00:00:00 2001 From: David Grote Date: Fri, 11 Aug 2023 15:14:51 -0700 Subject: [PATCH 026/100] In picmi.py, add G to fields to plot check (#4180) --- Python/pywarpx/picmi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/pywarpx/picmi.py b/Python/pywarpx/picmi.py index 941e3d1ff55..dbfdb09cf5e 100644 --- a/Python/pywarpx/picmi.py +++ b/Python/pywarpx/picmi.py @@ -1991,7 +1991,7 @@ def initialize_inputs(self): fields_to_plot.add(dataname) elif dataname in A_fields_list: fields_to_plot.add(dataname) - elif dataname in ['rho', 'phi', 'F', 'divE', 'divB', 'proc_number', 'part_per_cell']: + elif dataname in ['rho', 'phi', 'F', 'G', 'divE', 'divB', 'proc_number', 'part_per_cell']: fields_to_plot.add(dataname) elif dataname in J_fields_list: fields_to_plot.add(dataname.lower()) From f6760c8e6d64605f73476f9bc8292dc9d85df454 Mon Sep 17 00:00:00 2001 From: Ilian Kara-Mostefa <95044023+IlianCS@users.noreply.github.com> Date: Fri, 11 Aug 2023 17:04:08 -0700 Subject: [PATCH 027/100] LASY: Broadcast quantities to MPI processes (#4179) * Broadcast quantity & update tests * Make only one rank create the lasy file * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../LaserProfilesImpl/LaserProfileFromFile.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Source/Laser/LaserProfilesImpl/LaserProfileFromFile.cpp b/Source/Laser/LaserProfilesImpl/LaserProfileFromFile.cpp index 85cf9fc62af..b67be64b47e 100644 --- a/Source/Laser/LaserProfilesImpl/LaserProfileFromFile.cpp +++ b/Source/Laser/LaserProfilesImpl/LaserProfileFromFile.cpp @@ -212,6 +212,21 @@ WarpXLaserProfiles::FromFileLaserProfile::parse_lasy_file(std::string lasy_file_ WARPX_ABORT_WITH_MESSAGE("The lasy file's geometry has to be in either RZ or 3D cartesian coordinates"); } } + + //Broadcast parameters + ParallelDescriptor::Bcast(&m_params.nt, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.nx, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.ny, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.nr, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.n_rz_azimuthal_components, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.t_min, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.t_max, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.x_min, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.x_max, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.y_min, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.y_max, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.r_min, 1, ParallelDescriptor::IOProcessorNumber()); + ParallelDescriptor::Bcast(&m_params.r_max, 1, ParallelDescriptor::IOProcessorNumber()); #else amrex::ignore_unused(lasy_file_name); #endif From 6c93d9fc13830d574c69ac7b166f5fbdb0809731 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Sat, 12 Aug 2023 11:17:38 -0700 Subject: [PATCH 028/100] Transition to pyAMReX (#3474) * pyAMReX: Build System * CI Updates (Changed Options) * Callback modernization (#4) * refactor callbacks.py * added binding code in `pyWarpX.cpp` to add or remove keys from the callback dictionary * minor PR cleanups Co-authored-by: Axel Huebl * Added Python level reference to fetch the multifabs (#3) * pyAMReX: Build System * Added Python level reference to Ex_aux * Now uses the multifab map * Fix typo Co-authored-by: Axel Huebl * Add initialization and finalize routines (#5) A basic PICMI input file will now run to completion. * Regression Tests: WarpX_PYTHON=ON * Update Imports to nD pyAMReX * IPO/LTO Control Although pybind11 relies heavily on IPO/LTO to create low-latency, small-binary bindings, some compilers will have troubles with that. Thus, we add a compile-time option to optionally disable it when needed. * Fix: Link Legacy WarpXWrappers.cpp * Wrap WarpX instance and start multi particle container * Fix test Python_pass_mpi_comm * Start wrapper for multiparticle container * Add return policy Co-authored-by: Axel Huebl * Update fields to use MultiFabs directly Remove EOL white space Removed old routines accessing MultiFabs Update to use "node_centered" * Fix compilation with Python * Update fields.py to use modified MultiFab tag names * Remove incorrect, unused code * Add function to extract the WarpX MultiParticleContainer * Complete class WarpXParticleContainer * Wrap functions getNprocs / getMyProc * restore `install___` callback API - could remove later if we want but should maintain backward compatibility for now * add `gett_new` and `getistep` functions wrappers; fix typos in `callbacks.py`; avoid error in getting `rho` from `fields.py` * Update callback call and `getNproc`/`getMyProc` function * Replace function add_n_particles * Fix setitem in fields.py for 1d and 2d * also update `gett_new()` in `_libwarpx.py` in case we want to keep that API * added binding for `WarpXParIter` - needed to port `libwarpx.depositChargeDensity()` which is an ongoing effort * Wrap function num_real_comp * added binding for `TotalNumberOfParticles` and continue progress on enabling 1d MCC test to run * add `SyncRho()` binding and create helper function in `libwarpx.depositChargeDensity` to manage scope of the particle iter * Clean up issues in fields.py * update bindings for `get_particle_structs` * Fix setitem in fields.py * switch order of initialization for particle container and particle iterator * switch deposit_charge loop to C++ code; bind `ApplyInverseVolumeScalingToChargeDensity` * move `WarpXParticleContainer.cpp` and `MultiParticleContainer.cpp` to new Particles folder * added binding for `ParticleBoundaryBuffer` * More fixes for fields.py * Fix: Backtraces from Python Add the Python executable name with an absolute path, so backtraces in AMReX work. See linked AMReX issue for details. * Cleaning * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix: Backtraces from Python Part II Do not add Python script name - it confuses the AMReX ParmParser to build its table. * Fix: CMake Dependencies for Wheel This fixes a racecondition during `pip_install`: it was possible that not all dimensions where yet build from pybind before we start packing them in the wheel for pip install. * MCC Test: Install Callbacks before Run Otherwise hangs in aquiring the gil during shutdown. * addition of `Python/pywarpx/particle_containers.py` and various associated bindings * Fix: CMake Superbuild w/ Shared AMReX We MUST build AMReX as a shared (so/dll/dylib) library, otherwise all the global state in it will cause split-brain situations, where our Python modules operate on different stacks. * add `clear_all()` to callbacks in order to remove all callbacks at finalize * add `-DWarpX_PYTHON=ON` to CI tests that failed to build * add `get_comp_index` and continue to port particle data bindings * Add AMReX Module as `libwarpx_so.amr` Attribute to pass through the already loaded AMReX module with the matching dimensionality to the simulation. * Fix for fields accounting for guard cells * Fix handling of ghost cells in fields * Update & Test: Particle Boundary Scraping * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * CI: Python Updates - modernize Python setups - drop CUDA 11.0 for good and go 11.3+ as documented already ``` Error #3246: Internal Compiler Error (codegen): "there was an error in verifying the lgenfe output!" ``` * CI: Python Updates (chmod) * Add support for cupy in fields.py * Add MultiFab reduction routines * CI: CUDA 11.3 is <= Ubuntu 20.04 * changed `AddNParticles` to take `amrex::Vector` arguments * setup.py: WarpX_PYTHON=ON * update various 2d and rz tests with new APIs * add `-DWarpX_PYTHON_IPO=OFF` to compile string for 2d and 3d Python CI tests to speed up linking * CI: -DpyAMReX_IPO=OFF * CI: -DpyAMReX_IPO=OFF actually adding `=OFF` * CI: Intel Python * CI: macOS Python Executable Ensure we always use the same `python3` executable, as specified by the `PATH` priority. * CMake: Python Multi-Config Build Add support for multi-config generators, especially on Windows. * __init__.py: Windows DLL Support Python 3.8+ on Windows: DLL search paths for dependent shared libraries Refs.: - https://github.com/python/cpython/issues/80266 - https://docs.python.org/3.8/library/os.html#os.add_dll_directory * CI: pywarpx Update our setup.py cannot install pyamrex yet as a dependency. * ABLASTR: `ablastr/export.H` Add a new header to export public globals that are not covered by `WINDOWS_EXPORT_ALL_SYMBOLS`. https://stackoverflow.com/questions/54560832/cmake-windows-export-all-symbols-does-not-cover-global-variables/54568678#54568678 * WarpX: EXPORT Globals in `.dll` files WarpX still uses a lot of globals: - `static` member variables - `extern` global variables These globals cannot be auto-exported with CMake's `WINDOWS_EXPORT_ALL_SYMBOLS` helper and thus we need to mark them manually for DLL export (and import) via the new ABLASTR `ablastr/export.H` helper macros. This starts to export symbols in the: - WarpX and particle container classes - callback hook database map - ES solver * CI: pywarpx Clang CXXFLAGS Down Move CXXFLAGS (`-Werror ...`) down until deps are installed. * GNUmake: Generate `ablastr/export.H` * CMake: More Symbol Exports for Windows * `WarpX-tests.ini`: Simplify Python no-IPO Also avoids subtle differences in compilation that increase compile time. * Update PICMI_inputs_EB_API.py for embedded_boundary_python_API CI test * Fix Python_magnetostatic_eb_3d * Update: Python_restart_runtime_components New Python APIs * Windows: no dllimport for now * CI: Skip `PYINSTALLOPTIONS` For Now * CMake: Dependency Bump Min-Versions for external packages picked up by `find_package`. * Fix F and G_fp names in fields.py * Tests: Disable `Python_pass_mpi_comm` * Wrappers: Cleanup * pyWarpX: Include Cleaning * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fields.py: Fix F and G Wrappers Correct MultiFab names (w/o components). * Remove unused in fields.py * Windows: New Export Headers - ABLASTR: `ablastr/export.H` - WarpX: `Utils/export.H` * removed `WarpInterface.py` since that functionality is now in `particle_containers.py`; removed parts of `WarpXWrappers.cpp` that have been ported to pyamrex * CMake: Link OBJECT Target PRIVATE * CMake: Remove OBJECT Target Simplify and make `app` link `lib` (default: static). Remove OBJECT target. * Fix in fields.py for the components index * Update get_particle_id/cpu As implemented in pyAMReX with https://github.com/AMReX-Codes/pyamrex/pull/165 * WarpX: Update for Private Constructor * Import AMReX Before pyd DLL Call Importing AMReX will add the `add_dll_directory` to a potentially shared amrex DLL on Windows. * Windows CI: Set PATH to amrex_Nd.dll * CMake: AMReX_INSTALL After Python In superbuild, Python can modify `AMReX_BUILD_SHARED_LIBS`. * Clang Win CI: Manually Install requirements Sporadic error is: ``` ... Installing collected packages: pyparsing, numpy, scipy, periodictable, picmistandard ERROR: Could not install packages due to an OSError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\hostedtoolcache\\windows\\Python\\3.11.4\\x64\\Lib\\site-packages\\numpy\\polynomial\\__init__.py' Consider using the `--user` option or check the permissions. ``` * Hopefully final fixes to fields.py * Update getProbLo/getProbHi * Set plasma length strength Co-authored-by: Remi Lehe * Fix fields method to remove CodeQL notice * Update Comments & Some Finalize * Move: set_plasma_lens_strength to MPC --------- Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com> Co-authored-by: David Grote Co-authored-by: Remi Lehe Co-authored-by: Dave Grote Co-authored-by: Roelof Groenewald Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/cuda.yml | 14 +- .../dependencies/{nvcc11-0.sh => nvcc11-3.sh} | 35 +- .github/workflows/hip.yml | 10 +- .github/workflows/intel.yml | 29 +- .github/workflows/macos.yml | 12 +- .github/workflows/ubuntu.yml | 18 +- .github/workflows/windows.yml | 30 +- CMakeLists.txt | 299 +- Docs/source/install/cmake.rst | 26 +- .../capacitive_discharge/PICMI_inputs_1d.py | 13 +- .../PICMI_inputs_EB_API.py | 131 +- .../Tests/magnetostatic_eb/PICMI_inputs_3d.py | 12 +- .../PICMI_inputs.py | 9 +- .../PICMI_inputs.py | 29 +- .../PICMI_inputs.py | 2 +- .../PICMI_inputs_reflection.py | 12 +- .../PICMI_inputs_scrape.py | 19 +- .../particle_data_python/PICMI_inputs_2d.py | 22 +- .../PICMI_inputs_prev_pos_2d.py | 21 +- .../pass_mpi_communicator/PICMI_inputs_2d.py | 29 +- .../Tests/restart/PICMI_inputs_id_cpu_read.py | 15 +- .../PICMI_inputs_runtime_component_analyze.py | 19 +- Python/__init__.py | 0 Python/pywarpx/PGroup.py | 182 -- Python/pywarpx/WarpInterface.py | 190 -- Python/pywarpx/WarpX.py | 5 +- Python/pywarpx/__init__.py | 28 +- Python/pywarpx/_libwarpx.py | 2734 +---------------- Python/pywarpx/callbacks.py | 410 +-- Python/pywarpx/fields.py | 1286 ++++---- Python/pywarpx/particle_containers.py | 601 ++++ Regression/WarpX-tests.ini | 92 +- Source/AcceleratorLattice/CMakeLists.txt | 2 +- .../LatticeElements/CMakeLists.txt | 2 +- Source/BoundaryConditions/CMakeLists.txt | 4 +- Source/Diagnostics/CMakeLists.txt | 2 +- .../ComputeDiagFunctors/CMakeLists.txt | 2 +- .../Diagnostics/FlushFormats/CMakeLists.txt | 4 +- .../Diagnostics/ParticleDiag/CMakeLists.txt | 2 +- .../Diagnostics/ReducedDiags/CMakeLists.txt | 2 +- Source/EmbeddedBoundary/CMakeLists.txt | 2 +- Source/Evolve/CMakeLists.txt | 2 +- Source/FieldSolver/CMakeLists.txt | 2 +- Source/FieldSolver/ElectrostaticSolver.H | 9 +- Source/FieldSolver/ElectrostaticSolver.cpp | 4 +- .../FiniteDifferenceSolver/CMakeLists.txt | 2 +- .../HybridPICModel/CMakeLists.txt | 2 +- .../MacroscopicProperties/CMakeLists.txt | 2 +- .../MagnetostaticSolver/CMakeLists.txt | 2 +- .../MagnetostaticSolver.cpp | 2 +- .../FieldSolver/SpectralSolver/CMakeLists.txt | 4 +- .../SpectralAlgorithms/CMakeLists.txt | 4 +- .../SpectralHankelTransform/CMakeLists.txt | 2 +- Source/Filter/CMakeLists.txt | 2 +- Source/Initialization/CMakeLists.txt | 2 +- Source/Initialization/WarpXAMReXInit.H | 4 +- Source/Initialization/WarpXAMReXInit.cpp | 5 +- Source/Laser/LaserProfilesImpl/CMakeLists.txt | 2 +- Source/Make.WarpX | 27 + Source/Parallelization/CMakeLists.txt | 2 +- Source/Particles/CMakeLists.txt | 2 +- .../Collision/BackgroundMCC/CMakeLists.txt | 2 +- .../BackgroundStopping/CMakeLists.txt | 2 +- .../Collision/BinaryCollision/CMakeLists.txt | 2 +- Source/Particles/Collision/CMakeLists.txt | 2 +- .../ElementaryProcess/CMakeLists.txt | 4 +- .../QEDInternals/CMakeLists.txt | 2 +- Source/Particles/Gather/CMakeLists.txt | 2 +- Source/Particles/LaserParticleContainer.cpp | 9 +- .../NamedComponentParticleContainer.H | 4 +- Source/Particles/ParticleBoundaryBuffer.H | 16 +- .../Particles/ParticleCreation/CMakeLists.txt | 2 +- .../Particles/PhysicalParticleContainer.cpp | 96 +- Source/Particles/Resampling/CMakeLists.txt | 2 +- Source/Particles/Sorting/CMakeLists.txt | 2 +- Source/Particles/WarpXParticleContainer.H | 21 +- Source/Particles/WarpXParticleContainer.cpp | 50 +- Source/Python/CMakeLists.txt | 18 +- Source/Python/Particles/CMakeLists.txt | 17 + .../Particles/MultiParticleContainer.cpp | 46 + .../Particles/ParticleBoundaryBuffer.cpp | 59 + .../PinnedMemoryParticleContainer.cpp | 23 + .../Particles/WarpXParticleContainer.cpp | 119 + Source/Python/WarpX.cpp | 201 ++ Source/Python/WarpXWrappers.H | 201 +- Source/Python/WarpXWrappers.cpp | 626 +--- Source/Python/WarpX_py.H | 30 +- Source/Python/WarpX_py.cpp | 21 +- Source/Python/pyWarpX.H | 20 + Source/Python/pyWarpX.cpp | 136 + Source/Utils/CMakeLists.txt | 2 +- Source/Utils/Logo/CMakeLists.txt | 2 +- Source/Utils/Parser/CMakeLists.txt | 2 +- Source/WarpX.H | 4 +- WarpXConfig.cmake | 64 + cmake/WarpXFunctions.cmake | 85 +- cmake/dependencies/AMReX.cmake | 19 +- cmake/dependencies/pyAMReX.cmake | 83 + cmake/dependencies/pybind11.cmake | 56 + setup.py | 23 +- 100 files changed, 3139 insertions(+), 5375 deletions(-) rename .github/workflows/dependencies/{nvcc11-0.sh => nvcc11-3.sh} (60%) create mode 100644 Python/__init__.py delete mode 100644 Python/pywarpx/PGroup.py delete mode 100644 Python/pywarpx/WarpInterface.py create mode 100644 Python/pywarpx/particle_containers.py create mode 100644 Source/Python/Particles/CMakeLists.txt create mode 100644 Source/Python/Particles/MultiParticleContainer.cpp create mode 100644 Source/Python/Particles/ParticleBoundaryBuffer.cpp create mode 100644 Source/Python/Particles/PinnedMemoryParticleContainer.cpp create mode 100644 Source/Python/Particles/WarpXParticleContainer.cpp create mode 100644 Source/Python/WarpX.cpp create mode 100644 Source/Python/pyWarpX.H create mode 100644 Source/Python/pyWarpX.cpp create mode 100644 WarpXConfig.cmake create mode 100644 cmake/dependencies/pyAMReX.cmake create mode 100644 cmake/dependencies/pybind11.cmake diff --git a/.github/workflows/cuda.yml b/.github/workflows/cuda.yml index 3f11e108ba5..dd0d38d66cb 100644 --- a/.github/workflows/cuda.yml +++ b/.github/workflows/cuda.yml @@ -12,7 +12,7 @@ jobs: # https://github.com/ComputationalRadiationPhysics/picongpu/blob/0.5.0/share/picongpu/dockerfiles/ubuntu-1604/Dockerfile # https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ build_nvcc: - name: NVCC 11.0.3 SP + name: NVCC 11.3 SP runs-on: ubuntu-20.04 if: github.event.pull_request.draft == false env: @@ -30,7 +30,7 @@ jobs: python-version: '3.x' - name: install dependencies run: | - .github/workflows/dependencies/nvcc11-0.sh + .github/workflows/dependencies/nvcc11-3.sh - name: CCache Cache uses: actions/cache@v3 # - once stored under a key, they become immutable (even if local cache path content changes) @@ -65,7 +65,7 @@ jobs: -DCMAKE_VERBOSE_MAKEFILE=ON \ -DWarpX_COMPUTE=CUDA \ -DWarpX_EB=ON \ - -DWarpX_LIB=ON \ + -DWarpX_PYTHON=ON \ -DAMReX_CUDA_ARCH=6.0 \ -DWarpX_OPENPMD=ON \ -DWarpX_openpmd_internal=OFF \ @@ -77,7 +77,8 @@ jobs: python3 -m pip install --upgrade pip setuptools wheel export WARPX_MPI=ON - PYWARPX_LIB_DIR=$PWD/build_sp/lib python3 -m pip wheel . + export PYWARPX_LIB_DIR=$PWD/build_sp/lib/site-packages/pywarpx/ + python3 -m pip wheel . python3 -m pip install *.whl # make sure legacy build system continues to build, i.e., that we don't forget @@ -161,7 +162,7 @@ jobs: -DCMAKE_VERBOSE_MAKEFILE=ON \ -DWarpX_COMPUTE=CUDA \ -DWarpX_EB=ON \ - -DWarpX_LIB=ON \ + -DWarpX_PYTHON=ON \ -DAMReX_CUDA_ARCH=8.0 \ -DWarpX_OPENPMD=ON \ -DWarpX_PSATD=ON \ @@ -176,5 +177,6 @@ jobs: python3 -m pip install --upgrade pip setuptools wheel export WARPX_MPI=ON - PYWARPX_LIB_DIR=$PWD/build/lib python3 -m pip wheel . + export PYWARPX_LIB_DIR=$PWD/build/lib/site-packages/pywarpx/ + python3 -m pip wheel . python3 -m pip install *.whl diff --git a/.github/workflows/dependencies/nvcc11-0.sh b/.github/workflows/dependencies/nvcc11-3.sh similarity index 60% rename from .github/workflows/dependencies/nvcc11-0.sh rename to .github/workflows/dependencies/nvcc11-3.sh index a018c7a4877..ed9fd211128 100755 --- a/.github/workflows/dependencies/nvcc11-0.sh +++ b/.github/workflows/dependencies/nvcc11-3.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Copyright 2020-2022 The WarpX Community +# Copyright 2020-2023 The WarpX Community # # License: BSD-3-Clause-LBNL # Authors: Axel Huebl @@ -26,30 +26,27 @@ sudo apt-get install -y \ pkg-config \ wget -wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin -sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600 -sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub -echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /" \ - | sudo tee /etc/apt/sources.list.d/cuda.list +wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb +sudo dpkg -i cuda-keyring_1.0-1_all.deb sudo apt-get update sudo apt-get install -y \ - cuda-command-line-tools-11-0 \ - cuda-compiler-11-0 \ - cuda-cupti-dev-11-0 \ - cuda-minimal-build-11-0 \ - cuda-nvml-dev-11-0 \ - cuda-nvtx-11-0 \ - libcufft-dev-11-0 \ - libcurand-dev-11-0 -sudo ln -s cuda-11.0 /usr/local/cuda + cuda-command-line-tools-11-3 \ + cuda-compiler-11-3 \ + cuda-cupti-dev-11-3 \ + cuda-minimal-build-11-3 \ + cuda-nvml-dev-11-3 \ + cuda-nvtx-11-3 \ + libcufft-dev-11-3 \ + libcurand-dev-11-3 +sudo ln -s cuda-11.3 /usr/local/cuda # if we run out of temporary storage in CI: -#du -sh /usr/local/cuda-11.0 +#du -sh /usr/local/cuda-11.3 #echo "+++ REDUCING CUDA Toolkit install size +++" -#sudo rm -rf /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcu{fft,pti,rand}_static.a -#sudo rm -rf /usr/local/cuda-11.0/targets/x86_64-linux/lib/libnvperf_host_static.a -#du -sh /usr/local/cuda-11.0/ +#sudo rm -rf /usr/local/cuda-11.3/targets/x86_64-linux/lib/libcu{fft,pti,rand}_static.a +#sudo rm -rf /usr/local/cuda-11.3/targets/x86_64-linux/lib/libnvperf_host_static.a +#du -sh /usr/local/cuda-11.3/ #df -h # cmake-easyinstall diff --git a/.github/workflows/hip.yml b/.github/workflows/hip.yml index 612fe5c2d8a..40e5055cd8b 100644 --- a/.github/workflows/hip.yml +++ b/.github/workflows/hip.yml @@ -51,7 +51,7 @@ jobs: -DAMReX_AMD_ARCH=gfx900 \ -DWarpX_COMPUTE=HIP \ -DWarpX_EB=ON \ - -DWarpX_LIB=ON \ + -DWarpX_PYTHON=ON \ -DWarpX_MPI=ON \ -DWarpX_OPENPMD=ON \ -DWarpX_PRECISION=SINGLE \ @@ -59,7 +59,8 @@ jobs: cmake --build build_sp -j 2 export WARPX_MPI=OFF - PYWARPX_LIB_DIR=$PWD/build_sp/lib python3 -m pip wheel . + export PYWARPX_LIB_DIR=$PWD/build_sp/lib/site-packages/pywarpx/ + python3 -m pip wheel . python3 -m pip install *.whl build_hip_2d_dp: @@ -107,7 +108,7 @@ jobs: -DWarpX_DIMS=2 \ -DWarpX_COMPUTE=HIP \ -DWarpX_EB=ON \ - -DWarpX_LIB=ON \ + -DWarpX_PYTHON=ON \ -DWarpX_MPI=ON \ -DWarpX_OPENPMD=ON \ -DWarpX_PRECISION=DOUBLE \ @@ -115,5 +116,6 @@ jobs: cmake --build build_2d -j 2 export WARPX_MPI=OFF - PYWARPX_LIB_DIR=$PWD/build_2d/lib python3 -m pip wheel . + export PYWARPX_LIB_DIR=$PWD/build_2d/lib/site-packages/pywarpx/ + python3 -m pip wheel . python3 -m pip install *.whl diff --git a/.github/workflows/intel.yml b/.github/workflows/intel.yml index 9d08d3f0e51..aba8200f1b2 100644 --- a/.github/workflows/intel.yml +++ b/.github/workflows/intel.yml @@ -41,9 +41,13 @@ jobs: export CXX=$(which icpc) export CC=$(which icc) + python3 -m pip install --upgrade pip setuptools wheel + cmake -S . -B build_dp \ -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DWarpX_LIB=ON \ + -DpyAMReX_IPO=OFF \ + -DWarpX_PYTHON=ON \ + -DWarpX_PYTHON_IPO=OFF \ -DWarpX_MPI=OFF \ -DWarpX_OPENPMD=ON \ -DWarpX_openpmd_internal=OFF @@ -51,15 +55,15 @@ jobs: cmake -S . -B build_sp \ -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DWarpX_LIB=ON \ + -DpyAMReX_IPO=OFF \ + -DWarpX_PYTHON=ON \ + -DWarpX_PYTHON_IPO=OFF \ -DWarpX_MPI=OFF \ -DWarpX_OPENPMD=ON \ -DWarpX_openpmd_internal=OFF \ -DWarpX_PRECISION=SINGLE cmake --build build_sp -j 2 - - python3 -m pip install --upgrade pip setuptools wheel - PYWARPX_LIB_DIR=$PWD/build_sp/lib python3 -m pip install -v . + cmake --build build_sp --target pip_install build_icpx: name: oneAPI ICX SP @@ -99,20 +103,19 @@ jobs: export CXX=$(which icpx) export CC=$(which icx) + python3 -m pip install --upgrade pip + python3 -m pip install --upgrade setuptools wheel + cmake -S . -B build_sp \ -DCMAKE_CXX_FLAGS_RELEASE="-O1 -DNDEBUG" \ -DCMAKE_VERBOSE_MAKEFILE=ON \ -DWarpX_EB=ON \ - -DWarpX_LIB=ON \ + -DWarpX_PYTHON=ON \ -DWarpX_MPI=OFF \ -DWarpX_OPENPMD=ON \ -DWarpX_PRECISION=SINGLE cmake --build build_sp -j 2 - - python3 -m pip install --upgrade pip - python3 -m pip install --upgrade setuptools wheel - PYWARPX_LIB_DIR=$PWD/build_sp/lib python3 -m pip wheel -v . - python3 -m pip install *.whl + cmake --build build_sp --target pip_install - name: run pywarpx run: | @@ -167,7 +170,7 @@ jobs: -DCMAKE_VERBOSE_MAKEFILE=ON \ -DWarpX_COMPUTE=SYCL \ -DWarpX_EB=ON \ - -DWarpX_LIB=ON \ + -DWarpX_PYTHON=ON \ -DWarpX_MPI=OFF \ -DWarpX_OPENPMD=ON \ -DWarpX_PRECISION=SINGLE @@ -176,5 +179,5 @@ jobs: # Skip this as it will copy the binary artifacts and we are tight on disk space # python3 -m pip install --upgrade pip # python3 -m pip install --upgrade setuptools wheel - # PYWARPX_LIB_DIR=$PWD/build_sp/lib python3 -m pip wheel . + # PYWARPX_LIB_DIR=$PWD/build_sp/lib/site-packages/pywarpx/ python3 -m pip wheel . # python3 -m pip install *.whl diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index e37c985a1d2..0495155b430 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -63,6 +63,9 @@ jobs: ccache-macos-appleclang- - name: build WarpX run: | + python3 -m pip install --upgrade pip + python3 -m pip install --upgrade pip setuptools wheel + cmake -S . -B build_dp \ -DCMAKE_VERBOSE_MAKEFILE=ON \ -DWarpX_EB=ON \ @@ -72,17 +75,14 @@ jobs: cmake -S . -B build_sp \ -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DPython_EXECUTABLE=$(which python3) \ -DWarpX_EB=ON \ - -DWarpX_LIB=ON \ + -DWarpX_PYTHON=ON \ -DWarpX_OPENPMD=ON \ -DWarpX_openpmd_internal=OFF \ -DWarpX_PRECISION=SINGLE cmake --build build_sp -j 3 - - python3 -m pip install --upgrade pip setuptools wheel - export WARPX_MPI=ON - PYWARPX_LIB_DIR=$PWD/build_sp/lib python3 -m pip wheel . - python3 -m pip install *.whl + cmake --build build_sp --target pip_install - name: run pywarpx run: | diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 797ad285fd1..0b43760b621 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -163,6 +163,8 @@ jobs: runs-on: ubuntu-20.04 if: github.event.pull_request.draft == false env: + CC: clang + CXX: clang++ # On CI for this test, Ninja is slower than the default: #CMAKE_GENERATOR: Ninja # setuptools/mp4py work-around, see @@ -189,14 +191,16 @@ jobs: - name: build WarpX run: | python3 -m pip install --upgrade pip setuptools wheel - export WARPX_MPI=ON - export WARPX_OPENPMD=ON - export WARPX_PSATD=ON - export WARPX_QED_TABLE_GEN=ON - export CC=$(which clang) - export CXX=$(which clang++) + export CXXFLAGS="-Werror -Wno-error=pass-failed" - python3 -m pip install -v . + + cmake -S . -B build \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DWarpX_APP=OFF \ + -DWarpX_PSATD=ON \ + -DWarpX_PYTHON=ON \ + -DWarpX_QED_TABLE_GEN=ON + cmake --build build -j 2 --target pip_install - name: run pywarpx run: | diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index c6b89999338..e0629e3abca 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -13,6 +13,9 @@ jobs: if: github.event.pull_request.draft == false steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.x' - name: CCache Cache uses: actions/cache@v3 # - once stored under a key, they become immutable (even if local cache path content changes) @@ -33,16 +36,22 @@ jobs: -DWarpX_COMPUTE=NOACC ` -DWarpX_OPENPMD=ON ` -DWarpX_MPI=OFF ` - -DWarpX_LIB=ON + -DWarpX_PYTHON=ON if(!$?) { Exit $LASTEXITCODE } cmake --build build --config Debug --parallel 2 if(!$?) { Exit $LASTEXITCODE } python3 -m pip install --upgrade pip setuptools wheel if(!$?) { Exit $LASTEXITCODE } + cmake --build build --config Debug --target install + if(!$?) { Exit $LASTEXITCODE } cmake --build build --config Debug --target pip_install if(!$?) { Exit $LASTEXITCODE } + - name: Test + run: | + $env:PATH += ';C:/Program Files (x86)/WarpX/bin/' + python3 Examples\Tests\gaussian_beam\PICMI_inputs_gaussian_beam.py # JSON writes are currently very slow (50min) with MSVC # --diagformat=openpmd @@ -53,6 +62,10 @@ jobs: if: github.event.pull_request.draft == false steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.x' + - uses: seanmiddleditch/gha-setup-ninja@master - name: CCache Cache uses: actions/cache@v3 # - once stored under a key, they become immutable (even if local cache path content changes) @@ -65,7 +78,6 @@ jobs: restore-keys: | ccache-windows-winclang-${{ hashFiles('.github/workflows/windows.yml') }}- ccache-windows-winclang- - - uses: seanmiddleditch/gha-setup-ninja@master - name: Build & Install shell: cmd run: | @@ -78,17 +90,29 @@ jobs: -DCMAKE_VERBOSE_MAKEFILE=ON ^ -DWarpX_COMPUTE=OMP ^ -DWarpX_EB=ON ^ - -DWarpX_LIB=ON ^ + -DWarpX_PYTHON=ON ^ -DWarpX_MPI=OFF ^ -DWarpX_OPENPMD=ON if errorlevel 1 exit 1 cmake --build build --config Release --parallel 2 if errorlevel 1 exit 1 + cmake --build build --config Release --target install + if errorlevel 1 exit 1 + python3 -m pip install --upgrade pip setuptools wheel if errorlevel 1 exit 1 + python3 -m pip install --upgrade -r requirements.txt + if errorlevel 1 exit 1 + cmake --build build --config Release --target pip_install if errorlevel 1 exit 1 + - name: Test + shell: cmd + run: | + call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\vc\Auxiliary\build\vcvarsall.bat" x64 + set "PATH=C:/Program Files (x86)/WarpX/bin/;%PATH%" + python3 Examples\Tests\gaussian_beam\PICMI_inputs_gaussian_beam.py --diagformat=openpmd if errorlevel 1 exit 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index c3587942184..ffa0923fcec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,10 +64,11 @@ option(WarpX_EB "Embedded boundary support" OFF) cmake_dependent_option(WarpX_GPUCLOCK "Add GPU kernel timers (cost function)" ON "WarpX_COMPUTE STREQUAL CUDA OR WarpX_COMPUTE STREQUAL HIP" OFF) -option(WarpX_LIB "Build WarpX as a shared library" OFF) +option(WarpX_LIB "Build WarpX as a library" OFF) option(WarpX_MPI "Multi-node support (message-passing)" ON) option(WarpX_OPENPMD "openPMD I/O (HDF5, ADIOS)" ON) option(WarpX_PSATD "spectral solver support" OFF) +option(WarpX_PYTHON "Python bindings" OFF) option(WarpX_SENSEI "SENSEI in situ diagnostics" OFF) option(WarpX_QED "QED support (requires PICSAR)" ON) option(WarpX_QED_TABLE_GEN "QED table generation (requires PICSAR and Boost)" OFF) @@ -120,6 +121,15 @@ set_default_build_type("Release") # Option to enable interprocedural optimization # (also know as "link-time optimization" or "whole program optimization") option(WarpX_IPO "Compile WarpX with interprocedural optimization (will take more time)" OFF) +option(WarpX_PYTHON_IPO + "Compile Python bindings with interprocedural optimization (IPO) / link-time optimization (LTO)" + ON +) + +# enforce consistency of dependent options +if(WarpX_APP OR WarpX_PYTHON) + set(WarpX_LIB ON CACHE STRING "Build WarpX as a library" FORCE) +endif() # note: we could skip this if we solely build WarpX_APP, but if we build a # shared WarpX library or a third party, like ImpactX, uses ablastr in a @@ -168,44 +178,62 @@ if(WarpX_PSATD) endif() endif() +# Python +if(WarpX_PYTHON) + find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) + + # default installation directories: Python + warpx_set_default_install_dirs_python() + + # pybind11 + # builds pybind11 from git (default), form local source or + # finds an existing install + include(${WarpX_SOURCE_DIR}/cmake/dependencies/pybind11.cmake) + + # pyAMReX + include(${WarpX_SOURCE_DIR}/cmake/dependencies/pyAMReX.cmake) +endif() + # Targets ##################################################################### # +include(GenerateExportHeader) set(_ALL_TARGETS) foreach(D IN LISTS WarpX_DIMS) warpx_set_suffix_dims(SD ${D}) - # collect all objects for compilation - add_library(WarpX_${SD} OBJECT) - add_library(ablastr_${SD}) # ABLASTR library + add_library(ablastr_${SD}) set(_BUILDINFO_SRC ablastr_${SD}) - list(APPEND _ALL_TARGETS WarpX_${SD} ablastr_${SD}) + list(APPEND _ALL_TARGETS ablastr_${SD}) add_library(WarpX::ablastr_${SD} ALIAS ablastr_${SD}) + # link into a library (default: static) + if(WarpX_LIB) + add_library(lib_${SD}) + add_library(WarpX::lib_${SD} ALIAS lib_${SD}) + target_link_libraries(lib_${SD} PUBLIC ablastr_${SD}) + set(_BUILDINFO_SRC lib_${SD}) + list(APPEND _ALL_TARGETS lib_${SD}) + + set_target_properties(lib_${SD} PROPERTIES + POSITION_INDEPENDENT_CODE ON + WINDOWS_EXPORT_ALL_SYMBOLS ON + ) + endif() + # executable application # note: we currently avoid a dependency on a core library # for simpler usage, but could make this an option if(WarpX_APP) add_executable(app_${SD}) add_executable(WarpX::app_${SD} ALIAS app_${SD}) - target_link_libraries(app_${SD} PRIVATE WarpX_${SD} ablastr_${SD}) + target_link_libraries(app_${SD} PRIVATE lib_${SD}) set(_BUILDINFO_SRC app_${SD}) list(APPEND _ALL_TARGETS app_${SD}) endif() - # link into a shared library - if(WarpX_LIB) - add_library(shared_${SD} MODULE) - add_library(WarpX::shared_${SD} ALIAS shared_${SD}) - target_link_libraries(shared_${SD} PUBLIC WarpX_${SD} ablastr_${SD}) - set(_BUILDINFO_SRC shared_${SD}) - list(APPEND _ALL_TARGETS shared_${SD}) - - set_target_properties(WarpX_${SD} shared_${SD} PROPERTIES - POSITION_INDEPENDENT_CODE ON - WINDOWS_EXPORT_ALL_SYMBOLS ON - ) + if(WarpX_PYTHON OR WarpX_LIB) set(ABLASTR_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Build ABLASTR with position independent code" FORCE) endif() @@ -221,43 +249,143 @@ foreach(D IN LISTS WarpX_DIMS) endif() # own headers - target_include_directories(WarpX_${SD} PUBLIC - $ - $ - ) target_include_directories(ablastr_${SD} PUBLIC # future: own directory root $ + $ ) + if(WarpX_LIB) + target_include_directories(lib_${SD} PUBLIC + $ + $ + ) + endif() - # if we include we will need to call: - generate_buildinfo(${_BUILDINFO_SRC} "${WarpX_SOURCE_DIR}") - target_link_libraries(WarpX_${SD} PRIVATE buildInfo::${_BUILDINFO_SRC}) - unset(_BUILDINFO_SRC) + # build Python module (this is always a shared library) + if(WarpX_PYTHON) + add_library(pyWarpX_${SD} MODULE Source/Python/pyWarpX.cpp) + add_library(WarpX::pyWarpX_${SD} ALIAS pyWarpX_${SD}) + target_link_libraries(pyWarpX_${SD} PUBLIC lib_${SD}) + set(_BUILDINFO_SRC pyWarpX_${SD}) + list(APPEND _ALL_TARGETS pyWarpX_${SD}) + + # set Python module properties + set_target_properties(pyWarpX_${SD} PROPERTIES + # hide symbols for combining multiple pybind11 modules downstream & for + # reduced binary size + CXX_VISIBILITY_PRESET "hidden" + CUDA_VISIBILITY_PRESET "hidden" + # name of the pybind-generated python module, which is wrapped in another + # fluffy front-end modules, so we can extend it with pure Python + ARCHIVE_OUTPUT_NAME warpx_pybind_${SD} + LIBRARY_OUTPUT_NAME warpx_pybind_${SD} + # build output directories - mainly set to run tests from CMake & IDEs + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/pywarpx + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/pywarpx + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/pywarpx + PDB_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/pywarpx + COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/pywarpx + ) + get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(isMultiConfig) + foreach(CFG IN LISTS CMAKE_CONFIGURATION_TYPES) + string(TOUPPER "${CFG}" CFG_UPPER) + set_target_properties(pyWarpX_${SD} PROPERTIES + # build output directories - mainly set to run tests from CMake & IDEs + # note: same as above, but for Multi-Config generators + ARCHIVE_OUTPUT_DIRECTORY_${CFG_UPPER} ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/pywarpx + LIBRARY_OUTPUT_DIRECTORY_${CFG_UPPER} ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/pywarpx + RUNTIME_OUTPUT_DIRECTORY_${CFG_UPPER} ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/pywarpx + PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/pywarpx + COMPILE_PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/pywarpx + ) + endforeach() + endif() + if(EMSCRIPTEN) + set_target_properties(pyWarpX_${SD} PROPERTIES + PREFIX "") + else() + pybind11_extension(pyWarpX_${SD}) + endif() + if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo) + pybind11_strip(pyWarpX_${SD}) + endif() + endif() + + if(WarpX_LIB) + # if we include we will need to call: + generate_buildinfo(${_BUILDINFO_SRC} "${WarpX_SOURCE_DIR}") + target_link_libraries(lib_${SD} PRIVATE buildInfo::${_BUILDINFO_SRC}) + unset(_BUILDINFO_SRC) + + # add sources + target_sources(lib_${SD} PRIVATE Source/WarpX.cpp) + endif() # add sources - target_sources(WarpX_${SD} PRIVATE Source/WarpX.cpp) if(WarpX_APP) target_sources(app_${SD} PRIVATE Source/main.cpp) endif() endforeach() +# Headers controlling symbol visibility (for Windows) +# Note: once WarpX gets rid of all its globals, we will not need this. +# - extern ... functions +# - static class member variables +generate_export_header(ablastr_${WarpX_DIMS_LAST} + BASE_NAME ablastr + EXPORT_FILE_NAME Source/ablastr/export.H) +if(WarpX_LIB) + generate_export_header(lib_${WarpX_DIMS_LAST} + BASE_NAME warpx + EXPORT_FILE_NAME Source/Utils/export.H) +endif() +# At build-time, we might need to set WarpX__EXPORTS and ablastr__EXPORTS on all targets +foreach(D IN LISTS WarpX_DIMS) + warpx_set_suffix_dims(SD ${D}) + target_compile_definitions(ablastr_${SD} PRIVATE ablastr_${WarpX_DIMS_LAST}_EXPORTS) + if(WarpX_LIB) + target_compile_definitions(lib_${SD} PRIVATE lib_${WarpX_DIMS_LAST}_EXPORTS) # note: some collision risk here + endif() + # Static libs: WARPX_STATIC_DEFINE and ABLASTR_STATIC_DEFINE during build time + # note: using a static lib (lib_${SD}) in a .dll (pyWarpX_${SD}) still needs the exports for + # dllimport at DLL build time. + # https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(ablastr_${SD} PRIVATE ABLASTR_STATIC_DEFINE) + if(WarpX_LIB) + target_compile_definitions(lib_${SD} PRIVATE WARPX_STATIC_DEFINE) + endif() + endif() +endforeach() + +if(WarpX_PYTHON) + # copy PICMI and other Python scripts to build directory + add_custom_command(TARGET pyWarpX_${WarpX_DIMS_LAST} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${WarpX_SOURCE_DIR}/Python/pywarpx + $ + ) +endif() + add_subdirectory(Source/ablastr) -add_subdirectory(Source/AcceleratorLattice) -add_subdirectory(Source/BoundaryConditions) -add_subdirectory(Source/Diagnostics) -add_subdirectory(Source/EmbeddedBoundary) -add_subdirectory(Source/Evolve) -add_subdirectory(Source/FieldSolver) -add_subdirectory(Source/Filter) -add_subdirectory(Source/Initialization) -add_subdirectory(Source/Laser) -add_subdirectory(Source/Parallelization) -add_subdirectory(Source/Particles) -add_subdirectory(Source/Python) -add_subdirectory(Source/Utils) - -# Interprocedural optimization +if(WarpX_LIB) + add_subdirectory(Source/AcceleratorLattice) + add_subdirectory(Source/BoundaryConditions) + add_subdirectory(Source/Diagnostics) + add_subdirectory(Source/EmbeddedBoundary) + add_subdirectory(Source/Evolve) + add_subdirectory(Source/FieldSolver) + add_subdirectory(Source/Filter) + add_subdirectory(Source/Initialization) + add_subdirectory(Source/Laser) + add_subdirectory(Source/Parallelization) + add_subdirectory(Source/Particles) + add_subdirectory(Source/Python) + add_subdirectory(Source/Utils) +endif() + +# Interprocedural optimization (IPO) / Link-Time Optimization (LTO) if(WarpX_IPO) enable_IPO("${_ALL_TARGETS}") endif() @@ -270,7 +398,6 @@ foreach(D IN LISTS WarpX_DIMS) else() target_link_libraries(ablastr_${SD} PUBLIC WarpX::thirdparty::amrex_${D}d) endif() - target_link_libraries(WarpX_${SD} PUBLIC ablastr_${SD}) if(WarpX_PSATD) target_link_libraries(ablastr_${SD} PUBLIC WarpX::thirdparty::FFT) @@ -286,6 +413,13 @@ foreach(D IN LISTS WarpX_DIMS) endif() endif() + if(WarpX_PYTHON) + target_link_libraries(pyWarpX_${SD} PRIVATE pybind11::module pybind11::windows_extras) + if(WarpX_PYTHON_IPO) + target_link_libraries(pyWarpX_${SD} PRIVATE pybind11::lto) + endif() + endif() + if(WarpX_OPENPMD) target_link_libraries(ablastr_${SD} PUBLIC openPMD::openPMD) endif() @@ -325,14 +459,6 @@ endif() foreach(D IN LISTS WarpX_DIMS) warpx_set_suffix_dims(SD ${D}) - # avoid building all object files if we are only used as ABLASTR library - if(NOT WarpX_APP AND NOT WarpX_LIB) - set_target_properties(WarpX_${SD} PROPERTIES - EXCLUDE_FROM_ALL 1 - EXCLUDE_FROM_DEFAULT_BUILD 1 - ) - endif() - # fancy binary name for build variants set_warpx_binary_name(${D}) endforeach() @@ -371,10 +497,32 @@ foreach(D IN LISTS WarpX_DIMS) target_compile_definitions(ablastr_${SD} PUBLIC WARPX_USE_PSATD) endif() + if(WarpX_PYTHON) + # for module __version__ + target_compile_definitions(pyWarpX_${SD} PRIVATE + PYWARPX_VERSION_INFO=${pyWarpX_VERSION_INFO}) + endif() + # : M_PI if(WIN32) target_compile_definitions(ablastr_${SD} PUBLIC _USE_MATH_DEFINES) endif() + + # Windows DLLs and Global Symbols + # https://stackoverflow.com/questions/54560832/cmake-windows-export-all-symbols-does-not-cover-global-variables/54568678#54568678 + # + if(WIN32 AND BUILD_SHARED_LIBS) + set(ABLASTR_IS_DLL ON) + target_compile_definitions(ablastr_${SD} PRIVATE ABLASTR_IS_DLL_BUILDING) + endif() + if(WIN32 AND WarpX_LIB AND BUILD_SHARED_LIBS) + set(ABLASTR_IS_DLL ON) + target_compile_definitions(lib_${SD} PRIVATE ABLASTR_IS_DLL_BUILDING) + endif() + if(WIN32 AND WarpX_PYTHON) + set(ABLASTR_IS_DLL ON) + target_compile_definitions(pyWarpX_${SD} PRIVATE ABLASTR_IS_DLL_BUILDING) + endif() endforeach() @@ -413,7 +561,10 @@ foreach(D IN LISTS WarpX_DIMS) list(APPEND WarpX_INSTALL_TARGET_NAMES app_${SD}) endif() if(WarpX_LIB) - list(APPEND WarpX_INSTALL_TARGET_NAMES shared_${SD}) + list(APPEND WarpX_INSTALL_TARGET_NAMES lib_${SD}) + endif() + if(WarpX_PYTHON) + list(APPEND WarpX_INSTALL_TARGET_NAMES pyWarpX_${SD}) endif() install(TARGETS ${WarpX_INSTALL_TARGET_NAMES} @@ -427,25 +578,26 @@ foreach(D IN LISTS WarpX_DIMS) # simplified library alias # this is currently expected by Python bindings if(WarpX_LIB) - if(D STREQUAL "RZ") - set(lib_dim "rz") - else() - set(lib_dim "${WarpX_DIMS}d") - endif() if(IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR}) - set(ABS_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR}) + set(ABS_INSTALL_LIB_DIR "${CMAKE_INSTALL_LIBDIR}") else() - set(ABS_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) + set(ABS_INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") endif() # escape spaces for generated cmake_install.cmake file file(TO_CMAKE_PATH "${ABS_INSTALL_LIB_DIR}" ABS_INSTALL_LIB_DIR) install(CODE "file(CREATE_LINK - $ - \"${ABS_INSTALL_LIB_DIR}/libwarpx.${lib_dim}$\" + $ + \"${ABS_INSTALL_LIB_DIR}/libwarpx.${SD}$\" COPY_ON_ERROR SYMBOLIC)") endif() + # WarpX + # Utils/WarpXVersion.H + + # ABLASTR + # export.H + # CMake package file for find_package(WarpX::WarpX) in depending projects #install(EXPORT WarpXTargets # FILE WarpXTargets.cmake @@ -463,10 +615,17 @@ endforeach() # pip helpers for the pywarpx package ######################################### # -if(WarpX_LIB) +if(WarpX_PYTHON) set(PYINSTALLOPTIONS "" CACHE STRING "Additional parameters to pass to `pip install`") + # ensure all targets are built before we package them in a wheel + set(pyWarpX_INSTALL_TARGET_NAMES) + foreach(D IN LISTS WarpX_DIMS) + warpx_set_suffix_dims(SD ${D}) + list(APPEND pyWarpX_INSTALL_TARGET_NAMES pyWarpX_${SD}) + endforeach() + # add a prefix to custom targets so we do not collide if used as a subproject if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) set(_WarpX_CUSTOM_TARGET_PREFIX_DEFAULT "") @@ -476,16 +635,16 @@ if(WarpX_LIB) set(WarpX_CUSTOM_TARGET_PREFIX "${_WarpX_CUSTOM_TARGET_PREFIX_DEFAULT}" CACHE STRING "Prefix for custom targets") - # build the wheel by re-using the shared library we build + # build the wheel by re-using the python module that we build add_custom_target(${WarpX_CUSTOM_TARGET_PREFIX}pip_wheel ${CMAKE_COMMAND} -E rm -f -r warpx-whl COMMAND - ${CMAKE_COMMAND} -E env PYWARPX_LIB_DIR=$ + ${CMAKE_COMMAND} -E env PYWARPX_LIB_DIR=$ python3 -m pip wheel -v --no-build-isolation --no-deps --wheel-dir=warpx-whl ${WarpX_SOURCE_DIR} WORKING_DIRECTORY ${WarpX_BINARY_DIR} DEPENDS - shared_${WarpX_DIMS_LAST} + ${pyWarpX_INSTALL_TARGET_NAMES} ) # this will also upgrade/downgrade dependencies, e.g., when the version of picmistandard changes @@ -500,6 +659,13 @@ if(WarpX_LIB) ${WarpX_BINARY_DIR} ) + # if we do a superbuild, make sure we install pyAMReX via its custom install + # target + set(_EXTRA_INSTALL_DEPENDS) + if(WarpX_pyamrex_internal OR WarpX_pyamrex_src) + set(_EXTRA_INSTALL_DEPENDS pyamrex_pip_install) + endif() + # We force-install because in development, it is likely that the version of # the package does not change, but the code did change. We need --no-deps, # because otherwise pip would also force reinstall all dependencies. @@ -509,9 +675,10 @@ if(WarpX_LIB) WORKING_DIRECTORY ${WarpX_BINARY_DIR} DEPENDS - shared_${WarpX_DIMS_LAST} + pyWarpX_${WarpX_DIMS_LAST} ${WarpX_CUSTOM_TARGET_PREFIX}pip_wheel ${WarpX_CUSTOM_TARGET_PREFIX}pip_install_requirements + ${_EXTRA_INSTALL_DEPENDS} ) endif() diff --git a/Docs/source/install/cmake.rst b/Docs/source/install/cmake.rst index 2ea731561aa..a778909ae0a 100644 --- a/Docs/source/install/cmake.rst +++ b/Docs/source/install/cmake.rst @@ -40,6 +40,7 @@ From the base of the WarpX source directory, execute: # find dependencies & configure # see additional options below, e.g. + # -DWarpX_PYTHON=ON # -DCMAKE_INSTALL_PREFIX=$HOME/sw/warpx cmake -S . -B build @@ -64,7 +65,7 @@ You can inspect and modify build options after running ``cmake -S . -B build`` w ccmake build or by adding arguments with ``-D