From 2e4e7eaa50649f15c9c6a5545beb8fb3184a94ff Mon Sep 17 00:00:00 2001 From: nivesh Date: Fri, 8 Jun 2018 16:31:36 +0200 Subject: [PATCH] removed fe_enriched.templates.h and moved functions in internal namespace to fe_enriched.h --- include/deal.II/fe/fe_enriched.h | 188 +++++++++++++++++- include/deal.II/fe/fe_enriched.templates.h | 212 --------------------- source/fe/fe_enriched.cc | 4 +- tests/fe/fe_enriched_color_01.cc | 2 +- tests/fe/fe_enriched_color_02.cc | 2 +- tests/fe/fe_enriched_color_03.cc | 2 +- tests/fe/fe_enriched_color_04.cc | 2 +- tests/fe/fe_enriched_color_05.cc | 2 +- 8 files changed, 194 insertions(+), 220 deletions(-) delete mode 100644 include/deal.II/fe/fe_enriched.templates.h diff --git a/include/deal.II/fe/fe_enriched.h b/include/deal.II/fe/fe_enriched.h index 67335a223e..ecd651be01 100644 --- a/include/deal.II/fe/fe_enriched.h +++ b/include/deal.II/fe/fe_enriched.h @@ -721,6 +721,192 @@ namespace ColorEnriched using predicate_function = std::function::cell_iterator &)>; + namespace internal + { + /** + * Returns true if there is a connection between subdomains in the mesh + * associated with @p hp::DoFHandler i.e., if the subdomains share at least + * a vertex. The two subdomains are defined by predicates provided by + * @p predicate_1 and @p predicate_2. A predicate is a function (or + * object of a type with an operator()) which takes in a cell iterator and + * gives a boolean. It is said to be active in a cell if it returns true. + * + * An example of a custom predicate is one that checks the distance from a + * fixed point. Note that the operator() takes in a cell iterator. Using the + * constructor, the fixed point and the distance can be chosen. + * @code + * + * struct predicate + * { + * predicate(const Point p, const int radius) + * :p(p),radius(radius){} + * + * template + * bool operator () (const Iterator &i) + * { + * return ( (i->center() - p).norm() < radius); + * } + * + * private: + * Point p; + * int radius; + * + * }; + * @endcode + * and then the function can be used as follows to find if the subdomains + * are connected. + * @code + * find_connection_between_subdomains + * (dof_handler, + * predicate(Point(0,0), 1) + * predicate(Point(2,2), 1)); + * @endcode + * + * @param[in] hp::DoFHandler object + * @param[in] predicate_1 A function (or object of a type with an + * operator()) defining the subdomain 1. The function takes in a cell and + * returns a boolean. + * @param[in] predicate_2 Same as @p predicate_1 but defines subdomain 2. + * @return A boolean "true" if the subdomains share atleast a vertex. + */ + template + bool + find_connection_between_subdomains( + const hp::DoFHandler & dof_handler, + const predicate_function &predicate_1, + const predicate_function &predicate_2); + + /** + * Assign colors to subdomains using Graph coloring algorithm where each + * subdomain is considered as a graph node. Subdomains which are + * connected i.e share atleast a vertex have different color. Each subdomain + * is defined using a predicate function of @p predicates. + * + * @param[in] dof_handler a hp::DoFHandler object + * @param[in] predicates predicates defining the subdomains + * @param[out] predicate_colors Colors (unsigned int) associated with each + * subdomain. + */ + template + unsigned int + color_predicates( + const hp::DoFHandler & dof_handler, + const std::vector> &predicates, + std::vector & predicate_colors); + + /** + * Used to construct data members @p cellwise_color_predicate_map and + * @p fe_sets of Helper class. Inputs are hp::DoFHandler object, + * vector of predicates and colors associated with them. Before calling + * this function, colors can be assigned to predicates (i.e subdomains) + * using the function color_predicates. + * + * Each active FE index has a set of colors associated with it. + * A cell with an active FE index i has a set of colors given by + * fe_sets[i]. An active FE index with color {a,b} + * means that the cell has two active predicates (i.e they return true + * for the cell) of color a and b. + * + * Eg: fe_sets = { {}, {1}, {2}, {1,2} } means + * Cells with active FE index 0 have no predicates associated. + * Cells with index 1 have a active predicate with color 1. + * Cells with index 2 have a active predicate with color 2. + * Cells with index 3 have active predicates with color 1 and color 2. + * + * A map of maps cellwise_color_predicate_map is used to associate + * predicate colors in cells with predicate ids. For this purpose, each + * cell is given a unique id which is stored in material id for now. + * When the grid is refined, material id is inherited to the children, so + * map which associates material id with color map will still be relevant. + * + * Now the color map can be explained with an example. If the cell with + * material id 100 has active predicates 4 (color = 1) and 5 (color = 2), + * the map will insert pairs (1, 4) and (2, 5) at key 100 (i.e unique id + * of cell is mapped with a map which associates color with predicate id). + * + * @param[in] dof_handler hp::DoFHandler object + * @param[in] predicates vector of predicates defining the subdomains. + * @p predicates[i] returns true for a cell if it + * belongs to subdomain with index i. + * @param[in] predicate_colors vector of colors (unsigned int) associated + * with each subdomain. + * @param[out] cellwise_color_predicate_map A map of maps used to associate + * predicate colors in cells with predicate ids. + * @param[out] fe_sets a vector of color lists + */ + template + void + set_cellwise_color_set_and_fe_index( + hp::DoFHandler & dof_handler, + const std::vector> &predicates, + const std::vector & predicate_colors, + std::map> + & cellwise_color_predicate_map, + std::vector> &fe_sets); + + /** + * A function that returns a vector of enrichment functions corresponding + * to a color. The size of the vector is equal to total number of different + * colors associated with predicates (i.e subdomains). + * + * Assume that a cell has a active predicates with ids 4 (color = 1) and + * 5 (color = 2). cellwise_color_predicate_map has this information + * provided we know the material id. + * + * Now a call to color_enrichment[1](cell) should in turn call + * enrichments[4](cell). + * + * @param[in] num_colors number of colors for predicates + * @param[in] enrichments vector of enrichment functions + * @param[in] cellwise_color_predicate_map A map of maps used to associate + * predicate colors in cells with predicate ids. + * @param[out] color_enrichments A vector of functions that take in cell + * and return a function pointer. + */ + template + void + make_colorwise_enrichment_functions( + const unsigned int & num_colors, + const std::vector>> &enrichments, + const std::map> + &cellwise_color_predicate_map, + std::vector *( + const typename Triangulation::cell_iterator &)>> + &color_enrichments); + + + /** + * Creates a hp::FECollection object constructed using FE_Enriched + * elements which itself is constructed using color enrichment functions + * and is of size equal to number of colors. + * + * @param[in] fe_sets a vector of color lists + * @param[in] color_enrichments A vector of functions that take in cell + * and return a function pointer. + * @param[in] fe_base base FiniteElement + * @param[in] fe_enriched enriched FiniteElements + * @param[in] fe_nothing a finite element with zero degrees of freedom + * @param[out] fe_collection a collection of + * finite elements + */ + template + void + make_fe_collection_from_colored_enrichments( + const unsigned int &num_colors, + const std::vector> + &fe_sets, // total list of color sets possible + const std::vector *( + const typename Triangulation::cell_iterator &)>> + &color_enrichments, // color wise enrichment functions + const FE_Q &fe_base, // basic FE element + const FE_Q + &fe_enriched, // FE element multiplied by enrichment function + const FE_Nothing &fe_nothing, + hp::FECollection &fe_collection); + } // namespace internal + + + /** * ColorEnriched::Helper class creates a collection of FE_Enriched finite * elements (hp::FECollection) to be used with hp::DoFHandler in a domain @@ -1005,7 +1191,7 @@ namespace ColorEnriched std::vector> fe_sets; }; } // namespace ColorEnriched -//} + DEAL_II_NAMESPACE_CLOSE #endif // dealii_fe_enriched_h diff --git a/include/deal.II/fe/fe_enriched.templates.h b/include/deal.II/fe/fe_enriched.templates.h deleted file mode 100644 index 674aebef12..0000000000 --- a/include/deal.II/fe/fe_enriched.templates.h +++ /dev/null @@ -1,212 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 2016 - 2017 by the deal.II authors -// -// This file is part of the deal.II library. -// -// The deal.II library is free software; you can use it, redistribute -// it, and/or modify it under the terms of the GNU Lesser General -// Public License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// The full text of the license can be found in the file LICENSE at -// the top level of the deal.II distribution. -// -// --------------------------------------------------------------------- - -#ifndef dealii_fe_enriched_templates_h -#define dealii_fe_enriched_templates_h - -#include - -DEAL_II_NAMESPACE_OPEN - -namespace ColorEnriched -{ - namespace internal - { - /** - * Returns true if there is a connection between subdomains in the mesh - * associated with @p hp::DoFHandler i.e., if the subdomains share at least - * a vertex. The two subdomains are defined by predicates provided by - * @p predicate_1 and @p predicate_2. A predicate is a function (or - * object of a type with an operator()) which takes in a cell iterator and - * gives a boolean. It is said to be active in a cell if it returns true. - * - * An example of a custom predicate is one that checks the distance from a - * fixed point. Note that the operator() takes in a cell iterator. Using the - * constructor, the fixed point and the distance can be chosen. - * @code - * - * struct predicate - * { - * predicate(const Point p, const int radius) - * :p(p),radius(radius){} - * - * template - * bool operator () (const Iterator &i) - * { - * return ( (i->center() - p).norm() < radius); - * } - * - * private: - * Point p; - * int radius; - * - * }; - * @endcode - * and then the function can be used as follows to find if the subdomains - * are connected. - * @code - * find_connection_between_subdomains - * (dof_handler, - * predicate(Point(0,0), 1) - * predicate(Point(2,2), 1)); - * @endcode - * - * @param[in] hp::DoFHandler object - * @param[in] predicate_1 A function (or object of a type with an - * operator()) defining the subdomain 1. The function takes in a cell and - * returns a boolean. - * @param[in] predicate_2 Same as @p predicate_1 but defines subdomain 2. - * @return A boolean "true" if the subdomains share atleast a vertex. - */ - template - bool - find_connection_between_subdomains( - const hp::DoFHandler & dof_handler, - const predicate_function &predicate_1, - const predicate_function &predicate_2); - - /** - * Assign colors to subdomains using Graph coloring algorithm where each - * subdomain is considered as a graph node. Subdomains which are - * connected i.e share atleast a vertex have different color. Each subdomain - * is defined using a predicate function of @p predicates. - * - * @param[in] dof_handler a hp::DoFHandler object - * @param[in] predicates predicates defining the subdomains - * @param[out] predicate_colors Colors (unsigned int) associated with each - * subdomain. - */ - template - unsigned int - color_predicates( - const hp::DoFHandler & dof_handler, - const std::vector> &predicates, - std::vector & predicate_colors); - - /** - * Used to construct data members @p cellwise_color_predicate_map and - * @p fe_sets of Helper class. Inputs are hp::DoFHandler object, - * vector of predicates and colors associated with them. Before calling - * this function, colors can be assigned to predicates (i.e subdomains) - * using the function color_predicates. - * - * Each active FE index has a set of colors associated with it. - * A cell with an active FE index i has a set of colors given by - * fe_sets[i]. An active FE index with color {a,b} - * means that the cell has two active predicates (i.e they return true - * for the cell) of color a and b. - * - * Eg: fe_sets = { {}, {1}, {2}, {1,2} } means - * Cells with active FE index 0 have no predicates associated. - * Cells with index 1 have a active predicate with color 1. - * Cells with index 2 have a active predicate with color 2. - * Cells with index 3 have active predicates with color 1 and color 2. - * - * A map of maps cellwise_color_predicate_map is used to associate - * predicate colors in cells with predicate ids. For this purpose, each - * cell is given a unique id which is stored in material id for now. - * When the grid is refined, material id is inherited to the children, so - * map which associates material id with color map will still be relevant. - * - * Now the color map can be explained with an example. If the cell with - * material id 100 has active predicates 4 (color = 1) and 5 (color = 2), - * the map will insert pairs (1, 4) and (2, 5) at key 100 (i.e unique id - * of cell is mapped with a map which associates color with predicate id). - * - * @param[in] dof_handler hp::DoFHandler object - * @param[in] predicates vector of predicates defining the subdomains. - * @p predicates[i] returns true for a cell if it - * belongs to subdomain with index i. - * @param[in] predicate_colors vector of colors (unsigned int) associated - * with each subdomain. - * @param[out] cellwise_color_predicate_map A map of maps used to associate - * predicate colors in cells with predicate ids. - * @param[out] fe_sets a vector of color lists - */ - template - void - set_cellwise_color_set_and_fe_index( - hp::DoFHandler & dof_handler, - const std::vector> &predicates, - const std::vector & predicate_colors, - std::map> - & cellwise_color_predicate_map, - std::vector> &fe_sets); - - /** - * A function that returns a vector of enrichment functions corresponding - * to a color. The size of the vector is equal to total number of different - * colors associated with predicates (i.e subdomains). - * - * Assume that a cell has a active predicates with ids 4 (color = 1) and - * 5 (color = 2). cellwise_color_predicate_map has this information - * provided we know the material id. - * - * Now a call to color_enrichment[1](cell) should in turn call - * enrichments[4](cell). - * - * @param[in] num_colors number of colors for predicates - * @param[in] enrichments vector of enrichment functions - * @param[in] cellwise_color_predicate_map A map of maps used to associate - * predicate colors in cells with predicate ids. - * @param[out] color_enrichments A vector of functions that take in cell - * and return a function pointer. - */ - template - void - make_colorwise_enrichment_functions( - const unsigned int & num_colors, - const std::vector>> &enrichments, - const std::map> - &cellwise_color_predicate_map, - std::vector *( - const typename Triangulation::cell_iterator &)>> - &color_enrichments); - - - /** - * Creates a hp::FECollection object constructed using FE_Enriched - * elements which itself is constructed using color enrichment functions - * and is of size equal to number of colors. - * - * @param[in] fe_sets a vector of color lists - * @param[in] color_enrichments A vector of functions that take in cell - * and return a function pointer. - * @param[in] fe_base base FiniteElement - * @param[in] fe_enriched enriched FiniteElements - * @param[in] fe_nothing a finite element with zero degrees of freedom - * @param[out] fe_collection a collection of - * finite elements - */ - template - void - make_fe_collection_from_colored_enrichments( - const unsigned int &num_colors, - const std::vector> - &fe_sets, // total list of color sets possible - const std::vector *( - const typename Triangulation::cell_iterator &)>> - &color_enrichments, // color wise enrichment functions - const FE_Q &fe_base, // basic FE element - const FE_Q - &fe_enriched, // FE element multiplied by enrichment function - const FE_Nothing &fe_nothing, - hp::FECollection &fe_collection); - } // namespace internal -} // namespace ColorEnriched - -DEAL_II_NAMESPACE_CLOSE - -#endif // dealii_fe_enriched_templates_h diff --git a/source/fe/fe_enriched.cc b/source/fe/fe_enriched.cc index a6cf40b868..c634611fe4 100644 --- a/source/fe/fe_enriched.cc +++ b/source/fe/fe_enriched.cc @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -1287,7 +1286,8 @@ namespace ColorEnriched // find active indices of neighboring cells if (!cell->at_boundary(face)) { - unsigned int nbr_fe_index = cell->neighbor(face)->active_fe_index(); + unsigned int nbr_fe_index = + cell->neighbor(face)->active_fe_index(); // find corresponding fe set auto nbr_fe_set = fe_sets[nbr_fe_index]; diff --git a/tests/fe/fe_enriched_color_01.cc b/tests/fe/fe_enriched_color_01.cc index ddee3960d3..49d99eab72 100644 --- a/tests/fe/fe_enriched_color_01.cc +++ b/tests/fe/fe_enriched_color_01.cc @@ -18,7 +18,7 @@ // function. Check if the function correctly finds if two subdomains // share an edge/node. -#include +#include #include #include diff --git a/tests/fe/fe_enriched_color_02.cc b/tests/fe/fe_enriched_color_02.cc index f0657fd095..3ad1a224b3 100644 --- a/tests/fe/fe_enriched_color_02.cc +++ b/tests/fe/fe_enriched_color_02.cc @@ -22,7 +22,7 @@ * different predicates touch each other. */ -#include +#include #include #include diff --git a/tests/fe/fe_enriched_color_03.cc b/tests/fe/fe_enriched_color_03.cc index 24b69ad8b1..ad0624573c 100644 --- a/tests/fe/fe_enriched_color_03.cc +++ b/tests/fe/fe_enriched_color_03.cc @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include diff --git a/tests/fe/fe_enriched_color_04.cc b/tests/fe/fe_enriched_color_04.cc index ffd8c5a4db..58cd190d30 100644 --- a/tests/fe/fe_enriched_color_04.cc +++ b/tests/fe/fe_enriched_color_04.cc @@ -22,7 +22,7 @@ * function if cell and color of the function are provided. */ -#include +#include #include #include diff --git a/tests/fe/fe_enriched_color_05.cc b/tests/fe/fe_enriched_color_05.cc index 339e4a35fe..cfc341bec9 100644 --- a/tests/fe/fe_enriched_color_05.cc +++ b/tests/fe/fe_enriched_color_05.cc @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include -- 2.39.5