t8code icon indicating copy to clipboard operation
t8code copied to clipboard

Introduce populate functionality according to cmesh borders

Open lukasdreyer opened this issue 1 year ago • 1 comments

Describe your changes here: Unclean version of creating a forest according to the partitioned cmesh boundaries (cmesh elements are not allowed to be shared). For discussions with @CsatiZoltan about whether this satisfies his requirements.

All these boxes must be checked by the reviewers before merging the pull request:

As a reviewer please read through all the code lines and make sure that the code is fully understood, bug free, well-documented and well-structured.

General

  • [ ] The reviewer executed the new code features at least once and checked the results manually

  • [ ] The code follows the t8code coding guidelines

  • [ ] New source/header files are properly added to the Makefiles

  • [ ] The code is well documented

  • [ ] All function declarations, structs/classes and their members have a proper doxygen documentation

  • [ ] All new algorithms and data structures are sufficiently optimal in terms of memory and runtime (If this should be merged, but there is still potential for optimization, create a new issue)

Tests

  • [ ] The code is covered in an existing or new test case using Google Test

Github action

  • [ ] The code compiles without warning in debugging and release mode, with and without MPI (this should be executed automatically in a github action)

  • [ ] All tests pass (in various configurations, this should be executed automatically in a github action)

    If the Pull request introduces code that is not covered by the github action (for example coupling with a new library):

    • [ ] Should this use case be added to the github action?
    • [ ] If not, does the specific use case compile and all tests pass (check manually)

Scripts and Wiki

  • [ ] If a new directory with source-files is added, it must be covered by the script/find_all_source_files.scp to check the indentation of these files.
  • [ ] If this PR introduces a new feature, it must be covered in an example/tutorial and a Wiki article.

Licence

  • [ ] The author added a BSD statement to doc/ (or already has one)

lukasdreyer avatar Mar 25 '24 07:03 lukasdreyer

Here are two additional tests with three quadratic quads. The two_one_quad should fail, theone_two_quad test should pass.

TEST (t8_forest_new_from_partition, one_two_quad)
{
  /* Current process */
  int rank, size;
  sc_MPI_Comm_size (sc_MPI_COMM_WORLD, &size);
  sc_MPI_Comm_rank (sc_MPI_COMM_WORLD, &rank);

  /* Geometry */
  int degree = 2;
  std::vector<std::vector<double>> cells;
  cells.push_back (std::vector<double> { -1, 1.2, 0,   0, 1.2,  0,   -1, 3,    0, 0, 3,    0,   -1, 2.1,
                                         0,  0,   2.1, 0, -0.5, 1.2, 0,  -0.5, 3, 0, -0.5, 2.1, 0 });
  cells.push_back (std::vector<double> { 0, 1.2, 0,   2, 1.5, 0,    0, 3, 0, 2, 3,   0,   0, 2.1,
                                         0, 1.7, 2.1, 0, 1,   1.55, 0, 1, 3, 0, 0.9, 2.1, 0 });
  cells.push_back (
    std::vector<double> { 2, 1.5, 0, 4, 0, 0, 2, 3, 0, 4, 3, 0, 1.7, 2.1, 0, 4, 1.5, 0, 3, 1, 0, 3, 3, 0, 3, 2, 0 });

  /* Create a partitioned cmesh */
  t8_cmesh_t cmesh;
  t8_cmesh_init (&cmesh);
  if (size != 2)
    SC_ABORT ("Program must be run on two MPI processes.\n");
  else {
    if (rank == 0) {
      t8_cmesh_set_tree_class (cmesh, 0, T8_ECLASS_QUAD);
      t8_cmesh_set_tree_class (cmesh, 1, T8_ECLASS_QUAD);
      t8_cmesh_set_tree_vertices (cmesh, 0, cells[0].data (), cells[0].size ());
      t8_cmesh_set_tree_vertices (cmesh, 1, cells[1].data (), cells[1].size ());
      t8_cmesh_set_attribute (cmesh, 0, t8_get_package_id (), T8_CMESH_LAGRANGE_POLY_DEGREE, &degree, sizeof (int), 1);
      t8_cmesh_set_attribute (cmesh, 1, t8_get_package_id (), T8_CMESH_LAGRANGE_POLY_DEGREE, &degree, sizeof (int), 1);
      t8_cmesh_set_join (cmesh, 0, 1, 1, 0, 0);
      t8_cmesh_set_partition_range (cmesh, 3, 0, 0);
    }
    else if (rank == 1) {
      for (size_t itree = 0; itree < 3; ++itree) {
        t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD);
        t8_cmesh_set_tree_vertices (cmesh, itree, cells[itree].data (), cells[itree].size ());
        t8_cmesh_set_attribute (cmesh, itree, t8_get_package_id (), T8_CMESH_LAGRANGE_POLY_DEGREE, &degree,
                                sizeof (int), 1);
      }
      t8_cmesh_set_join (cmesh, 0, 1, 1, 0, 0);
      t8_cmesh_set_join (cmesh, 1, 2, 1, 0, 0);
      t8_cmesh_set_partition_range (cmesh, 3, 1, 2);
    }
  }
  t8_cmesh_register_geometry<t8_geometry_lagrange> (cmesh, 2);
  t8_cmesh_commit (cmesh, sc_MPI_COMM_WORLD);
  t8_cmesh_vtk_write_file (cmesh, "cmesh");
  t8_forest_t forest
    = t8_forest_new_uniform_with_cmesh_partition (cmesh, t8_scheme_new_default_cxx (), 0, 0, sc_MPI_COMM_WORLD);
  // t8_forest_t forest = t8_forest_new_uniform (cmesh, t8_scheme_new_default_cxx (), 0, 1, sc_MPI_COMM_WORLD);
  t8_forest_write_vtk (forest, "forest");
  t8_cmesh_destroy (&cmesh);
}

TEST (t8_forest_new_from_partition, two_one_quad)
{
  /* Current process */
  int rank, size;
  sc_MPI_Comm_size (sc_MPI_COMM_WORLD, &size);
  sc_MPI_Comm_rank (sc_MPI_COMM_WORLD, &rank);

  /* Geometry */
  int degree = 2;
  std::vector<std::vector<double>> cells;
  cells.push_back (std::vector<double> { -1, 1.2, 0,   0, 1.2,  0,   -1, 3,    0, 0, 3,    0,   -1, 2.1,
                                         0,  0,   2.1, 0, -0.5, 1.2, 0,  -0.5, 3, 0, -0.5, 2.1, 0 });
  cells.push_back (std::vector<double> { 0, 1.2, 0,   2, 1.5, 0,    0, 3, 0, 2, 3,   0,   0, 2.1,
                                         0, 1.7, 2.1, 0, 1,   1.55, 0, 1, 3, 0, 0.9, 2.1, 0 });
  cells.push_back (
    std::vector<double> { 2, 1.5, 0, 4, 0, 0, 2, 3, 0, 4, 3, 0, 1.7, 2.1, 0, 4, 1.5, 0, 3, 1, 0, 3, 3, 0, 3, 2, 0 });

  /* Create a partitioned cmesh */
  t8_cmesh_t cmesh;
  t8_cmesh_init (&cmesh);
  if (size != 2)
    SC_ABORT ("Program must be run on two MPI processes.\n");
  else {
    if (rank == 0) {
      for (size_t itree = 0; itree < 3; ++itree) {
        t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD);
        t8_cmesh_set_tree_vertices (cmesh, itree, cells[itree].data (), cells[itree].size ());
        t8_cmesh_set_attribute (cmesh, itree, t8_get_package_id (), T8_CMESH_LAGRANGE_POLY_DEGREE, &degree,
                                sizeof (int), 1);
      }
      t8_cmesh_set_join (cmesh, 0, 1, 1, 0, 0);
      t8_cmesh_set_join (cmesh, 1, 2, 1, 0, 0);
      t8_cmesh_set_partition_range (cmesh, 3, 0, 1);
    }
    else if (rank == 1) {
      t8_cmesh_set_tree_class (cmesh, 1, T8_ECLASS_QUAD);
      t8_cmesh_set_tree_class (cmesh, 2, T8_ECLASS_QUAD);
      t8_cmesh_set_tree_vertices (cmesh, 1, cells[1].data (), cells[1].size ());
      t8_cmesh_set_tree_vertices (cmesh, 2, cells[2].data (), cells[2].size ());
      t8_cmesh_set_attribute (cmesh, 1, t8_get_package_id (), T8_CMESH_LAGRANGE_POLY_DEGREE, &degree, sizeof (int), 1);
      t8_cmesh_set_attribute (cmesh, 2, t8_get_package_id (), T8_CMESH_LAGRANGE_POLY_DEGREE, &degree, sizeof (int), 1);
      t8_cmesh_set_join (cmesh, 1, 2, 1, 0, 0);
      t8_cmesh_set_partition_range (cmesh, 3, 2, 2);
    }
  }
  t8_cmesh_register_geometry<t8_geometry_lagrange> (cmesh, 2);
  t8_cmesh_commit (cmesh, sc_MPI_COMM_WORLD);
  t8_cmesh_vtk_write_file (cmesh, "cmesh");
  t8_forest_t forest
    = t8_forest_new_uniform_with_cmesh_partition (cmesh, t8_scheme_new_default_cxx (), 0, 0, sc_MPI_COMM_WORLD);
  // t8_forest_t forest = t8_forest_new_uniform (cmesh, t8_scheme_new_default_cxx (), 0, 1, sc_MPI_COMM_WORLD);
  t8_forest_write_vtk (forest, "forest");
  t8_cmesh_destroy (&cmesh);
}

CsatiZoltan avatar Mar 25 '24 16:03 CsatiZoltan