libMesh
Classes | Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction > Class Template Reference

The GenericProjector class implements the core of other projection operations, using two input functors to read values to be projected and an output functor to set degrees of freedom in the result. More...

#include <generic_projector.h>

Classes

struct  ProjectEdges
 
struct  ProjectInteriors
 
struct  ProjectSides
 
struct  ProjectVertices
 
struct  SortAndCopy
 
struct  SubFunctor
 
struct  SubProjector
 

Public Types

typedef std::set< unsigned intvar_set
 
typedef std::pair< const Node *, std::tuple< const Elem *, unsigned short, var_set > > node_projection
 
typedef StoredRange< std::vector< node_projection >::const_iterator, node_projectionnode_range
 
typedef StoredRange< std::vector< const Elem * >::const_iterator, const Elem * > interior_range
 

Public Member Functions

 GenericProjector (const System &system_in, const FFunctor &f_in, const GFunctor *g_in, const ProjectionAction &act_in, const std::vector< unsigned int > &variables_in, std::unordered_map< dof_id_type, std::vector< dof_id_type >> *nodes_to_elem_in=nullptr)
 
 GenericProjector (const GenericProjector &in)
 
 ~GenericProjector ()
 
void project (const ConstElemRange &range)
 Function definitions. More...
 
void send_and_insert_dof_values (std::unordered_map< dof_id_type, std::pair< FValue, processor_id_type >> &ids_to_push, ProjectionAction &action) const
 

Public Attributes

std::unordered_map< dof_id_type, FValue > ids_to_save
 

Private Attributes

const Systemsystem
 
const FFunctor & master_f
 
const GFunctor * master_g
 
bool g_was_copied
 
bool map_was_created
 
const ProjectionAction & master_action
 
const std::vector< unsigned int > & variables
 
std::unordered_map< dof_id_type, std::vector< dof_id_type > > * nodes_to_elem
 
bool done_saving_ids
 

Detailed Description

template<typename FFunctor, typename GFunctor, typename FValue, typename ProjectionAction>
class libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >

The GenericProjector class implements the core of other projection operations, using two input functors to read values to be projected and an output functor to set degrees of freedom in the result.

This may be executed in parallel on multiple threads.

Author
Roy H. Stogner
Date
2016

Definition at line 80 of file generic_projector.h.

Member Typedef Documentation

◆ interior_range

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
typedef StoredRange<std::vector<const Elem *>::const_iterator, const Elem *> libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::interior_range

Definition at line 327 of file generic_projector.h.

◆ node_projection

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
typedef std::pair<const Node *, std::tuple<const Elem *, unsigned short, var_set> > libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::node_projection

Definition at line 208 of file generic_projector.h.

◆ node_range

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
typedef StoredRange<std::vector<node_projection>::const_iterator, node_projection> libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::node_range

Definition at line 211 of file generic_projector.h.

◆ var_set

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
typedef std::set<unsigned int> libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::var_set

Definition at line 149 of file generic_projector.h.

Constructor & Destructor Documentation

◆ GenericProjector() [1/2]

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::GenericProjector ( const System system_in,
const FFunctor &  f_in,
const GFunctor *  g_in,
const ProjectionAction &  act_in,
const std::vector< unsigned int > &  variables_in,
std::unordered_map< dof_id_type, std::vector< dof_id_type >> *  nodes_to_elem_in = nullptr 
)
inline

Definition at line 96 of file generic_projector.h.

102  :
103  system(system_in),
104  master_f(f_in),
105  master_g(g_in),
106  g_was_copied(false),
107  map_was_created(!nodes_to_elem_in),
108  master_action(act_in),
109  variables(variables_in),
110  nodes_to_elem(nodes_to_elem_in)
111  {
112  if (map_was_created) // past tense misnomer here
113  {
114  nodes_to_elem = new
115  std::unordered_map<dof_id_type, std::vector<dof_id_type>>;
117  }
118  }

References libMesh::MeshTools::build_nodes_to_elem_map(), libMesh::System::get_mesh(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::map_was_created, libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::nodes_to_elem, and libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::system.

◆ GenericProjector() [2/2]

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::GenericProjector ( const GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction > &  in)
inline

Definition at line 120 of file generic_projector.h.

120  :
121  system(in.system),
122  master_f(in.master_f),
123  master_g(in.master_g ? new GFunctor(*in.master_g) : nullptr),
124  g_was_copied(in.master_g),
125  master_action(in.master_action),
126  variables(in.variables),
127  nodes_to_elem(in.nodes_to_elem)
128  {}

◆ ~GenericProjector()

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::~GenericProjector ( )
inline

Member Function Documentation

◆ project()

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
void libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::project ( const ConstElemRange range)

Function definitions.

Definition at line 951 of file generic_projector.h.

952 {
953  LOG_SCOPE ("project", "GenericProjector");
954 
955  // Unless we split sort and copy into two passes we can't know for
956  // sure ahead of time whether we need to save the copied ids
957  done_saving_ids = false;
958 
959  SortAndCopy sort_work(*this);
960  Threads::parallel_reduce (range, sort_work);
961  ProjectionAction action(master_action);
962 
963  // Keep track of dof ids and values to send to other ranks
964  std::unordered_map<dof_id_type, std::pair<FValue, processor_id_type>> ids_to_push;
965 
966  ids_to_push.insert(sort_work.new_ids_to_push.begin(),
967  sort_work.new_ids_to_push.end());
968  ids_to_save.insert(sort_work.new_ids_to_save.begin(),
969  sort_work.new_ids_to_save.end());
970 
971  std::vector<node_projection> vertices(sort_work.vertices.begin(),
972  sort_work.vertices.end());
973 
974  done_saving_ids = sort_work.edges.empty() &&
975  sort_work.sides.empty() && sort_work.interiors.empty();
976  system.comm().max(done_saving_ids);
977 
978  {
979  ProjectVertices project_vertices(*this);
980  Threads::parallel_reduce (node_range(&vertices), project_vertices);
981  ids_to_push.insert(project_vertices.new_ids_to_push.begin(),
982  project_vertices.new_ids_to_push.end());
983  ids_to_save.insert(project_vertices.new_ids_to_save.begin(),
984  project_vertices.new_ids_to_save.end());
985  }
986 
987  done_saving_ids = sort_work.sides.empty() && sort_work.interiors.empty();
988  system.comm().max(done_saving_ids);
989 
990  this->send_and_insert_dof_values(ids_to_push, action);
991 
992  {
993  std::vector<node_projection> edges(sort_work.edges.begin(), sort_work.edges.end());
994  ProjectEdges project_edges(*this);
995  Threads::parallel_reduce (node_range(&edges), project_edges);
996  ids_to_push.insert(project_edges.new_ids_to_push.begin(),
997  project_edges.new_ids_to_push.end());
998  ids_to_save.insert(project_edges.new_ids_to_save.begin(),
999  project_edges.new_ids_to_save.end());
1000  }
1001 
1002  done_saving_ids = sort_work.interiors.empty();
1003  system.comm().max(done_saving_ids);
1004 
1005  this->send_and_insert_dof_values(ids_to_push, action);
1006 
1007  {
1008  std::vector<node_projection> sides(sort_work.sides.begin(), sort_work.sides.end());
1009  ProjectSides project_sides(*this);
1010  Threads::parallel_reduce (node_range(&sides), project_sides);
1011  ids_to_push.insert(project_sides.new_ids_to_push.begin(),
1012  project_sides.new_ids_to_push.end());
1013  ids_to_save.insert(project_sides.new_ids_to_save.begin(),
1014  project_sides.new_ids_to_save.end());
1015  }
1016 
1017  done_saving_ids = true;
1018  this->send_and_insert_dof_values(ids_to_push, action);
1019 
1020  // No ids to save or push this time, but we still use a reduce since
1021  // nominally ProjectInteriors still has non-const operator()
1022  ProjectInteriors project_interiors(*this);
1023  Threads::parallel_reduce (interior_range(&sort_work.interiors),
1024  project_interiors);
1025 }

References libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SortAndCopy::edges, libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SortAndCopy::interiors, libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SubFunctor::new_ids_to_push, libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SubFunctor::new_ids_to_save, libMesh::Threads::parallel_reduce(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SortAndCopy::sides, and libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SortAndCopy::vertices.

◆ send_and_insert_dof_values()

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
void libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::send_and_insert_dof_values ( std::unordered_map< dof_id_type, std::pair< FValue, processor_id_type >> &  ids_to_push,
ProjectionAction &  action 
) const

Definition at line 2405 of file generic_projector.h.

2407 {
2408  // See if we calculated any ids that need to be pushed; get them
2409  // ready to push.
2410  std::unordered_map<processor_id_type, std::vector<dof_id_type>>
2411  pushed_dof_ids, received_dof_ids;
2412  std::unordered_map<processor_id_type, std::vector<typename TypeToSend<FValue>::type>>
2413  pushed_dof_values, received_dof_values;
2414  for (auto & id_val_pid : ids_to_push)
2415  {
2416  processor_id_type pid = id_val_pid.second.second;
2418  {
2419  pushed_dof_ids[pid].push_back(id_val_pid.first);
2420  pushed_dof_values[pid].push_back(convert_to_send(id_val_pid.second.first));
2421  }
2422  }
2423 
2424  // If and when we get ids pushed to us, act on them if we have
2425  // corresponding values or save them if not
2426  auto ids_action_functor =
2427  [&action, &received_dof_ids, &received_dof_values]
2428  (processor_id_type pid,
2429  const std::vector<dof_id_type> & data)
2430  {
2431  auto iter = received_dof_values.find(pid);
2432  if (iter == received_dof_values.end())
2433  {
2434  libmesh_assert(received_dof_ids.find(pid) ==
2435  received_dof_ids.end());
2436  received_dof_ids[pid] = data;
2437  }
2438  else
2439  {
2440  auto & vals = iter->second;
2441  std::size_t vals_size = vals.size();
2442  libmesh_assert_equal_to(vals_size, data.size());
2443  for (std::size_t i=0; i != vals_size; ++i)
2444  {
2445  FValue val;
2446  convert_from_receive(vals[i], val);
2447  action.insert(data[i], val);
2448  }
2449  received_dof_values.erase(iter);
2450  }
2451  };
2452 
2453  // If and when we get values pushed to us, act on them if we have
2454  // corresponding ids or save them if not
2455  auto values_action_functor =
2456  [&action, &received_dof_ids, &received_dof_values]
2457  (processor_id_type pid,
2458  const std::vector<typename TypeToSend<FValue>::type> & data)
2459  {
2460  auto iter = received_dof_ids.find(pid);
2461  if (iter == received_dof_ids.end())
2462  {
2463  // We get no more than 1 values vector from anywhere
2464  libmesh_assert(received_dof_values.find(pid) ==
2465  received_dof_values.end());
2466  received_dof_values[pid] = data;
2467  }
2468  else
2469  {
2470  auto & ids = iter->second;
2471  std::size_t ids_size = ids.size();
2472  libmesh_assert_equal_to(ids_size, data.size());
2473  for (std::size_t i=0; i != ids_size; ++i)
2474  {
2475  FValue val;
2476  convert_from_receive(data[i], val);
2477  action.insert(ids[i], val);
2478  }
2479  received_dof_ids.erase(iter);
2480  }
2481  };
2482 
2483  Parallel::push_parallel_vector_data
2484  (system.comm(), pushed_dof_ids, ids_action_functor);
2485 
2486  Parallel::push_parallel_vector_data
2487  (system.comm(), pushed_dof_values, values_action_functor);
2488 
2489  // At this point we shouldn't have any unprocessed data left
2490  libmesh_assert(received_dof_ids.empty());
2491  libmesh_assert(received_dof_values.empty());
2492 
2493 }

References libMesh::convert_from_receive(), libMesh::convert_to_send(), data, libMesh::DofObject::invalid_processor_id, and libMesh::libmesh_assert().

Member Data Documentation

◆ done_saving_ids

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
bool libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::done_saving_ids
private

Definition at line 93 of file generic_projector.h.

◆ g_was_copied

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
bool libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::g_was_copied
private

◆ ids_to_save

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
std::unordered_map<dof_id_type, FValue> libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ids_to_save

Definition at line 145 of file generic_projector.h.

◆ map_was_created

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
bool libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::map_was_created
private

◆ master_action

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
const ProjectionAction& libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::master_action
private

Definition at line 90 of file generic_projector.h.

◆ master_f

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
const FFunctor& libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::master_f
private

Definition at line 87 of file generic_projector.h.

◆ master_g

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
const GFunctor* libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::master_g
private

◆ nodes_to_elem

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
std::unordered_map<dof_id_type, std::vector<dof_id_type> >* libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::nodes_to_elem
private

◆ system

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
const System& libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::system
private

◆ variables

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
const std::vector<unsigned int>& libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::variables
private

Definition at line 91 of file generic_projector.h.


The documentation for this class was generated from the following file:
libMesh::GenericProjector::g_was_copied
bool g_was_copied
Definition: generic_projector.h:89
libMesh::GenericProjector::map_was_created
bool map_was_created
Definition: generic_projector.h:89
libMesh::GenericProjector::interior_range
StoredRange< std::vector< const Elem * >::const_iterator, const Elem * > interior_range
Definition: generic_projector.h:327
libMesh::GenericProjector::master_g
const GFunctor * master_g
Definition: generic_projector.h:88
libMesh::GenericProjector::master_f
const FFunctor & master_f
Definition: generic_projector.h:87
libMesh::GenericProjector::master_action
const ProjectionAction & master_action
Definition: generic_projector.h:90
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::MeshTools::build_nodes_to_elem_map
void build_nodes_to_elem_map(const MeshBase &mesh, std::vector< std::vector< dof_id_type >> &nodes_to_elem_map)
After calling this function the input vector nodes_to_elem_map will contain the node to element conne...
Definition: mesh_tools.C:248
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::GenericProjector::done_saving_ids
bool done_saving_ids
Definition: generic_projector.h:93
libMesh::System::get_mesh
const MeshBase & get_mesh() const
Definition: system.h:2083
libMesh::processor_id_type
uint8_t processor_id_type
Definition: id_types.h:104
libMesh::Threads::parallel_reduce
void parallel_reduce(const Range &range, Body &body)
Execute the provided reduction operation in parallel on the specified range.
Definition: threads_none.h:101
libMesh::GenericProjector::nodes_to_elem
std::unordered_map< dof_id_type, std::vector< dof_id_type > > * nodes_to_elem
Definition: generic_projector.h:92
libMesh::convert_from_receive
void convert_from_receive(SendT &received, T &converted)
Definition: generic_projector.h:65
libMesh::DofObject::invalid_processor_id
static const processor_id_type invalid_processor_id
An invalid processor_id to distinguish DoFs that have not been assigned to a processor.
Definition: dof_object.h:432
data
IterBase * data
Ideally this private member data should have protected access.
Definition: variant_filter_iterator.h:337
libMesh::GenericProjector::ids_to_save
std::unordered_map< dof_id_type, FValue > ids_to_save
Definition: generic_projector.h:145
libMesh::GenericProjector::system
const System & system
Definition: generic_projector.h:83
libMesh::GenericProjector::variables
const std::vector< unsigned int > & variables
Definition: generic_projector.h:91
libMesh::GenericProjector::send_and_insert_dof_values
void send_and_insert_dof_values(std::unordered_map< dof_id_type, std::pair< FValue, processor_id_type >> &ids_to_push, ProjectionAction &action) const
Definition: generic_projector.h:2405
libMesh::GenericProjector::node_range
StoredRange< std::vector< node_projection >::const_iterator, node_projection > node_range
Definition: generic_projector.h:211
libMesh::convert_to_send
const TypeToSend< T >::type convert_to_send(const T &in)
Definition: generic_projector.h:61