/** * @brief * Use Euler Advection Scheme to Solve the PDE. */ int ConvectionSolve2d(structMesh *mesh, physics *phy, double** c, double finalTime){ double time, CFL, dt; double **rhs = Matrix_create(mesh->ndim1, mesh->ndim2); time = 0.0; CFL = 0.1; // calculate time interval - dt dt = getTimeInterval(mesh, phy, CFL); double start, stop; start = MPI_Wtime(); while (time < finalTime) { // increase local time if (time+dt > finalTime) { dt = finalTime - time; time = finalTime; }else{ time += dt; } TimeEvolution(mesh, phy, c, time, dt, rhs); } stop = MPI_Wtime(); printf("Time Usaged: %f\n", (stop-start)*1000.0 ); Matrix_free(rhs); return 0; }
/* ************************************************************************ */ static void freeMatrices (struct calculation_arguments* arguments) { int i; for (i = 0; i < arguments->num_matrices; i++) { //free(arguments->Matrix[i]); Matrix_free(arguments->Mat[i]); } free(arguments->Mat); //free(arguments->Matrix); //free(arguments->M); }
int main(int argc, char **argv) { physics *phys = PhysicsCreate(); structMesh *mesh = MeshCreate(); double **c = ConcentrationCreate(mesh, phys); double finalTime = 0.5; ConvectionSolve2d(mesh, phys, c, finalTime); double L2, Linf; NormErr(mesh, phys, finalTime, c, &L2, &Linf); printf("The Mesh Grid, [%d, %d]\n", mesh->ndim1, mesh->ndim2); printf("The Norm Error, L2=%f, Linf=%f\n", L2, Linf); free(phys); Matrix_free(c); MeshFree(mesh); return 0; }
/** * @brief * Calculate the Norm Error of Numerical Solution at Spicific Time. */ void NormErr(structMesh *mesh, physics *phys, double time, double **c, double *L2, double *Linf) { double **temp = Matrix_create(mesh->ndim1, mesh->ndim2); ExactSol(mesh, phys, time, temp); double err = 0; double maxerr = 0.0; int dim1, dim2; for (dim1=0; dim1<mesh->ndim1; dim1++) { for (dim2=0; dim2<mesh->ndim2; dim2++) { double dc = c[dim1][dim2]-temp[dim1][dim2]; maxerr = maxf(fabs(dc), maxerr); err += dc*dc; } } *L2 = sqrt(err/mesh->ndim1/mesh->ndim2); *Linf = maxerr; Matrix_free(temp); return; }
void ConcentrationFree(double **c) { Matrix_free(c); return; }
/** * @brief * Deallocate Memory for Mesh strucutre. */ void MeshFree(structMesh *mesh) { Matrix_free(mesh->x); Matrix_free(mesh->y); return; }