17 #include <deal.II/lac/vector.h> 18 #include <deal.II/lac/block_vector.h> 19 #include <deal.II/lac/parallel_vector.h> 20 #include <deal.II/lac/parallel_block_vector.h> 21 #include <deal.II/lac/petsc_vector.h> 22 #include <deal.II/lac/petsc_block_vector.h> 23 #include <deal.II/lac/trilinos_vector.h> 24 #include <deal.II/lac/trilinos_block_vector.h> 26 #include <deal.II/numerics/vector_tools.h> 28 #include <deal.II/numerics/point_value_history.h> 33 DEAL_II_NAMESPACE_OPEN
45 const std::vector <types::global_dof_index> &new_sol_indices)
47 requested_location = new_requested_location;
48 support_point_locations = new_locations;
49 solution_indices = new_sol_indices;
59 n_indep (n_independent_variables)
63 triangulation_changed =
false;
64 have_dof_handler =
false;
67 dataset_key = std::vector <double> ();
71 = std::vector<std::vector <double> > (n_indep, std::vector <double> (0));
72 indep_names = std::vector <std::string> ();
79 const unsigned int n_independent_variables) :
80 dof_handler (&dof_handler),
81 n_indep (n_independent_variables)
93 = std::vector<std::vector <double> > (
n_indep, std::vector <double> (0));
97 std_cxx11::ref(*
this)));
127 std_cxx11::ref(*
this)));
159 std_cxx11::ref(*
this)));
196 std::vector <Point <dim> >
207 support_point_quadrature,
209 unsigned int n_support_points
211 unsigned int n_components
226 std::vector <unsigned int> current_fe_index (n_components, 0);
227 fe_values.reinit (cell);
228 std::vector <Point <dim> > current_points (n_components,
Point <dim > ());
229 for (
unsigned int support_point = 0;
230 support_point < n_support_points; support_point++)
234 unsigned int component
236 current_points [component] = fe_values.quadrature_point (support_point);
237 current_fe_index [component] = support_point;
250 for (; cell != endc; cell++)
252 fe_values.reinit (cell);
254 for (
unsigned int support_point = 0;
255 support_point < n_support_points; support_point++)
257 unsigned int component
260 = fe_values.quadrature_point (support_point);
262 if (location.
distance (test_point) <
263 location.
distance (current_points [component]))
266 current_points [component] = test_point;
268 current_fe_index [component] = support_point;
274 std::vector<types::global_dof_index>
276 std::vector <types::global_dof_index> new_solution_indices;
277 current_cell->get_dof_indices (local_dof_indices);
297 for (
unsigned int component = 0;
301 .push_back (local_dof_indices[current_fe_index [component]]);
305 new_point_geometry_data (location, current_points, new_solution_indices);
308 std::map <std::string, std::vector <std::vector <double> > >::iterator
310 for (; data_store_begin !=
data_store.end (); data_store_begin++)
316 for (
unsigned int component = 0; component < n_stored; component++)
318 data_store_begin->second.push_back (std::vector<double> (0));
371 std::vector <typename DoFHandler<dim>::active_cell_iterator > current_cell (locations.size (), cell);
373 fe_values.reinit (cell);
374 std::vector <Point <dim> > temp_points (n_components,
Point <dim > ());
375 std::vector <unsigned int> temp_fe_index (n_components, 0);
376 for (
unsigned int support_point = 0; support_point < n_support_points; support_point++)
381 temp_points [component] = fe_values.quadrature_point (support_point);
382 temp_fe_index [component] = support_point;
384 std::vector <std::vector <Point <dim> > > current_points (locations.size (), temp_points);
385 std::vector <std::vector <unsigned int> > current_fe_index (locations.size (), temp_fe_index);
396 for (; cell != endc; cell++)
398 fe_values.reinit (cell);
399 for (
unsigned int support_point = 0; support_point < n_support_points; support_point++)
402 Point<dim> test_point = fe_values.quadrature_point (support_point);
404 for (
unsigned int point = 0; point < locations.size (); point++)
406 if (locations[point].distance (test_point) < locations[point].distance (current_points[point][component]))
409 current_points[point][component] = test_point;
410 current_cell[point] = cell;
411 current_fe_index[point][component] = support_point;
418 for (
unsigned int point = 0; point < locations.size (); point++)
420 current_cell[point]->get_dof_indices (local_dof_indices);
421 std::vector<types::global_dof_index> new_solution_indices;
425 new_solution_indices.push_back (local_dof_indices[current_fe_index[point][component]]);
432 std::map <std::string, std::vector <std::vector <double> > >::iterator
434 for (; data_store_begin !=
data_store.end (); data_store_begin++)
440 for (
unsigned int component = 0; component < n_stored; component++)
442 data_store_begin->second.push_back (std::vector<double> (0));
475 std::pair <std::string, std::vector <std::string> >
476 empty_names (vector_name, std::vector <std::string> ());
481 std::pair<std::string, std::vector <std::vector <double> > > pair_data;
482 pair_data.first = vector_name;
490 std::vector < std::vector <double> > vector_size (n_datastreams,
491 std::vector <double> (0));
492 pair_data.second = vector_size;
501 std::vector <bool> temp_mask (n_components,
true);
509 const std::vector <std::string> &component_names)
511 typename std::map <std::string, std::vector <std::string> >::iterator names =
component_names_map.find(vector_name);
514 typename std::map <std::string, ComponentMask>::iterator mask =
component_mask.find(vector_name);
516 unsigned int n_stored = mask->second.n_selected_components();
518 Assert (component_names.size() == n_stored, ExcDimensionMismatch (component_names.size(), n_stored));
520 names->second = component_names;
528 Assert (independent_names.size() ==
n_indep, ExcDimensionMismatch (independent_names.size(),
n_indep));
565 template <
typename VectorType>
585 typename std::map <std::string, std::vector <std::vector <double> > >::iterator data_store_field =
data_store.find(vector_name);
588 typename std::map <std::string, ComponentMask>::iterator mask =
component_mask.find(vector_name);
593 typename std::vector <internal::PointValueHistory::PointGeometryData <dim> >::iterator point =
point_geometry_data.begin ();
594 for (
unsigned int data_store_index = 0; point !=
point_geometry_data.end (); point++, data_store_index++)
603 if (mask->second[comp])
605 unsigned int solution_index = point->solution_indices[comp];
606 data_store_field->second[data_store_index * n_stored + store_index].push_back (solution (solution_index));
618 template <
typename VectorType>
621 const VectorType &solution,
638 ExcMessage(
"The update of normal vectors may not be requested for evaluation of " 639 "data on cells via DataPostprocessor."));
642 unsigned int n_quadrature_points = quadrature.
size();
644 unsigned int n_output_variables = data_postprocessor.
get_names().size();
647 typename std::vector <internal::PointValueHistory::PointGeometryData <dim> >::iterator point =
point_geometry_data.begin ();
648 for (
unsigned int data_store_index = 0; point !=
point_geometry_data.end (); point++, data_store_index++)
652 Point <dim> requested_location = point->requested_location;
656 fe_values.reinit (cell);
657 std::vector< Vector< double > > computed_quantities (1,
Vector <double> (n_output_variables));
660 if (n_components == 1)
664 std::vector< typename VectorType::value_type > uh (n_quadrature_points, 0.0);
667 std::vector<Point<dim> > dummy_normals (1,
Point<dim> ());
668 std::vector<Point<dim> > evaluation_points;
673 fe_values.get_function_values (solution,
676 fe_values.get_function_gradients (solution,
679 fe_values.get_function_hessians (solution,
683 evaluation_points = fe_values.get_quadrature_points();
684 double distance = cell->diameter ();
685 unsigned int selected_point = 0;
686 for (
unsigned int q_point = 0; q_point < n_quadrature_points; q_point++)
688 if (requested_location.
distance (evaluation_points[q_point]) < distance)
690 selected_point = q_point;
691 distance = requested_location.
distance (evaluation_points[q_point]);
699 compute_derived_quantities_scalar(std::vector< double > (1, uh[selected_point]),
703 std::vector<
Point<dim> > (1, evaluation_points[selected_point]),
704 computed_quantities);
713 std::vector<Point<dim> > dummy_normals (1,
Point<dim> ());
714 std::vector<Point<dim> > evaluation_points;
720 fe_values.get_function_values (solution,
723 fe_values.get_function_gradients (solution,
726 fe_values.get_function_hessians (solution,
730 evaluation_points = fe_values.get_quadrature_points();
731 double distance = cell->diameter ();
732 unsigned int selected_point = 0;
733 for (
unsigned int q_point = 0; q_point < n_quadrature_points; q_point++)
735 if (requested_location.
distance (evaluation_points[q_point]) < distance)
737 selected_point = q_point;
738 distance = requested_location.
distance (evaluation_points[q_point]);
746 const std::vector< Tensor< 1, dim, typename VectorType::value_type > > &duh_s = duh[selected_point];
747 const std::vector< Tensor< 2, dim, typename VectorType::value_type > > &dduh_s = dduh[selected_point];
748 std::vector< Tensor< 1, dim > > tmp_d (duh_s.size());
749 for (
unsigned int i = 0; i < duh_s.size(); i++)
752 std::vector< Tensor< 2, dim > > tmp_dd (dduh_s.size());
753 for (
unsigned int i = 0; i < dduh_s.size(); i++)
754 tmp_dd[i] = dduh_s[i];
757 for (
unsigned int i = 0; i < uh_s.
size(); i++)
766 std::vector<
Point<dim> > (1, evaluation_points[selected_point]),
767 computed_quantities);
773 typename std::vector<std::string>::const_iterator name = vector_names.begin();
774 for (; name != vector_names.end(); name++)
776 typename std::map <std::string, std::vector <std::vector <double> > >::iterator data_store_field =
data_store.find(*name);
779 typename std::map <std::string, ComponentMask>::iterator mask =
component_mask.find(*name);
782 unsigned int n_stored = mask->second.n_selected_components(n_output_variables);
786 for (
unsigned int store_index = 0, comp = 0; comp < n_output_variables; comp++)
788 if (mask->second[comp])
790 data_store_field->second[data_store_index * n_stored + store_index].push_back (computed_quantities[0](comp));
800 template <
typename VectorType>
803 const VectorType &solution,
807 std::vector <std::string> vector_names;
808 vector_names.push_back (vector_name);
809 evaluate_field (vector_names, solution, data_postprocessor, quadrature);
815 template <
typename VectorType>
818 const VectorType &solution)
835 typename std::map <std::string, std::vector <std::vector <double> > >::iterator data_store_field =
data_store.find(vector_name);
838 typename std::map <std::string, ComponentMask>::iterator mask =
component_mask.find(vector_name);
843 typename std::vector <internal::PointValueHistory::PointGeometryData <dim> >::iterator point =
point_geometry_data.begin ();
845 for (
unsigned int data_store_index = 0; point !=
point_geometry_data.end (); point++, data_store_index++)
854 for (
unsigned int store_index = 0, comp = 0; comp < mask->second.size(); comp++)
856 if (mask->second[comp])
858 data_store_field->second[data_store_index * n_stored + store_index].push_back (value (comp));
893 for (
unsigned int component = 0; component <
n_indep; component++)
910 std::string filename = base_name +
"_indep.gpl";
911 std::ofstream to_gnuplot (filename.c_str ());
913 to_gnuplot <<
"# Data independent of mesh location\n";
916 to_gnuplot <<
"# <Key> ";
920 for (
unsigned int name = 0; name <
indep_names.size(); name++)
928 for (
unsigned int component = 0; component <
n_indep; component++)
930 to_gnuplot <<
"<Indep_" << component <<
"> ";
935 for (
unsigned int key = 0; key <
dataset_key.size (); key++)
939 for (
unsigned int component = 0; component <
n_indep; component++)
970 typename std::vector <internal::PointValueHistory::PointGeometryData <dim> >::iterator point =
point_geometry_data.begin ();
971 for (
unsigned int data_store_index = 0; point !=
point_geometry_data.end (); point++, data_store_index++)
980 std::ofstream to_gnuplot (filename.c_str ());
985 to_gnuplot <<
"# Requested location: " << point->requested_location <<
"\n";
986 to_gnuplot <<
"# DoF_index : Support location (for each component)\n";
989 to_gnuplot <<
"# " << point->solution_indices[component] <<
" : " << point->support_point_locations [component] <<
"\n";
992 to_gnuplot <<
"# (Original components and locations, may be invalidated by mesh change.)\n";
994 if (postprocessor_locations.size() != 0)
996 to_gnuplot <<
"# Postprocessor location: " << postprocessor_locations[data_store_index];
998 to_gnuplot <<
" (may be approximate)\n";
1000 to_gnuplot <<
"#\n";
1004 to_gnuplot <<
"# <Key> ";
1008 for (
unsigned int name = 0; name <
indep_names.size(); name++)
1015 for (
unsigned int component = 0; component <
n_indep; component++)
1017 to_gnuplot <<
"<Indep_" << component <<
"> ";
1021 for (std::map <std::string, std::vector <std::vector <double> > >::iterator
1022 data_store_begin =
data_store.begin (); data_store_begin !=
data_store.end (); ++data_store_begin)
1024 typename std::map <std::string, ComponentMask>::iterator mask =
component_mask.find(data_store_begin->first);
1025 unsigned int n_stored = mask->second.n_selected_components();
1026 std::vector <std::string> names = (
component_names_map.find (data_store_begin->first))->second;
1028 if (names.size() > 0)
1030 AssertThrow (names.size() == n_stored, ExcDimensionMismatch (names.size(), n_stored));
1031 for (
unsigned int component = 0; component < names.size(); component++)
1033 to_gnuplot <<
"<" << names[component] <<
"> ";
1038 for (
unsigned int component = 0; component < n_stored; component++)
1040 to_gnuplot <<
"<" << data_store_begin->first <<
"_" << component <<
"> ";
1047 for (
unsigned int key = 0; key <
dataset_key.size (); key++)
1051 for (
unsigned int component = 0; component <
n_indep; component++)
1056 for (std::map <std::string, std::vector <std::vector <double> > >::iterator
1058 data_store_begin !=
data_store.end (); ++data_store_begin)
1060 typename std::map <std::string, ComponentMask>::iterator mask =
component_mask.find(data_store_begin->first);
1061 unsigned int n_stored = mask->second.n_selected_components();
1063 for (
unsigned int component = 0; component < n_stored; component++)
1065 to_gnuplot <<
" " << (data_store_begin->second)[data_store_index * n_stored + component][key];
1071 to_gnuplot.close ();
1090 typename std::vector <internal::PointValueHistory::PointGeometryData <dim> >::iterator point =
point_geometry_data.begin ();
1095 dof_vector (point->solution_indices[component]) = 1;
1110 std::vector <std::vector <Point <dim> > > actual_points;
1111 typename std::vector <internal::PointValueHistory::PointGeometryData <dim> >::iterator point =
point_geometry_data.begin ();
1115 actual_points.push_back (point->support_point_locations);
1117 locations = actual_points;
1136 locations = std::vector<Point <dim> > ();
1139 unsigned int n_quadrature_points = quadrature.
size();
1140 std::vector<Point<dim> > evaluation_points;
1143 typename std::vector <internal::PointValueHistory::PointGeometryData <dim> >::iterator point =
point_geometry_data.begin ();
1144 for (
unsigned int data_store_index = 0; point !=
point_geometry_data.end (); point++, data_store_index++)
1148 Point <dim> requested_location = point->requested_location;
1150 fe_values.reinit (cell);
1152 evaluation_points = fe_values.get_quadrature_points();
1153 double distance = cell->diameter ();
1154 unsigned int selected_point = 0;
1156 for (
unsigned int q_point = 0; q_point < n_quadrature_points; q_point++)
1158 if (requested_location.
distance (evaluation_points[q_point]) < distance)
1160 selected_point = q_point;
1161 distance = requested_location.
distance (evaluation_points[q_point]);
1165 locations.push_back (evaluation_points[selected_point]);
1174 out <<
"***PointValueHistory status output***\n\n";
1175 out <<
"Closed: " <<
closed <<
"\n";
1176 out <<
"Cleared: " <<
cleared <<
"\n";
1179 out <<
"Geometric Data" <<
"\n";
1181 typename std::vector <internal::PointValueHistory::PointGeometryData <dim> >::iterator point =
point_geometry_data.begin ();
1184 out <<
"No points stored currently\n";
1192 out <<
"# Requested location: " << point->requested_location <<
"\n";
1193 out <<
"# DoF_index : Support location (for each component)\n";
1196 out << point->solution_indices[component] <<
" : " << point->support_point_locations [component] <<
"\n";
1203 out <<
"#Cannot access DoF_indices once cleared\n";
1214 for (
unsigned int name = 0; name <
indep_names.size(); name++)
1223 out <<
"No independent values stored\n";
1226 std::map <std::string, std::vector <std::vector <double> > >::iterator
1230 out <<
"Mnemonic: data set size (mask size, n true components) : n data sets\n";
1232 for (; data_store_begin !=
data_store.end (); data_store_begin++)
1235 std::string vector_name = data_store_begin->first;
1236 typename std::map <std::string, ComponentMask>::iterator mask =
component_mask.find(vector_name);
1238 typename std::map <std::string, std::vector <std::string> >::iterator component_names =
component_names_map.find(vector_name);
1241 if (data_store_begin->second.size () != 0)
1243 out << data_store_begin->first <<
": " << data_store_begin->second.size () <<
" (";
1244 out << mask->second.size() <<
", " << mask->second.n_selected_components() <<
") : ";
1245 out << (data_store_begin->second)[0].size () <<
"\n";
1249 out << data_store_begin->first <<
": " << data_store_begin->second.size () <<
" (";
1250 out << mask->second.size() <<
", " << mask->second.n_selected_components() <<
") : ";
1251 out <<
"No points added" <<
"\n";
1254 if (component_names->second.size() > 0)
1256 for (
unsigned int name = 0; name < component_names->second.size(); name++)
1258 out <<
"<" << component_names->second[name] <<
"> ";
1264 out <<
"***end of status output***\n\n";
1284 std::map <std::string, std::vector <std::vector <double> > >::iterator
1288 for (; data_store_begin !=
data_store.end (); data_store_begin++)
1290 Assert (data_store_begin->second.size() > 0,
1291 ExcInternalError());
1292 if ((data_store_begin->second)[0].size () !=
dataset_key.size ())
1314 std::map <std::string, std::vector <std::vector <double> > >::iterator
1316 for (; data_store_begin !=
data_store.end (); data_store_begin++)
1318 Assert (data_store_begin->second.size() > 0,
1319 ExcInternalError());
1321 if (std::abs ((
int) (data_store_begin->second)[0].size () - (int)
dataset_key.size ()) >= 2)
1355 #include "point_value_history.inst" 1358 DEAL_II_NAMESPACE_CLOSE
std::map< std::string, std::vector< std::vector< double > > > data_store
void get_postprocessor_locations(const Quadrature< dim > &quadrature, std::vector< Point< dim > > &locations)
PointValueHistory(const unsigned int n_independent_variables=0)
::ExceptionBase & ExcMessage(std::string arg1)
cell_iterator end() const
PointGeometryData(const Point< dim > &new_requested_location, const std::vector< Point< dim > > &new_locations, const std::vector< types::global_dof_index > &new_sol_indices)
Only a constructor needed for this class (a struct really)
std::vector< double > dataset_key
bool represents_the_all_selected_mask() const
Transformed quadrature points.
#define AssertThrow(cond, exc)
std::vector< std::string > indep_names
const FiniteElement< dim, spacedim > & get_fe() const
void add_points(const std::vector< Point< dim > > &locations)
void write_gnuplot(const std::string &base_name, const std::vector< Point< dim > > postprocessor_locations=std::vector< Point< dim > >())
bool has_support_points() const
std::vector< internal::PointValueHistory::PointGeometryData< dim > > point_geometry_data
active_cell_iterator begin_active(const unsigned int level=0) const
void add_component_names(const std::string &vector_name, const std::vector< std::string > &component_names)
void add_field_name(const std::string &vector_name, const ComponentMask &component_mask=ComponentMask())
boost::signals2::connection tria_listener
#define Assert(cond, exc)
void evaluate_field_at_requested_location(const std::string &name, const VectorType &solution)
std::vector< std::vector< double > > independent_values
void evaluate_field(const std::string &name, const VectorType &solution)
types::global_dof_index n_dofs() const
void start_new_dataset(const double key)
SmartPointer< const DoFHandler< dim >, PointValueHistory< dim > > dof_handler
PointValueHistory & operator=(const PointValueHistory &point_value_history)
Second derivatives of shape functions.
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
numbers::NumberTraits< Number >::real_type distance(const Point< dim, Number > &p) const
unsigned int size() const
const unsigned int dofs_per_cell
const std::vector< Point< dim > > & get_unit_support_points() const
void add_independent_names(const std::vector< std::string > &independent_names)
void tria_change_listener()
Vector< double > mark_support_locations()
bool deep_check(const bool strict)
std::pair< unsigned int, unsigned int > system_to_component_index(const unsigned int index) const
unsigned int n_components() const
bool triangulation_changed
std::map< std::string, ComponentMask > component_mask
Shape function gradients.
unsigned int n_selected_components(const unsigned int overall_number_of_components=numbers::invalid_unsigned_int) const
void status(std::ostream &out)
const Triangulation< dim, spacedim > & get_triangulation() const
void add_point(const Point< dim > &location)
void get_points(std::vector< std::vector< Point< dim > > > &locations)
std::map< std::string, std::vector< std::string > > component_names_map
void get_support_locations(std::vector< std::vector< Point< dim > > > &locations)
virtual std::vector< std::string > get_names() const =0
virtual UpdateFlags get_needed_update_flags() const =0
void push_back_independent(const std::vector< double > &independent_values)