https://mooseframework.inl.gov
ComputeInitialConditionThread.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 
11 #include "FEProblem.h"
12 #include "DisplacedProblem.h"
13 #include "Assembly.h"
14 #include "InitialCondition.h"
15 
17  : _fe_problem(fe_problem)
18 {
19 }
20 
22  Threads::split /*split*/)
23  : _fe_problem(x._fe_problem)
24 {
25 }
26 
28  FEProblemBase & fe_problem, const std::set<VariableName> * target_vars)
29  : _fe_problem(fe_problem), _target_vars(target_vars)
30 {
31 }
32 
33 void
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 }
119 
120 void
122 {
123 }
124 
125 void
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 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.
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
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:1499
const InitialConditionWarehouse & getInitialConditionWarehouse() const
Return InitialCondition storage.
ComputeInitialConditionThread(FEProblemBase &fe_problem)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const dof_id_type n_nodes
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
virtual void reinitElem(const Elem *elem, const THREAD_ID tid) override
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid) override
const ConsoleStream & console() const
Return console handle.
Definition: Problem.h:48
virtual MooseMesh & mesh() override
void operator()(const libMesh::ConstElemRange &range)
void join(const ComputeInitialConditionThread &)