https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
ComputeInitialConditionThread Class Reference

#include <ComputeInitialConditionThread.h>

Public Member Functions

 ComputeInitialConditionThread (FEProblemBase &fe_problem)
 
 ComputeInitialConditionThread (ComputeInitialConditionThread &x, Threads::split split)
 
void operator() (const libMesh::ConstElemRange &range)
 
void join (const ComputeInitialConditionThread &)
 

Protected Member Functions

void printGeneralExecutionInformation () const
 Print information about the loop, mostly order of execution of objects. More...
 

Protected Attributes

FEProblemBase_fe_problem
 
THREAD_ID _tid
 

Private Member Functions

 ComputeInitialConditionThread (FEProblemBase &fe_problem, const std::set< VariableName > *target_vars)
 Set IC on specific variables. More...
 

Private Attributes

const std::set< VariableName > * _target_vars = nullptr
 the names of target variables for which the initial conditions are applied More...
 

Friends

class FEProblemBase
 

Detailed Description

Definition at line 20 of file ComputeInitialConditionThread.h.

Constructor & Destructor Documentation

◆ ComputeInitialConditionThread() [1/3]

ComputeInitialConditionThread::ComputeInitialConditionThread ( FEProblemBase fe_problem)

Definition at line 16 of file ComputeInitialConditionThread.C.

17  : _fe_problem(fe_problem)
18 {
19 }

◆ ComputeInitialConditionThread() [2/3]

ComputeInitialConditionThread::ComputeInitialConditionThread ( ComputeInitialConditionThread x,
Threads::split  split 
)

Definition at line 21 of file ComputeInitialConditionThread.C.

◆ ComputeInitialConditionThread() [3/3]

ComputeInitialConditionThread::ComputeInitialConditionThread ( FEProblemBase fe_problem,
const std::set< VariableName > *  target_vars 
)
private

Set IC on specific variables.

Definition at line 27 of file ComputeInitialConditionThread.C.

29  : _fe_problem(fe_problem), _target_vars(target_vars)
30 {
31 }
const std::set< VariableName > * _target_vars
the names of target variables for which the initial conditions are applied

Member Function Documentation

◆ join()

void ComputeInitialConditionThread::join ( const ComputeInitialConditionThread )

Definition at line 121 of file ComputeInitialConditionThread.C.

122 {
123 }

◆ operator()()

void ComputeInitialConditionThread::operator() ( const libMesh::ConstElemRange range)

Definition at line 34 of file ComputeInitialConditionThread.C.

35 {
36  ParallelUniqueId puid;
37  _tid = puid.id;
38  const auto current_ic_state = _fe_problem.getCurrentICState();
39 
42 
43  // Iterate over all the elements in the range
44  for (const auto & elem : range)
45  {
46  const unsigned int n_nodes = elem->n_nodes();
47 
48  // we need to execute objects that are for all subdomains covered by this
49  // elements' nodes.
50  std::set<SubdomainID> block_ids;
51  for (unsigned int n = 0; n < n_nodes; n++)
52  {
53  auto node = elem->node_ptr(n);
54  const auto & ids = _fe_problem.mesh().getNodeBlockIds(*node);
55  block_ids.insert(ids.begin(), ids.end());
56  }
57 
58  // we need to remember the order the variables originally are provided in
59  // since the ics dependencies are resolved to handle the inter-variable
60  // dependencies correctly.
61  std::vector<MooseVariableFEBase *> order;
62 
63  // group all initial condition objects by variable. so we can compute all
64  // its dof values at once and copy into solution vector once. This is
65  // necessary because we have to collect extra off-block ic objects from
66  // nodes shared between subdomains for cases where the off-block ic "wins"
67  // on the interface. The grouping is required because we need to have all
68  // the dof values for the element determined together so we can compute
69  // the correct qp values, etc. for the variable.
70  std::map<MooseVariableFEBase *, std::vector<std::shared_ptr<InitialConditionBase>>> groups;
71  for (auto id : block_ids)
72  if (warehouse.hasActiveBlockObjects(id, _tid))
73  for (auto ic : warehouse.getActiveBlockObjects(id, _tid))
74  {
75  if ((id != elem->subdomain_id() && !ic->variable().isNodal()) ||
76  ic->getState() != current_ic_state)
77  continue;
78 
79  // Skip initial conditions based on target variable usage
80  const auto & var_name = ic->variable().name();
81  if (_target_vars && !_target_vars->count(var_name))
82  continue;
83 
84  order.push_back(&(ic->variable()));
85  groups[&(ic->variable())].push_back(ic);
86  }
87 
89  _fe_problem.prepare(elem, _tid);
91 
92  for (auto var : order)
93  {
94  DenseVector<Real> Ue;
95  auto & vec = groups[var];
96 
97  // because of all the off-node shenanigans/grouping above, per-variable
98  // objects could possible have their order jumbled - so re-sort just in
99  // case.
100  try
101  {
102  DependencyResolverInterface::sort<std::shared_ptr<InitialConditionBase>>(vec);
103  }
104  catch (CyclicDependencyException<std::shared_ptr<InitialConditionBase>> & e)
105  {
106  DependencyResolverInterface::cyclicDependencyError<std::shared_ptr<InitialConditionBase>>(
107  e, "Cyclic dependency detected in object ordering");
108  }
109 
110  for (auto ic : vec)
111  ic->compute();
112  vec.clear();
113 
114  // Now that all dofs are set for this variable, solemnize the solution.
115  var->insert(var->sys().solution());
116  }
117  }
118 }
const std::set< VariableName > * _target_vars
the names of target variables for which the initial conditions are applied
unsigned short getCurrentICState()
Retrieves the current initial condition state.
bool hasActiveBlockObjects(THREAD_ID tid=0) const
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
virtual void prepare(const Elem *elem, const THREAD_ID tid) override
Warehouse for storing initial conditions.
void printGeneralExecutionInformation() const
Print information about the loop, mostly order of execution of objects.
const std::set< SubdomainID > & getNodeBlockIds(const Node &node) const
Return list of blocks to which the given node belongs.
Definition: MooseMesh.C:1537
const InitialConditionWarehouse & getInitialConditionWarehouse() const
Return InitialCondition storage.
const dof_id_type n_nodes
virtual void reinitElem(const Elem *elem, const THREAD_ID tid) override
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid) override
virtual MooseMesh & mesh() override

◆ printGeneralExecutionInformation()

void ComputeInitialConditionThread::printGeneralExecutionInformation ( ) const
protected

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

Definition at line 126 of file ComputeInitialConditionThread.C.

Referenced by operator()().

127 {
128  const auto & ic_wh = _fe_problem.getInitialConditionWarehouse();
129  if (_fe_problem.shouldPrintExecution(_tid) && ic_wh.hasActiveObjects())
130  {
131  const auto & console = _fe_problem.console();
132  const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
133  console << "[DBG] Executing initial conditions on elements on " << execute_on << std::endl;
134  console << "[DBG] Unordered list:" << std::endl;
135  console << ic_wh.activeObjectsToFormattedString() << std::endl;
136  console << "[DBG] The order of execution is defined by dependency resolution on every element"
137  << std::endl;
138  }
139 }
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
const InitialConditionWarehouse & getInitialConditionWarehouse() const
Return InitialCondition storage.
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
const ConsoleStream & console() const
Return console handle.
Definition: Problem.h:48

Friends And Related Function Documentation

◆ FEProblemBase

friend class FEProblemBase
friend

Definition at line 48 of file ComputeInitialConditionThread.h.

Member Data Documentation

◆ _fe_problem

FEProblemBase& ComputeInitialConditionThread::_fe_problem
protected

Definition at line 36 of file ComputeInitialConditionThread.h.

Referenced by operator()(), and printGeneralExecutionInformation().

◆ _target_vars

const std::set<VariableName>* ComputeInitialConditionThread::_target_vars = nullptr
private

the names of target variables for which the initial conditions are applied

Definition at line 41 of file ComputeInitialConditionThread.h.

Referenced by operator()().

◆ _tid

THREAD_ID ComputeInitialConditionThread::_tid
protected

Definition at line 37 of file ComputeInitialConditionThread.h.

Referenced by operator()(), and printGeneralExecutionInformation().


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