void getEulerFlux(double* q_arr, double* nrm, int ndofPerNode, int nnodesPerElement, int numEl, double* flux) { int idx_q = 0; // hold starting index of current node's q values int idx_nrm = 0; // hold starting index of current node's nrm values for (int k=0; k < numEl; k++) { for (int j=0; j < nnodesPerElement; j++) { idx_q = getInd(0, j, k, ndofPerNode, nnodesPerElement, numEl); idx_nrm = getInd(0, j, k, 2, nnodesPerElement, numEl); calcEulerFlux(q_arr + idx_q, nrm + idx_nrm, flux + idx_q); } } } // end function getEulerFlux
int main(int argc, char** argv) { // главная часть, обработка параметров входа и выполнение init(); char* data_file1=argv[1]; char* data_file2=argv[2]; char* strl = argv[3]; FILE* f=fopen(data_file,"r"); FILE* f2=fopen(data_file2,"r"); if(!f) { printf("Wrong file\n"); return 1; } char tmp[51]; char mnoj_name; int elem; int num_mnoj=0; while(fgets(tmp,51,f)!=NULL) { mnoj_name=tmp[0]; elem=getElem(tmp); int ind=getInd(mnoj_name); if(ind!=-1) { bool is_new=true; int l; for(l=0;l<num_elems[ind];l++) { if(elems[ind][l]==elem) { is_new=false; } } if(is_new) { num_elems[ind]++; elems[ind]=(int *) realloc(elems[ind],num_elems[ind]*sizeof(int)); elems[ind][num_elems[ind]-1]=elem; } } else { num_mnoj++; mnoj=(char*) realloc(mnoj,num_mnoj*sizeof(char)); mnoj[num_mnoj-1]=mnoj_name; elems=(int**) realloc(elems,num_mnoj*sizeof(int*)); elems[num_mnoj-1]=(int*) calloc(1,sizeof(int)); elems[num_mnoj-1][0]=elem; num_elems=(int*) realloc(num_elems,num_mnoj*sizeof(int)); num_elems[num_mnoj-1]=1; } } puts("Data file is read"); int j=1; // номер анализируемого элемента puts(sum_mem); while(strlen(sum_mem)!=1) { printf("%s-%d\n",sum_mem,j); if(ifChar(sum_mem[j-2]) && ifChar(sum_mem[j]) && isOper(sum_mem[j-1])) { char newMn=gnm(); // выбирает неиспользованную букву. num_mnoj++; mnoj=(char*) realloc(mnoj,num_mnoj*sizeof(char)); mnoj[num_mnoj-1]=newMn; // мы нашли множество и создаём для него место elems=(int**) realloc(elems,num_mnoj*sizeof(int*)); elems[num_mnoj-1]=(int*) calloc(0,sizeof(int)); num_elems=(int*) realloc(num_elems,num_mnoj*sizeof(int)); num_elems[num_mnoj-1]=0; if(sum_mem[j-1]=='*') { peresech(sum_mem[j-2],sum_mem[j],newMn); sum_mem[j-2]=newMn; movePointer(sum_mem,j+1,2); } else if(sum_mem[j-1]=='+') { sumg(sum_mem[j-2],sum_mem[j],newMn); sum_mem[j-2]=newMn; movePointer(sum_mem,j+1,2); } else if(sum_mem[j-1]=='-') { minus(sum_mem[j-2],sum_mem[j],newMn); sum_mem[j-2]=newMn; movePointer(sum_mem,j+1,2); } j=2; } } puts(sum_mem); int last_ind=getInd(sum_mem[0]); int l; for(l=0;l<num_elems[last_ind];l++) { printf("%d\n",elems[last_ind][l]); } return (EXIT_SUCCESS); }
int main() { std::cout << "Hello World" << std::endl; const int imax = 4; // ndofPerNode const int jmax = 3; // nnodesPerEl const int kmax = 4000; // numEl double* arr = (double *) malloc(sizeof(double)*imax*jmax*kmax); double* flux = (double *) malloc(sizeof(double)*imax*jmax*kmax); double* nrm = (double *) malloc(sizeof(double)*2*jmax*kmax); /* std::cout << "arr = " << arr << std::endl; std::cout << "arr + 0 = " << arr + 0 << std::endl; std::cout << "arr + 1 = " << arr +1 << std::endl; std::cout << "arr + 2 = " << arr + 2 << std::endl; std::cout << "flux = " << flux << std::endl; std::cout << "nrm = " << nrm << std::endl; */ for (int k = 0; k < kmax; k++) { for (int j=0; j < jmax; j++) { // std::cout << "j, k = " << j << ", " << k << std::endl; int idx = getInd(0, j, k, imax, jmax, kmax); // std::cout << "arr idx = " << idx << std::endl; arr[idx] = 1.0; arr[idx+1] = 2.0; arr[idx+2] = 3.0; arr[idx+3] = 7.0; flux[idx] = 0.0; flux[idx+1] = 0.0; flux[idx+2] = 0.0; flux[idx+3] = 0.0; idx = getInd(0, j, k, 2, jmax, kmax); // std::cout << "nrm idx = " << idx << std::endl; nrm[idx] = sqrt(2.0)/2.0; nrm[idx+1] = sqrt(2.0)/2.0; } } double t1 = get_time(); double t2; // hold final time getEulerFlux(arr, nrm, imax, jmax, kmax, flux); t2 = get_time(); std::cout << "elapsed time = " << t2 - t1 << std::endl; /* std::cout << "printing results: " << std::endl; for (int k = 0; k < kmax; k++) { for (int j=0; j < jmax; j++) { int idx = getInd(0, j, k, imax, jmax, kmax); std::cout << "arr idx = " << idx << std::endl; std::cout << "arr[:," << j << "," << k << "] = " << arr[idx] << ", " << arr[idx+1] << ", " << arr[idx+2] << ", " << arr[idx+3] << std::endl; std::cout << "flux[:," << j << "," << k << "] = " << flux[idx] << ", " << flux[idx+1] << ", " << flux[idx+2] << ", " << flux[idx+3] << std::endl; idx = getInd(0, j, k, 2, jmax, kmax); std::cout << "nrm idx = " << idx << std::endl; std::cout << "nrm = " << nrm[idx] << "," << nrm[idx+1] << std::endl; } } */ return 0; }