Commit 443f3c48 authored by Cyrille Bonamy's avatar Cyrille Bonamy
Browse files

update src_cpp

parent e494e1f81ca9
......@@ -149,7 +149,7 @@ myreal FFT3DWithCUFFT::compute_energy_from_K(mycomplex* fieldK)
i2 = nK2 - 1;
for (i0=0; i0<nK0; i0++)
for (i1=0; i1<nK1; i1++)
energy += (double) pow(abs(fieldK[i2 + (i1 + i0*nK1)*nK2]), 2);
energy += (double) square_abs(fieldK[i2 + (i1 + i0*nK1)*nK2]);
// we must divide by 2 ==> after
energy *= 0.5; //divide by 2!!!
......@@ -158,13 +158,13 @@ myreal FFT3DWithCUFFT::compute_energy_from_K(mycomplex* fieldK)
for (i0=0; i0<nK0; i0++)
for (i1=0; i1<nK1; i1++)
for (i2=1; i2<nK2-1; i2++)
energy += (double) pow(abs(fieldK[i2 + (i1 + i0*nK1)*nK2]), 2);
energy += (double) square_abs(fieldK[i2 + (i1 + i0*nK1)*nK2]);
// modes i1_seq = iKx = 0
i2 = 0;
for (i0=0; i0<nK0; i0++)
for (i1=0; i1<nK1; i1++)
energy0 += (double) pow(abs(fieldK[(i1 + i0*nK1)*nK2]), 2);
energy0 += (double) square_abs(fieldK[(i1 + i0*nK1)*nK2]);
// we must divide by 2 ==> after
energy += energy0/2.;
......
......@@ -153,7 +153,7 @@ myreal FFT3DWithFFTW3D::compute_energy_from_K(mycomplex* fieldK)
i2 = 0;
for (i0=0; i0<nK0; i0++)
for (i1=0; i1<nK1; i1++)
energy_tmp += (double) pow(abs(fieldK[(i1 + i0 * nK1) * nK2]), 2);
energy_tmp += (double) square_abs(fieldK[(i1 + i0 * nK1) * nK2]);
energy = energy_tmp/2;
......@@ -162,7 +162,7 @@ myreal FFT3DWithFFTW3D::compute_energy_from_K(mycomplex* fieldK)
energy_tmp = 0.;
for (i0=0; i0<nK0; i0++)
for (i1=0; i1<nK1; i1++)
energy_tmp += (double) pow(abs(fieldK[i2 + (i1 + i0 * nK1) * nK2]), 2);
energy_tmp += (double) square_abs(fieldK[i2 + (i1 + i0 * nK1) * nK2]);
if (N2%2 == 0)
energy += energy_tmp/2;
......@@ -173,7 +173,7 @@ myreal FFT3DWithFFTW3D::compute_energy_from_K(mycomplex* fieldK)
for (i0=0; i0<nK0; i0++)
for (i1=0; i1<nK1; i1++)
for (i2=1; i2<nK2-1; i2++)
energy += (double) pow(abs(fieldK[i2 + (i1 + i0 * nK1) * nK2]), 2);
energy += (double) square_abs(fieldK[i2 + (i1 + i0 * nK1) * nK2]);
return (myreal) energy;
}
......
......@@ -186,12 +186,12 @@ myreal FFT3DMPIWithFFTW1D::compute_energy_from_K(mycomplex* fieldK)
myreal energy_loc = 0;
myreal energy_tmp = 0;
myreal energy;
mycomplex toto = 0;
// modes i0 = iKx = 0
i0 = 0;
for (i1=0; i1<nK1; i1++)
for (i2=0; i2<nK2; i2++)
energy_tmp += pow(abs(fieldK[i1*nK2 + i2]), 2);
energy_tmp += square_abs(fieldK[i1*nK2 + i2]);
if (rank == 0) // i.e. if iKx == 0
energy_loc = energy_tmp/2.;
......@@ -202,7 +202,7 @@ myreal FFT3DMPIWithFFTW1D::compute_energy_from_K(mycomplex* fieldK)
for (i0=1; i0<nK0loc; i0++)
for (i1=0; i1<nK1; i1++)
for (i2=0; i2<nK2; i2++)
energy_loc += pow(abs(fieldK[i2 + i1*nK2 + i0*nK1*nK2]), 2);
energy_loc += square_abs(fieldK[i2 + i1*nK2 + i0*nK1*nK2]);
MPI_Allreduce(&energy_loc, &energy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
// cout << "energy" << energy << endl;
......
......@@ -166,7 +166,7 @@ myreal FFT3DMPIWithFFTWMPI3D::compute_energy_from_K(mycomplex* fieldK)
i2 = 0;
for (i0=0; i0<nK0loc; i0++)
for (i1=0; i1<nK1; i1++)
energy_tmp += (double) pow(abs(fieldK[(i1 + i0 * nK1) * nK2]), 2);
energy_tmp += (double) square_abs(fieldK[(i1 + i0 * nK1) * nK2]);
energy_loc = energy_tmp/2.;
......@@ -175,7 +175,7 @@ myreal FFT3DMPIWithFFTWMPI3D::compute_energy_from_K(mycomplex* fieldK)
energy_tmp = 0;
for (i0=0; i0<nK0loc; i0++)
for (i1=0; i1<nK1; i1++)
energy_tmp += (double) pow(abs(fieldK[i2 + (i1 + i0 * nK1) * nK2]), 2);
energy_tmp += (double) square_abs(fieldK[i2 + (i1 + i0 * nK1) * nK2]);
if (N2%2 == 0)
energy_loc += energy_tmp/2.;
......@@ -186,7 +186,7 @@ myreal FFT3DMPIWithFFTWMPI3D::compute_energy_from_K(mycomplex* fieldK)
for (i0=0; i0<nK0loc; i0++)
for (i1=0; i1<nK1; i1++)
for (i2=1; i2<nK2-1; i2++)
energy_loc += (double) pow(abs(fieldK[i2 + (i1 + i0 * nK1) * nK2]), 2);
energy_loc += (double) square_abs(fieldK[i2 + (i1 + i0 * nK1) * nK2]);
MPI_Allreduce(&energy_loc, &energy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
......
......@@ -143,7 +143,7 @@ myreal FFT3DMPIWithP3DFFT::compute_energy_from_K(mycomplex* fieldK)
energy_tmp=0.;
for (i2=0; i2<nK2loc; i2++)
for (i1=0; i1<nK1loc; i1++)
energy_tmp += (double) pow(abs(fieldK[i0 + (i1+i2*nK1loc)*nK0loc]), 2);
energy_tmp += (double) square_abs(fieldK[i0 + (i1+i2*nK1loc)*nK0loc]);
if ((local_K0_start == 1) || (nK0loc == 1 and local_K0_start + nK0loc == nK0 + 1))
energy_loc = energy_tmp /2.;
......@@ -157,7 +157,7 @@ myreal FFT3DMPIWithP3DFFT::compute_energy_from_K(mycomplex* fieldK)
energy_tmp = 0;
for (i2=0; i2<nK2loc; i2++)
for (i1=0; i1<nK1loc; i1++)
energy_tmp += (double) pow(abs(fieldK[i0 + (i1 + i2*nK1loc)*nK0loc]), 2);
energy_tmp += (double) square_abs(fieldK[i0 + (i1 + i2*nK1loc)*nK0loc]);
if (local_K0_start + nK0loc -1== nK0/2+1)
energy_loc += energy_tmp/2.;
......@@ -167,7 +167,7 @@ myreal FFT3DMPIWithP3DFFT::compute_energy_from_K(mycomplex* fieldK)
for (i2=0; i2<nK2loc; i2++)
for (i1=0; i1<nK1loc; i1++)
for (i0=1; i0<nK0loc-1; i0++)
energy_loc += (double) pow(abs(fieldK[i0 + (i1 + i2*nK1loc)*nK0loc]), 2);
energy_loc += (double) square_abs(fieldK[i0 + (i1 + i2*nK1loc)*nK0loc]);
}
MPI_Allreduce(&energy_loc, &energy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
......
......@@ -217,7 +217,7 @@ myreal FFT3DMPIWithPFFT::compute_energy_from_K(mycomplex* fieldK)
i1 = 0;
for (i0=0; i0<nK0loc; i0++)
for (i2=0; i2<nK2; i2++)
energy_tmp += (double) pow(abs(fieldK[i2 + (i0*nK1loc)*nK2]), 2);
energy_tmp += (double) square_abs(fieldK[i2 + (i0*nK1loc)*nK2]);
if ((local_K1_start == 0) || (nK1loc == 1 and local_K1_start + nK1loc == nK1))
energy_loc = energy_tmp/2.;
......@@ -231,7 +231,7 @@ myreal FFT3DMPIWithPFFT::compute_energy_from_K(mycomplex* fieldK)
energy_tmp = 0;
for (i0=0; i0<nK0loc; i0++)
for (i2=0; i2<nK2; i2++)
energy_tmp += (double) pow(abs(fieldK[i2 + (i1 + i0*nK1loc)*nK2]), 2);
energy_tmp += (double) square_abs(fieldK[i2 + (i1 + i0*nK1loc)*nK2]);
if (N1%2 == 0 and local_K1_start + nK1loc == nK1)
energy_loc += energy_tmp/2.;
......@@ -242,7 +242,7 @@ myreal FFT3DMPIWithPFFT::compute_energy_from_K(mycomplex* fieldK)
for (i0=0; i0<nK0loc; i0++)
for (i1=1; i1<nK1loc-1; i1++)
for (i2=0; i2<nK2; i2++)
energy_loc += (double) pow(abs(fieldK[i2 + (i1 + i0*nK1loc)*nK2]), 2);
energy_loc += (double) square_abs(fieldK[i2 + (i1 + i0*nK1loc)*nK2]);
}
MPI_Allreduce(&energy_loc, &energy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
......
......@@ -268,3 +268,10 @@ int BaseFFT::get_local_size_K()
cout << "BaseFFT::get_local_size_K" << endl;
return nKxloc * nKy;
}
myreal BaseFFT::square_abs(mycomplex cm)
{
// return pow(abs(cm), 2);
return real(cm) * real(cm) + imag(cm) * imag(cm);
}
......@@ -63,6 +63,8 @@ class BaseFFT
virtual void alloc_array_X(myreal* &fieldX);
myreal square_abs(mycomplex cm);
int rank, nb_proc;
myreal coef_norm;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment