Skip to content

Commit 8734942

Browse files
authored
SpectralFieldData, SpectralFieldDataRZ, SpectralSolver : move implementation of some methods from the header to the cpp file (BLAST-WarpX#6226)
This PR moves the implementation of some methods of `SpectralFieldData`, `SpectralFieldDataRZ`, and `SpectralSolver` from the header file to the cpp file. This makes the header files smaller and more readable.
1 parent ee3efe7 commit 8734942

File tree

6 files changed

+135
-94
lines changed

6 files changed

+135
-94
lines changed

Source/FieldSolver/SpectralSolver/SpectralFieldDataRZ.H

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -77,59 +77,22 @@ class SpectralFieldDataRZ
7777
* \param[in] src_comp component of the source FabArray from which the data are copied
7878
* \param[in] dest_comp component of the destination FabArray where the data are copied
7979
*/
80-
void CopySpectralDataComp (int src_comp, int dest_comp)
81-
{
82-
// In spectral space fields of each mode are grouped together, so that the index
83-
// of a field for a specific mode is given by field_index + mode*n_fields.
84-
// That’s why, looping over all azimuthal modes, we need to take into account corresponding
85-
// shift, given by imode * m_n_fields.
86-
for (int imode=0 ; imode < n_rz_azimuthal_modes ; imode++)
87-
{
88-
const int shift_comp = imode * m_n_fields;
89-
// The last two arguments represent the number of components and
90-
// the number of ghost cells to perform this operation
91-
Copy(fields, fields, src_comp + shift_comp, dest_comp + shift_comp, 1, 0);
92-
}
93-
}
80+
void CopySpectralDataComp (int src_comp, int dest_comp);
9481

9582
/**
9683
* \brief Set to zero the data on component \c icomp of \c fields
9784
*
9885
* \param[in] icomp component of the FabArray where the data are set to zero
9986
*/
100-
void ZeroOutDataComp(int icomp)
101-
{
102-
// In spectral space fields of each mode are grouped together, so that the index
103-
// of a field for a specific mode is given by field_index + mode*n_fields.
104-
// That’s why, looping over all azimuthal modes, we need to take into account corresponding
105-
// shift, given by imode * m_n_fields.
106-
for (int imode=0 ; imode < n_rz_azimuthal_modes ; imode++)
107-
{
108-
const int shift_comp = imode * m_n_fields;
109-
// The last argument represents the number of components to perform this operation
110-
fields.setVal(0., icomp + shift_comp, 1);
111-
}
112-
}
87+
void ZeroOutDataComp(int icomp);
11388

11489
/**
11590
* \brief Scale the data on component \c icomp of \c fields by a given scale factor
11691
*
11792
* \param[in] icomp component of the FabArray where the data are scaled
11893
* \param[in] scale_factor scale factor to use for scaling
11994
*/
120-
void ScaleDataComp(int icomp, amrex::Real scale_factor)
121-
{
122-
// In spectral space fields of each mode are grouped together, so that the index
123-
// of a field for a specific mode is given by field_index + mode*n_fields.
124-
// That’s why, looping over all azimuthal modes, we need to take into account corresponding
125-
// shift, given by imode * m_n_fields.
126-
for (int imode=0 ; imode < n_rz_azimuthal_modes ; imode++)
127-
{
128-
const int shift_comp = imode * m_n_fields;
129-
// The last argument represents the number of components to perform this operation
130-
fields.mult(scale_factor, icomp + shift_comp, 1);
131-
}
132-
}
95+
void ScaleDataComp(int icomp, amrex::Real scale_factor);
13396

13497
void InitFilter (amrex::IntVect const & filter_npass_each_dir, bool compensation,
13598
SpectralKSpaceRZ const & k_space);

Source/FieldSolver/SpectralSolver/SpectralFieldDataRZ.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,50 @@ SpectralFieldDataRZ::BackwardTransform (const int lev,
751751

752752
}
753753

754+
755+
void SpectralFieldDataRZ::CopySpectralDataComp (const int src_comp, const int dest_comp)
756+
{
757+
// In spectral space fields of each mode are grouped together, so that the index
758+
// of a field for a specific mode is given by field_index + mode*n_fields.
759+
// That’s why, looping over all azimuthal modes, we need to take into account corresponding
760+
// shift, given by imode * m_n_fields.
761+
for (int imode=0 ; imode < n_rz_azimuthal_modes ; imode++)
762+
{
763+
const int shift_comp = imode * m_n_fields;
764+
// The last two arguments represent the number of components and
765+
// the number of ghost cells to perform this operation
766+
Copy(fields, fields, src_comp + shift_comp, dest_comp + shift_comp, 1, 0);
767+
}
768+
}
769+
770+
void SpectralFieldDataRZ::ZeroOutDataComp(const int icomp)
771+
{
772+
// In spectral space fields of each mode are grouped together, so that the index
773+
// of a field for a specific mode is given by field_index + mode*n_fields.
774+
// That’s why, looping over all azimuthal modes, we need to take into account corresponding
775+
// shift, given by imode * m_n_fields.
776+
for (int imode=0 ; imode < n_rz_azimuthal_modes ; imode++)
777+
{
778+
const int shift_comp = imode * m_n_fields;
779+
// The last argument represents the number of components to perform this operation
780+
fields.setVal(0., icomp + shift_comp, 1);
781+
}
782+
}
783+
784+
void SpectralFieldDataRZ::ScaleDataComp(const int icomp, const amrex::Real scale_factor)
785+
{
786+
// In spectral space fields of each mode are grouped together, so that the index
787+
// of a field for a specific mode is given by field_index + mode*n_fields.
788+
// That’s why, looping over all azimuthal modes, we need to take into account corresponding
789+
// shift, given by imode * m_n_fields.
790+
for (int imode=0 ; imode < n_rz_azimuthal_modes ; imode++)
791+
{
792+
const int shift_comp = imode * m_n_fields;
793+
// The last argument represents the number of components to perform this operation
794+
fields.mult(scale_factor, icomp + shift_comp, 1);
795+
}
796+
}
797+
754798
/* \brief Initialize arrays used for filtering */
755799
void
756800
SpectralFieldDataRZ::InitFilter (amrex::IntVect const & filter_npass_each_dir, bool const compensation,

Source/FieldSolver/SpectralSolver/SpectralSolver.H

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -130,33 +130,23 @@ class SpectralSolver
130130
void ComputeSpectralDivE (
131131
int lev,
132132
ablastr::fields::VectorField const & Efield,
133-
amrex::MultiFab& divE
134-
)
135-
{
136-
algorithm->ComputeSpectralDivE( lev, field_data, Efield, divE );
137-
}
133+
amrex::MultiFab& divE);
138134

139135
/**
140136
* \brief Public interface to call the virtual function \c CurrentCorrection,
141137
* defined in the base class SpectralBaseAlgorithm and possibly overridden
142138
* by its derived classes (e.g. PsatdAlgorithm, PsatdAlgorithmComoving, etc.), from
143139
* objects of class SpectralSolver through the private unique pointer \c algorithm
144140
*/
145-
void CurrentCorrection ()
146-
{
147-
algorithm->CurrentCorrection(field_data);
148-
}
141+
void CurrentCorrection ();
149142

150143
/**
151144
* \brief Public interface to call the virtual function \c VayDeposition,
152145
* declared in the base class SpectralBaseAlgorithm and defined in its
153146
* derived classes, from objects of class SpectralSolver through the private
154147
* unique pointer \c algorithm.
155148
*/
156-
void VayDeposition ()
157-
{
158-
algorithm->VayDeposition(field_data);
159-
}
149+
void VayDeposition ();
160150

161151
/**
162152
* \brief Copy spectral data from component \c src_comp to component \c dest_comp
@@ -165,23 +155,14 @@ class SpectralSolver
165155
* \param[in] src_comp component of the source FabArray from which the data are copied
166156
* \param[in] dest_comp component of the destination FabArray where the data are copied
167157
*/
168-
void CopySpectralDataComp (const int src_comp, const int dest_comp)
169-
{
170-
// The last two arguments represent the number of components and
171-
// the number of ghost cells to perform this operation
172-
Copy(field_data.fields, field_data.fields, src_comp, dest_comp, 1, 0);
173-
}
158+
void CopySpectralDataComp (int src_comp, int dest_comp);
174159

175160
/**
176161
* \brief Set to zero the data on component \c icomp of \c field_data.fields
177162
*
178163
* \param[in] icomp component of the FabArray where the data are set to zero
179164
*/
180-
void ZeroOutDataComp (const int icomp)
181-
{
182-
// The last argument represents the number of components to perform this operation
183-
field_data.fields.setVal(0., icomp, 1);
184-
}
165+
void ZeroOutDataComp (int icomp);
185166

186167
/**
187168
* \brief Scale the data on component \c icomp of \c field_data.fields
@@ -190,11 +171,7 @@ class SpectralSolver
190171
* \param[in] icomp component of the FabArray where the data are scaled
191172
* \param[in] scale_factor scale factor to use for scaling
192173
*/
193-
void ScaleDataComp (const int icomp, const amrex::Real scale_factor)
194-
{
195-
// The last argument represents the number of components to perform this operation
196-
field_data.fields.mult(scale_factor, icomp, 1);
197-
}
174+
void ScaleDataComp (int icomp, amrex::Real scale_factor);
198175

199176
SpectralFieldIndex m_spectral_index;
200177

Source/FieldSolver/SpectralSolver/SpectralSolver.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,41 @@ SpectralSolver::pushSpectralFields(){
144144
algorithm->pushSpectralFields( field_data );
145145
}
146146

147+
void SpectralSolver::ComputeSpectralDivE (
148+
const int lev,
149+
ablastr::fields::VectorField const & Efield,
150+
amrex::MultiFab& divE)
151+
{
152+
algorithm->ComputeSpectralDivE(lev, field_data, Efield, divE );
153+
}
154+
155+
void SpectralSolver::CurrentCorrection ()
156+
{
157+
algorithm->CurrentCorrection(field_data);
158+
}
159+
160+
void SpectralSolver::VayDeposition ()
161+
{
162+
algorithm->VayDeposition(field_data);
163+
}
164+
165+
void SpectralSolver::CopySpectralDataComp (const int src_comp, const int dest_comp)
166+
{
167+
// The last two arguments represent the number of components and
168+
// the number of ghost cells to perform this operation
169+
Copy(field_data.fields, field_data.fields, src_comp, dest_comp, 1, 0);
170+
}
171+
172+
void SpectralSolver::ZeroOutDataComp (const int icomp)
173+
{
174+
// The last argument represents the number of components to perform this operation
175+
field_data.fields.setVal(0., icomp, 1);
176+
}
177+
178+
void SpectralSolver::ScaleDataComp (const int icomp, const amrex::Real scale_factor)
179+
{
180+
// The last argument represents the number of components to perform this operation
181+
field_data.fields.mult(scale_factor, icomp, 1);
182+
}
183+
147184
#endif // WARPX_USE_FFT

Source/FieldSolver/SpectralSolver/SpectralSolverRZ.H

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,14 @@ class SpectralSolverRZ
7474

7575
/* \brief Initialize K space filtering arrays */
7676
void InitFilter (amrex::IntVect const & filter_npass_each_dir,
77-
bool const compensation)
78-
{
79-
field_data.InitFilter(filter_npass_each_dir, compensation, k_space);
80-
}
77+
bool compensation);
8178

8279
/* \brief Apply K space filtering for a scalar */
83-
void ApplyFilter (const int lev, int const field_index)
84-
{
85-
field_data.ApplyFilter(lev, field_index);
86-
}
80+
void ApplyFilter (int lev, int field_index);
8781

8882
/* \brief Apply K space filtering for a vector */
89-
void ApplyFilter (const int lev, int const field_index1,
90-
int const field_index2, int const field_index3)
91-
{
92-
field_data.ApplyFilter(lev, field_index1, field_index2, field_index3);
93-
}
83+
void ApplyFilter (int lev, int field_index1,
84+
int field_index2, int field_index3);
9485

9586
/**
9687
* \brief Public interface to call the member function ComputeSpectralDivE
@@ -123,20 +114,14 @@ class SpectralSolverRZ
123114
* \param[in] src_comp component of the source FabArray from which the data are copied
124115
* \param[in] dest_comp component of the destination FabArray where the data are copied
125116
*/
126-
void CopySpectralDataComp (const int src_comp, const int dest_comp)
127-
{
128-
field_data.CopySpectralDataComp(src_comp, dest_comp);
129-
}
117+
void CopySpectralDataComp (int src_comp, int dest_comp);
130118

131119
/**
132120
* \brief Set to zero the data on component \c icomp of \c field_data.fields
133121
*
134122
* \param[in] icomp component of the FabArray where the data are set to zero
135123
*/
136-
void ZeroOutDataComp (const int icomp)
137-
{
138-
field_data.ZeroOutDataComp(icomp);
139-
}
124+
void ZeroOutDataComp (int icomp);
140125

141126
/**
142127
* \brief Scale the data on component \c icomp of \c field_data.fields
@@ -145,10 +130,7 @@ class SpectralSolverRZ
145130
* \param[in] icomp component of the FabArray where the data are scaled
146131
* \param[in] scale_factor scale factor to use for scaling
147132
*/
148-
void ScaleDataComp (const int icomp, const amrex::Real scale_factor)
149-
{
150-
field_data.ScaleDataComp(icomp, scale_factor);
151-
}
133+
void ScaleDataComp (int icomp, amrex::Real scale_factor);
152134

153135
SpectralFieldIndex m_spectral_index;
154136

Source/FieldSolver/SpectralSolver/SpectralSolverRZ.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,25 @@ SpectralSolverRZ::pushSpectralFields (const bool doing_pml) {
136136
}
137137
}
138138

139+
void SpectralSolverRZ::InitFilter (
140+
amrex::IntVect const & filter_npass_each_dir,
141+
bool const compensation)
142+
{
143+
field_data.InitFilter(filter_npass_each_dir, compensation, k_space);
144+
}
145+
146+
void SpectralSolverRZ::ApplyFilter (const int lev, int const field_index)
147+
{
148+
field_data.ApplyFilter(lev, field_index);
149+
}
150+
151+
void SpectralSolverRZ::ApplyFilter (
152+
const int lev, int const field_index1,
153+
int const field_index2, int const field_index3)
154+
{
155+
field_data.ApplyFilter(lev, field_index1, field_index2, field_index3);
156+
}
157+
139158
/**
140159
* \brief Public interface to call the member function ComputeSpectralDivE
141160
* of the base class SpectralBaseAlgorithmRZ from objects of class SpectralSolverRZ
@@ -166,3 +185,22 @@ SpectralSolverRZ::VayDeposition ()
166185
{
167186
algorithm->VayDeposition(field_data);
168187
}
188+
189+
190+
void
191+
SpectralSolverRZ::CopySpectralDataComp (const int src_comp, const int dest_comp)
192+
{
193+
field_data.CopySpectralDataComp(src_comp, dest_comp);
194+
}
195+
196+
void
197+
SpectralSolverRZ::ZeroOutDataComp (const int icomp)
198+
{
199+
field_data.ZeroOutDataComp(icomp);
200+
}
201+
202+
void
203+
SpectralSolverRZ::ScaleDataComp (const int icomp, const amrex::Real scale_factor)
204+
{
205+
field_data.ScaleDataComp(icomp, scale_factor);
206+
}

0 commit comments

Comments
 (0)