Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use "Include What You Use" on WarpX #1947

Merged
merged 71 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
61347a8
initial tests with IWYU
lucafedeli88 May 9, 2021
ce3e39c
added a couple of forward declarations
lucafedeli88 May 10, 2021
523006c
used iwyu on more files
lucafedeli88 May 10, 2021
3e39b87
progress
lucafedeli88 May 11, 2021
397e612
used iwyu on more files
lucafedeli88 May 11, 2021
0f88dfc
progress with iwyu
lucafedeli88 May 11, 2021
02ddc41
progress with iwyu
lucafedeli88 May 11, 2021
1f2f793
fixed bug
lucafedeli88 May 11, 2021
0758826
progress with iwyu
lucafedeli88 May 11, 2021
2cd1fa0
progress with IWYU
lucafedeli88 May 12, 2021
3f61f6f
progress with IWYU
lucafedeli88 May 12, 2021
ab6667c
fixed merge conflict
lucafedeli88 May 12, 2021
0088e48
fixed bug
lucafedeli88 May 12, 2021
b178fe3
fixed bug
lucafedeli88 May 12, 2021
2c13171
progress with IWYU
lucafedeli88 May 12, 2021
dbb9cd7
progress with IWYU + use forward declarations in WarpX.H
lucafedeli88 May 12, 2021
377cfe7
first try with .def files
lucafedeli88 May 15, 2021
a4ff747
fix bugs
lucafedeli88 May 15, 2021
7a9f121
progress with IWYU
lucafedeli88 May 17, 2021
ea84d3c
fix merge conflict
lucafedeli88 May 17, 2021
c4a319d
progress with IWYU
lucafedeli88 May 17, 2021
845a8e0
progress with iwyu
lucafedeli88 May 18, 2021
e77595c
fixed merge conflict
lucafedeli88 May 20, 2021
3510163
correct copyright
lucafedeli88 May 20, 2021
6d17b53
fixed bug
lucafedeli88 May 20, 2021
8aea73f
fixed bugs
lucafedeli88 May 20, 2021
90ed4ce
fix missing include
lucafedeli88 May 21, 2021
d8a42f0
Merge remote-tracking branch 'upstream/development' into use_iwyu
lucafedeli88 May 21, 2021
ff96003
fixed bug
lucafedeli88 May 22, 2021
e01484a
Merge remote-tracking branch 'upstream/development' into use_iwyu
lucafedeli88 May 22, 2021
4ec73cb
fix bug
lucafedeli88 May 22, 2021
f3ca90a
fix bug introduced during last bugfix
lucafedeli88 May 22, 2021
ed35716
use iwyu on newly added files
lucafedeli88 May 22, 2021
bb3b6ac
add space
lucafedeli88 May 22, 2021
7a2abbc
fix bug
lucafedeli88 May 22, 2021
620ba3c
fix missing include
lucafedeli88 May 22, 2021
8bdadbe
fix missing include
lucafedeli88 May 22, 2021
59a45ee
fix missing include
lucafedeli88 May 22, 2021
7e03a34
fixed bugs
lucafedeli88 May 22, 2021
50394a4
fixed bug
lucafedeli88 May 22, 2021
f965f6e
attempt at fixing issue with math functions
lucafedeli88 May 24, 2021
c66ddb0
fixed merge conflict
lucafedeli88 May 24, 2021
39644ba
fixed merge conflict
lucafedeli88 May 25, 2021
d4c2fc5
added missing include
lucafedeli88 May 25, 2021
c4ba1f9
fixed missing include
lucafedeli88 May 25, 2021
e943840
Merge remote-tracking branch 'upstream/development' into use_iwyu
lucafedeli88 Jun 1, 2021
761fe17
fixed merge
lucafedeli88 Jun 10, 2021
90d98bd
using _fwd.H
lucafedeli88 Jun 10, 2021
8ca245e
fixed bug
lucafedeli88 Jun 10, 2021
5299f3b
progress with iwyu
lucafedeli88 Jun 10, 2021
c962551
Merge remote-tracking branch 'upstream/development' into use_iwyu
lucafedeli88 Jun 13, 2021
721d814
update AMReX branch
lucafedeli88 Jun 13, 2021
67303e8
fixed merge
lucafedeli88 Jun 14, 2021
829a112
enforce alphabetic order
lucafedeli88 Jun 14, 2021
35d3723
progress with iwyu
lucafedeli88 Jun 14, 2021
fd0126c
Merge remote-tracking branch 'upstream/development' into use_iwyu
lucafedeli88 Jun 15, 2021
4d6166e
use right version of amrex
lucafedeli88 Jun 15, 2021
9b482a6
use right version of amrex for tests
lucafedeli88 Jun 15, 2021
6fceb05
fixed bug
lucafedeli88 Jun 15, 2021
f690826
fix another bug
lucafedeli88 Jun 15, 2021
106287f
fix missing include
lucafedeli88 Jun 15, 2021
6572bf7
fix missing include
lucafedeli88 Jun 15, 2021
2ba8484
fix missing include
lucafedeli88 Jun 15, 2021
f9ab286
updated amrex
lucafedeli88 Jun 15, 2021
ad2e7a0
initial work to document new include strategy
lucafedeli88 Jun 17, 2021
eae69d7
fixed merge conflicts
lucafedeli88 Jun 24, 2021
6288550
updated documentation
lucafedeli88 Jun 24, 2021
dc1b020
Fix rst & private includes
ax3l Jun 25, 2021
547f6ed
Remove accidentially added files
ax3l Jun 25, 2021
43ff84d
Fix rst code blocks
ax3l Jun 25, 2021
f1d9cae
one more rst block
ax3l Jun 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions Docs/source/developers/repo_organization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,63 @@ All WarpX header files need to be specified relative to the ``Source/`` director
- e.g. ``#include "Utils/WarpXConst.H"``
- files in the same directory as the including header-file can be included with ``#include "FileName.H"``

The `include order <https://github.com/ECP-WarpX/WarpX/pull/874#issuecomment-607038803>`_ and `proper quotation marks <https://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html>`_ are:
By default, in a ``MyName.cpp`` source file we do not include headers already included in ``MyName.H``. Besides this exception, if a function or a class
is used in a source file, the header file containing its declaration must be included, unless the inclusion of a façade header is more appropriate. This is
ax3l marked this conversation as resolved.
Show resolved Hide resolved
sometimes the case for AMReX headers. For instance ``AMReX_GpuLaunch.H`` is a façade header for ``AMReX_GpuLaunchFunctsC.H`` and ``AMReX_GpuLaunchFunctsG.H``, which
contain respectively the CPU and the GPU implemetation of some methods, and which should not be included directly.
Whenever possible, forward declarations headers are included instead of the actual headers, in order to save compilation time (see dedicated section below). In WarpX forward
declaration headers have the suffix ``*_fwd.H``, while in AMReX they have the suffix ``*Fwd.H``.
The include order (see `PR #874 <https://github.com/ECP-WarpX/WarpX/pull/874#issuecomment-607038803>` _ and `PR #1947 <https://github.com/ECP-WarpX/WarpX/pull/1947>` ) _ and `proper quotation marks <https://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html>`_ are:

1. In a ``<MyName>.cpp`` file: ``#include "<MyName>.H"`` (its header) then
1. In a ``MyName.cpp`` file: ``#include "MyName.H"`` (its header) then
ax3l marked this conversation as resolved.
Show resolved Hide resolved
2. (further) WarpX header files ``#include "..."`` then
3. PICSAR and AMReX header files ``#include <...>`` then
4. other third party includes ``#include <...>`` then
5. standard library includes, e.g. ``#include <vector>``
3. WarpX forward declaration header files ``#include "..._fwd.H"``
4. AMReX header files ``#include <...>`` then
5. AMReX forward declaration header files ``#include <...Fwd.H>`` then
6. PICSAR header files ``#include <...>`` then
7. other third party includes ``#include <...>`` then
8. standard library includes, e.g. ``#include <vector>``

For details why this is needed, please see `PR #874 <https://github.com/ECP-WarpX/WarpX/pull/874#issuecomment-607038803>`_, the `LLVM guidelines <https://llvm.org/docs/CodingStandards.html#include-style>`_, and `include-what-you-use <https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md>`_.
1. In a ``MyName.H`` file: ``#include "MyName_fwd.H"`` (the corresponding forward declaration header, if it exists) then
ax3l marked this conversation as resolved.
Show resolved Hide resolved
2. WarpX header files ``#include "..."`` then
3. WarpX forward declaration header files ``#include "..._fwd.H"``
4. AMReX header files ``#include <...>`` then
5. AMReX forward declaration header files ``#include <...Fwd.H>`` then
6. PICSAR header files ``#include <...>`` then
7. other third party includes ``#include <...>`` then
8. standard library includes, e.g. ``#include <vector>``

Each of these groups of header files should ideally be sorted alphabetically, and a blank line should be placed between the groups.

For details why this is needed, please see `PR #874 <https://github.com/ECP-WarpX/WarpX/pull/874#issuecomment-607038803>`_, `PR #1947 <https://github.com/ECP-WarpX/WarpX/pull/1947>`_, the `LLVM guidelines <https://llvm.org/docs/CodingStandards.html#include-style>`_, and `include-what-you-use <https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md>`_.

Forward declaration headers
------------
ax3l marked this conversation as resolved.
Show resolved Hide resolved
Forward declarations can be used when a header file needs only to know that a given class exists, without any further detail (e.g., when only a pointer to an instance of
that class is used). Forward declaration headers are a convenient way to organize forward declarations. If a forward declaration is needed for a given class ``MyClass``, declared in ``MyClass.H``,
the forward declaration should appear in a header file named ``MyClass_fwd.H``, placed in the same folder containing ``MyClass.H``.
Below we provide a simple example:

``MyClass_fwd.H``:
.. code-block:: cpp
ax3l marked this conversation as resolved.
Show resolved Hide resolved
class MyClass;

``MyClass.H``:
.. code-block:: cpp
#include “MyClass_fwd.H”
#include “someHeader.H”
class MyClass{/* stuff */};

``MyClass.cpp``:
.. code-block:: cpp
#include “MyClass.H”
class MyClass{/* stuff */};

Usage:
``SimpleUsage.H``
.. code-block:: cpp
#include “MyClass_fwd.H”
#include <memory>
ax3l marked this conversation as resolved.
Show resolved Hide resolved

WarpX-specific vocabulary
-------------------------
Expand Down
19 changes: 16 additions & 3 deletions Source/BoundaryConditions/PML.H
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,28 @@
#ifndef WARPX_PML_H_
#define WARPX_PML_H_

#include "Utils/WarpXProfilerWrapper.H"
#include "PML_fwd.H"

#ifdef WARPX_USE_PSATD
# include "FieldSolver/SpectralSolver/SpectralSolver.H"
#endif

#include <AMReX_MultiFab.H>
#include <AMReX_Geometry.H>
#include <AMReX_BoxArray.H>
#include <AMReX_Config.H>
#include <AMReX_FabArray.H>
ax3l marked this conversation as resolved.
Show resolved Hide resolved
#include <AMReX_FabFactory.H>
#include <AMReX_GpuContainers.H>
#include <AMReX_IntVect.H>
#include <AMReX_REAL.H>
#include <AMReX_Vector.H>

#include <array>
#include <AMReX_BaseFwd.H>
ax3l marked this conversation as resolved.
Show resolved Hide resolved

#include <array>
#include <memory>
#include <string>
#include <vector>

struct Sigma : amrex::Gpu::DeviceVector<amrex::Real>
{
Expand Down Expand Up @@ -170,6 +181,8 @@ public:

static void Exchange (amrex::MultiFab& pml, amrex::MultiFab& reg, const amrex::Geometry& geom, int do_pml_in_domain);

~PML () = default;

private:
bool m_ok;

Expand Down
37 changes: 30 additions & 7 deletions Source/BoundaryConditions/PML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,46 @@
*
* License: BSD-3-Clause-LBNL
*/
#include "PML.H"

#include "BoundaryConditions/PML.H"
#include "BoundaryConditions/PMLComponent.H"
#include "Utils/WarpXConst.H"
#ifdef WARPX_USE_PSATD
# include "FieldSolver/SpectralSolver/SpectralFieldData.H"
#endif
#include "Utils/WarpXAlgorithmSelection.H"
#include "Utils/WarpXConst.H"
#include "Utils/WarpXProfilerWrapper.H"
#include "WarpX.H"

#include <AMReX.H>
#include <AMReX_Print.H>
#include <AMReX_Algorithm.H>
#include <AMReX_Array.H>
#include <AMReX_Array4.H>
#include <AMReX_BLassert.H>
#include <AMReX_Box.H>
#include <AMReX_BoxList.H>
#include <AMReX_DistributionMapping.H>
#include <AMReX_FArrayBox.H>
#include <AMReX_FBI.H>
#include <AMReX_FabArrayBase.H>
#include <AMReX_Geometry.H>
#include <AMReX_GpuControl.H>
#include <AMReX_GpuDevice.H>
#include <AMReX_GpuLaunch.H>
#include <AMReX_GpuQualifiers.H>
#include <AMReX_IndexType.H>
#include <AMReX_MFIter.H>
#include <AMReX_ParmParse.H>
#include <AMReX_RealVect.H>
#include <AMReX_SPACE.H>
#include <AMReX_VisMF.H>

#ifdef AMREX_USE_OMP
# include <omp.h>
#endif
#include <AMReX_ccse-mpi.H>
ax3l marked this conversation as resolved.
Show resolved Hide resolved

#include <algorithm>
#include <cmath>
#include <memory>

#include <utility>

using namespace amrex;

Expand Down
1 change: 1 addition & 0 deletions Source/BoundaryConditions/PML_current.H
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define PML_CURRENT_H_

#include "BoundaryConditions/PMLComponent.H"

#include <AMReX.H>
#include <AMReX_FArrayBox.H>

Expand Down
16 changes: 16 additions & 0 deletions Source/BoundaryConditions/PML_fwd.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright 2021 Luca Fedeli
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/

struct Sigma;
struct SigmaBox;

class SigmaBoxFactory;
class MultiSigmaBox;

enum struct PatchType;

class PML;
27 changes: 21 additions & 6 deletions Source/BoundaryConditions/WarpXEvolvePML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,33 @@
* License: BSD-3-Clause-LBNL
*/
#include "WarpX.H"
#include "Utils/WarpXConst.H"
#include "WarpX_PML_kernels.H"

#include "BoundaryConditions/PML.H"
#include "PML_current.H"
#include "Utils/WarpXProfilerWrapper.H"
#include "WarpX_PML_kernels.H"

#ifdef BL_USE_SENSEI_INSITU
# include <AMReX_AmrMeshInSituBridge.H>
#endif

#include <cmath>
#include <limits>

#include <AMReX_Array4.H>
#include <AMReX_Config.H>
#include <AMReX_Extension.H>
#include <AMReX_FabArray.H>
#include <AMReX_GpuControl.H>
#include <AMReX_GpuLaunch.H>
#include <AMReX_GpuQualifiers.H>
#include <AMReX_IndexType.H>
#include <AMReX_IntVect.H>
#include <AMReX_MFIter.H>
#include <AMReX_MultiFab.H>
#include <AMReX_REAL.H>
#include <AMReX_Vector.H>

#include <AMReX_BaseFwd.H>

#include <array>
#include <memory>

using namespace amrex;

Expand Down
9 changes: 7 additions & 2 deletions Source/BoundaryConditions/WarpXFieldBoundaries.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#include "WarpX.H"

#include "WarpX_PEC.H"
#include <AMReX.H>

#include <AMReX_REAL.H>
#include <AMReX_Vector.H>
#include <AMReX_MultiFab.H>

#include <array>
#include <memory>

using namespace amrex::literals;

void WarpX::ApplyEfieldBoundary(const int lev, PatchType patch_type)
Expand Down
12 changes: 12 additions & 0 deletions Source/BoundaryConditions/WarpX_PEC.H
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
#include "WarpX.H"
#include "Utils/WarpXAlgorithmSelection.H"

#include <AMReX_Array.H>
#include <AMReX_Array4.H>
#include <AMReX_Config.H>
#include <AMReX_Extension.H>
#include <AMReX_GpuQualifiers.H>
#include <AMReX_IntVect.H>
#include <AMReX_REAL.H>

#include <AMReX_BaseFwd.H>

#include <array>
#include <memory>

namespace PEC {
using namespace amrex;
Expand Down
14 changes: 11 additions & 3 deletions Source/BoundaryConditions/WarpX_PEC.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#include "BoundaryConditions/WarpX_PEC.H"

#include "WarpX.H"
#include <AMReX.H>
#include <AMReX_Vector.H>

#include <AMReX_Box.H>
#include <AMReX_Geometry.H>
#include <AMReX_GpuControl.H>
#include <AMReX_GpuLaunch.H>
#include <AMReX_IndexType.H>
#include <AMReX_MFIter.H>
#include <AMReX_MultiFab.H>
using namespace amrex::literals;
#include <AMReX_SPACE.H>
#include <AMReX_Vector.H>

using namespace amrex::literals;

bool
PEC::isAnyBoundaryPEC() {
Expand Down
1 change: 1 addition & 0 deletions Source/BoundaryConditions/WarpX_PML_kernels.H
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define WARPX_PML_KERNELS_H_

#include "BoundaryConditions/PMLComponent.H"

#include <AMReX.H>
#include <AMReX_FArrayBox.H>

Expand Down
9 changes: 7 additions & 2 deletions Source/Diagnostics/BTD_Plotfile_Header_Impl.H
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#ifndef BTD_PLOTFILE_HEADER_IMPL_H
#define BTD_PLOTFILE_HEADER_IMPL_H

#include <string>
#include <AMReX_Array.H>
#include <AMReX_Box.H>
#include <AMReX_BoxArray.H>
#include <AMReX_Config.H>
#include <AMReX_REAL.H>
#include <AMReX_SPACE.H>
#include <AMReX_Vector.H>
#include <AMReX_MultiFab.H>

#include <string>

/**
* \brief Class to read, modify, and write plotfile header when
Expand Down
11 changes: 7 additions & 4 deletions Source/Diagnostics/BTD_Plotfile_Header_Impl.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#include "BTD_Plotfile_Header_Impl.H"

#include "WarpX.H"

#include <AMReX_ParallelDescriptor.H>
#include <AMReX_PlotFileUtil.H>
#include <AMReX.H>
#include <AMReX_FileSystem.H>
#include <AMReX_INT.H>
#include <memory>
#include <AMReX_Print.H>
#include <AMReX_Utility.H>

using namespace amrex::literals;
#include <array>
#include <istream>

using namespace amrex::literals;

BTDPlotfileHeaderImpl::BTDPlotfileHeaderImpl (std::string const & Headerfile_path)
: m_Header_path(Headerfile_path)
Expand Down
14 changes: 14 additions & 0 deletions Source/Diagnostics/BTDiagnostics.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
#define WARPX_BTDIAGNOSTICS_H_

#include "Diagnostics.H"
#include "Diagnostics/ComputeDiagFunctors/ComputeDiagFunctor.H"
#include "Utils/WarpXConst.H"

#include <AMReX_Box.H>
#include <AMReX_Geometry.H>
#include <AMReX_IntVect.H>
#include <AMReX_MultiFab.H>
#include <AMReX_REAL.H>
#include <AMReX_RealBox.H>
#include <AMReX_Vector.H>

#include <limits>
#include <memory>
#include <string>

class
BTDiagnostics final : public Diagnostics
Expand Down
30 changes: 23 additions & 7 deletions Source/Diagnostics/BTDiagnostics.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
#include "BTDiagnostics.H"

#include "BTD_Plotfile_Header_Impl.H"
#include "WarpX.H"
#include "Utils/WarpXConst.H"
#include "ComputeDiagFunctors/ComputeDiagFunctor.H"
#include "ComputeDiagFunctors/CellCenterFunctor.H"
#include "ComputeDiagFunctors/BackTransformFunctor.H"
#include "ComputeDiagFunctors/CellCenterFunctor.H"
#include "ComputeDiagFunctors/ComputeDiagFunctor.H"
#include "ComputeDiagFunctors/RhoFunctor.H"
#include "Diagnostics/Diagnostics.H"
#include "Diagnostics/FlushFormats/FlushFormat.H"
#include "Utils/CoarsenIO.H"
#include "Utils/WarpXConst.H"
#include "Utils/WarpXUtil.H"
#include "WarpX.H"


#include <AMReX.H>
#include <AMReX_Algorithm.H>
#include <AMReX_BLassert.H>
#include <AMReX_BoxArray.H>
#include <AMReX_Config.H>
#include <AMReX_CoordSys.H>
#include <AMReX_DistributionMapping.H>
#include <AMReX_FileSystem.H>
#include <AMReX_ParallelContext.H>
#include <AMReX_ParallelDescriptor.H>
#include <AMReX_PlotFileUtil.H>
#include <AMReX_VisMF.H>
#include <AMReX_ParmParse.H>
#include <AMReX_Utility.H>

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <memory>
#include <vector>

using namespace amrex::literals;

Expand Down
Loading