www.mooseframework.org
Public Member Functions | Protected Attributes | List of all members
FlagElementsThread Class Reference

#include <FlagElementsThread.h>

Inheritance diagram for FlagElementsThread:
[legend]

Public Member Functions

 FlagElementsThread (FEProblemBase &fe_problem, std::vector< Number > &serialized_solution, unsigned int max_h_level, const std::string &marker_name)
 
 FlagElementsThread (FlagElementsThread &x, Threads::split split)
 
virtual void onElement (const Elem *elem) override
 Assembly of the element (not including surface assembly) More...
 
void join (const FlagElementsThread &)
 
virtual void caughtMooseException (MooseException &e) override
 Called if a MooseException is caught anywhere during the computation. More...
 
virtual bool keepGoing () override
 Whether or not the loop should continue. More...
 
virtual void preElement (const Elem *elem) override
 Called before the element assembly. More...
 
virtual void preInternalSide (const Elem *elem, unsigned int side) override
 Called before evaluations on an element internal side. More...
 
virtual void neighborSubdomainChanged () override
 Called every time the neighbor subdomain changes (i.e. More...
 
void operator() (const ConstElemRange &range, bool bypass_threading=false)
 
virtual void pre ()
 Called before the element range loop. More...
 
virtual void post ()
 Called after the element range loop. More...
 
virtual void postElement (const Elem *elem)
 Called after the element assembly is done (including surface assembling) More...
 
virtual void onBoundary (const Elem *elem, unsigned int side, BoundaryID bnd_id)
 Called when doing boundary assembling. More...
 
virtual void postInternalSide (const Elem *elem, unsigned int side)
 Called after evaluations on an element internal side. More...
 
virtual void onInternalSide (const Elem *elem, unsigned int side)
 Called when doing internal edge assembling. More...
 
virtual void onInterface (const Elem *elem, unsigned int side, BoundaryID bnd_id)
 Called when doing interface assembling. More...
 
virtual void subdomainChanged ()
 Called every time the current subdomain changes (i.e. More...
 

Protected Attributes

FEProblemBase_fe_problem
 
std::shared_ptr< DisplacedProblem_displaced_problem
 
AuxiliarySystem_aux_sys
 
unsigned int _system_number
 
Adaptivity_adaptivity
 
MooseVariableFEBase_field_var
 
unsigned int _field_var_number
 
std::vector< Number > & _serialized_solution
 
unsigned int _max_h_level
 
MooseMesh_mesh
 
THREAD_ID _tid
 
SubdomainID _subdomain
 The subdomain for the current element. More...
 
SubdomainID _old_subdomain
 The subdomain for the last element. More...
 
SubdomainID _neighbor_subdomain
 The subdomain for the current neighbor. More...
 
SubdomainID _old_neighbor_subdomain
 The subdomain for the last neighbor. More...
 

Detailed Description

Definition at line 21 of file FlagElementsThread.h.

Constructor & Destructor Documentation

◆ FlagElementsThread() [1/2]

FlagElementsThread::FlagElementsThread ( FEProblemBase fe_problem,
std::vector< Number > &  serialized_solution,
unsigned int  max_h_level,
const std::string &  marker_name 
)

Definition at line 25 of file FlagElementsThread.C.

30  _fe_problem(fe_problem),
32  _aux_sys(fe_problem.getAuxiliarySystem()),
38  _serialized_solution(serialized_solution),
39  _max_h_level(max_h_level)
40 {
41 }
FEProblemBase & _fe_problem
unsigned int _max_h_level
virtual MooseVariableFEBase & getVariable(THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) override
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
unsigned int _system_number
unsigned int number() const
Get variable number coming from libMesh.
MooseVariableFEBase & _field_var
Adaptivity & _adaptivity
virtual std::shared_ptr< DisplacedProblem > getDisplacedProblem()
virtual unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:894
AuxiliarySystem & getAuxiliarySystem()
std::shared_ptr< DisplacedProblem > _displaced_problem
unsigned int _field_var_number
std::vector< Number > & _serialized_solution
AuxiliarySystem & _aux_sys
Adaptivity & adaptivity()

◆ FlagElementsThread() [2/2]

FlagElementsThread::FlagElementsThread ( FlagElementsThread x,
Threads::split  split 
)

Definition at line 44 of file FlagElementsThread.C.

46  _fe_problem(x._fe_problem),
47  _displaced_problem(x._displaced_problem),
48  _aux_sys(x._aux_sys),
49  _system_number(x._system_number),
50  _adaptivity(x._adaptivity),
51  _field_var(x._field_var),
52  _field_var_number(x._field_var_number),
53  _serialized_solution(x._serialized_solution),
54  _max_h_level(x._max_h_level)
55 {
56 }
FEProblemBase & _fe_problem
unsigned int _max_h_level
unsigned int _system_number
MooseVariableFEBase & _field_var
static PetscErrorCode Vec x
Adaptivity & _adaptivity
std::vector< std::string > split(const std::string &str, const std::string &delimiter)
Python like split function for strings.
Definition: MooseUtils.C:782
std::shared_ptr< DisplacedProblem > _displaced_problem
unsigned int _field_var_number
std::vector< Number > & _serialized_solution
AuxiliarySystem & _aux_sys

Member Function Documentation

◆ caughtMooseException()

void ThreadedElementLoop< ConstElemRange >::caughtMooseException ( MooseException e)
overridevirtualinherited

Called if a MooseException is caught anywhere during the computation.

The single input parameter taken is a MooseException object.

Reimplemented from ThreadedElementLoopBase< ConstElemRange >.

Definition at line 76 of file ThreadedElementLoop.h.

77 {
78  Threads::spin_mutex::scoped_lock lock(threaded_element_mutex);
79 
80  std::string what(e.what());
82 }
virtual const char * what() const
Get out the error message.
virtual void setException(const std::string &message)
Set an exception.
static Threads::spin_mutex threaded_element_mutex
This mutex is used by all derived classes of the ThreadedElementLoop.

◆ join()

void FlagElementsThread::join ( const FlagElementsThread )

Definition at line 94 of file FlagElementsThread.C.

95 {
96 }

◆ keepGoing()

virtual bool ThreadedElementLoop< ConstElemRange >::keepGoing ( )
inlineoverridevirtualinherited

Whether or not the loop should continue.

Returns
true to keep going, false to stop.

Reimplemented from ThreadedElementLoopBase< ConstElemRange >.

Definition at line 44 of file ThreadedElementLoop.h.

44 { return !_fe_problem.hasException(); }
virtual bool hasException()
Whether or not an exception has occurred.

◆ neighborSubdomainChanged()

void ThreadedElementLoop< ConstElemRange >::neighborSubdomainChanged ( )
overridevirtualinherited

Called every time the neighbor subdomain changes (i.e.

the subdomain of this neighbor is not the same as the subdomain of the last neighbor). Beware of over-using this! You might think that you can do some expensive stuff in here and get away with it... but there are applications that have TONS of subdomains....

Reimplemented from ThreadedElementLoopBase< ConstElemRange >.

Definition at line 100 of file ThreadedElementLoop.h.

101 {
104 }
virtual void neighborSubdomainSetup(SubdomainID subdomain, THREAD_ID tid)
Base class for assembly-like calculations.

◆ onBoundary()

void ThreadedElementLoopBase< ConstElemRange >::onBoundary ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id 
)
virtualinherited

Called when doing boundary assembling.

Parameters
elem- The element we are checking is on the boundary.
side- The side of the element in question.
bnd_id- ID of the boundary we are at

Reimplemented in ComputeUserObjectsThread, ComputeMaterialsObjectThread, ComputeResidualThread, ComputeIndicatorThread, ComputeJacobianThread, and ComputeMarkerThread.

Definition at line 283 of file ThreadedElementLoopBase.h.

286 {
287 }

◆ onElement()

void FlagElementsThread::onElement ( const Elem *  elem)
overridevirtual

Assembly of the element (not including surface assembly)

Parameters
elem- active element

Reimplemented from ThreadedElementLoopBase< ConstElemRange >.

Definition at line 59 of file FlagElementsThread.C.

60 {
61  // By default do nothing, and only grab the marker from the solution if the current variable is
62  // active
63  // on the element subdomain.
65  if (_field_var.activeOnSubdomain(elem->subdomain_id()))
66  {
67  dof_id_type dof_number = elem->dof_number(_system_number, _field_var_number, 0);
68 
69  // round() is a C99 function, it is not located in the std:: namespace.
70  marker_value = static_cast<Marker::MarkerValue>(round(_serialized_solution[dof_number]));
71 
72  // Make sure we aren't masking an issue in the Marker system by rounding its values.
73  if (std::abs(marker_value - _serialized_solution[dof_number]) > TOLERANCE * TOLERANCE)
74  mooseError("Invalid Marker value detected: ", _serialized_solution[dof_number]);
75  }
76 
77  // If no Markers cared about what happened to this element let's just leave it alone
78  if (marker_value == Marker::DONT_MARK)
79  marker_value = Marker::DO_NOTHING;
80 
81  // Don't refine past the max level
82  if (_max_h_level && marker_value == Marker::REFINE && elem->level() >= _max_h_level)
83  marker_value = Marker::DO_NOTHING;
84 
85  const_cast<Elem *>(elem)->set_refinement_flag((Elem::RefinementState)marker_value);
86 
88  _displaced_problem->mesh()
89  .elemPtr(elem->id())
90  ->set_refinement_flag((Elem::RefinementState)marker_value);
91 }
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
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:208
unsigned int _system_number
Real round(Real x)
Definition: MathUtils.h:23
MooseVariableFEBase & _field_var
virtual bool activeOnSubdomain(SubdomainID subdomain) const =0
Is the variable active on the subdomain?
MarkerValue
This mirrors the main refinement flag values in libMesh in Elem::RefinementState but adds "dont_mark"...
Definition: Marker.h:56
std::shared_ptr< DisplacedProblem > _displaced_problem
unsigned int _field_var_number
std::vector< Number > & _serialized_solution

◆ onInterface()

void ThreadedElementLoopBase< ConstElemRange >::onInterface ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id 
)
virtualinherited

Called when doing interface assembling.

Parameters
elem- Element we are on
side- local side number of the element 'elem'
bnd_id- ID of the interface we are at

Reimplemented in ComputeResidualThread, and ComputeJacobianThread.

Definition at line 309 of file ThreadedElementLoopBase.h.

312 {
313 }

◆ onInternalSide()

void ThreadedElementLoopBase< ConstElemRange >::onInternalSide ( const Elem *  elem,
unsigned int  side 
)
virtualinherited

Called when doing internal edge assembling.

Parameters
elem- Element we are on
side- local side number of the element 'elem'

Reimplemented in ComputeUserObjectsThread, ComputeMaterialsObjectThread, ComputeResidualThread, ComputeIndicatorThread, ComputeJacobianThread, and ComputeMarkerThread.

Definition at line 303 of file ThreadedElementLoopBase.h.

304 {
305 }

◆ operator()()

void ThreadedElementLoopBase< ConstElemRange >::operator() ( const ConstElemRange &  range,
bool  bypass_threading = false 
)
inherited

Definition at line 173 of file ThreadedElementLoopBase.h.

174 {
175  try
176  {
177  try
178  {
179  ParallelUniqueId puid;
180  _tid = bypass_threading ? 0 : puid.id;
181 
182  pre();
183 
186  typename RangeType::const_iterator el = range.begin();
187  for (el = range.begin(); el != range.end(); ++el)
188  {
189  if (!keepGoing())
190  break;
191 
192  const Elem * elem = *el;
193 
194  preElement(elem);
195 
197  _subdomain = elem->subdomain_id();
198  if (_subdomain != _old_subdomain)
200 
201  onElement(elem);
202 
203  for (unsigned int side = 0; side < elem->n_sides(); side++)
204  {
205  std::vector<BoundaryID> boundary_ids = _mesh.getBoundaryIDs(elem, side);
206 
207  if (boundary_ids.size() > 0)
208  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
209  it != boundary_ids.end();
210  ++it)
211  onBoundary(elem, side, *it);
212 
213  const Elem * neighbor = elem->neighbor_ptr(side);
214  if (neighbor != nullptr)
215  {
216  preInternalSide(elem, side);
217 
219  _neighbor_subdomain = neighbor->subdomain_id();
222 
223  onInternalSide(elem, side);
224 
225  if (boundary_ids.size() > 0)
226  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
227  it != boundary_ids.end();
228  ++it)
229  onInterface(elem, side, *it);
230 
231  postInternalSide(elem, side);
232  }
233  } // sides
234  postElement(elem);
235 
236  } // range
237 
238  post();
239  }
240  catch (libMesh::LogicError & e)
241  {
242  throw MooseException("We caught a libMesh error");
243  }
244  }
245  catch (MooseException & e)
246  {
248  }
249 }
virtual bool keepGoing()
Whether or not the loop should continue.
virtual void onElement(const Elem *elem)
Assembly of the element (not including surface assembly)
virtual void pre()
Called before the element range loop.
virtual void subdomainChanged()
Called every time the current subdomain changes (i.e.
virtual void neighborSubdomainChanged()
Called every time the neighbor subdomain changes (i.e.
virtual void preInternalSide(const Elem *elem, unsigned int side)
Called before evaluations on an element internal side.
virtual void postInternalSide(const Elem *elem, unsigned int side)
Called after evaluations on an element internal side.
const SubdomainID INVALID_BLOCK_ID
Definition: MooseTypes.C:16
virtual void postElement(const Elem *elem)
Called after the element assembly is done (including surface assembling)
virtual void onInterface(const Elem *elem, unsigned int side, BoundaryID bnd_id)
Called when doing interface assembling.
SubdomainID _old_neighbor_subdomain
The subdomain for the last neighbor.
virtual void onInternalSide(const Elem *elem, unsigned int side)
Called when doing internal edge assembling.
Provides a way for users to bail out of the current solve.
virtual void caughtMooseException(MooseException &)
Called if a MooseException is caught anywhere during the computation.
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
Definition: MooseMesh.C:2148
SubdomainID _subdomain
The subdomain for the current element.
SubdomainID _old_subdomain
The subdomain for the last element.
virtual void post()
Called after the element range loop.
virtual void preElement(const Elem *elem)
Called before the element assembly.
SubdomainID _neighbor_subdomain
The subdomain for the current neighbor.
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id)
Called when doing boundary assembling.

◆ post()

void ThreadedElementLoopBase< ConstElemRange >::post ( )
virtualinherited

◆ postElement()

void ThreadedElementLoopBase< ConstElemRange >::postElement ( const Elem *  elem)
virtualinherited

Called after the element assembly is done (including surface assembling)

Parameters
elem- active element

Reimplemented in ComputeJacobianBlocksThread, ComputeResidualThread, ComputeIndicatorThread, ComputeJacobianThread, and ComputeMarkerThread.

Definition at line 277 of file ThreadedElementLoopBase.h.

278 {
279 }

◆ postInternalSide()

void ThreadedElementLoopBase< ConstElemRange >::postInternalSide ( const Elem *  elem,
unsigned int  side 
)
virtualinherited

Called after evaluations on an element internal side.

Parameters
elem- Element we are on
side- local side number of the element 'elem'

Definition at line 297 of file ThreadedElementLoopBase.h.

298 {
299 }

◆ pre()

void ThreadedElementLoopBase< ConstElemRange >::pre ( )
virtualinherited

Called before the element range loop.

Definition at line 253 of file ThreadedElementLoopBase.h.

254 {
255 }

◆ preElement()

void ThreadedElementLoop< ConstElemRange >::preElement ( const Elem *  elem)
overridevirtualinherited

Called before the element assembly.

Parameters
elem- active element

Reimplemented from ThreadedElementLoopBase< ConstElemRange >.

Definition at line 86 of file ThreadedElementLoop.h.

87 {
89 }
virtual void setCurrentSubdomainID(const Elem *elem, THREAD_ID tid) override
Base class for assembly-like calculations.

◆ preInternalSide()

void ThreadedElementLoop< ConstElemRange >::preInternalSide ( const Elem *  elem,
unsigned int  side 
)
overridevirtualinherited

Called before evaluations on an element internal side.

Parameters
elem- Element we are on
side- local side number of the element 'elem'

Reimplemented from ThreadedElementLoopBase< ConstElemRange >.

Definition at line 93 of file ThreadedElementLoop.h.

94 {
96 }
Base class for assembly-like calculations.
virtual void setNeighborSubdomainID(const Elem *elem, unsigned int side, THREAD_ID tid) override

◆ subdomainChanged()

void ThreadedElementLoopBase< ConstElemRange >::subdomainChanged ( )
virtualinherited

Called every time the current subdomain changes (i.e.

the subdomain of this element is not the same as the subdomain of the last element). Beware of over-using this! You might think that you can do some expensive stuff in here and get away with it... but there are applications that have TONS of subdomains....

Reimplemented in ComputeUserObjectsThread, ComputeMaterialsObjectThread, ComputeResidualThread, ComputeIndicatorThread, ComputeJacobianThread, ComputeElemAuxVarsThread, and ComputeMarkerThread.

Definition at line 317 of file ThreadedElementLoopBase.h.

318 {
319 }

Member Data Documentation

◆ _adaptivity

Adaptivity& FlagElementsThread::_adaptivity
protected

Definition at line 41 of file FlagElementsThread.h.

◆ _aux_sys

AuxiliarySystem& FlagElementsThread::_aux_sys
protected

Definition at line 39 of file FlagElementsThread.h.

◆ _displaced_problem

std::shared_ptr<DisplacedProblem> FlagElementsThread::_displaced_problem
protected

Definition at line 38 of file FlagElementsThread.h.

Referenced by onElement().

◆ _fe_problem

FEProblemBase& FlagElementsThread::_fe_problem
protected

Definition at line 37 of file FlagElementsThread.h.

◆ _field_var

MooseVariableFEBase& FlagElementsThread::_field_var
protected

Definition at line 42 of file FlagElementsThread.h.

Referenced by onElement().

◆ _field_var_number

unsigned int FlagElementsThread::_field_var_number
protected

Definition at line 43 of file FlagElementsThread.h.

Referenced by onElement().

◆ _max_h_level

unsigned int FlagElementsThread::_max_h_level
protected

Definition at line 45 of file FlagElementsThread.h.

Referenced by onElement().

◆ _mesh

MooseMesh& ThreadedElementLoopBase< ConstElemRange >::_mesh
protectedinherited

Definition at line 138 of file ThreadedElementLoopBase.h.

◆ _neighbor_subdomain

SubdomainID ThreadedElementLoopBase< ConstElemRange >::_neighbor_subdomain
protectedinherited

The subdomain for the current neighbor.

Definition at line 148 of file ThreadedElementLoopBase.h.

◆ _old_neighbor_subdomain

SubdomainID ThreadedElementLoopBase< ConstElemRange >::_old_neighbor_subdomain
protectedinherited

The subdomain for the last neighbor.

Definition at line 151 of file ThreadedElementLoopBase.h.

◆ _old_subdomain

SubdomainID ThreadedElementLoopBase< ConstElemRange >::_old_subdomain
protectedinherited

The subdomain for the last element.

Definition at line 145 of file ThreadedElementLoopBase.h.

◆ _serialized_solution

std::vector<Number>& FlagElementsThread::_serialized_solution
protected

Definition at line 44 of file FlagElementsThread.h.

Referenced by onElement().

◆ _subdomain

SubdomainID ThreadedElementLoopBase< ConstElemRange >::_subdomain
protectedinherited

◆ _system_number

unsigned int FlagElementsThread::_system_number
protected

Definition at line 40 of file FlagElementsThread.h.

Referenced by onElement().

◆ _tid

THREAD_ID ThreadedElementLoopBase< ConstElemRange >::_tid
protectedinherited

Definition at line 139 of file ThreadedElementLoopBase.h.

Referenced by ComputeFullJacobianThread::computeFaceJacobian(), ComputeJacobianThread::computeFaceJacobian(), ComputeFullJacobianThread::computeInternalFaceJacobian(), ComputeJacobianThread::computeInternalFaceJacobian(), ComputeFullJacobianThread::computeInternalInterFaceJacobian(), ComputeJacobianThread::computeInternalInterFaceJacobian(), ComputeFullJacobianThread::computeJacobian(), ComputeJacobianThread::computeJacobian(), ComputeJacobianThread::onBoundary(), ComputeResidualThread::onBoundary(), ComputeMaterialsObjectThread::onBoundary(), ComputeUserObjectsThread::onBoundary(), ComputeMarkerThread::onElement(), ComputeElemDampingThread::onElement(), ComputeElemAuxVarsThread::onElement(), ComputeJacobianThread::onElement(), ComputeIndicatorThread::onElement(), ComputeResidualThread::onElement(), ComputeMaterialsObjectThread::onElement(), ComputeUserObjectsThread::onElement(), ComputeJacobianThread::onInterface(), ComputeResidualThread::onInterface(), ComputeJacobianThread::onInternalSide(), ComputeIndicatorThread::onInternalSide(), ComputeResidualThread::onInternalSide(), ComputeMaterialsObjectThread::onInternalSide(), ComputeUserObjectsThread::onInternalSide(), ComputeMarkerThread::post(), ComputeElemAuxVarsThread::post(), ComputeMaterialsObjectThread::post(), ComputeIndicatorThread::post(), ComputeJacobianThread::post(), ComputeResidualThread::post(), ComputeUserObjectsThread::post(), ComputeJacobianThread::postElement(), ComputeResidualThread::postElement(), ComputeJacobianBlocksThread::postElement(), ComputeUserObjectsThread::queryBoundary(), ComputeUserObjectsThread::querySubdomain(), ComputeMarkerThread::subdomainChanged(), ComputeElemAuxVarsThread::subdomainChanged(), ComputeJacobianThread::subdomainChanged(), ComputeIndicatorThread::subdomainChanged(), ComputeResidualThread::subdomainChanged(), ComputeMaterialsObjectThread::subdomainChanged(), and ComputeUserObjectsThread::subdomainChanged().


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