18#ifdef DEAL_II_WITH_P4EST
30 namespace experimental
32 template <
int dim,
typename VectorType,
int spacedim>
40 const auto coarsening_strategy =
42 const typename ::Triangulation<dim, spacedim>::cell_iterator
44 const std::vector<Vector<Number>> &children_values) {
54 fe_index = ::internal::hp::DoFHandlerImplementation::
55 dominated_future_fe_on_children<dim, spacedim>(
59 Assert(fe.n_dofs_per_cell() > 0,
61 "Cannot coarsen onto a FiniteElement with no DoFs."));
63 children_values.size());
65 const auto child_iterators = dof_cell_iterator->child_iterators();
66 const unsigned int n_children_with_fe_nothing =
67 std::count_if(child_iterators.begin(),
68 child_iterators.end(),
69 [](
const auto &child_cell) {
70 return child_cell->get_fe().n_dofs_per_cell() ==
75 n_children_with_fe_nothing == 0 ||
76 n_children_with_fe_nothing == dof_cell_iterator->n_children(),
78 "Coarsening is only supported for parent cells where either all"
79 " or none of the child cells are FE_Nothing."));
84 if (n_children_with_fe_nothing == dof_cell_iterator->n_children())
86 return children_values[0];
89 const unsigned int dofs_per_cell = fe.n_dofs_per_cell();
96 for (
unsigned int child = 0;
97 child < dof_cell_iterator->n_children();
102 fe.get_restriction_matrix(child,
103 dof_cell_iterator->refinement_case())
104 .vmult(tmp, children_values[child]);
107 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
108 if (fe.restriction_is_additive(i))
109 interpolated_values(i) += tmp(i);
110 else if (tmp(i) !=
Number())
111 interpolated_values(i) = tmp(i);
114 return interpolated_values;
124 &::AdaptationStrategies::Refinement::
125 preserve<dim, spacedim, Vector<Number>>,
126 coarsening_strategy);
131 template <
int dim,
typename VectorType,
int spacedim>
135 const VectorType & in,
136 const unsigned int fe_nothing_index)
138 const unsigned int dofs_per_cell =
139 dof_handler.get_fe_collection().max_dofs_per_cell();
144 for (
auto &val : dummy_cell_solution)
146 val = std::numeric_limits<Number>::infinity();
149 in.update_ghost_values();
151 std::vector<types::global_dof_index> dof_indices(dofs_per_cell);
152 for (
const auto &cell : dof_handler.active_cell_iterators())
154 if ((cell->is_locally_owned()) &&
155 (cell->active_fe_index() != fe_nothing_index))
157 cell->get_dof_values(in, cell_solution);
158 data_to_transfer.push_back(cell_solution);
162 data_to_transfer.push_back(dummy_cell_solution);
166 cell_data_transfer->prepare_for_coarsening_and_refinement(
172 template <
int dim,
typename VectorType,
int spacedim>
179 const unsigned int dofs_per_cell =
180 dof_handler.get_fe_collection().max_dofs_per_cell();
181 std::vector<Vector<Number>> transferred_data(
182 dof_handler.get_triangulation().n_active_cells(),
185 cell_data_transfer->unpack(transferred_data);
188 data_to_transfer.clear();
190 for (
unsigned int i = 0; i < out.locally_owned_size(); ++i)
191 out.local_element(i) = std::numeric_limits<Number>::infinity();
193 unsigned int cell_i = 0;
194 for (
auto const &cell : dof_handler.active_cell_iterators())
196 if ((cell->is_locally_owned()) &&
197 (transferred_data[cell_i][0] !=
198 std::numeric_limits<Number>::infinity()))
200 cell->set_dof_values(transferred_data[cell_i], out);
210 std::vector<types::global_dof_index> dof_indices;
211 std::vector<types::global_dof_index> dofs_map;
212 std::vector<std::vector<std::pair<types::global_dof_index, Number>>>
214 std::vector<Number> constraint_values;
215 IndexSet locally_owned_dofs = dof_handler.locally_owned_dofs();
216 for (
auto constrained_dof : locally_owned_dofs)
221 const unsigned int line_size = constraint->size();
222 bool add_line =
false;
223 for (
unsigned int i = 0; i < line_size; ++i)
226 (*constraint)[i].first;
229 if (out[constraining_dof] ==
230 std::numeric_limits<Number>::infinity())
239 std::vector<std::pair<types::global_dof_index, Number>> line;
240 Number val = out[constrained_dof];
242 for (
unsigned int i = 0; i < line_size; ++i)
245 (*constraint)[i].first;
247 if (out[constraining_dof] ==
248 std::numeric_limits<Number>::infinity())
250 auto constraining_dof_map_it =
251 std::find(dofs_map.begin(),
254 if (constraining_dof_map_it == dofs_map.end())
256 dofs_map.push_back(constraining_dof);
258 line.push_back((*constraint)[i]);
263 out[constraining_dof] * (*constraint)[i].second;
266 constraint_lines.push_back(line);
267 constraint_values.push_back(val);
272 const unsigned int n_rows = constraint_lines.size();
275 const unsigned int n_cols = dofs_map.size();
279 for (
unsigned int i = 0; i < n_rows; ++i)
281 for (
unsigned int j = 0; j < n_cols; ++j)
283 if (j < constraint_lines[i].size())
286 std::find(dofs_map.begin(),
288 constraint_lines[i][j].first);
289 constraints_matrix(i,
290 constraint_it - dofs_map.begin()) =
291 constraint_lines[i][j].second;
295 constraint_values_vec[i] = constraint_values[i];
301 constraints_matrix.
vmult(new_constrained_values,
302 constraint_values_vec);
304 for (
unsigned int i = 0; i < n_cols; ++i)
306 out[dofs_map[i]] = new_constrained_values[i];
311 std::for_each(out.begin(), out.end(), [&](
Number &val) {
312 if (val == std::numeric_limits<Number>::infinity())
323# include "field_transfer.inst"
bool is_constrained(const size_type line_n) const
const std::vector< std::pair< size_type, number > > * get_constraint_entries(const size_type line_n) const
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index index=0) const
const Triangulation< dim, spacedim > & get_triangulation() const
bool has_hp_capabilities() const
void vmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
void compute_inverse_svd(const double threshold=0.)
std::unique_ptr< CellDataTransfer< dim, spacedim, std::vector< Vector< Number > > > > cell_data_transfer
void prepare_for_coarsening_and_refinement(const VectorType &in, const unsigned int fe_nothing_index)
FieldTransfer(const DoFHandler< dim, spacedim > &dof_handler)
typename VectorType::value_type Number
const DoFHandler< dim, spacedim > & dof_handler
void interpolate(const Number &new_value, const AffineConstraints< Number > &affine_constraints, VectorType &out)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcMessage(std::string arg1)
typename ActiveSelector::cell_iterator cell_iterator