libMesh
Loading...
Searching...
No Matches
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.
 
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.
 
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.
 
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.
 
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.

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 }
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...
ProjectionAction & master_action
const MeshBase & get_mesh() const
Definition system.h:2401
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:456

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.

◆ 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),
150 {}
std::unique_ptr< GFunctor > master_g_deepcopy
Needed for C1 type elements only.
const Elem & get(const ElemType type_in)

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

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}
std::unordered_map< dof_id_type, typename FFunctor::ValuePushType > ids_to_save
StoredRange< std::vector< const Elem * >::const_iterator, const Elem * > interior_range
StoredRange< std::vector< node_projection >::const_iterator, node_projection > node_range
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 parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided reduction operation in parallel on the specified range.
void libmesh_merge_move(T &target, T &source)

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.

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

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

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

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

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