libMesh
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
libMesh::DTKAdapter Class Reference

The DTKAdapter is used with the DTKSolutionTransfer object to adapt libmesh data to the DTK interface. More...

#include <dtk_adapter.h>

Public Types

typedef DataTransferKit::MeshContainer< intMeshContainerType
 
typedef DataTransferKit::FieldContainer< double > FieldContainerType
 
typedef DataTransferKit::MeshTraits< MeshContainerType >::global_ordinal_type GlobalOrdinal
 
typedef DataTransferKit::FieldEvaluator< GlobalOrdinal, FieldContainerTypeEvaluatorType
 
typedef Teuchos::RCP< EvaluatorTypeRCP_Evaluator
 

Public Member Functions

 DTKAdapter (Teuchos::RCP< const Teuchos::Comm< int > > in_comm, EquationSystems &in_es)
 
Teuchos::RCP< DataTransferKit::MeshManager< MeshContainerType > > get_mesh_manager ()
 
RCP_Evaluator get_variable_evaluator (std::string var_name)
 
Teuchos::RCP< DataTransferKit::FieldManager< MeshContainerType > > get_target_coords ()
 
Teuchos::RCP< DataTransferKit::FieldManager< FieldContainerType > > get_values_to_fill (std::string var_name)
 
void update_variable_values (std::string var_name)
 After computing values for a variable in this EquationSystems we need to take those values and put them in the actual solution vector.
 

Protected Member Functions

Systemfind_sys (std::string var_name)
 Small helper function for finding the system containing the variable.
 
DataTransferKit::DTK_ElementTopology get_element_topology (const Elem *elem)
 
void get_semi_local_nodes (std::set< unsigned int > &semi_local_nodes)
 Helper function that fills the std::set with all of the node numbers of nodes connected to local elements.
 

Protected Attributes

Teuchos::RCP< const Teuchos::Comm< int > > comm
 
EquationSystemses
 
const MeshBasemesh
 
unsigned int dim
 
unsigned int num_local_nodes
 
Teuchos::ArrayRCP< intvertices
 
Teuchos::RCP< DataTransferKit::MeshManager< MeshContainerType > > mesh_manager
 
RCP_Evaluator field_evaluator
 
Teuchos::RCP< DataTransferKit::FieldManager< MeshContainerType > > target_coords
 
std::map< std::string, Teuchos::RCP< DataTransferKit::FieldManager< FieldContainerType > > > values_to_fill
 Map of variable names to arrays to be filled by a transfer.
 
std::map< std::string, RCP_Evaluatorevaluators
 Map of variable names to RCP_Evaluator objects.
 

Detailed Description

The DTKAdapter is used with the DTKSolutionTransfer object to adapt libmesh data to the DTK interface.

Author
Derek Gaston
Date
2013

Definition at line 52 of file dtk_adapter.h.

Member Typedef Documentation

◆ EvaluatorType

typedef DataTransferKit::FieldEvaluator<GlobalOrdinal,FieldContainerType> libMesh::DTKAdapter::EvaluatorType

Definition at line 60 of file dtk_adapter.h.

◆ FieldContainerType

typedef DataTransferKit::FieldContainer<double> libMesh::DTKAdapter::FieldContainerType

Definition at line 58 of file dtk_adapter.h.

◆ GlobalOrdinal

typedef DataTransferKit::MeshTraits<MeshContainerType>::global_ordinal_type libMesh::DTKAdapter::GlobalOrdinal

Definition at line 59 of file dtk_adapter.h.

◆ MeshContainerType

typedef DataTransferKit::MeshContainer<int> libMesh::DTKAdapter::MeshContainerType

Definition at line 57 of file dtk_adapter.h.

◆ RCP_Evaluator

Definition at line 61 of file dtk_adapter.h.

Constructor & Destructor Documentation

◆ DTKAdapter()

libMesh::DTKAdapter::DTKAdapter ( Teuchos::RCP< const Teuchos::Comm< int > >  in_comm,
EquationSystems in_es 
)

Definition at line 46 of file dtk_adapter.C.

46 :
47 comm(in_comm),
48 es(in_es),
49 mesh(in_es.get_mesh()),
51{
52 std::set<unsigned int> semi_local_nodes;
53 get_semi_local_nodes(semi_local_nodes);
54
55 num_local_nodes = semi_local_nodes.size();
56
58 Teuchos::ArrayRCP<double> coordinates(num_local_nodes * dim);
59
60 // Fill in the vertices and coordinates
61 {
62 unsigned int i = 0;
63
64 for (const auto & id : semi_local_nodes)
65 {
66 const Node & node = mesh.node_ref(id);
67
68 vertices[i] = node.id();
69
70 for (unsigned int j=0; j<dim; j++)
71 coordinates[(j*num_local_nodes) + i] = node(j);
72
73 i++;
74 }
75 }
76
77 // Currently assuming all elements are the same!
78 DataTransferKit::DTK_ElementTopology element_topology = get_element_topology(mesh.elem_ptr(0));
79 unsigned int n_nodes_per_elem = mesh.elem_ptr(0)->n_nodes();
80
81 unsigned int n_local_elem = mesh.n_local_elem();
82
83 Teuchos::ArrayRCP<int> elements(n_local_elem);
84 Teuchos::ArrayRCP<int> connectivity(n_nodes_per_elem*n_local_elem);
85
86 // Fill in the elements and connectivity
87 {
88 unsigned int i = 0;
89
90 for (const auto & elem : as_range(mesh.local_elements_begin(),
91 mesh.local_elements_end()))
92 {
93 elements[i] = elem->id();
94
95 for (unsigned int j=0; j<n_nodes_per_elem; j++)
96 connectivity[(j*n_local_elem)+i] = elem->node_id(j);
97
98 i++;
99 }
100 }
101
102 Teuchos::ArrayRCP<int> permutation_list(n_nodes_per_elem);
103 std::iota(permutation_list.begin(), permutation_list.end(), 0);
104
105 /*
106 if (this->processor_id() == 1)
107 sleep(1);
108
109 libMesh::out<<"n_nodes_per_elem: "<<n_nodes_per_elem<<std::endl;
110
111 libMesh::out<<"Dim: "<<dim<<std::endl;
112
113 libMesh::err<<"Vertices size: "<<vertices.size()<<std::endl;
114 {
115 libMesh::err<<this->processor_id()<<" Vertices: ";
116
117 for (std::size_t i=0; i<vertices.size(); i++)
118 libMesh::err<<vertices[i]<<" ";
119
120 libMesh::err<<std::endl;
121 }
122
123 libMesh::err<<"Coordinates size: "<<coordinates.size()<<std::endl;
124 {
125 libMesh::err<<this->processor_id()<<" Coordinates: ";
126
127 for (std::size_t i=0; i<coordinates.size(); i++)
128 libMesh::err<<coordinates[i]<<" ";
129
130 libMesh::err<<std::endl;
131 }
132
133 libMesh::err<<"Connectivity size: "<<connectivity.size()<<std::endl;
134 {
135 libMesh::err<<this->processor_id()<<" Connectivity: ";
136
137 for (std::size_t i=0; i<connectivity.size(); i++)
138 libMesh::err<<connectivity[i]<<" ";
139
140 libMesh::err<<std::endl;
141 }
142
143 libMesh::err<<"Permutation_List size: "<<permutation_list.size()<<std::endl;
144 {
145 libMesh::err<<this->processor_id()<<" Permutation_List: ";
146
147 for (std::size_t i=0; i<permutation_list.size(); i++)
148 libMesh::err<<permutation_list[i]<<" ";
149
150 libMesh::err<<std::endl;
151 }
152
153 */
154 Teuchos::RCP<MeshContainerType>
155 mesh_container = Teuchos::rcp(new MeshContainerType(dim,
156 vertices,
157 coordinates,
158 element_topology,
159 n_nodes_per_elem,
160 elements,
161 connectivity,
162 permutation_list));
163
164 // We only have 1 element topology in this grid so we make just one mesh block
165 Teuchos::ArrayRCP<Teuchos::RCP<MeshContainerType>> mesh_blocks(1);
166 mesh_blocks[0] = mesh_container;
167
168 // Create the MeshManager
169 mesh_manager = Teuchos::rcp(new DataTransferKit::MeshManager<MeshContainerType>(mesh_blocks, comm, dim) );
170
171 // Pack the coordinates into a field, this will be the positions we'll ask for other systems fields at
172 target_coords = Teuchos::rcp(new DataTransferKit::FieldManager<MeshContainerType>(mesh_container, comm));
173}
Teuchos::RCP< DataTransferKit::FieldManager< MeshContainerType > > target_coords
const MeshBase & mesh
Definition dtk_adapter.h:96
DataTransferKit::MeshContainer< int > MeshContainerType
Definition dtk_adapter.h:57
Teuchos::ArrayRCP< int > vertices
Teuchos::RCP< DataTransferKit::MeshManager< MeshContainerType > > mesh_manager
DataTransferKit::DTK_ElementTopology get_element_topology(const Elem *elem)
unsigned int dim
Definition dtk_adapter.h:97
void get_semi_local_nodes(std::set< unsigned int > &semi_local_nodes)
Helper function that fills the std::set with all of the node numbers of nodes connected to local elem...
EquationSystems & es
Definition dtk_adapter.h:95
unsigned int num_local_nodes
Definition dtk_adapter.h:99
Teuchos::RCP< const Teuchos::Comm< int > > comm
Definition dtk_adapter.h:94
dof_id_type id() const
Definition dof_object.h:819
virtual unsigned int n_nodes() const =0
virtual const Node & node_ref(const dof_id_type i) const
Definition mesh_base.h:745
unsigned int mesh_dimension() const
Definition mesh_base.C:430
virtual const Elem * elem_ptr(const dof_id_type i) const =0
dof_id_type n_local_elem() const
Definition mesh_base.h:697
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.

References libMesh::as_range(), comm, dim, libMesh::MeshBase::elem_ptr(), get_element_topology(), get_semi_local_nodes(), libMesh::DofObject::id(), mesh, mesh_manager, libMesh::MeshBase::n_local_elem(), libMesh::Elem::n_nodes(), libMesh::MeshBase::node_ref(), num_local_nodes, target_coords, and vertices.

Member Function Documentation

◆ find_sys()

System * libMesh::DTKAdapter::find_sys ( std::string  var_name)
protected

Small helper function for finding the system containing the variable.

Note
This implies that variable names are unique across all systems!

Note that this implies that variable names are unique across all systems!

Definition at line 245 of file dtk_adapter.C.

246{
247 System * sys = nullptr;
248
249 // Find the system this variable is from
250 for (auto i : make_range(es.n_systems()))
251 {
252 if (es.get_system(i).has_variable(var_name))
253 {
254 sys = &es.get_system(i);
255 break;
256 }
257 }
258
259 libmesh_assert(sys);
260
261 return sys;
262}
const T_sys & get_system(std::string_view name) const
libmesh_assert(ctx)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176

References es, libMesh::EquationSystems::get_system(), libMesh::libmesh_assert(), libMesh::make_range(), and libMesh::EquationSystems::n_systems().

Referenced by get_variable_evaluator(), and update_variable_values().

◆ get_element_topology()

DataTransferKit::DTK_ElementTopology libMesh::DTKAdapter::get_element_topology ( const Elem elem)
protected
Returns
The DTK ElementTopology for a given Elem.

Definition at line 265 of file dtk_adapter.C.

266{
267 ElemType type = elem->type();
268
269 if (type == EDGE2)
270 return DataTransferKit::DTK_LINE_SEGMENT;
271 else if (type == TRI3)
272 return DataTransferKit::DTK_TRIANGLE;
273 else if (type == QUAD4)
274 return DataTransferKit::DTK_QUADRILATERAL;
275 else if (type == TET4)
276 return DataTransferKit::DTK_TETRAHEDRON;
277 else if (type == HEX8)
278 return DataTransferKit::DTK_HEXAHEDRON;
279 else if (type == PYRAMID5)
280 return DataTransferKit::DTK_PYRAMID;
281
282 libmesh_error_msg("Element type not supported by DTK!");
283}
ElemType
Defines an enum for geometric element types.

References libMesh::EDGE2, libMesh::HEX8, libMesh::PYRAMID5, libMesh::QUAD4, libMesh::TET4, libMesh::TRI3, and libMesh::Elem::type().

Referenced by DTKAdapter().

◆ get_mesh_manager()

Teuchos::RCP< DataTransferKit::MeshManager< MeshContainerType > > libMesh::DTKAdapter::get_mesh_manager ( )
inline

Definition at line 64 of file dtk_adapter.h.

64{ return mesh_manager; }

References mesh_manager.

Referenced by libMesh::DTKSolutionTransfer::transfer().

◆ get_semi_local_nodes()

void libMesh::DTKAdapter::get_semi_local_nodes ( std::set< unsigned int > &  semi_local_nodes)
protected

Helper function that fills the std::set with all of the node numbers of nodes connected to local elements.

Definition at line 286 of file dtk_adapter.C.

287{
288 for (const auto & elem : as_range(mesh.local_elements_begin(), mesh.local_elements_end()))
289 for (const Node & node : elem->node_ref_range())
290 semi_local_nodes.insert(node.id());
291}

References libMesh::as_range(), and mesh.

Referenced by DTKAdapter().

◆ get_target_coords()

Teuchos::RCP< DataTransferKit::FieldManager< MeshContainerType > > libMesh::DTKAdapter::get_target_coords ( )
inline

Definition at line 66 of file dtk_adapter.h.

66{ return target_coords; }

References target_coords.

Referenced by libMesh::DTKSolutionTransfer::transfer().

◆ get_values_to_fill()

Teuchos::RCP< DataTransferKit::FieldManager< DTKAdapter::FieldContainerType > > libMesh::DTKAdapter::get_values_to_fill ( std::string  var_name)

Definition at line 193 of file dtk_adapter.C.

194{
195 // We try emplacing a nullptr into the "values_to_fill" map.
196 auto [it, emplaced] = values_to_fill.emplace(var_name, nullptr);
197
198 // If the emplace succeeded, that means it was a new entry in the
199 // map, so we need to actually construct the object.
200 if (emplaced)
201 {
202 Teuchos::ArrayRCP<double> data_space(num_local_nodes);
203 Teuchos::RCP<FieldContainerType> field_container = Teuchos::rcp(new FieldContainerType(data_space, 1));
204 it->second = Teuchos::rcp(new DataTransferKit::FieldManager<FieldContainerType>(field_container, comm));
205 }
206
207 return it->second;
208}
std::map< std::string, Teuchos::RCP< DataTransferKit::FieldManager< FieldContainerType > > > values_to_fill
Map of variable names to arrays to be filled by a transfer.
DataTransferKit::FieldContainer< double > FieldContainerType
Definition dtk_adapter.h:58

References comm, num_local_nodes, and values_to_fill.

Referenced by libMesh::DTKSolutionTransfer::transfer().

◆ get_variable_evaluator()

DTKAdapter::RCP_Evaluator libMesh::DTKAdapter::get_variable_evaluator ( std::string  var_name)

Definition at line 176 of file dtk_adapter.C.

177{
178 // We try emplacing a nullptr into the "evaluators" map.
179 auto [it, emplaced] = evaluators.emplace(var_name, nullptr);
180
181 // If the emplace succeeded, that means it was a new entry in the
182 // map, so we need to actually construct the object.
183 if (emplaced)
184 {
185 System * sys = find_sys(var_name);
186 it->second = Teuchos::rcp(new DTKEvaluator(*sys, var_name));
187 }
188
189 return it->second;
190}
std::map< std::string, RCP_Evaluator > evaluators
Map of variable names to RCP_Evaluator objects.
System * find_sys(std::string var_name)
Small helper function for finding the system containing the variable.

References evaluators, and find_sys().

Referenced by libMesh::DTKSolutionTransfer::transfer().

◆ update_variable_values()

void libMesh::DTKAdapter::update_variable_values ( std::string  var_name)

After computing values for a variable in this EquationSystems we need to take those values and put them in the actual solution vector.

Definition at line 211 of file dtk_adapter.C.

212{
213 System * sys = find_sys(var_name);
214 unsigned int var_num = sys->variable_number(var_name);
215
216 Teuchos::RCP<FieldContainerType> values = values_to_fill[var_name]->field();
217
218 unsigned int i=0;
219 // Loop over the values (one for each node) and assign the value of this variable at each node
220 for (const auto & value : *values)
221 {
222 unsigned int node_num = vertices[i];
223 const Node & node = mesh.node_ref(node_num);
224
225 if (node.processor_id() == sys->processor_id())
226 {
227 // The 0 is for the component... this only works for LAGRANGE!
228 dof_id_type dof = node.dof_number(sys->number(), var_num, 0);
229 sys->solution->set(dof, value);
230 }
231
232 i++;
233 }
234
235 sys->solution->close();
236}
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
uint8_t dof_id_type
Definition id_types.h:67
static const bool value
Definition xdr_io.C:55

References libMesh::DofObject::dof_number(), find_sys(), mesh, libMesh::MeshBase::node_ref(), libMesh::System::number(), libMesh::DofObject::processor_id(), libMesh::ParallelObject::processor_id(), libMesh::System::solution, value, values_to_fill, libMesh::System::variable_number(), and vertices.

Referenced by libMesh::DTKSolutionTransfer::transfer().

Member Data Documentation

◆ comm

Teuchos::RCP<const Teuchos::Comm<int> > libMesh::DTKAdapter::comm
protected

Definition at line 94 of file dtk_adapter.h.

Referenced by DTKAdapter(), and get_values_to_fill().

◆ dim

unsigned int libMesh::DTKAdapter::dim
protected

Definition at line 97 of file dtk_adapter.h.

Referenced by DTKAdapter().

◆ es

EquationSystems& libMesh::DTKAdapter::es
protected

Definition at line 95 of file dtk_adapter.h.

Referenced by find_sys().

◆ evaluators

std::map<std::string, RCP_Evaluator> libMesh::DTKAdapter::evaluators
protected

Map of variable names to RCP_Evaluator objects.

Definition at line 110 of file dtk_adapter.h.

Referenced by get_variable_evaluator().

◆ field_evaluator

RCP_Evaluator libMesh::DTKAdapter::field_evaluator
protected

Definition at line 103 of file dtk_adapter.h.

◆ mesh

const MeshBase& libMesh::DTKAdapter::mesh
protected

Definition at line 96 of file dtk_adapter.h.

Referenced by DTKAdapter(), get_semi_local_nodes(), and update_variable_values().

◆ mesh_manager

Teuchos::RCP<DataTransferKit::MeshManager<MeshContainerType> > libMesh::DTKAdapter::mesh_manager
protected

Definition at line 102 of file dtk_adapter.h.

Referenced by DTKAdapter(), and get_mesh_manager().

◆ num_local_nodes

unsigned int libMesh::DTKAdapter::num_local_nodes
protected

Definition at line 99 of file dtk_adapter.h.

Referenced by DTKAdapter(), and get_values_to_fill().

◆ target_coords

Teuchos::RCP<DataTransferKit::FieldManager<MeshContainerType> > libMesh::DTKAdapter::target_coords
protected

Definition at line 104 of file dtk_adapter.h.

Referenced by DTKAdapter(), and get_target_coords().

◆ values_to_fill

std::map<std::string, Teuchos::RCP<DataTransferKit::FieldManager<FieldContainerType> > > libMesh::DTKAdapter::values_to_fill
protected

Map of variable names to arrays to be filled by a transfer.

Definition at line 107 of file dtk_adapter.h.

Referenced by get_values_to_fill(), and update_variable_values().

◆ vertices

Teuchos::ArrayRCP<int> libMesh::DTKAdapter::vertices
protected

Definition at line 100 of file dtk_adapter.h.

Referenced by DTKAdapter(), and update_variable_values().


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