/// <summary> /// Constructor /// </summary> /// <param name="fs">FluidSolver containing solution</param> /// <param name="omega">Domain containing geometry information and /// exact solutions (if known)</param> public PostProcessor(FluidSolver fs, Domain omega) { this.fs = fs; this.omega = omega; de = new DataExtractor(omega, fs); }
/// <summary> /// Computes L2 and L-infinity error between FFD approximation and exact solution. /// </summary> /// <param name="fs">FluidSolver containing FFD solution at time t</param> /// <pram name="omega">Domain on which exact solution is given</pram> /// <param name="err_l2">Normalized pointwise L2 error</param> /// <param name="err_inf">Pointwise L-infinity error</param> /// <param name="t">Time</param> /// <param name="component">Component to evaluate</param> /// <remarks>The component to evaluate must be one of: /// 1 for pressure /// 2 for x component of velocity /// 3 for y component of velocity /// 4 for z component of velocity</remarks> public static void calculate_errors(FluidSolver fs, Domain omega, out double err_l2, out double err_inf, double t, int component) { DataExtractor de = new DataExtractor(omega, fs); double nu = fs.nu; int Nx = omega.Nx - 1; int Ny = omega.Ny - 1; int Nz = omega.Nz - 1; double[, ,] err_array = new double[Nx, Ny, Nz]; double[, ,] comp_interp = new double[Nx, Ny, Nz]; double[, ,] zeros = new double[Nx, Ny, Nz]; for (int i = 0; i < Nx; i++) { for (int j = 0; j < Ny; j++) { for (int k = 0; k < Nz; k++) { double x = i * omega.hx; double y = j * omega.hy; double z = k * omega.hz; double[] coordinate = new double[] { x, y, z }; double[] velocity_interp = de.get_velocity(x, y, z); double u_exact, v_exact, w_exact, p_exact; omega.exact_solution(coordinate, nu, t, out u_exact, out v_exact, out w_exact, out p_exact); switch (component) { case 1: comp_interp[i, j, k] = de.get_pressure(x, y, z); err_array[i, j, k] = Math.Abs(de.get_pressure(x, y, z) - p_exact); break; case 2: comp_interp[i, j, k] = velocity_interp[0]; err_array[i, j, k] = Math.Abs(velocity_interp[0] - u_exact); break; case 3: comp_interp[i, j, k] = velocity_interp[1]; err_array[i, j, k] = Math.Abs(velocity_interp[1] - v_exact); break; case 4: comp_interp[i, j, k] = velocity_interp[2]; err_array[i, j, k] = Math.Abs(velocity_interp[2] - w_exact); break; } } } } err_l2 = Utilities.compute_L2_difference(err_array, zeros); //L2 norm of errors err_inf = err_array.Cast <double>().Max(); }