Skip to content

Commit

Permalink
Merge pull request #939 from DLR-AMR/add-parametrized_cmesh_example
Browse files Browse the repository at this point in the history
Add parametrized cmesh example
  • Loading branch information
Davknapp authored Mar 1, 2024
2 parents 29524e9 + ea509a1 commit 6234992
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/t8_cmesh/t8_cmesh_examples.c
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,10 @@ t8_cmesh_t
t8_cmesh_new_disjoint_bricks (t8_gloidx_t num_x, t8_gloidx_t num_y, t8_gloidx_t num_z, int x_periodic, int y_periodic,
int z_periodic, sc_MPI_Comm comm)
{
if (!sc_package_is_registered (p4est_package_id)) {
t8_global_errorf ("WARNING: p4est is not yet initialized. Doing it now for you.\n");
p4est_init (NULL, SC_LP_ESSENTIAL);
}
p4est_connectivity_t *my_brick = NULL; /* pre-initialized to prevent compiler warning */
p8est_connectivity_t *my_brick_3d = NULL;
t8_cmesh_t cmesh;
Expand Down
7 changes: 4 additions & 3 deletions test/t8_cmesh_generator/t8_cmesh_example_sets.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ along with t8code; if not, write to the Free Software Foundation, Inc.,
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_new_prism_cake_param.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_new_from_class_param.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_new_bigmesh_param.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_new_disjoint_bricks_param.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_new_comm.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_new_hypercube_pad.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_new_hypercube_param.hxx"
Expand All @@ -49,9 +50,9 @@ auto pretty_print_base_example = [] (const testing::TestParamInfo<cmesh_example_
namespace cmesh_list
{
std::vector<example_set *> cart_prod_vec
= { new_from_class::cmesh_example, new_prism_cake::cmesh_example, new_bigmesh::cmesh_example,
new_cmesh_comm::cmesh_example, new_hypercube_pad::cmesh_example, new_hypercube_cmesh::cmesh_example,
new_hypercube_cmesh::cmesh_example_pyra };
= { new_from_class::cmesh_example, new_prism_cake::cmesh_example, new_bigmesh::cmesh_example,
new_cmesh_comm::cmesh_example, new_hypercube_pad::cmesh_example, new_hypercube_cmesh::cmesh_example,
new_hypercube_cmesh::cmesh_example_pyra, new_disjoint_bricks::cmesh_example };

cmesh_sum_of_sets cmesh_sums (cart_prod_vec);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
This file is part of t8code.
t8code is a C library to manage a collection (a forest) of multiple
connected adaptive space-trees of general element classes in parallel.
Copyright (C) 2024 the developers
t8code is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
t8code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with t8code; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include "test/t8_cmesh_generator/t8_gtest_cmesh_cartestian_product.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_params.hxx"
#include "t8_cmesh/t8_cmesh_examples.h"

#ifndef T8_CMESH_NEW_DISJOINT_BRICKS_PARAM_HXX
#define T8_CMESH_NEW_DISJOINT_BRICKS_PARAM_HXX

namespace new_disjoint_bricks
{
std::function<t8_cmesh_t (t8_gloidx_t, t8_gloidx_t, t8_gloidx_t, int, int, int, sc_MPI_Comm)> disjoint_bricks
= t8_cmesh_new_disjoint_bricks;

std::string
make_param_string (const t8_gloidx_t num_x, const t8_gloidx_t num_y, const t8_gloidx_t num_z, const int num_x_periodic,
const int num_y_periodic, const int num_z_periodic, sc_MPI_Comm comm)
{
std::string delimiter = std::string ("_");
std::string params = delimiter + std::to_string (num_x) + delimiter + std::to_string (num_y) + delimiter
+ std::to_string (num_z) + delimiter + std::to_string (num_x_periodic) + delimiter
+ std::to_string (num_y_periodic) + delimiter + std::to_string (num_z_periodic) + delimiter
+ cmesh_params::comm_to_string (comm);
return params;
}

std::function<std::string (const t8_gloidx_t, const t8_gloidx_t, const t8_gloidx_t, const int, const int, const int,
const sc_MPI_Comm)>
make_param_string_wrapper = make_param_string;

example_set *cmesh_example = (example_set *) new cmesh_cartesian_product_params<
decltype (cmesh_params::elems_per_dim.begin ()), decltype (cmesh_params::elems_per_dim.begin ()),
decltype (cmesh_params::elems_per_dim.begin ()), decltype (cmesh_params::periodic.begin ()),
decltype (cmesh_params::periodic.begin ()), decltype (cmesh_params::periodic.begin ()),
decltype (cmesh_params::my_comms.begin ())> (
std::make_pair (cmesh_params::elems_per_dim.begin (), cmesh_params::elems_per_dim.end ()),
std::make_pair (cmesh_params::elems_per_dim.begin (), cmesh_params::elems_per_dim.end ()),
std::make_pair (cmesh_params::elems_per_dim.begin (), cmesh_params::elems_per_dim.end ()),
std::make_pair (cmesh_params::periodic.begin (), cmesh_params::periodic.end ()),
std::make_pair (cmesh_params::periodic.begin (), cmesh_params::periodic.end ()),
std::make_pair (cmesh_params::periodic.begin (), cmesh_params::periodic.end ()),
std::make_pair (cmesh_params::my_comms.begin (), cmesh_params::my_comms.end ()), disjoint_bricks,
make_param_string_wrapper, "t8_cmesh_new_disjoint_brick_");
} // namespace new_disjoint_bricks

#endif /* T8_CMESH_NEW_DISJOINT_BRICKS_PARAM_HXX */
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ comm_to_string (const sc_MPI_Comm &comm)
return std::string ("No_String_for_this_communicator");
}

std::vector<int>
filled_vector (const size_t size, int start)
template <typename T>
std::vector<T>
filled_vector (const size_t size, T start)
{
std::vector<int> tmp (size);
std::vector<T> tmp (size);
std::iota (tmp.begin (), tmp.end (), start);
return tmp;
}
Expand All @@ -63,7 +64,7 @@ std::vector<int> use_axis_aligned = { 0, 1 };

std::vector<int> large_mesh = filled_vector (20, 500);

std::vector<int> elems_per_dim = filled_vector (5, 1);
std::vector<int> elems_per_dim = filled_vector (3, 1);

std::vector<sc_MPI_Comm> my_comms = { sc_MPI_COMM_WORLD };
std::vector<t8_eclass_t> eclasses = { T8_ECLASS_VERTEX, T8_ECLASS_LINE, T8_ECLASS_QUAD, T8_ECLASS_TRIANGLE,
Expand Down

0 comments on commit 6234992

Please sign in to comment.