16 #include <deal.II/base/work_stream.h> 17 #include <deal.II/numerics/data_out.h> 18 #include <deal.II/grid/tria.h> 19 #include <deal.II/dofs/dof_handler.h> 20 #include <deal.II/dofs/dof_accessor.h> 21 #include <deal.II/hp/dof_handler.h> 22 #include <deal.II/grid/tria_iterator.h> 23 #include <deal.II/fe/fe.h> 24 #include <deal.II/fe/fe_dgq.h> 25 #include <deal.II/fe/fe_values.h> 26 #include <deal.II/hp/fe_values.h> 27 #include <deal.II/fe/mapping_q1.h> 31 DEAL_II_NAMESPACE_OPEN
36 namespace DataOutImplementation
38 template <
int dim,
int spacedim>
39 ParallelData<dim,spacedim>::
40 ParallelData (
const unsigned int n_datasets,
41 const unsigned int n_subdivisions,
42 const std::vector<unsigned int> &n_postprocessor_outputs,
46 const std::vector<std::vector<unsigned int> > &cell_to_patch_index_map)
48 ParallelDataBase<dim,spacedim> (n_datasets,
50 n_postprocessor_outputs,
55 cell_to_patch_index_map (&cell_to_patch_index_map)
62 template <
int dim,
typename DoFHandlerType>
66 (
const std::pair<cell_iterator, unsigned int> *cell_and_index,
68 const unsigned int n_subdivisions,
78 for (
unsigned int vertex=0; vertex<GeometryInfo<DoFHandlerType::dimension>::vertices_per_cell; ++vertex)
79 if (scratch_data.mapping_collection[0].preserves_vertex_locations())
80 patch.
vertices[vertex] = cell_and_index->first->vertex(vertex);
82 patch.
vertices[vertex] = scratch_data.mapping_collection[0].transform_unit_to_real_cell
83 (cell_and_index->first,
87 scratch_data.reinit_all_fe_values(this->dof_data, cell_and_index->first);
90 = scratch_data.get_present_fe_values (0);
101 if (curved_cell_region==curved_inner_cells
103 (curved_cell_region==curved_boundary
105 (cell_and_index->first->at_boundary()
107 (DoFHandlerType::dimension != DoFHandlerType::space_dimension))))
117 const std::vector<Point<DoFHandlerType::space_dimension> > &q_points
120 patch.
data.
reinit (scratch_data.n_datasets+DoFHandlerType::space_dimension, n_q_points);
121 for (
unsigned int i=0; i<DoFHandlerType::space_dimension; ++i)
122 for (
unsigned int q=0; q<n_q_points; ++q)
123 patch.
data(patch.
data.
size(0)-DoFHandlerType::space_dimension+i,q) = q_points[q][i];
127 patch.
data.
reinit(scratch_data.n_datasets, n_q_points);
132 if (scratch_data.n_datasets > 0)
135 unsigned int offset=0;
138 for (
unsigned int dataset=0; dataset<this->dof_data.size(); ++dataset)
141 = scratch_data.get_present_fe_values (dataset);
143 this_fe_patch_values.
get_fe().n_components();
146 = this->dof_data[dataset]->postprocessor;
148 if (postprocessor !=
nullptr)
158 this->dof_data[dataset]->get_function_values (this_fe_patch_values,
159 internal::DataOutImplementation::ComponentExtractor::real_part,
160 scratch_data.patch_values_scalar.solution_values);
162 this->dof_data[dataset]->get_function_gradients (this_fe_patch_values,
163 internal::DataOutImplementation::ComponentExtractor::real_part,
164 scratch_data.patch_values_scalar.solution_gradients);
166 this->dof_data[dataset]->get_function_hessians (this_fe_patch_values,
167 internal::DataOutImplementation::ComponentExtractor::real_part,
168 scratch_data.patch_values_scalar.solution_hessians);
173 const typename DoFHandlerType::active_cell_iterator dh_cell(&cell_and_index->first->get_triangulation(),
174 cell_and_index->first->level(),
175 cell_and_index->first->index(),
176 this->dof_data[dataset]->dof_handler);
177 scratch_data.patch_values_scalar.template set_cell<DoFHandlerType> (dh_cell);
180 evaluate_scalar_field(scratch_data.patch_values_scalar,
181 scratch_data.postprocessed_values[dataset]);
190 this->dof_data[dataset]->get_function_values (this_fe_patch_values,
191 internal::DataOutImplementation::ComponentExtractor::real_part,
192 scratch_data.patch_values_system.solution_values);
194 this->dof_data[dataset]->get_function_gradients (this_fe_patch_values,
195 internal::DataOutImplementation::ComponentExtractor::real_part,
196 scratch_data.patch_values_system.solution_gradients);
198 this->dof_data[dataset]->get_function_hessians (this_fe_patch_values,
199 internal::DataOutImplementation::ComponentExtractor::real_part,
200 scratch_data.patch_values_system.solution_hessians);
205 const typename DoFHandlerType::active_cell_iterator dh_cell(&cell_and_index->first->get_triangulation(),
206 cell_and_index->first->level(),
207 cell_and_index->first->index(),
208 this->dof_data[dataset]->dof_handler);
209 scratch_data.patch_values_system.template set_cell<DoFHandlerType> (dh_cell);
212 evaluate_vector_field(scratch_data.patch_values_system,
213 scratch_data.postprocessed_values[dataset]);
216 for (
unsigned int q=0; q<n_q_points; ++q)
217 for (
unsigned int component=0;
218 component<this->dof_data[dataset]->n_output_variables;
220 patch.
data(offset+component,q)
221 = scratch_data.postprocessed_values[dataset][q](component);
230 this->dof_data[dataset]->get_function_values (this_fe_patch_values,
231 internal::DataOutImplementation::ComponentExtractor::real_part,
232 scratch_data.patch_values_scalar.solution_values);
233 for (
unsigned int q=0; q<n_q_points; ++q)
234 patch.
data(offset,q) = scratch_data.patch_values_scalar.solution_values[q];
237 if (this->dof_data[dataset]->is_complex_valued() ==
true)
239 this->dof_data[dataset]->get_function_values (this_fe_patch_values,
240 internal::DataOutImplementation::ComponentExtractor::imaginary_part,
241 scratch_data.patch_values_scalar.solution_values);
242 for (
unsigned int q=0; q<n_q_points; ++q)
243 patch.
data(offset+1,q) = scratch_data.patch_values_scalar.solution_values[q];
251 const unsigned int stride = (this->dof_data[dataset]->is_complex_valued() ? 2 : 1);
252 this->dof_data[dataset]->get_function_values (this_fe_patch_values,
253 internal::DataOutImplementation::ComponentExtractor::real_part,
254 scratch_data.patch_values_system.solution_values);
257 for (
unsigned int q=0; q<n_q_points; ++q)
258 patch.
data(offset+component*stride,q) =
259 scratch_data.patch_values_system.solution_values[q](component);
262 if (this->dof_data[dataset]->is_complex_valued() ==
true)
264 this->dof_data[dataset]->get_function_values (this_fe_patch_values,
265 internal::DataOutImplementation::ComponentExtractor::imaginary_part,
266 scratch_data.patch_values_system.solution_values);
269 for (
unsigned int q=0; q<n_q_points; ++q)
270 patch.
data(offset+component*stride+1,q) =
271 scratch_data.patch_values_system.solution_values[q](component);
276 offset += this->dof_data[dataset]->n_output_variables *
277 (this->dof_data[dataset]->is_complex_valued() ? 2 : 1);
283 if (this->cell_data.size() != 0)
287 for (
unsigned int dataset=0; dataset<this->cell_data.size(); ++dataset)
292 = this->cell_data[dataset]->get_cell_data_value (cell_and_index->second,
293 internal::DataOutImplementation::ComponentExtractor::real_part);
294 for (
unsigned int q=0; q<n_q_points; ++q)
295 patch.
data(offset,q) = value;
299 if (this->cell_data[dataset]->is_complex_valued() ==
true)
302 = this->cell_data[dataset]->get_cell_data_value (cell_and_index->second,
303 internal::DataOutImplementation::ComponentExtractor::imaginary_part);
304 for (
unsigned int q=0; q<n_q_points; ++q)
305 patch.
data(offset+1,q) = value;
308 offset += (this->cell_data[dataset]->is_complex_valued() ? 2 : 1);
314 for (
unsigned int f=0; f<GeometryInfo<DoFHandlerType::dimension>::faces_per_cell; ++f)
326 if (cell_and_index->first->at_boundary(f)
328 (cell_and_index->first->neighbor(f)->level() != cell_and_index->first->level()))
334 const cell_iterator neighbor = cell_and_index->first->neighbor(f);
335 Assert (static_cast<unsigned int>(neighbor->level()) <
336 scratch_data.cell_to_patch_index_map->size(),
338 if ((static_cast<unsigned int>(neighbor->index()) >=
339 (*scratch_data.cell_to_patch_index_map)[neighbor->level()].size())
341 ((*scratch_data.cell_to_patch_index_map)[neighbor->level()][neighbor->index()]
352 = (*scratch_data.cell_to_patch_index_map)[neighbor->level()][neighbor->index()];
355 const unsigned int patch_idx =
356 (*scratch_data.cell_to_patch_index_map)[cell_and_index->first->level()][cell_and_index->first->index()];
364 this->patches[patch_idx].swap (patch);
369 template <
int dim,
typename DoFHandlerType>
373 n_subdivisions, no_curved_cells);
378 template <
int dim,
typename DoFHandlerType>
381 const unsigned int n_subdivisions_,
387 Assert (this->triangulation !=
nullptr,
390 const unsigned int n_subdivisions = (n_subdivisions_ != 0)
392 : this->default_subdivisions;
393 Assert (n_subdivisions >= 1,
396 this->validate_dataset_names();
411 std::vector<std::vector<unsigned int> > cell_to_patch_index_map;
412 cell_to_patch_index_map.resize (this->triangulation->n_levels());
413 for (
unsigned int l=0; l<this->triangulation->n_levels(); ++l)
416 unsigned int max_index = 0;
417 for (
cell_iterator cell=first_locally_owned_cell(); cell != this->triangulation->end();
418 cell = next_locally_owned_cell(cell))
419 if (static_cast<unsigned int>(cell->level()) == l)
420 max_index = std::max (max_index,
421 static_cast<unsigned int>(cell->index()));
423 cell_to_patch_index_map[l].resize (max_index+1,
425 DoFHandlerType::space_dimension>::no_neighbor);
429 std::vector<std::pair<cell_iterator, unsigned int> > all_cells;
436 active_cell_iterator active_cell = this->triangulation->begin_active();
437 unsigned int active_index = 0;
439 for (; cell != this->triangulation->end();
440 cell = next_locally_owned_cell(cell))
444 while (active_cell!=this->triangulation->end()
446 && active_cell_iterator(cell) != active_cell)
452 Assert (static_cast<unsigned int>(cell->level()) <
453 cell_to_patch_index_map.size(),
455 Assert (static_cast<unsigned int>(cell->index()) <
456 cell_to_patch_index_map[cell->level()].size(),
458 Assert (active_index < this->triangulation->n_active_cells(),
460 cell_to_patch_index_map[cell->level()][cell->index()] = all_cells.size();
462 all_cells.emplace_back (cell, active_index);
466 this->patches.clear ();
467 this->patches.resize(all_cells.size());
470 unsigned int n_datasets = 0;
471 for (
unsigned int i=0; i<this->cell_data.size(); ++i)
472 n_datasets += (this->cell_data[i]->is_complex_valued() ? 2 : 1);
473 for (
unsigned int i=0; i<this->dof_data.size(); ++i)
474 n_datasets += (this->dof_data[i]->n_output_variables
475 * (this->dof_data[i]->is_complex_valued() ? 2 : 1));
477 std::vector<unsigned int> n_postprocessor_outputs (this->dof_data.size());
478 for (
unsigned int dataset=0; dataset<this->dof_data.size(); ++dataset)
479 if (this->dof_data[dataset]->postprocessor)
480 n_postprocessor_outputs[dataset] = this->dof_data[dataset]->n_output_variables;
482 n_postprocessor_outputs[dataset] = 0;
485 = (n_subdivisions<2 ? no_curved_cells : curved_region);
488 if (curved_cell_region != no_curved_cells)
491 for (
unsigned int i=0; i<this->dof_data.size(); ++i)
492 if (this->dof_data[i]->postprocessor)
493 update_flags |= this->dof_data[i]->postprocessor->get_needed_update_flags();
497 ExcMessage(
"The update of normal vectors may not be requested for evaluation of " 498 "data on cells via DataPostprocessor."));
501 thread_data (n_datasets, n_subdivisions,
502 n_postprocessor_outputs,
506 cell_to_patch_index_map);
509 if (all_cells.size() > 0)
511 &all_cells[0]+all_cells.size(),
514 std::placeholders::_1,
515 std::placeholders::_2,
522 std::function<void (const int &)>(),
537 template <
int dim,
typename DoFHandlerType>
541 return this->triangulation->begin_active ();
546 template <
int dim,
typename DoFHandlerType>
554 active_cell_iterator active_cell = cell;
561 template <
int dim,
typename DoFHandlerType>
570 while ((cell != this->triangulation->end()) &&
571 (cell->has_children() ==
false) &&
572 !cell->is_locally_owned())
573 cell = next_cell(cell);
580 template <
int dim,
typename DoFHandlerType>
586 cell = next_cell(old_cell);
587 while ((cell != this->triangulation->end()) &&
588 (cell->has_children() ==
false) &&
589 !cell->is_locally_owned())
590 cell = next_cell(cell);
596 #include "data_out.inst" 598 DEAL_II_NAMESPACE_CLOSE
static const unsigned int invalid_unsigned_int
static ::ExceptionBase & ExcNoTriangulationSelected()
void build_one_patch(const std::pair< cell_iterator, unsigned int > *cell_and_index, internal::DataOutImplementation::ParallelData< DoFHandlerType::dimension, DoFHandlerType::space_dimension > &scratch_data, const unsigned int n_subdivisions, const CurvedCellRegion curved_cell_region)
unsigned int neighbors[dim > 0 ? GeometryInfo< dim >::faces_per_cell :1]
virtual cell_iterator next_cell(const cell_iterator &cell)
const FiniteElement< dim, spacedim > & get_fe() const
Transformed quadrature points.
static ::ExceptionBase & ExcInvalidNumberOfSubdivisions(int arg1)
Point< spacedim > vertices[GeometryInfo< dim >::vertices_per_cell]
virtual void build_patches(const unsigned int n_subdivisions=0)
const std::vector< Point< spacedim > > & get_quadrature_points() const
static ::ExceptionBase & ExcMessage(std::string arg1)
virtual cell_iterator first_locally_owned_cell()
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
Abstract base class for mapping classes.
virtual cell_iterator first_cell()
unsigned int n_subdivisions
DataOut_DoFData< DoFHandler< dim >, DoFHandler< dim > ::dimension, DoFHandler< dim > ::space_dimension >::cell_iterator cell_iterator
Second derivatives of shape functions.
const unsigned int n_quadrature_points
size_type size(const unsigned int i) const
static const unsigned int space_dim
Shape function gradients.
void run(const std::vector< std::vector< Iterator > > &colored_iterators, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length=2 *MultithreadInfo::n_threads(), const unsigned int chunk_size=8)
static ::ExceptionBase & ExcNotImplemented()
static unsigned int n_threads()
bool points_are_available
unsigned int n_components(const DoFHandler< dim, spacedim > &dh)
virtual cell_iterator next_locally_owned_cell(const cell_iterator &cell)
static ::ExceptionBase & ExcInternalError()
virtual UpdateFlags get_needed_update_flags() const =0