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::unordered_map< dof_id_type, std::vector< dof_id_type > > NodesToElemMap
 Convenience typedef for the Node-to-attached-Elem mapping that may be passed in to the constructor. More...
 
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, FFunctor &f_in, GFunctor *g_in, ProjectionAction &act_in, const std::vector< unsigned int > &variables_in, NodesToElemMap *nodes_to_elem_in=nullptr)
 
 GenericProjector (const GenericProjector &in)
 
 ~GenericProjector ()=default
 
void project (const ConstElemRange &range)
 Function definitions. More...
 
template<typename Value >
void send_and_insert_dof_values (std::unordered_map< dof_id_type, std::pair< Value, processor_id_type >> &ids_to_push, ProjectionAction &action) const
 

Public Attributes

std::unordered_map< dof_id_type, typename FFunctor::ValuePushType > ids_to_save
 

Private Attributes

const Systemsystem
 
FFunctor & master_f
 
std::unique_ptr< GFunctor > master_g_deepcopy
 Needed for C1 type elements only. More...
 
GFunctor * master_g
 
ProjectionAction & master_action
 
const std::vector< unsigned int > & variables
 
NodesToElemMap nodes_to_elem_ourcopy
 nodes_to_elem is either a shallow copy of a map passed in to the constructor, or points to nodes_to_elem_ourcopy, if no such map was provided. More...
 
NodesToElemMapnodes_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 83 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 367 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 247 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 250 of file generic_projector.h.

◆ NodesToElemMap

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
typedef std::unordered_map<dof_id_type, std::vector<dof_id_type> > libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::NodesToElemMap

Convenience typedef for the Node-to-attached-Elem mapping that may be passed in to the constructor.

Definition at line 90 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 165 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,
FFunctor &  f_in,
GFunctor *  g_in,
ProjectionAction &  act_in,
const std::vector< unsigned int > &  variables_in,
NodesToElemMap nodes_to_elem_in = nullptr 
)
inline

Definition at line 122 of file generic_projector.h.

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

127  :
128  system(system_in),
129  master_f(f_in),
130  master_g(g_in),
131  master_action(act_in),
132  variables(variables_in),
133  nodes_to_elem(nodes_to_elem_in)
134  {
135  if (!nodes_to_elem_in)
136  {
139  }
140  }
NodesToElemMap * nodes_to_elem
ProjectionAction & master_action
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:449
const MeshBase & get_mesh() const
Definition: system.h:2358
const std::vector< unsigned int > & variables
NodesToElemMap nodes_to_elem_ourcopy
nodes_to_elem is either a shallow copy of a map passed in to the constructor, or points to nodes_to_e...

◆ 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 142 of file generic_projector.h.

142  :
143  system(in.system),
144  master_f(in.master_f),
145  master_g_deepcopy(in.master_g ? std::make_unique<GFunctor>(*in.master_g) : nullptr),
146  master_g(in.master_g ? master_g_deepcopy.get() : nullptr),
147  master_action(in.master_action),
148  variables(in.variables),
149  nodes_to_elem(in.nodes_to_elem)
150  {}
std::unique_ptr< GFunctor > master_g_deepcopy
Needed for C1 type elements only.
NodesToElemMap * nodes_to_elem
ProjectionAction & master_action
const std::vector< unsigned int > & variables

◆ ~GenericProjector()

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

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 1214 of file generic_projector.h.

References libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SortAndCopy::edges, libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SortAndCopy::interiors, libMesh::libmesh_merge_move(), 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.

1215 {
1216  LOG_SCOPE ("project", "GenericProjector");
1217 
1218  // Unless we split sort and copy into two passes we can't know for
1219  // sure ahead of time whether we need to save the copied ids
1220  done_saving_ids = false;
1221 
1222  SortAndCopy sort_work(*this);
1223  Threads::parallel_reduce (range, sort_work);
1224  ProjectionAction action(master_action);
1225 
1226  // Keep track of dof ids and values to send to other ranks
1227  std::unordered_map<dof_id_type, std::pair<typename FFunctor::ValuePushType, processor_id_type>>
1228  ids_to_push;
1229 
1230  ids_to_push.insert(sort_work.new_ids_to_push.begin(),
1231  sort_work.new_ids_to_push.end());
1232  ids_to_save.insert(sort_work.new_ids_to_save.begin(),
1233  sort_work.new_ids_to_save.end());
1234 
1235  std::vector<node_projection> vertices(sort_work.vertices.begin(),
1236  sort_work.vertices.end());
1237 
1238  done_saving_ids = sort_work.edges.empty() &&
1239  sort_work.sides.empty() && sort_work.interiors.empty();
1240 
1241  {
1242  ProjectVertices project_vertices(*this);
1243  Threads::parallel_reduce (node_range(&vertices), project_vertices);
1244  libmesh_merge_move(ids_to_push, project_vertices.new_ids_to_push);
1245  libmesh_merge_move(ids_to_save, project_vertices.new_ids_to_save);
1246  }
1247 
1248  done_saving_ids = sort_work.sides.empty() && sort_work.interiors.empty();
1249 
1250  this->send_and_insert_dof_values(ids_to_push, action);
1251 
1252  {
1253  std::vector<node_projection> edges(sort_work.edges.begin(), sort_work.edges.end());
1254  ProjectEdges project_edges(*this);
1255  Threads::parallel_reduce (node_range(&edges), project_edges);
1256  libmesh_merge_move(ids_to_push, project_edges.new_ids_to_push);
1257  libmesh_merge_move(ids_to_save, project_edges.new_ids_to_save);
1258  }
1259 
1260  done_saving_ids = sort_work.interiors.empty();
1261 
1262  this->send_and_insert_dof_values(ids_to_push, action);
1263 
1264  {
1265  std::vector<node_projection> sides(sort_work.sides.begin(), sort_work.sides.end());
1266  ProjectSides project_sides(*this);
1267  Threads::parallel_reduce (node_range(&sides), project_sides);
1268  libmesh_merge_move(ids_to_push, project_sides.new_ids_to_push);
1269  libmesh_merge_move(ids_to_save, project_sides.new_ids_to_save);
1270  }
1271 
1272  done_saving_ids = true;
1273  this->send_and_insert_dof_values(ids_to_push, action);
1274 
1275  // No ids to save or push this time, but we still use a reduce since
1276  // nominally ProjectInteriors still has non-const operator()
1277  ProjectInteriors project_interiors(*this);
1278  Threads::parallel_reduce (interior_range(&sort_work.interiors),
1279  project_interiors);
1280 }
void send_and_insert_dof_values(std::unordered_map< dof_id_type, std::pair< Value, processor_id_type >> &ids_to_push, ProjectionAction &action) const
void libmesh_merge_move(T &target, T &source)
ProjectionAction & master_action
std::unordered_map< dof_id_type, typename FFunctor::ValuePushType > ids_to_save
StoredRange< std::vector< node_projection >::const_iterator, node_projection > node_range
void parallel_reduce(const Range &range, Body &body)
Execute the provided reduction operation in parallel on the specified range.
Definition: threads_none.h:101
StoredRange< std::vector< const Elem * >::const_iterator, const Elem * > interior_range

◆ send_and_insert_dof_values()

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

Definition at line 2900 of file generic_projector.h.

References libMesh::ParallelObject::comm(), libMesh::convert_from_receive(), libMesh::convert_to_send(), libMesh::DofObject::invalid_processor_id, libMesh::libmesh_assert(), and libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::system.

2902 {
2903  LOG_SCOPE ("send_and_insert_dof_values", "GenericProjector");
2904 
2905  // See if we calculated any ids that need to be pushed; get them
2906  // ready to push.
2907  std::unordered_map<processor_id_type, std::vector<dof_id_type>>
2908  pushed_dof_ids, received_dof_ids;
2909  std::unordered_map<processor_id_type, std::vector<typename TypeToSend<Value>::type>>
2910  pushed_dof_values, received_dof_values;
2911  for (auto & id_val_pid : ids_to_push)
2912  {
2913  processor_id_type pid = id_val_pid.second.second;
2915  {
2916  pushed_dof_ids[pid].push_back(id_val_pid.first);
2917  pushed_dof_values[pid].push_back(convert_to_send(id_val_pid.second.first));
2918  }
2919  }
2920 
2921  // If and when we get ids pushed to us, act on them if we have
2922  // corresponding values or save them if not
2923  auto ids_action_functor =
2924  [&action, &received_dof_ids, &received_dof_values]
2925  (processor_id_type pid,
2926  const std::vector<dof_id_type> & data)
2927  {
2928  auto iter = received_dof_values.find(pid);
2929  if (iter == received_dof_values.end())
2930  {
2931  libmesh_assert(received_dof_ids.find(pid) ==
2932  received_dof_ids.end());
2933  received_dof_ids[pid] = data;
2934  }
2935  else
2936  {
2937  auto & vals = iter->second;
2938  std::size_t vals_size = vals.size();
2939  libmesh_assert_equal_to(vals_size, data.size());
2940  for (std::size_t i=0; i != vals_size; ++i)
2941  {
2942  Value val;
2943  convert_from_receive(vals[i], val);
2944  action.insert(data[i], val);
2945  }
2946  received_dof_values.erase(iter);
2947  }
2948  };
2949 
2950  // If and when we get values pushed to us, act on them if we have
2951  // corresponding ids or save them if not
2952  auto values_action_functor =
2953  [&action, &received_dof_ids, &received_dof_values]
2954  (processor_id_type pid,
2955  const std::vector<typename TypeToSend<Value>::type> & data)
2956  {
2957  auto iter = received_dof_ids.find(pid);
2958  if (iter == received_dof_ids.end())
2959  {
2960  // We get no more than 1 values vector from anywhere
2961  libmesh_assert(received_dof_values.find(pid) ==
2962  received_dof_values.end());
2963  received_dof_values[pid] = data;
2964  }
2965  else
2966  {
2967  auto & ids = iter->second;
2968  std::size_t ids_size = ids.size();
2969  libmesh_assert_equal_to(ids_size, data.size());
2970  for (std::size_t i=0; i != ids_size; ++i)
2971  {
2972  Value val;
2973  convert_from_receive(data[i], val);
2974  action.insert(ids[i], val);
2975  }
2976  received_dof_ids.erase(iter);
2977  }
2978  };
2979 
2980  Parallel::push_parallel_vector_data
2981  (system.comm(), pushed_dof_ids, ids_action_functor);
2982 
2983  Parallel::push_parallel_vector_data
2984  (system.comm(), pushed_dof_values, values_action_functor);
2985 
2986  // At this point we shouldn't have any unprocessed data left
2987  libmesh_assert(received_dof_ids.empty());
2988  libmesh_assert(received_dof_values.empty());
2989 
2990 }
const Parallel::Communicator & comm() const
uint8_t processor_id_type
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:493
libmesh_assert(ctx)
void convert_from_receive(SendT &received, T &converted)
const TypeToSend< T >::type convert_to_send(const T &in)

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 119 of file generic_projector.h.

◆ ids_to_save

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

◆ master_action

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

Definition at line 108 of file generic_projector.h.

◆ master_f

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

Definition at line 97 of file generic_projector.h.

◆ master_g

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

◆ master_g_deepcopy

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
std::unique_ptr<GFunctor> libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::master_g_deepcopy
private

Needed for C1 type elements only.

master_g is either a shallow copy of a GFunctor pointer passed to the constructor, or to master_g_deepcopy.get(), depending on which constructor was called.

Definition at line 105 of file generic_projector.h.

◆ nodes_to_elem

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
NodesToElemMap* libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::nodes_to_elem
private

◆ nodes_to_elem_ourcopy

template<typename FFunctor , typename GFunctor , typename FValue , typename ProjectionAction >
NodesToElemMap libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::nodes_to_elem_ourcopy
private

nodes_to_elem is either a shallow copy of a map passed in to the constructor, or points to nodes_to_elem_ourcopy, if no such map was provided.

Definition at line 116 of file generic_projector.h.

Referenced by libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::GenericProjector().

◆ 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 109 of file generic_projector.h.


The documentation for this class was generated from the following file: