www.mooseframework.org
FlagElementsThread.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 #include "FlagElementsThread.h"
15 
16 // MOOSE includes
17 #include "AuxiliarySystem.h"
18 #include "DisplacedProblem.h"
19 #include "FEProblem.h"
20 #include "Marker.h"
21 #include "MooseVariable.h"
22 #include "Problem.h"
23 
24 #include "libmesh/threads.h"
25 
26 // C++ includes
27 #include <cmath> // provides round, not std::round (see http://www.cplusplus.com/reference/cmath/round/)
28 
30  std::vector<Number> & serialized_solution,
31  unsigned int max_h_level,
32  const std::string & marker_name)
33  : ThreadedElementLoop<ConstElemRange>(fe_problem),
34  _fe_problem(fe_problem),
35  _displaced_problem(_fe_problem.getDisplacedProblem()),
36  _aux_sys(fe_problem.getAuxiliarySystem()),
37  _system_number(_aux_sys.number()),
38  _adaptivity(_fe_problem.adaptivity()),
39  _field_var(_fe_problem.getVariable(0, marker_name)),
40  _field_var_number(_field_var.number()),
41  _serialized_solution(serialized_solution),
42  _max_h_level(max_h_level)
43 {
44 }
45 
46 // Splitting Constructor
48  : ThreadedElementLoop<ConstElemRange>(x, split),
51  _aux_sys(x._aux_sys),
58 {
59 }
60 
61 void
63 {
64  // By default do nothing, and only grab the marker from the solution if the current variable is
65  // active
66  // on the element subdomain.
68  if (_field_var.activeOnSubdomain(elem->subdomain_id()))
69  {
70  dof_id_type dof_number = elem->dof_number(_system_number, _field_var_number, 0);
71 
72  // round() is a C99 function, it is not located in the std:: namespace.
73  marker_value = static_cast<Marker::MarkerValue>(round(_serialized_solution[dof_number]));
74 
75  // Make sure we aren't masking an issue in the Marker system by rounding its values.
76  if (std::abs(marker_value - _serialized_solution[dof_number]) > TOLERANCE * TOLERANCE)
77  mooseError("Invalid Marker value detected: ", _serialized_solution[dof_number]);
78  }
79 
80  // If no Markers cared about what happened to this element let's just leave it alone
81  if (marker_value == Marker::DONT_MARK)
82  marker_value = Marker::DO_NOTHING;
83 
84  // Don't refine past the max level
85  if (_max_h_level && marker_value == Marker::REFINE && elem->level() >= _max_h_level)
86  marker_value = Marker::DO_NOTHING;
87 
88  const_cast<Elem *>(elem)->set_refinement_flag((Elem::RefinementState)marker_value);
89 
91  _displaced_problem->mesh()
92  .elemPtr(elem->id())
93  ->set_refinement_flag((Elem::RefinementState)marker_value);
94 }
95 
96 void
98 {
99 }
FlagElementsThread(FEProblemBase &fe_problem, std::vector< Number > &serialized_solution, unsigned int max_h_level, const std::string &marker_name)
Base class for assembly-like calculations.
FEProblemBase & _fe_problem
unsigned int _max_h_level
unsigned int _system_number
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
MarkerValue
This mirrors the main refinement flag values in libMesh in Elem::RefinementState but adds "dont_mark"...
Definition: Marker.h:58
void join(const FlagElementsThread &)
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
static PetscErrorCode Vec x
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Adaptivity & _adaptivity
bool activeOnSubdomain(SubdomainID subdomain) const
Is the variable active on the subdomain?
std::shared_ptr< DisplacedProblem > _displaced_problem
unsigned int _field_var_number
std::vector< Number > & _serialized_solution
AuxiliarySystem & _aux_sys
MooseVariable & _field_var