You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
simulacion-permeabilidad/fftma_module/gen/lib_src/length.c

60 lines
1.6 KiB
C

#include "log.h"
#include <math.h>
#include <time.h>
/* compute the length for one dimension*/
int length(int N, int i, double* scf, double* ap, double D, int Nvari) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
log_info("RESULT = in progress, N = %d, i = %d, D = %f, Nvari = %d", N, i, D, Nvari);
int maxfactor(int n);
double temp1, temp2;
int n, j, k, nmax;
int nlimit = 13;
if (N == 1) {
n = 1;
} else {
for (k = 0; k < Nvari; k++) {
temp1 = fabs(ap[9 * k + i]) * scf[3 * k] * scf[3 * k];
for (j = 1; j < 3; j++) {
temp2 = fabs(ap[9 * k + 3 * j + i]) * scf[3 * k + j] * scf[3 * k + j];
if (temp2 > temp1)
temp1 = temp2;
}
}
temp1 = sqrt(temp1);
temp1 /= (double)D;
if ((double)N / temp1 < 2.) {
n = N + (int)(2 * temp1);
} else {
n = N + (int)temp1;
}
if ((n % 2) != 0)
n = n + 1;
nmax = maxfactor(n);
while (nmax > nlimit) {
n += 2;
nmax = maxfactor(n);
}
}
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time
double* used_ram_tf = malloc(sizeof(double));
getVirtualMemUsed(used_ram_tf);
log_info("RESULT = success, n = %d, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", n, time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
return n;
}