https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ComputeNodalKernelJacobiansThread Class Reference

#include <ComputeNodalKernelJacobiansThread.h>

Inheritance diagram for ComputeNodalKernelJacobiansThread:
[legend]

Public Member Functions

 ComputeNodalKernelJacobiansThread (FEProblemBase &fe_problem, NonlinearSystemBase &nl, MooseObjectTagWarehouse< NodalKernelBase > &nodal_kernels, const std::set< TagID > &tags)
 
 ComputeNodalKernelJacobiansThread (ComputeNodalKernelJacobiansThread &x, Threads::split split)
 
virtual void pre () override
 Called before the node range loop.
 
virtual void onNode (ConstNodeRange::const_iterator &node_it) override
 
void join (const ComputeNodalKernelJacobiansThread &)
 
void operator() (const ConstNodeRange &range)
 
virtual void post ()
 Called after the node range loop.
 
virtual void onNode (ConstNodeRange::const_iterator &node_it)
 Called for each node.
 
virtual void postNode (ConstNodeRange::const_iterator &node_it)
 Called after the node assembly is done (including surface assembling)
 
virtual void caughtMooseException (MooseException &e)
 Called if a MooseException is caught anywhere during the computation.
 
virtual bool keepGoing ()
 Whether or not the loop should continue.
 

Protected Member Functions

void printGeneralExecutionInformation () const override
 Print information about the loop, mostly order of execution of objects.
 
void printExecutionOrdering (const std::vector< T * > &objs, const bool print_header=true, const std::string &line_prefix="[DBG]") const
 Routine to output the ordering of objects within a vector of pointers to these objects.
 

Protected Attributes

FEProblemBase & _fe_problem
 
NonlinearSystemBase & _nl
 
AuxiliarySystem & _aux_sys
 
const std::set< TagID > & _tags
 
MooseObjectTagWarehouse< NodalKernelBase > & _nodal_kernels
 
MooseObjectWarehouse< NodalKernelBase > * _nkernel_warehouse
 
unsigned int _num_cached
 Number of contributions cached up.
 
THREAD_ID _tid
 

Detailed Description

Definition at line 30 of file ComputeNodalKernelJacobiansThread.h.

Constructor & Destructor Documentation

◆ ComputeNodalKernelJacobiansThread() [1/2]

ComputeNodalKernelJacobiansThread::ComputeNodalKernelJacobiansThread ( FEProblemBase &  fe_problem,
NonlinearSystemBase &  nl,
MooseObjectTagWarehouse< NodalKernelBase > &  nodal_kernels,
const std::set< TagID > &  tags 
)

Definition at line 23 of file ComputeNodalKernelJacobiansThread.C.

◆ ComputeNodalKernelJacobiansThread() [2/2]

ComputeNodalKernelJacobiansThread::ComputeNodalKernelJacobiansThread ( ComputeNodalKernelJacobiansThread &  x,
Threads::split  split 
)

Member Function Documentation

◆ caughtMooseException()

virtual void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::caughtMooseException ( MooseException &  e)
inlinevirtualinherited

Called if a MooseException is caught anywhere during the computation.

The single input parameter taken is a MooseException object.

Definition at line 56 of file ThreadedNodeLoop.h.

57 {
58 Threads::spin_mutex::scoped_lock lock(threaded_node_mutex);
59
60 std::string what(e.what());
62 };
static Threads::spin_mutex threaded_node_mutex
virtual void setException(const std::string &message)
Set an exception, which is stored at this point by toggling a member variable in this class,...
virtual const char * what() const
Get out the error message.

◆ join()

void ComputeNodalKernelJacobiansThread::join ( const ComputeNodalKernelJacobiansThread &  )

Definition at line 145 of file ComputeNodalKernelJacobiansThread.C.

146{
147}

◆ keepGoing()

virtual bool ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::keepGoing ( )
inlinevirtualinherited

Whether or not the loop should continue.

Returns
true to keep going, false to stop.

Definition at line 69 of file ThreadedNodeLoop.h.

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

◆ onNode() [1/2]

void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::onNode ( ConstNodeRange::const_iterator &  node_it)
virtualinherited

Called for each node.

Definition at line 43 of file ThreadedNodeLoop.h.

153{
154}

◆ onNode() [2/2]

void ComputeNodalKernelJacobiansThread::onNode ( ConstNodeRange::const_iterator &  node_it)
overridevirtual

Definition at line 65 of file ComputeNodalKernelJacobiansThread.C.

66{
67 const Node * node = *node_it;
68
70 for (const auto & it : ce)
71 {
72 MooseVariableFEBase & ivariable = *(it.first);
73 MooseVariableFEBase & jvariable = *(it.second);
74
75 unsigned int ivar = ivariable.number();
76 unsigned int jvar = jvariable.number();
77
78 // The NodalKernels that are active and are coupled to the jvar in question
79 std::vector<std::shared_ptr<NodalKernelBase>> active_involved_kernels;
80 // A NodalKernel active on several of the node's blocks must contribute only once
81 std::set<const NodalKernelBase *> involved_kernels;
82
83 const auto & block_ids = _aux_sys.mesh().getNodeBlockIds(*node);
84 for (const auto & block : block_ids)
85 {
87 {
88 // Loop over each NodalKernel to see if it's involved with the jvar
89 const auto & objects = _nkernel_warehouse->getActiveBlockObjects(block, _tid);
90 for (const auto & nodal_kernel : objects)
91 {
92 if (nodal_kernel->variable().number() == ivar)
93 {
94 // If this NodalKernel is acting on the jvar add it to the list and short-circuit the
95 // loop
96 if (nodal_kernel->variable().number() == jvar)
97 {
98 if (involved_kernels.insert(nodal_kernel.get()).second)
99 active_involved_kernels.push_back(nodal_kernel);
100 continue;
101 }
102
103 // See if this NodalKernel is coupled to the jvar
104 const std::vector<MooseVariableFEBase *> & coupled_vars =
105 nodal_kernel->getCoupledMooseVars();
106 for (const auto & var : coupled_vars)
107 if (var->number() == jvar)
108 {
109 if (involved_kernels.insert(nodal_kernel.get()).second)
110 active_involved_kernels.push_back(nodal_kernel);
111 break; // It only takes one
112 }
113 }
114 }
115 }
116 }
117
118 // Did we find any NodalKernels coupled to this jvar?
119 if (!active_involved_kernels.empty())
120 {
121 // prepare variables
122 for (auto * var : _aux_sys._nodal_vars[_tid])
123 var->prepareAux();
124
126
127 for (const auto & nodal_kernel : active_involved_kernels)
128 {
129 nodal_kernel->setSubdomains(block_ids);
130 nodal_kernel->computeOffDiagJacobian(jvar);
131 }
132
133 _num_cached++;
134
135 if (_num_cached == 20) // Cache 20 nodes worth before adding into the residual
136 {
137 _num_cached = 0;
139 }
140 }
141 }
142}
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
MooseObjectWarehouse< NodalKernelBase > * _nkernel_warehouse
virtual void addCachedJacobian(const THREAD_ID tid) override
virtual void reinitNode(const Node *node, const THREAD_ID tid) override
std::vector< std::pair< MooseVariableFieldBase *, MooseVariableFieldBase * > > & couplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num)
const std::set< SubdomainID > & getNodeBlockIds(const Node &node) const
Return list of blocks to which the given node belongs.
Definition MooseMesh.C:1479
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
bool hasActiveBlockObjects(THREAD_ID tid=0) const
unsigned int number() const
Get variable number coming from libMesh.
This class provides an interface for common operations on field variables of both FE and FV types wit...
unsigned int number() const
Gets the number of this system.
MooseMesh & mesh()
Definition SystemBase.h:100

◆ operator()()

void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::operator() ( const ConstNodeRange &  range)
inherited

Definition at line 28 of file ThreadedNodeLoop.h.

111{
112 try
113 {
114 ParallelUniqueId puid;
115 _tid = puid.id;
116
117 pre();
119
120 for (IteratorType nd = range.begin(); nd != range.end(); ++nd)
121 {
122 if (!keepGoing())
123 break;
124
125 onNode(nd);
126
127 postNode(nd);
128 }
129
130 post();
131 }
132 catch (MooseException & e)
133 {
135 }
136}
Provides a way for users to bail out of the current solve.
virtual void printGeneralExecutionInformation() const
Print information about the loop, mostly order of execution of objects.
virtual void postNode(ConstNodeRange::const_iterator &node_it)
Called after the node assembly is done (including surface assembling)
virtual void onNode(ConstNodeRange::const_iterator &node_it)
Called for each node.
virtual bool keepGoing()
Whether or not the loop should continue.
virtual void pre()
Called before the node range loop.
virtual void post()
Called after the node range loop.
virtual void caughtMooseException(MooseException &e)
Called if a MooseException is caught anywhere during the computation.

◆ post()

void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::post ( )
virtualinherited

Called after the node range loop.

Reimplemented in ComputeNodalAuxVarsThread< AuxKernelType >.

Definition at line 38 of file ThreadedNodeLoop.h.

147{
148}

◆ postNode()

void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::postNode ( ConstNodeRange::const_iterator &  node_it)
virtualinherited

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

Parameters
node- active node

Definition at line 50 of file ThreadedNodeLoop.h.

159{
160}

◆ pre()

void ComputeNodalKernelJacobiansThread::pre ( )
overridevirtual

Called before the node range loop.

Reimplemented from ThreadedNodeLoop< ConstNodeRange, ConstNodeRange::const_iterator >.

Definition at line 52 of file ComputeNodalKernelJacobiansThread.C.

53{
54 _num_cached = 0;
55
56 if (!_tags.size() || _tags.size() == _fe_problem.numMatrixTags())
58 else if (_tags.size() == 1)
60 else
62}
MooseObjectWarehouse< T > & getMatrixTagsObjectWarehouse(const std::set< TagID > &tags, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has one of the given matrix tags.
MooseObjectWarehouse< T > & getMatrixTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given matrix tag.
virtual unsigned int numMatrixTags() const
The total number of tags.
Definition SubProblem.h:251

◆ printExecutionOrdering()

void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::printExecutionOrdering ( const std::vector< T * > &  objs,
const bool  print_header = true,
const std::string &  line_prefix = "[DBG]" 
) const
protectedinherited

Routine to output the ordering of objects within a vector of pointers to these objects.

These objects must implement the name() routine, and it must return a string or compatible type.

Template Parameters
Tthe object type
Parameters
objsthe vector with all the objects (should be pointers)
print_headerwhether to print a header about the timing of execution and the type of objects
line_prefixprefix to prepend to each line of the console output

Definition at line 90 of file ThreadedNodeLoop.h.

167{
168 if (!objs.size())
169 return;
170
171 auto & console = _fe_problem.console();
172 const auto objects_type = MooseUtils::prettyCppType(objs[0]);
173 std::vector<MooseObject *> moose_objs;
174 moose_objs.reserve(objs.size());
175 for (auto obj_ptr : objs)
176 moose_objs.push_back(cast_ptr<MooseObject *>(obj_ptr));
177 const auto names = ConsoleUtils::mooseObjectVectorToString(moose_objs);
178
179 // Print string with a DBG prefix and with sufficient line breaks
180 std::string message = print_header ? "Executing " + objects_type + " on " +
182 : "";
183 message += (print_header ? "Order of execution:\n" : "") + names;
184 console << ConsoleUtils::formatString(message, line_prefix) << std::endl;
185}
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
const std::string & name() const
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
const ConsoleStream & console() const
Return console handle.
Definition Problem.h:48
std::string formatString(std::string message, const std::string &prefix)
Add new lines and prefixes to a string for pretty display in output NOTE: This makes a copy of the st...
std::string mooseObjectVectorToString(const std::vector< MooseObject * > &objs, const std::string &sep=" ")
Routine to output the name of MooseObjects in a string.
std::string prettyCppType(const std::string &cpp_type)
Tnew cast_ptr(Told *oldvar)

◆ printGeneralExecutionInformation()

void ComputeNodalKernelJacobiansThread::printGeneralExecutionInformation ( ) const
overrideprotectedvirtual

Print information about the loop, mostly order of execution of objects.

Reimplemented from ThreadedNodeLoop< ConstNodeRange, ConstNodeRange::const_iterator >.

Definition at line 150 of file ComputeNodalKernelJacobiansThread.C.

151{
153 return;
154
155 const auto & console = _fe_problem.console();
156 const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
157 console << "[DBG] Executing nodal kernels contribution to Jacobian on nodes on " << execute_on
158 << std::endl;
159 console << _nkernel_warehouse->activeObjectsToFormattedString() << std::endl;
160}
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
std::string activeObjectsToFormattedString(THREAD_ID tid=0, const std::string &prefix="[DBG]") const
Output the active content of the warehouse to a string, meant to be output to the console.
bool hasActiveObjects(THREAD_ID tid=0) const

Member Data Documentation

◆ _aux_sys

AuxiliarySystem& ComputeNodalKernelJacobiansThread::_aux_sys
protected

Definition at line 54 of file ComputeNodalKernelJacobiansThread.h.

Referenced by onNode().

◆ _fe_problem

FEProblemBase& ComputeNodalKernelJacobiansThread::_fe_problem
protected

◆ _nkernel_warehouse

MooseObjectWarehouse<NodalKernelBase>* ComputeNodalKernelJacobiansThread::_nkernel_warehouse
protected

◆ _nl

NonlinearSystemBase& ComputeNodalKernelJacobiansThread::_nl
protected

Definition at line 53 of file ComputeNodalKernelJacobiansThread.h.

Referenced by onNode().

◆ _nodal_kernels

MooseObjectTagWarehouse<NodalKernelBase>& ComputeNodalKernelJacobiansThread::_nodal_kernels
protected

Definition at line 58 of file ComputeNodalKernelJacobiansThread.h.

Referenced by pre().

◆ _num_cached

unsigned int ComputeNodalKernelJacobiansThread::_num_cached
protected

Number of contributions cached up.

Definition at line 63 of file ComputeNodalKernelJacobiansThread.h.

Referenced by onNode(), and pre().

◆ _tags

const std::set<TagID>& ComputeNodalKernelJacobiansThread::_tags
protected

Definition at line 56 of file ComputeNodalKernelJacobiansThread.h.

Referenced by pre().

◆ _tid

THREAD_ID ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::_tid
protectedinherited

Definition at line 73 of file ThreadedNodeLoop.h.


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