node.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 // C++ includes
21 #include <sstream>
22 
23 // Local includes
24 #include "libmesh/node.h"
25 
26 namespace libMesh
27 {
28 
29 
30 
31 
32 // ------------------------------------------------------------
33 // Node class static member initialization
34 //const unsigned int Node::invalid_id = libMesh::invalid_uint;
35 
36 
37 bool Node::operator==(const Node& rhs) const
38 {
39  // Explicitly calling the operator== defined in Point
40  return this->Point::operator==(rhs);
41 }
42 
43 
44 
45 void Node::print_info (std::ostream& os) const
46 {
47  os << this->get_info()
48  << std::endl;
49 }
50 
51 
52 
53 std::string Node::get_info () const
54 {
55  std::ostringstream oss;
56 
57  oss << " Node id()=";
58 
59  if (this->valid_id())
60  oss << this->id();
61  else
62  oss << "invalid";
63 
64  oss << ", processor_id()=" << this->processor_id() <<
65  ", Point=" << *static_cast<const Point*>(this) << '\n';
66 
67  oss << " DoFs=";
68  for (unsigned int s=0; s != this->n_systems(); ++s)
69  for (unsigned int v=0; v != this->n_vars(s); ++v)
70  for (unsigned int c=0; c != this->n_comp(s,v); ++c)
71  oss << '(' << s << '/' << v << '/' << this->dof_number(s,v,c) << ") ";
72 
73  return oss.str();
74 }
75 
76 
77 
78 #ifdef LIBMESH_HAVE_MPI
80 {
81  MPI_Datatype packed_node_type;
82  MPI_Datatype types[] = { MPI_UNSIGNED, MPI_REAL };
83  int blocklengths[] = { 2, 3 };
84  MPI_Aint displs[2];
85 
86  // create a Packed node and get the addresses of the elements.
87  // this will properly handle id/pid getting padded, for example,
88  // in which case id and x may not be 2*sizeof(unsigned int) apart.
90 
91 #if MPI_VERSION > 1
92  MPI_Get_address (&pn.id, &displs[0]);
93  MPI_Get_address (&pn.x, &displs[1]);
94 #else
95  MPI_Address (&pn.id, &displs[0]);
96  MPI_Address (&pn.x, &displs[1]);
97 #endif // #if MPI_VERSION > 1
98 
99  displs[1] -= displs[0];
100  displs[0] = 0;
101 
102 #if MPI_VERSION > 1
103  MPI_Type_create_struct (2, blocklengths, displs, types, &packed_node_type);
104 #else
105  MPI_Type_struct (2, blocklengths, displs, types, &packed_node_type);
106 #endif // #if MPI_VERSION > 1
107 
108  return packed_node_type;
109 }
110 
111 
112 void Node::PackedNode::pack (std::vector<largest_id_type> &conn, const Node* node)
113 {
114  libmesh_assert(node);
115 
116  conn.reserve (conn.size() + node->packed_size());
117 
118  conn.push_back (static_cast<largest_id_type>(node->processor_id()));
119  conn.push_back (static_cast<largest_id_type>(node->id()));
120 
121  // use "(a+b-1)/b" trick to get a/b to round up
122  static const unsigned int idtypes_per_Real =
123  (sizeof(Real) + sizeof(largest_id_type) - 1) / sizeof(largest_id_type);
124 
125  for (unsigned int i=0; i != LIBMESH_DIM; ++i)
126  {
127  const largest_id_type* Real_as_idtypes = reinterpret_cast<const largest_id_type*>(&((*node)(i)));
128  for (unsigned int j=0; j != idtypes_per_Real; ++j)
129  {
130  conn.push_back(Real_as_idtypes[j]);
131  }
132  }
133 
134  node->pack_indexing(std::back_inserter(conn));
135 }
136 
137 
138 void Node::PackedNode::unpack (std::vector<largest_id_type>::const_iterator start, Node& node)
139 {
140  processor_id_type processor_id = static_cast<processor_id_type>(*start++);
142  processor_id < libMesh::n_processors());
143 
144  dof_id_type id = static_cast<dof_id_type>(*start++);
145 
146  // use "(a+b-1)/b" trick to get a/b to round up
147  static const unsigned int idtypes_per_Real =
148  (sizeof(Real) + sizeof(largest_id_type) - 1) / sizeof(largest_id_type);
149 
150  std::vector<Real> xyz(3,0.);
151 
152  for (unsigned int i=0; i != LIBMESH_DIM; ++i)
153  {
154  const Real* ints_as_Real = reinterpret_cast<const Real*>(&(*start));
155  node(i) = *ints_as_Real;
156  start += idtypes_per_Real;
157  }
158 
159  node.set_id() = id;
160  node.processor_id() = processor_id;
161 
162  node.unpack_indexing(start);
163 }
164 
165 #endif // #ifdef LIBMESH_HAVE_MPI
166 
167 } // namespace libMesh

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo