www.mooseframework.org
SlopeReconstructionBase.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
9 
10 // Static mutex definition
11 Threads::spin_mutex SlopeReconstructionBase::_mutex;
12 
13 template <>
14 InputParameters
16 {
17  InputParameters params = validParams<ElementLoopUserObject>();
18  params.addClassDescription("Base class for piecewise linear slope reconstruction to get the "
19  "slopes of element average variables.");
20  return params;
21 }
22 
23 SlopeReconstructionBase::SlopeReconstructionBase(const InputParameters & parameters)
24  : ElementLoopUserObject(parameters),
25  _q_point_face(_assembly.qPointsFace()),
26  _qrule_face(_assembly.qRuleFace()),
27  _JxW_face(_assembly.JxWFace()),
28  _normals_face(_assembly.normals()),
29  _side(_assembly.side()),
30  _side_elem(_assembly.sideElem()),
31  _side_volume(_assembly.sideElemVolume()),
32  _neighbor_elem(_assembly.neighbor()),
33  _side_geoinfo_cached(false)
34 {
35 }
36 
37 void
39 {
41 
42  _rslope.clear();
43  _avars.clear();
44 }
45 
46 void
48 {
50 
51  if (_app.n_processors() > 1)
52  {
53  _side_geoinfo_cached = true;
54 
55  std::vector<std::string> send_buffers(1);
56  std::vector<std::string> recv_buffers;
57 
58  recv_buffers.reserve(_app.n_processors());
59  serialize(send_buffers[0]);
60  comm().allgather_packed_range((void *)(nullptr),
61  send_buffers.begin(),
62  send_buffers.end(),
63  std::back_inserter(recv_buffers));
64  deserialize(recv_buffers);
65  }
66 }
67 
68 void
70 {
72 
73  _side_geoinfo_cached = false;
74  _side_centroid.clear();
75  _bnd_side_centroid.clear();
76  _side_normal.clear();
77  _bnd_side_normal.clear();
78  _side_area.clear();
79  _bnd_side_area.clear();
80 }
81 
82 const std::vector<RealGradient> &
83 SlopeReconstructionBase::getElementSlope(dof_id_type elementid) const
84 {
85  Threads::spin_mutex::scoped_lock lock(_mutex);
86  std::map<dof_id_type, std::vector<RealGradient>>::const_iterator pos = _rslope.find(elementid);
87 
88  if (pos == _rslope.end())
89  mooseError(
90  "Reconstructed slope is not cached for element id '", elementid, "' in ", __FUNCTION__);
91 
92  return pos->second;
93 }
94 
95 const std::vector<Real> &
97 {
98  Threads::spin_mutex::scoped_lock lock(_mutex);
99  std::map<dof_id_type, std::vector<Real>>::const_iterator pos = _avars.find(elementid);
100 
101  if (pos == _avars.end())
102  mooseError("Average variable values are not cached for element id '",
103  elementid,
104  "' in ",
105  __FUNCTION__);
106 
107  return pos->second;
108 }
109 
110 const std::vector<Real> &
111 SlopeReconstructionBase::getBoundaryAverageValue(dof_id_type elementid, unsigned int side) const
112 {
113  Threads::spin_mutex::scoped_lock lock(_mutex);
114  std::map<std::pair<dof_id_type, unsigned int>, std::vector<Real>>::const_iterator pos =
115  _bnd_avars.find(std::pair<dof_id_type, unsigned int>(elementid, side));
116 
117  if (pos == _bnd_avars.end())
118  mooseError("Average variable values are not cached for element id '",
119  elementid,
120  "' and side '",
121  side,
122  "' in ",
123  __FUNCTION__);
124 
125  return pos->second;
126 }
127 
128 const Point &
129 SlopeReconstructionBase::getSideCentroid(dof_id_type elementid, dof_id_type neighborid) const
130 {
131  Threads::spin_mutex::scoped_lock lock(_mutex);
132  std::map<std::pair<dof_id_type, dof_id_type>, Point>::const_iterator pos =
133  _side_centroid.find(std::pair<dof_id_type, dof_id_type>(elementid, neighborid));
134 
135  if (pos == _side_centroid.end())
136  mooseError("Side centroid values are not cached for element id '",
137  elementid,
138  "' and neighbor id '",
139  neighborid,
140  "' in ",
141  __FUNCTION__);
142 
143  return pos->second;
144 }
145 
146 const Point &
147 SlopeReconstructionBase::getBoundarySideCentroid(dof_id_type elementid, unsigned int side) const
148 {
149  Threads::spin_mutex::scoped_lock lock(_mutex);
150  std::map<std::pair<dof_id_type, unsigned int>, Point>::const_iterator pos =
151  _bnd_side_centroid.find(std::pair<dof_id_type, unsigned int>(elementid, side));
152 
153  if (pos == _bnd_side_centroid.end())
154  mooseError("Boundary side centroid values are not cached for element id '",
155  elementid,
156  "' and side '",
157  side,
158  "' in ",
159  __FUNCTION__);
160 
161  return pos->second;
162 }
163 
164 const Point &
165 SlopeReconstructionBase::getSideNormal(dof_id_type elementid, dof_id_type neighborid) const
166 {
167  Threads::spin_mutex::scoped_lock lock(_mutex);
168  std::map<std::pair<dof_id_type, dof_id_type>, Point>::const_iterator pos =
169  _side_normal.find(std::pair<dof_id_type, dof_id_type>(elementid, neighborid));
170 
171  if (pos == _side_normal.end())
172  mooseError("Side normal values are not cached for element id '",
173  elementid,
174  "' and neighbor id '",
175  neighborid,
176  "' in ",
177  __FUNCTION__);
178 
179  return pos->second;
180 }
181 
182 const Point &
183 SlopeReconstructionBase::getBoundarySideNormal(dof_id_type elementid, unsigned int side) const
184 {
185  Threads::spin_mutex::scoped_lock lock(_mutex);
186  std::map<std::pair<dof_id_type, unsigned int>, Point>::const_iterator pos =
187  _bnd_side_normal.find(std::pair<dof_id_type, unsigned int>(elementid, side));
188 
189  if (pos == _bnd_side_normal.end())
190  mooseError("Boundary side normal values are not cached for element id '",
191  elementid,
192  "' and side '",
193  side,
194  "' in ",
195  __FUNCTION__);
196 
197  return pos->second;
198 }
199 
200 const Real &
201 SlopeReconstructionBase::getSideArea(dof_id_type elementid, dof_id_type neighborid) const
202 {
203  Threads::spin_mutex::scoped_lock lock(_mutex);
204  std::map<std::pair<dof_id_type, dof_id_type>, Real>::const_iterator pos =
205  _side_area.find(std::pair<dof_id_type, dof_id_type>(elementid, neighborid));
206 
207  if (pos == _side_area.end())
208  mooseError("Side area values are not cached for element id '",
209  elementid,
210  "' and neighbor id '",
211  neighborid,
212  "' in ",
213  __FUNCTION__);
214 
215  return pos->second;
216 }
217 
218 const Real &
219 SlopeReconstructionBase::getBoundarySideArea(dof_id_type elementid, unsigned int side) const
220 {
221  Threads::spin_mutex::scoped_lock lock(_mutex);
222  std::map<std::pair<dof_id_type, unsigned int>, Real>::const_iterator pos =
223  _bnd_side_area.find(std::pair<dof_id_type, unsigned int>(elementid, side));
224 
225  if (pos == _bnd_side_area.end())
226  mooseError("Boundary side area values are not cached for element id '",
227  elementid,
228  "' and side '",
229  side,
230  "' in ",
231  __FUNCTION__);
232 
233  return pos->second;
234 }
235 
236 void
238 {
240 }
241 
242 void
243 SlopeReconstructionBase::serialize(std::string & serialized_buffer)
244 {
245  std::ostringstream oss;
246 
247  // First store the number of elements to send
248  unsigned int size = _interface_elem_ids.size();
249  oss.write((char *)&size, sizeof(size));
250 
251  for (auto it = _interface_elem_ids.begin(); it != _interface_elem_ids.end(); ++it)
252  {
253  storeHelper(oss, *it, this);
254  storeHelper(oss, _rslope[*it], this);
255  }
256 
257  // Populate the passed in string pointer with the string stream's buffer contents
258  serialized_buffer.assign(oss.str());
259 }
260 
261 void
262 SlopeReconstructionBase::deserialize(std::vector<std::string> & serialized_buffers)
263 {
264  // The input string stream used for deserialization
265  std::istringstream iss;
266 
267  mooseAssert(serialized_buffers.size() == _app.n_processors(),
268  "Unexpected size of serialized_buffers: " << serialized_buffers.size());
269 
270  for (auto rank = decltype(_app.n_processors())(0); rank < serialized_buffers.size(); ++rank)
271  {
272  if (rank == processor_id())
273  continue;
274 
275  iss.str(serialized_buffers[rank]); // populate the stream with a new buffer
276  iss.clear(); // reset the string stream state
277 
278  // Load the communicated data into all of the other processors' slots
279 
280  unsigned int size = 0;
281  iss.read((char *)&size, sizeof(size));
282 
283  for (unsigned int i = 0; i < size; i++)
284  {
285  dof_id_type key;
286  loadHelper(iss, key, this);
287 
288  std::vector<RealGradient> value;
289  loadHelper(iss, value, this);
290 
291  // merge the data we received from other procs
292  _rslope.insert(std::pair<dof_id_type, std::vector<RealGradient>>(key, value));
293  }
294  }
295 }
virtual void serialize(std::string &serialized_buffer)
A base class that loops over elements and do things.
std::map< std::pair< dof_id_type, dof_id_type >, Real > _side_area
store the side area into this map indexed by pair of element ID and neighbor ID
virtual const std::vector< RealGradient > & getElementSlope(dof_id_type elementid) const
accessor function call to get element slope values
virtual void reconstructElementSlope()=0
compute the slope of the cell
std::map< dof_id_type, std::vector< Real > > _avars
store the average variable values into this map indexed by element ID
virtual const Point & getSideCentroid(dof_id_type elementid, dof_id_type neighborid) const
accessor function call to get cached internal side centroid
InputParameters validParams< ElementLoopUserObject >()
static Threads::spin_mutex _mutex
virtual void deserialize(std::vector< std::string > &serialized_buffers)
virtual const Real & getBoundarySideArea(dof_id_type elementid, unsigned int side) const
accessor function call to get cached boundary side area
std::map< std::pair< dof_id_type, dof_id_type >, Point > _side_normal
store the side normal into this map indexed by pair of element ID and neighbor ID ...
std::map< dof_id_type, std::vector< RealGradient > > _rslope
store the reconstructed slopes into this map indexed by element ID
SlopeReconstructionBase(const InputParameters &parameters)
std::map< std::pair< dof_id_type, unsigned int >, Point > _bnd_side_normal
store the boundary side normal into this map indexed by pair of element ID and local side ID ...
virtual const Point & getBoundarySideNormal(dof_id_type elementid, unsigned int side) const
accessor function call to get cached boundary side centroid
std::set< dof_id_type > _interface_elem_ids
List of element IDs that are on the processor boundary and need to be send to other processors...
std::map< std::pair< dof_id_type, dof_id_type >, Point > _side_centroid
store the side centroid into this map indexed by pair of element ID and neighbor ID ...
std::map< std::pair< dof_id_type, unsigned int >, Point > _bnd_side_centroid
store the boundary side centroid into this map indexed by pair of element ID and local side ID ...
std::map< std::pair< dof_id_type, unsigned int >, Real > _bnd_side_area
store the boundary side area into this map indexed by pair of element ID and local side ID ...
virtual const Point & getBoundarySideCentroid(dof_id_type elementid, unsigned int side) const
accessor function call to get cached boundary side centroid
InputParameters validParams< SlopeReconstructionBase >()
virtual const std::vector< Real > & getElementAverageValue(dof_id_type elementid) const
accessor function call to get element average variable values
virtual const Point & getSideNormal(dof_id_type elementid, dof_id_type neighborid) const
accessor function call to get cached internal side normal
virtual const std::vector< Real > & getBoundaryAverageValue(dof_id_type elementid, unsigned int side) const
accessor function call to get boundary average variable values
bool _side_geoinfo_cached
flag to indicated if side geometry info is cached
virtual const Real & getSideArea(dof_id_type elementid, dof_id_type neighborid) const
accessor function call to get cached internal side area
std::map< std::pair< dof_id_type, unsigned int >, std::vector< Real > > _bnd_avars
store the boundary average variable values into this map indexed by pair of element ID and local side...