https://mooseframework.inl.gov
FlagElementsThread.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "FlagElementsThread.h"
11 
12 // MOOSE includes
13 #include "AuxiliarySystem.h"
14 #include "DisplacedProblem.h"
15 #include "FEProblem.h"
16 #include "Marker.h"
17 #include "MooseVariableFE.h"
18 #include "Problem.h"
19 
20 #include "libmesh/threads.h"
21 
22 // C++ includes
23 #include <cmath> // provides round, not std::round (see http://www.cplusplus.com/reference/cmath/round/)
24 
26  std::vector<Number> & serialized_solution,
27  unsigned int max_h_level,
28  const std::string & marker_name,
29  bool is_serialized_solution)
30  : ThreadedElementLoop<ConstElemRange>(fe_problem),
31  _fe_problem(fe_problem),
32  _displaced_problem(_fe_problem.getDisplacedProblem()),
33  _aux_sys(fe_problem.getAuxiliarySystem()),
34  _system_number(_aux_sys.number()),
35  _adaptivity(_fe_problem.adaptivity()),
36  _field_var(_fe_problem.getVariable(
38  _field_var_number(_field_var.number()),
39  _serialized_solution(serialized_solution),
40  _max_h_level(max_h_level),
41  _is_serialized_solution(is_serialized_solution)
42 {
43 }
44 
45 // Splitting Constructor
48  _fe_problem(x._fe_problem),
49  _displaced_problem(x._displaced_problem),
50  _aux_sys(x._aux_sys),
51  _system_number(x._system_number),
52  _adaptivity(x._adaptivity),
53  _field_var(x._field_var),
54  _field_var_number(x._field_var_number),
55  _serialized_solution(x._serialized_solution),
56  _max_h_level(x._max_h_level),
57  _is_serialized_solution(x._is_serialized_solution)
58 {
59 }
60 
61 void
63 {
64  mooseAssert(elem->active(), "This thread should only act on active elements");
65 
66  // By default do nothing, and only grab the marker from the solution if the current variable is
67  // active
68  // on the element subdomain.
70  if (_field_var.activeOnSubdomain(elem->subdomain_id()))
71  {
72  dof_id_type dof_number = elem->dof_number(_system_number, _field_var_number, 0);
73 
74  Number dof_value = 0.;
75  // If solution is serialized in the caller,
76  // we use the serialized solution
78  dof_value = _serialized_solution[dof_number];
79  else // Otherwise, we look at the ghosted local solution
80  {
81  // Local ghosted solution
82  auto & current_local_solution = *_aux_sys.currentSolution();
83  // Libesh will convert a global dof number to a local one,
84  // then return the corresponding entry value
85  dof_value = current_local_solution(dof_number);
86  }
87 
88  // round() is a C99 function, it is not located in the std:: namespace.
89  marker_value = static_cast<Marker::MarkerValue>(round(dof_value));
90 
91  // Make sure we aren't masking an issue in the Marker system by rounding its values.
92  if (std::abs(marker_value - dof_value) > TOLERANCE * TOLERANCE)
93  mooseError("Invalid Marker value detected: ", dof_value);
94  }
95 
96  // If no Markers cared about what happened to this element let's just leave it alone
97  if (marker_value == Marker::DONT_MARK)
98  marker_value = Marker::DO_NOTHING;
99 
100  // Don't refine past the max level
101  if (_max_h_level && marker_value == Marker::REFINE && elem->level() >= _max_h_level)
102  marker_value = Marker::DO_NOTHING;
103 
104  const_cast<Elem *>(elem)->set_refinement_flag((Elem::RefinementState)marker_value);
105 
106  if (_displaced_problem)
107  _displaced_problem->mesh()
108  .elemPtr(elem->id())
109  ->set_refinement_flag((Elem::RefinementState)marker_value);
110 }
111 
112 void
114 {
115 }
VarFieldType
Definition: MooseTypes.h:721
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: EigenADReal.h:42
Base class for assembly-like calculations.
unsigned int _max_h_level
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
unsigned int _system_number
MooseVariableFEBase & _field_var
const NumericVector< Number > *const & currentSolution() const override
The solution vector that is currently being operated on.
MarkerValue
This mirrors the main refinement flag values in libMesh in Elem::RefinementState but adds "dont_mark"...
Definition: Marker.h:59
void join(const FlagElementsThread &)
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
T round(T x)
Definition: MathUtils.h:77
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:714
FlagElementsThread(FEProblemBase &fe_problem, std::vector< Number > &serialized_solution, unsigned int max_h_level, const std::string &marker_name, bool is_serialized_solution)
tbb::split split
std::shared_ptr< DisplacedProblem > _displaced_problem
unsigned int _field_var_number
std::vector< Number > & _serialized_solution
AuxiliarySystem & _aux_sys
bool activeOnSubdomain(SubdomainID subdomain) const
Is the variable active on the subdomain?
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
Real Number
uint8_t dof_id_type