コード例 #1
0
ファイル: test_helmholtzbem3d_ocl.c プロジェクト: c1887/H2Lib
int
main(int argc, char **argv)
{
  pmacrosurface3d mg;
  psurface3d gr;
  pamatrix  Vfull, KMfull;
  pbem3d    bem_slp, bem_dlp;
  pcluster  root;
  pblock block;
  phmatrix  V, KM;
  pclusterbasis Vrb, Vcb, KMrb, KMcb;
  ph2matrix V2, KM2;
  uint      n, q, clf, m, l;
  real      eta, delta, eps_aca;
  field     kvec[3];
  cl_device_id *devices;
  cl_uint   ndevices;
  uint     *idx;
  uint      i;

  init_h2lib(&argc, &argv);

  get_opencl_devices(&devices, &ndevices);
  ndevices = 1;
  set_opencl_devices(devices, ndevices, 2);

  kvec[0] = 2.0, kvec[1] = 0.0, kvec[2] = 0.0;
  n = 512;
  q = 2;
  clf = 16;
  eta = 1.0;

  mg = new_sphere_macrosurface3d();
  gr = build_from_macrosurface3d_surface3d(mg, REAL_SQRT(n * 0.125));
  n = gr->triangles;

  printf("Testing unit sphere with %d triangles\n", n);

  bem_slp = new_slp_helmholtz_ocl_bem3d(kvec, gr, q, q + 2,
					BASIS_CONSTANT_BEM3D);
  bem_dlp = new_dlp_helmholtz_ocl_bem3d(kvec, gr, q, q + 2,
					BASIS_CONSTANT_BEM3D,
					BASIS_CONSTANT_BEM3D, 0.5);
  root = build_bem3d_cluster(bem_slp, clf, BASIS_CONSTANT_BEM3D);
  block = build_nonstrict_block(root, root, &eta, admissible_max_cluster);

  max_pardepth = 0;

  Vfull = new_amatrix(n, n);
  KMfull = new_amatrix(n, n);
  idx = allocuint(n);
  for (i = 0; i < n; ++i) {
    idx[i] = i;
  }
  SCHEDULE_OPENCL(0, 1, bem_slp->nearfield, idx, idx, bem_slp, false, Vfull);
  SCHEDULE_OPENCL(0, 1, bem_dlp->nearfield, idx, idx, bem_dlp, false, KMfull);

  V = build_from_block_hmatrix(block, 0);
  KM = build_from_block_hmatrix(block, 0);

  printf("----------------------------------------\n");
  printf("Testing outer Boundary integral equations:\n");
  printf("----------------------------------------\n\n");

  /*
   * Test Interpolation
   */

  m = 4;

  setup_hmatrix_aprx_inter_row_bem3d(bem_slp, root, root, block, m);
  setup_hmatrix_aprx_inter_row_bem3d(bem_dlp, root, root, block, m);
  test_hmatrix_system("Interpolation row", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false, true, 1.0e-3, 2.0e-3);

  setup_hmatrix_aprx_inter_col_bem3d(bem_slp, root, root, block, m);
  setup_hmatrix_aprx_inter_col_bem3d(bem_dlp, root, root, block, m);
  test_hmatrix_system("Interpolation column", Vfull, KMfull, block, bem_slp,
		      V, bem_dlp, KM, false, true, 1.0e-3, 2.0e-3);

  setup_hmatrix_aprx_inter_mixed_bem3d(bem_slp, root, root, block, m);
  setup_hmatrix_aprx_inter_mixed_bem3d(bem_dlp, root, root, block, m);
  test_hmatrix_system("Interpolation mixed", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false, true, 1.0e-3, 2.0e-3);

  /*
   * Test Green
   */

  m = 5;
  l = 1;
  delta = 0.5;

  setup_hmatrix_aprx_green_row_bem3d(bem_slp, root, root, block, m, l, delta,
				     build_bem3d_cube_quadpoints);
  setup_hmatrix_aprx_green_row_bem3d(bem_dlp, root, root, block, m, l, delta,
				     build_bem3d_cube_quadpoints);
  test_hmatrix_system("Green row", Vfull, KMfull, block, bem_slp, V, bem_dlp,
		      KM, false, true, 1.0e-3, 2.0e-3);

  setup_hmatrix_aprx_green_col_bem3d(bem_slp, root, root, block, m, l, delta,
				     build_bem3d_cube_quadpoints);
  setup_hmatrix_aprx_green_col_bem3d(bem_dlp, root, root, block, m, l, delta,
				     build_bem3d_cube_quadpoints);
  test_hmatrix_system("Green column", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false, true, 1.0e-3, 2.0e-3);

  setup_hmatrix_aprx_green_mixed_bem3d(bem_slp, root, root, block, m, l,
				       delta, build_bem3d_cube_quadpoints);
  setup_hmatrix_aprx_green_mixed_bem3d(bem_dlp, root, root, block, m, l,
				       delta, build_bem3d_cube_quadpoints);
  test_hmatrix_system("Green mixed", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false, true, 1.0e-3, 2.0e-3);

  /*
   * Test Greenhybrid
   */

  m = 2;
  l = 1;
  delta = 1.0;
  eps_aca = 2.0e-2;

  setup_hmatrix_aprx_greenhybrid_row_bem3d(bem_slp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem3d_cube_quadpoints);
  setup_hmatrix_aprx_greenhybrid_row_bem3d(bem_dlp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem3d_cube_quadpoints);
  test_hmatrix_system("Greenhybrid row", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false, true, 1.0e-3, 2.0e-3);

  setup_hmatrix_aprx_greenhybrid_col_bem3d(bem_slp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem3d_cube_quadpoints);
  setup_hmatrix_aprx_greenhybrid_col_bem3d(bem_dlp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem3d_cube_quadpoints);
  test_hmatrix_system("Greenhybrid column", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false, true, 1.0e-3, 2.0e-3);

  setup_hmatrix_aprx_greenhybrid_mixed_bem3d(bem_slp, root, root, block, m, l,
					     delta, eps_aca,
					     build_bem3d_cube_quadpoints);
  setup_hmatrix_aprx_greenhybrid_mixed_bem3d(bem_dlp, root, root, block, m, l,
					     delta, eps_aca,
					     build_bem3d_cube_quadpoints);
  test_hmatrix_system("Greenhybrid mixed", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false, true, 1.0e-3, 2.0e-3);

  /*
   * Test ACA / PACA / HCA
   */

  m = 2;
  eps_aca = 1.0e-2;

  /* Nearfield computation on GPU not applicable here yet! */

//  setup_hmatrix_aprx_aca_bem3d(bem_slp, root, root, block, eps_aca);
//  setup_hmatrix_aprx_aca_bem3d(bem_dlp, root, root, block, eps_aca);
//  test_hmatrix_system("ACA full pivoting", Vfull, KMfull, block, bem_slp, V,
//      bem_dlp, KM, false, true, 1.0e-3, 2.0e-3);
//
//  setup_hmatrix_aprx_paca_bem3d(bem_slp, root, root, block, eps_aca);
//  setup_hmatrix_aprx_paca_bem3d(bem_slp, root, root, block, eps_aca);
//  test_hmatrix_system("ACA partial pivoting", Vfull, KMfull, block, bem_slp, V,
//      bem_dlp, KM, false, true, 1.0e-3, 2.0e-3);
  setup_hmatrix_aprx_hca_bem3d(bem_slp, root, root, block, m, eps_aca);
  setup_hmatrix_aprx_hca_bem3d(bem_slp, root, root, block, m, eps_aca);
  test_hmatrix_system("HCA2", Vfull, KMfull, block, bem_slp, V, bem_dlp, KM,
		      false, true, 1.0e-3, 2.0e-3);

  del_hmatrix(V);
  del_hmatrix(KM);
  del_block(block);

  /*
   * H2-matrix
   */

  block = build_strict_block(root, root, &eta, admissible_max_cluster);

  Vrb = build_from_cluster_clusterbasis(root);
  Vcb = build_from_cluster_clusterbasis(root);
  KMrb = build_from_cluster_clusterbasis(root);
  KMcb = build_from_cluster_clusterbasis(root);

  V2 = build_from_block_h2matrix(block, Vrb, Vcb);
  KM2 = build_from_block_h2matrix(block, KMrb, KMcb);

  /*
   * Test Interpolation
   */

  m = 3;

  setup_h2matrix_aprx_inter_bem3d(bem_slp, Vrb, Vcb, block, m);
  setup_h2matrix_aprx_inter_bem3d(bem_dlp, KMrb, KMcb, block, m);
  test_h2matrix_system("Interpolation", Vfull, KMfull, block, bem_slp, V2,
		       bem_dlp, KM2, false, true, 1.0e-3, 2.0e-3);

  /*
   * Test Greenhybrid
   */

  m = 2;
  l = 1;
  delta = 1.0;
  eps_aca = 2.0e-2;

  setup_h2matrix_aprx_greenhybrid_bem3d(bem_slp, Vrb, Vcb, block, m, l, delta,
					eps_aca, build_bem3d_cube_quadpoints);
  setup_h2matrix_aprx_greenhybrid_bem3d(bem_dlp, KMrb, KMcb, block, m, l,
					delta, eps_aca,
					build_bem3d_cube_quadpoints);
  test_h2matrix_system("Greenhybrid", Vfull, KMfull, block, bem_slp, V2,
		       bem_dlp, KM2, false, true, 1.0e-3, 2.0e-3);

  /* Nearfield computation on GPU not applicable here yet! */

//  setup_h2matrix_aprx_greenhybrid_ortho_bem3d(bem_slp, Vrb, Vcb, block, m, l,
//      delta, eps_aca, build_bem3d_cube_quadpoints);
//  setup_h2matrix_aprx_greenhybrid_ortho_bem3d(bem_dlp, KMrb, KMcb, block, m, l,
//      delta, eps_aca, build_bem3d_cube_quadpoints);
//  test_h2matrix_system("Greenhybrid ortho", Vfull, KMfull, block, bem_slp, V2,
//      bem_dlp, KM2, false, true, 1.0e-3, 2.0e-3);
  del_h2matrix(V2);
  del_h2matrix(KM2);
  del_block(block);
  freemem(root->idx);
  del_cluster(root);
  del_helmholtz_ocl_bem3d(bem_slp);
  del_helmholtz_ocl_bem3d(bem_dlp);

  del_amatrix(Vfull);
  del_amatrix(KMfull);
  del_surface3d(gr);
  del_macrosurface3d(mg);
  freemem(idx);

  (void) printf("----------------------------------------\n"
		"  %u matrices and\n"
		"  %u vectors still active\n"
		"  %u errors found\n", getactives_amatrix(),
		getactives_avector(), problems);

  uninit_h2lib();

  return problems;
}
コード例 #2
0
ファイル: test_laplacebem2d.c プロジェクト: c-abird/H2Lib
int
main(int argc, char **argv)
{
  pcurve2d  gr;
  pamatrix  Vfull, KMfull;
  pbem2d    bem_slp, bem_dlp;
  pcluster  root;
  pblock block;
  phmatrix  V, KM;
  pclusterbasis Vrb, Vcb, KMrb, KMcb;
  ph2matrix V2, KM2;
  uint      n, q, clf, m, l;
  real      eta, delta, eps_aca;

  init_h2lib(&argc, &argv);

  n = 579;
  q = 2;
  clf = 16;
  eta = 1.0;

  gr = new_circle_curve2d(n, 0.333);
  bem_slp = new_slp_laplace_bem2d(gr, q, BASIS_CONSTANT_BEM2D);
  bem_dlp = new_dlp_laplace_bem2d(gr, q, BASIS_CONSTANT_BEM2D,
				  BASIS_CONSTANT_BEM2D, 0.5);
  root = build_bem2d_cluster(bem_slp, clf, BASIS_CONSTANT_BEM2D);
  block = build_nonstrict_block(root, root, &eta, admissible_max_cluster);

  Vfull = new_amatrix(n, n);
  KMfull = new_amatrix(n, n);
  bem_slp->nearfield(NULL, NULL, bem_slp, false, Vfull);
  bem_dlp->nearfield(NULL, NULL, bem_dlp, false, KMfull);

  V = build_from_block_hmatrix(block, 0);
  KM = build_from_block_hmatrix(block, 0);

  printf("----------------------------------------\n");
  printf("Testing inner Boundary integral equations:\n");
  printf("----------------------------------------\n\n");

  /*
   * Test Interpolation
   */

  m = 9;

  setup_hmatrix_aprx_inter_row_bem2d(bem_slp, root, root, block, m);
  setup_hmatrix_aprx_inter_row_bem2d(bem_dlp, root, root, block, m);
  test_hmatrix_system("Interpolation row", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false);

  setup_hmatrix_aprx_inter_col_bem2d(bem_slp, root, root, block, m);
  setup_hmatrix_aprx_inter_col_bem2d(bem_dlp, root, root, block, m);
  test_hmatrix_system("Interpolation column", Vfull, KMfull, block, bem_slp,
		      V, bem_dlp, KM, false);

  setup_hmatrix_aprx_inter_mixed_bem2d(bem_slp, root, root, block, m);
  setup_hmatrix_aprx_inter_mixed_bem2d(bem_dlp, root, root, block, m);
  test_hmatrix_system("Interpolation mixed", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false);

  /*
   * Test Green
   */

  m = 10;
  l = 2;
  delta = 0.5;

  setup_hmatrix_aprx_green_row_bem2d(bem_slp, root, root, block, m, l, delta,
				     build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_green_row_bem2d(bem_dlp, root, root, block, m, l, delta,
				     build_bem2d_rect_quadpoints);
  test_hmatrix_system("Green row", Vfull, KMfull, block, bem_slp, V, bem_dlp,
		      KM, false);

  setup_hmatrix_aprx_green_col_bem2d(bem_slp, root, root, block, m, l, delta,
				     build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_green_col_bem2d(bem_dlp, root, root, block, m, l, delta,
				     build_bem2d_rect_quadpoints);
  test_hmatrix_system("Green column", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false);

  setup_hmatrix_aprx_green_mixed_bem2d(bem_slp, root, root, block, m, l,
				       delta, build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_green_mixed_bem2d(bem_dlp, root, root, block, m, l,
				       delta, build_bem2d_rect_quadpoints);
  test_hmatrix_system("Green mixed", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false);

  /*
   * Test Greenhybrid
   */

  m = 3;
  l = 1;
  delta = 1.0;
  eps_aca = 1.0e-7;

  setup_hmatrix_aprx_greenhybrid_row_bem2d(bem_slp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_greenhybrid_row_bem2d(bem_dlp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem2d_rect_quadpoints);
  test_hmatrix_system("Greenhybrid row", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false);

  setup_hmatrix_aprx_greenhybrid_col_bem2d(bem_slp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_greenhybrid_col_bem2d(bem_dlp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem2d_rect_quadpoints);
  test_hmatrix_system("Greenhybrid column", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false);

  setup_hmatrix_aprx_greenhybrid_mixed_bem2d(bem_slp, root, root, block, m, l,
					     delta, eps_aca,
					     build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_greenhybrid_mixed_bem2d(bem_dlp, root, root, block, m, l,
					     delta, eps_aca,
					     build_bem2d_rect_quadpoints);
  test_hmatrix_system("Greenhybrid mixed", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false);

  /*
   * Test ACA / PACA / HCA
   */

  m = 4;
  eps_aca = 1.0e-6;

  setup_hmatrix_aprx_aca_bem2d(bem_slp, root, root, block, eps_aca);
  setup_hmatrix_aprx_aca_bem2d(bem_dlp, root, root, block, eps_aca);
  test_hmatrix_system("ACA full pivoting", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, false);

  setup_hmatrix_aprx_paca_bem2d(bem_slp, root, root, block, eps_aca);
  setup_hmatrix_aprx_paca_bem2d(bem_dlp, root, root, block, eps_aca);
  test_hmatrix_system("ACA partial pivoting", Vfull, KMfull, block, bem_slp,
		      V, bem_dlp, KM, false);

  setup_hmatrix_aprx_hca_bem2d(bem_slp, root, root, block, m, eps_aca);
  setup_hmatrix_aprx_hca_bem2d(bem_dlp, root, root, block, m, eps_aca);
  test_hmatrix_system("HCA2", Vfull, KMfull, block, bem_slp, V, bem_dlp, KM,
		      false);

  /*
   * H2-matrix
   */

  del_hmatrix(V);
  del_hmatrix(KM);
  del_block(block);

  block = build_strict_block(root, root, &eta, admissible_max_cluster);

  Vrb = build_from_cluster_clusterbasis(root);
  Vcb = build_from_cluster_clusterbasis(root);
  KMrb = build_from_cluster_clusterbasis(root);
  KMcb = build_from_cluster_clusterbasis(root);

  V2 = build_from_block_h2matrix(block, Vrb, Vcb);
  KM2 = build_from_block_h2matrix(block, KMrb, KMcb);

  /*
   * Test Interpolation
   */

  m = 9;

  setup_h2matrix_aprx_inter_bem2d(bem_slp, Vrb, Vcb, block, m);
  setup_h2matrix_aprx_inter_bem2d(bem_dlp, KMrb, KMcb, block, m);
  test_h2matrix_system("Interpolation", Vfull, KMfull, block, bem_slp, V2,
		       bem_dlp, KM2, false);

  /*
   * Test Greenhybrid
   */

  m = 3;
  l = 1;
  delta = 1.0;
  eps_aca = 1.0e-7;

  setup_h2matrix_aprx_greenhybrid_bem2d(bem_slp, Vrb, Vcb, block, m, l, delta,
					eps_aca, build_bem2d_rect_quadpoints);
  setup_h2matrix_aprx_greenhybrid_bem2d(bem_dlp, KMrb, KMcb, block, m, l,
					delta, eps_aca,
					build_bem2d_rect_quadpoints);
  test_h2matrix_system("Greenhybrid", Vfull, KMfull, block, bem_slp, V2,
		       bem_dlp, KM2, false);

  setup_h2matrix_aprx_greenhybrid_ortho_bem2d(bem_slp, Vrb, Vcb, block, m, l,
					      delta, eps_aca,
					      build_bem2d_rect_quadpoints);
  setup_h2matrix_aprx_greenhybrid_ortho_bem2d(bem_dlp, KMrb, KMcb, block, m,
					      l, delta, eps_aca,
					      build_bem2d_rect_quadpoints);
  test_h2matrix_system("Greenhybrid ortho", Vfull, KMfull, block, bem_slp, V2,
		       bem_dlp, KM2, false);

  del_h2matrix(V2);
  del_h2matrix(KM2);
  del_block(block);
  del_bem2d(bem_dlp);

  printf("----------------------------------------\n");
  printf("Testing outer Boundary integral equations:\n");
  printf("----------------------------------------\n\n");

  bem_dlp = new_dlp_laplace_bem2d(gr, q, BASIS_CONSTANT_BEM2D,
				  BASIS_CONSTANT_BEM2D, -0.5);
  block = build_nonstrict_block(root, root, &eta, admissible_max_cluster);
  bem_dlp->nearfield(NULL, NULL, bem_dlp, false, KMfull);

  V = build_from_block_hmatrix(block, 0);
  KM = build_from_block_hmatrix(block, 0);

  /*
   * Test Interpolation
   */

  m = 9;

  setup_hmatrix_aprx_inter_row_bem2d(bem_slp, root, root, block, m);
  setup_hmatrix_aprx_inter_row_bem2d(bem_dlp, root, root, block, m);
  test_hmatrix_system("Interpolation row", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, true);

  setup_hmatrix_aprx_inter_col_bem2d(bem_slp, root, root, block, m);
  setup_hmatrix_aprx_inter_col_bem2d(bem_dlp, root, root, block, m);
  test_hmatrix_system("Interpolation column", Vfull, KMfull, block, bem_slp,
		      V, bem_dlp, KM, true);

  setup_hmatrix_aprx_inter_mixed_bem2d(bem_slp, root, root, block, m);
  setup_hmatrix_aprx_inter_mixed_bem2d(bem_dlp, root, root, block, m);
  test_hmatrix_system("Interpolation mixed", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, true);

  /*
   * Test Green
   */

  m = 10;
  l = 2;
  delta = 0.5;

  setup_hmatrix_aprx_green_row_bem2d(bem_slp, root, root, block, m, l, delta,
				     build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_green_row_bem2d(bem_dlp, root, root, block, m, l, delta,
				     build_bem2d_rect_quadpoints);
  test_hmatrix_system("Green row", Vfull, KMfull, block, bem_slp, V, bem_dlp,
		      KM, true);

  setup_hmatrix_aprx_green_col_bem2d(bem_slp, root, root, block, m, l, delta,
				     build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_green_col_bem2d(bem_dlp, root, root, block, m, l, delta,
				     build_bem2d_rect_quadpoints);
  test_hmatrix_system("Green column", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, true);

  setup_hmatrix_aprx_green_mixed_bem2d(bem_slp, root, root, block, m, l,
				       delta, build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_green_mixed_bem2d(bem_dlp, root, root, block, m, l,
				       delta, build_bem2d_rect_quadpoints);
  test_hmatrix_system("Green mixed", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, true);

  /*
   * Test Greenhybrid
   */

  m = 3;
  l = 1;
  delta = 1.0;
  eps_aca = 1.0e-7;

  setup_hmatrix_aprx_greenhybrid_row_bem2d(bem_slp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_greenhybrid_row_bem2d(bem_dlp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem2d_rect_quadpoints);
  test_hmatrix_system("Greenhybrid row", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, true);

  setup_hmatrix_aprx_greenhybrid_col_bem2d(bem_slp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_greenhybrid_col_bem2d(bem_dlp, root, root, block, m, l,
					   delta, eps_aca,
					   build_bem2d_rect_quadpoints);
  test_hmatrix_system("Greenhybrid column", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, true);

  setup_hmatrix_aprx_greenhybrid_mixed_bem2d(bem_slp, root, root, block, m, l,
					     delta, eps_aca,
					     build_bem2d_rect_quadpoints);
  setup_hmatrix_aprx_greenhybrid_mixed_bem2d(bem_dlp, root, root, block, m, l,
					     delta, eps_aca,
					     build_bem2d_rect_quadpoints);
  test_hmatrix_system("Greenhybrid mixed", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, true);

  /*
   * Test ACA / PACA / HCA
   */

  m = 4;
  eps_aca = 1.0e-6;

  setup_hmatrix_aprx_aca_bem2d(bem_slp, root, root, block, eps_aca);
  setup_hmatrix_aprx_aca_bem2d(bem_dlp, root, root, block, eps_aca);
  test_hmatrix_system("ACA full pivoting", Vfull, KMfull, block, bem_slp, V,
		      bem_dlp, KM, true);

  setup_hmatrix_aprx_paca_bem2d(bem_slp, root, root, block, eps_aca);
  setup_hmatrix_aprx_paca_bem2d(bem_dlp, root, root, block, eps_aca);
  test_hmatrix_system("ACA partial pivoting", Vfull, KMfull, block, bem_slp,
		      V, bem_dlp, KM, true);

  setup_hmatrix_aprx_hca_bem2d(bem_slp, root, root, block, m, eps_aca);
  setup_hmatrix_aprx_hca_bem2d(bem_dlp, root, root, block, m, eps_aca);
  test_hmatrix_system("HCA2", Vfull, KMfull, block, bem_slp, V, bem_dlp, KM,
		      true);

  /*
   * H2-matrix
   */

  del_hmatrix(V);
  del_hmatrix(KM);
  del_block(block);

  block = build_strict_block(root, root, &eta, admissible_max_cluster);

  Vrb = build_from_cluster_clusterbasis(root);
  Vcb = build_from_cluster_clusterbasis(root);
  KMrb = build_from_cluster_clusterbasis(root);
  KMcb = build_from_cluster_clusterbasis(root);

  V2 = build_from_block_h2matrix(block, Vrb, Vcb);
  KM2 = build_from_block_h2matrix(block, KMrb, KMcb);

  /*
   * Test Interpolation
   */

  m = 9;

  setup_h2matrix_aprx_inter_bem2d(bem_slp, Vrb, Vcb, block, m);
  setup_h2matrix_aprx_inter_bem2d(bem_dlp, KMrb, KMcb, block, m);
  test_h2matrix_system("Interpolation", Vfull, KMfull, block, bem_slp, V2,
		       bem_dlp, KM2, true);

  /*
   * Test Greenhybrid
   */

  m = 3;
  l = 1;
  delta = 1.0;
  eps_aca = 1.0e-7;

  setup_h2matrix_aprx_greenhybrid_bem2d(bem_slp, Vrb, Vcb, block, m, l, delta,
					eps_aca, build_bem2d_rect_quadpoints);
  setup_h2matrix_aprx_greenhybrid_bem2d(bem_dlp, KMrb, KMcb, block, m, l,
					delta, eps_aca,
					build_bem2d_rect_quadpoints);
  test_h2matrix_system("Greenhybrid", Vfull, KMfull, block, bem_slp, V2,
		       bem_dlp, KM2, true);

  setup_h2matrix_aprx_greenhybrid_ortho_bem2d(bem_slp, Vrb, Vcb, block, m, l,
					      delta, eps_aca,
					      build_bem2d_rect_quadpoints);
  setup_h2matrix_aprx_greenhybrid_ortho_bem2d(bem_dlp, KMrb, KMcb, block, m,
					      l, delta, eps_aca,
					      build_bem2d_rect_quadpoints);
  test_h2matrix_system("Greenhybrid Ortho", Vfull, KMfull, block, bem_slp, V2,
		       bem_dlp, KM2, true);

  del_h2matrix(V2);
  del_h2matrix(KM2);
  del_block(block);
  freemem(root->idx);
  del_cluster(root);
  del_bem2d(bem_slp);
  del_bem2d(bem_dlp);
  del_amatrix(Vfull);
  del_amatrix(KMfull);
  del_curve2d(gr);

  (void) printf("----------------------------------------\n"
		"  %u matrices and\n"
		"  %u vectors still active\n"
		"  %u errors found\n", getactives_amatrix(),
		getactives_avector(), problems);

  uninit_h2lib();

  return problems;
}
コード例 #3
0
ファイル: test_h2matrix.c プロジェクト: florian98765/H2Lib
int
main()
{
    ph2matrix h2, h2copy, L, R;
    pclusterbasis rb, cb, rbcopy, cbcopy, rblow, cblow, rbup, cbup;
    pclusteroperator rwf, cwf, rwflow, cwflow, rwfup, cwfup, rwfh2, cwfh2;
    ptruncmode tm;

    pavector  x, b;
    uint      n;
    real      error;
    pcurve2d  gr2;
    pbem2d    bem2;
    pcluster  root2;
    pblock    block2;
    uint      clf, m;
    real      tol, eta, delta, eps_aca;

    n = 579;
    tol = 1.0e-13;

    clf = 16;
    eta = 1.0;
    m = 4;
    delta = 1.0;
    eps_aca = 1.0e-13;

    gr2 = new_circle_curve2d(n, 0.333);
    bem2 = new_slp_laplace_bem2d(gr2, 2, BASIS_CONSTANT_BEM2D);
    root2 = build_bem2d_cluster(bem2, clf, BASIS_CONSTANT_BEM2D);
    block2 = build_strict_block(root2, root2, &eta, admissible_max_cluster);

    rb = build_from_cluster_clusterbasis(root2);
    cb = build_from_cluster_clusterbasis(root2);
    setup_h2matrix_aprx_greenhybrid_bem2d(bem2, rb, cb, block2, m, 1, delta,
                                          eps_aca, build_bem2d_rect_quadpoints);

    (void) printf("----------------------------------------\n"
                  "Check %u x %u Cholesky factorization\n", n, n);

    (void) printf("Creating laplacebem2d SLP matrix\n");
    assemble_bem2d_h2matrix_row_clusterbasis(bem2, rb);
    assemble_bem2d_h2matrix_col_clusterbasis(bem2, cb);
    h2 = build_from_block_h2matrix(block2, rb, cb);
    assemble_bem2d_h2matrix(bem2, block2, h2);

    (void) printf("Creating random solution and right-hand side\n");
    x = new_avector(n);
    random_avector(x);
    b = new_avector(n);
    clear_avector(b);
    mvm_h2matrix_avector(1.0, false, h2, x, b);

    (void) printf("Copying matrix\n");

    rbcopy = clone_clusterbasis(h2->rb);
    cbcopy = clone_clusterbasis(h2->cb);
    h2copy = clone_h2matrix(h2, rbcopy, cbcopy);


    (void) printf("Computing Cholesky factorization\n");

    tm = new_releucl_truncmode();
    rblow = build_from_cluster_clusterbasis(root2);
    cblow = build_from_cluster_clusterbasis(root2);
    L = build_from_block_lower_h2matrix(block2, rblow, cblow);

    rwflow = prepare_row_clusteroperator(L->rb, L->cb, tm);
    cwflow = prepare_col_clusteroperator(L->rb, L->cb, tm);
    rwf = NULL;
    cwf = NULL;
    init_cholesky_h2matrix(h2, &rwf, &cwf, tm);
    choldecomp_h2matrix(h2, rwf, cwf, L, rwflow, cwflow, tm, tol);

    (void) printf("Solving\n");

    cholsolve_h2matrix_avector(L, b);

    add_avector(-1.0, x, b);
    error = norm2_avector(b) / norm2_avector(x);
    (void) printf("  Accuracy %g, %sokay\n", error,
                  IS_IN_RANGE(2.0e-13, error, 3.0e-12) ? "" : "    NOT ");
    if (!IS_IN_RANGE(2.0e-13, error, 3.0e-12))
        problems++;

    rwfh2 = prepare_row_clusteroperator(h2copy->rb, h2copy->cb, tm);
    cwfh2 = prepare_col_clusteroperator(h2copy->rb, h2copy->cb, tm);

    (void) printf("Checking factorization\n");
    error = norm2_h2matrix(h2copy);
    addmul_h2matrix(-1.0, L, true, L, h2copy, rwfh2, cwfh2, tm, tol);
    error = norm2_h2matrix(h2copy) / error;
    (void) printf("  Accuracy %g, %sokay\n", error,
                  IS_IN_RANGE(4.0e-15, error, 4.0e-14) ? "" : "    NOT ");
    if (!IS_IN_RANGE(4.0e-15, error, 4.0e-14))
        problems++;




    del_h2matrix(h2copy);
    del_h2matrix(h2);
    del_h2matrix(L);
    del_avector(b);
    del_avector(x);
    del_truncmode(tm);

    del_clusteroperator(rwflow);
    del_clusteroperator(cwflow);
    del_clusteroperator(rwf);
    del_clusteroperator(cwf);
    del_clusteroperator(rwfh2);
    del_clusteroperator(cwfh2);


    rb = build_from_cluster_clusterbasis(root2);
    cb = build_from_cluster_clusterbasis(root2);
    setup_h2matrix_aprx_greenhybrid_bem2d(bem2, rb, cb, block2, m, 1, delta,
                                          eps_aca, build_bem2d_rect_quadpoints);

    (void) printf("----------------------------------------\n"
                  "Check %u x %u LR factorization\n", n, n);

    (void) printf("Creating laplacebem2d SLP matrix\n");
    assemble_bem2d_h2matrix_row_clusterbasis(bem2, rb);
    assemble_bem2d_h2matrix_col_clusterbasis(bem2, cb);
    h2 = build_from_block_h2matrix(block2, rb, cb);
    assemble_bem2d_h2matrix(bem2, block2, h2);

    (void) printf("Creating random solution and right-hand side\n");
    x = new_avector(n);
    random_avector(x);
    b = new_avector(n);
    clear_avector(b);
    mvm_h2matrix_avector(1.0, false, h2, x, b);

    (void) printf("Copying matrix\n");
    rbcopy = clone_clusterbasis(h2->rb);
    cbcopy = clone_clusterbasis(h2->cb);
    h2copy = clone_h2matrix(h2, rbcopy, cbcopy);

    (void) printf("Computing LR factorization\n");
    rblow = build_from_cluster_clusterbasis(root2);
    cblow = build_from_cluster_clusterbasis(root2);
    L = build_from_block_lower_h2matrix(block2, rblow, cblow);

    rbup = build_from_cluster_clusterbasis(root2);
    cbup = build_from_cluster_clusterbasis(root2);
    R = build_from_block_upper_h2matrix(block2, rbup, cbup);

    tm = new_releucl_truncmode();
    rwf = prepare_row_clusteroperator(h2->rb, h2->cb, tm);
    cwf = prepare_col_clusteroperator(h2->rb, h2->cb, tm);
    rwflow = prepare_row_clusteroperator(L->rb, L->cb, tm);
    cwflow = prepare_col_clusteroperator(L->rb, L->cb, tm);
    rwfup = prepare_row_clusteroperator(R->rb, R->cb, tm);
    cwfup = prepare_col_clusteroperator(R->rb, R->cb, tm);

    lrdecomp_h2matrix(h2, rwf, cwf, L, rwflow, cwflow, R, rwfup, cwfup, tm,
                      tol);

    (void) printf("Solving\n");
    lrsolve_h2matrix_avector(L, R, b);

    add_avector(-1.0, x, b);
    error = norm2_avector(b) / norm2_avector(x);
    (void) printf("  Accuracy %g, %sokay\n", error,
                  IS_IN_RANGE(2e-13, error, 2e-12) ? "" : "    NOT ");
    if (!IS_IN_RANGE(2e-13, error, 2e-12))
        problems++;


    rwfh2 = prepare_row_clusteroperator(h2copy->rb, h2copy->cb, tm);
    cwfh2 = prepare_col_clusteroperator(h2copy->rb, h2copy->cb, tm);

    (void) printf("Checking factorization\n");
    error = norm2_h2matrix(h2copy);
    addmul_h2matrix(-1.0, L, false, R, h2copy, rwfh2, cwfh2, tm, tol);
    error = norm2_h2matrix(h2copy) / error;
    (void) printf("  Accuracy %g, %sokay\n", error,
                  IS_IN_RANGE(4.0e-15, error, 5.0e-14) ? "" : "    NOT ");
    if (!IS_IN_RANGE(4.0e-15, error, 5.0e-14))
        problems++;


    /* Final clean-up */
    (void) printf("Cleaning up\n");

    del_h2matrix(h2);
    del_h2matrix(h2copy);
    del_h2matrix(L);
    del_h2matrix(R);
    del_clusteroperator(rwf);
    del_clusteroperator(cwf);
    del_clusteroperator(rwflow);
    del_clusteroperator(cwflow);
    del_clusteroperator(rwfup);
    del_clusteroperator(cwfup);
    del_clusteroperator(rwfh2);
    del_clusteroperator(cwfh2);

    del_avector(b);
    del_avector(x);
    del_truncmode(tm);

    freemem(root2->idx);
    del_bem2d(bem2);
    del_block(block2);
    del_cluster(root2);
    del_curve2d(gr2);

    (void) printf("----------------------------------------\n"
                  "  %u matrices and\n"
                  "  %u vectors still active\n"
                  "  %u errors found\n", getactives_amatrix(),
                  getactives_avector(), problems);

    return problems;
}