Skip to content

Commit

Permalink
more size_t fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Mar 26, 2020
1 parent b6fec4d commit 221c64d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
28 changes: 14 additions & 14 deletions src/dft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,17 @@ dft_flux::dft_flux(const dft_flux &f) : where(f.where) {
}

double *dft_flux::flux() {
const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
double *F = new double[Nfreq];
for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
F[i] = 0;
for (dft_chunk *curE = E, *curH = H; curE && curH;
curE = curE->next_in_dft, curH = curH->next_in_dft)
for (size_t k = 0; k < curE->N; ++k)
for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
F[i] += real(curE->dft[k * Nfreq + i] * conj(curH->dft[k * Nfreq + i]));
double *Fsum = new double[Nfreq];
sum_to_all(F, Fsum, Nfreq);
sum_to_all(F, Fsum, int(Nfreq));
delete[] F;
return Fsum;
}
Expand Down Expand Up @@ -511,43 +511,43 @@ dft_energy::dft_energy(const dft_energy &f) : where(f.where) {
}

double *dft_energy::electric() {
const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
double *F = new double[Nfreq];
for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
F[i] = 0;
for (dft_chunk *curE = E, *curD = D; curE && curD;
curE = curE->next_in_dft, curD = curD->next_in_dft)
for (size_t k = 0; k < curE->N; ++k)
for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
F[i] += 0.5 * real(conj(curE->dft[k * Nfreq + i]) * curD->dft[k * Nfreq + i]);
double *Fsum = new double[Nfreq];
sum_to_all(F, Fsum, Nfreq);
sum_to_all(F, Fsum, int(Nfreq));
delete[] F;
return Fsum;
}

double *dft_energy::magnetic() {
const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
double *F = new double[Nfreq];
for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
F[i] = 0;
for (dft_chunk *curH = H, *curB = B; curH && curB;
curH = curH->next_in_dft, curB = curB->next_in_dft)
for (size_t k = 0; k < curH->N; ++k)
for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
F[i] += 0.5 * real(conj(curH->dft[k * Nfreq + i]) * curB->dft[k * Nfreq + i]);
double *Fsum = new double[Nfreq];
sum_to_all(F, Fsum, Nfreq);
sum_to_all(F, Fsum, int(Nfreq));
delete[] F;
return Fsum;
}

double *dft_energy::total() {
const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
double *Fe = electric();
double *Fm = magnetic();
double *F = new double[Nfreq];
for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
F[i] = Fe[i] + Fm[i];
delete[] Fe;
delete[] Fm;
Expand Down
12 changes: 6 additions & 6 deletions src/dft_ldos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ dft_ldos::dft_ldos(double freq_min, double freq_max, int Nfreq) {
}

dft_ldos::dft_ldos(const std::vector<double> freq_) {
const int Nfreq = freq_.size();
const size_t Nfreq = freq_.size();
freq = freq_;
Fdft = new complex<realnum>[Nfreq];
Jdft = new complex<realnum>[Nfreq];
for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
Fdft[i] = Jdft[i] = 0.0;
Jsum = 1.0;
}
Expand All @@ -56,9 +56,9 @@ double *dft_ldos::ldos() const {
* -0.5 // power = -1/2 Re[E* J]
/ (Jsum_all * Jsum_all); // normalize to unit-integral current

const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
double *sum = new double[Nfreq];
for (int i = 0; i < Nfreq; ++i) /* 4/pi * work done by unit dipole */
for (size_t i = 0; i < Nfreq; ++i) /* 4/pi * work done by unit dipole */
sum[i] = scale * real(Fdft[i] * conj(Jdft[i])) / abs2(Jdft[i]);
double *out = new double[Nfreq];
sum_to_all(sum, out, Nfreq);
Expand All @@ -67,14 +67,14 @@ double *dft_ldos::ldos() const {
}

complex<double> *dft_ldos::F() const {
const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
complex<double> *out = new complex<double>[Nfreq];
sum_to_all(Fdft, out, Nfreq);
return out;
}

complex<double> *dft_ldos::J() const {
const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
complex<double> *out = new complex<double>[Nfreq];
sum_to_all(Jdft, out, Nfreq);
return out;
Expand Down
22 changes: 11 additions & 11 deletions src/near2far.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ void dft_near2far::farfield_lowlevel(std::complex<double> *EH, const vec &x) {
abort("only 2d or 3d or cylindrical far-field computation is supported");
greenfunc green = x.dim == D2 ? green2d : green3d;

const int Nfreq = freq.size();
for (int i = 0; i < 6 * Nfreq; ++i)
const size_t Nfreq = freq.size();
for (size_t i = 0; i < 6 * Nfreq; ++i)
EH[i] = 0.0;

for (dft_chunk *f = F; f; f = f->next_in_dft) {
Expand All @@ -340,7 +340,7 @@ void dft_near2far::farfield_lowlevel(std::complex<double> *EH, const vec &x) {
#ifdef HAVE_OPENMP
#pragma omp parallel for
#endif
for (int i = 0; i < Nfreq; ++i) {
for (size_t i = 0; i < Nfreq; ++i) {
std::complex<double> EH6[6];
size_t idx_dft = 0;
LOOP_OVER_IVECS(f->fc->gv, f->is, f->ie, idx) {
Expand Down Expand Up @@ -372,7 +372,7 @@ void dft_near2far::farfield_lowlevel(std::complex<double> *EH, const vec &x) {

std::complex<double> *dft_near2far::farfield(const vec &x) {
std::complex<double> *EH, *EH_local;
const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
EH_local = new std::complex<double>[6 * Nfreq];
farfield_lowlevel(EH_local, x);
EH = new std::complex<double>[6 * Nfreq];
Expand Down Expand Up @@ -401,7 +401,7 @@ realnum *dft_near2far::get_farfields_array(const volume &where, int &rank, size_
}
if (where.dim == Dcyl) dirs[2] = P; // otherwise Z is listed twice

const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
if (N * Nfreq < 1) return NULL; /* nothing to output */

/* 6 x 2 x N x Nfreq array of fields in row-major order */
Expand Down Expand Up @@ -433,7 +433,7 @@ realnum *dft_near2far::get_farfields_array(const volume &where, int &rank, size_
farfield_lowlevel(EH1, x);
if (verbosity > 1) all_wait(); // Allow consistent progress updates from master
ptrdiff_t idx = (i0 * dims[1] + i1) * dims[2] + i2;
for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
for (int k = 0; k < 6; ++k) {
EH_[((k * 2 + 0) * N + idx) * Nfreq + i] = real(EH1[i * 6 + k]);
EH_[((k * 2 + 1) * N + idx) * Nfreq + i] = imag(EH1[i * 6 + k]);
Expand Down Expand Up @@ -464,7 +464,7 @@ void dft_near2far::save_farfields(const char *fname, const char *prefix, const v
realnum *EH = get_farfields_array(where, rank, dims, N, resolution);
if (!EH) return; /* nothing to output */

const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
/* frequencies are the last dimension */
if (Nfreq > 1) dims[rank++] = Nfreq;

Expand Down Expand Up @@ -497,16 +497,16 @@ double *dft_near2far::flux(direction df, const volume &where, double resolution)

realnum *EH = get_farfields_array(where, rank, dims, N, resolution);

const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
double *F = new double[Nfreq];
std::complex<realnum> ff_EH[6];
std::complex<realnum> cE[2], cH[2];

for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
F[i] = 0;

for (size_t idx = 0; idx < N; ++idx) {
for (int i = 0; i < Nfreq; ++i) {
for (size_t i = 0; i < Nfreq; ++i) {
for (int k = 0; k < 6; ++k)
ff_EH[k] = std::complex<realnum>(*(EH + ((k * 2 + 0) * N + idx) * Nfreq + i),
*(EH + ((k * 2 + 1) * N + idx) * Nfreq + i));
Expand All @@ -529,7 +529,7 @@ double *dft_near2far::flux(direction df, const volume &where, double resolution)
if (dim > 1) dV *= where.in_direction(d) / (dim - 1);
}

for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
F[i] *= dV;

delete[] EH;
Expand Down
10 changes: 5 additions & 5 deletions src/stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,27 @@ void dft_force::operator-=(const dft_force &st) {
if (diag && st.diag) *diag -= *st.diag;
}

static void stress_sum(int Nfreq, double *F, const dft_chunk *F1, const dft_chunk *F2) {
static void stress_sum(size_t Nfreq, double *F, const dft_chunk *F1, const dft_chunk *F2) {
for (const dft_chunk *curF1 = F1, *curF2 = F2; curF1 && curF2;
curF1 = curF1->next_in_dft, curF2 = curF2->next_in_dft) {
complex<realnum> extra_weight(real(curF1->extra_weight), imag(curF1->extra_weight));
for (size_t k = 0; k < curF1->N; ++k)
for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
F[i] += real(extra_weight * curF1->dft[k * Nfreq + i] * conj(curF2->dft[k * Nfreq + i]));
}
}

double *dft_force::force() {
const int Nfreq = freq.size();
const size_t Nfreq = freq.size();
double *F = new double[Nfreq];
for (int i = 0; i < Nfreq; ++i)
for (size_t i = 0; i < Nfreq; ++i)
F[i] = 0;

stress_sum(Nfreq, F, offdiag1, offdiag2);
stress_sum(Nfreq, F, diag, diag);

double *Fsum = new double[Nfreq];
sum_to_all(F, Fsum, Nfreq);
sum_to_all(F, Fsum, int(Nfreq));
delete[] F;
return Fsum;
}
Expand Down

0 comments on commit 221c64d

Please sign in to comment.