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 
27 void
29 {
30  ParallelUniqueId puid;
31  _tid = puid.id;
32  const auto current_ic_state = _fe_problem.getCurrentICState();
33 
36 
37  // Iterate over all the elements in the range
38  for (const auto & elem : range)
39  {
40  const unsigned int n_nodes = elem->n_nodes();
41 
42  // we need to execute objects that are for all subdomains covered by this
43  // elements' nodes.
44  std::set<SubdomainID> block_ids;
45  for (unsigned int n = 0; n < n_nodes; n++)
46  {
47  auto node = elem->node_ptr(n);
48  const auto & ids = _fe_problem.mesh().getNodeBlockIds(*node);
49  block_ids.insert(ids.begin(), ids.end());
50  }
51 
52  // we need to remember the order the variables originally are provided in
53  // since the ics dependencies are resolved to handle the inter-variable
54  // dependencies correctly.
55  std::vector<MooseVariableFEBase *> order;
56 
57  // group all initial condition objects by variable. so we can compute all
58  // its dof values at once and copy into solution vector once. This is
59  // necessary because we have to collect extra off-block ic objects from
60  // nodes shared between subdomains for cases where the off-block ic "wins"
61  // on the interface. The grouping is required because we need to have all
62  // the dof values for the element determined together so we can compute
63  // the correct qp values, etc. for the variable.
64  std::map<MooseVariableFEBase *, std::vector<std::shared_ptr<InitialConditionBase>>> groups;
65  for (auto id : block_ids)
66  if (warehouse.hasActiveBlockObjects(id, _tid))
67  for (auto ic : warehouse.getActiveBlockObjects(id, _tid))
68  {
69  if ((id != elem->subdomain_id() && !ic->variable().isNodal()) ||
70  ic->getState() != current_ic_state)
71  continue;
72  order.push_back(&(ic->variable()));
73  groups[&(ic->variable())].push_back(ic);
74  }
75 
77  _fe_problem.prepare(elem, _tid);
79 
80  for (auto var : order)
81  {
82  DenseVector<Real> Ue;
83  auto & vec = groups[var];
84 
85  // because of all the off-node shenanigans/grouping above, per-variable
86  // objects could possible have their order jumbled - so re-sort just in
87  // case.
88  try
89  {
90  DependencyResolverInterface::sort<std::shared_ptr<InitialConditionBase>>(vec);
91  }
92  catch (CyclicDependencyException<std::shared_ptr<InitialConditionBase>> & e)
93  {
94  DependencyResolverInterface::cyclicDependencyError<std::shared_ptr<InitialConditionBase>>(
95  e, "Cyclic dependency detected in object ordering");
96  }
97 
98  for (auto ic : vec)
99  ic->compute();
100  vec.clear();
101 
102  // Now that all dofs are set for this variable, solemnize the solution.
103  var->insert(var->sys().solution());
104  }
105  }
106 }
107 
108 void
110 {
111 }
112 
113 void
115 {
116  const auto & ic_wh = _fe_problem.getInitialConditionWarehouse();
117  if (_fe_problem.shouldPrintExecution(_tid) && ic_wh.hasActiveObjects())
118  {
119  const auto & console = _fe_problem.console();
120  const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
121  console << "[DBG] Executing initial conditions on elements on " << execute_on << std::endl;
122  console << "[DBG] Unordered list:" << std::endl;
123  console << ic_wh.activeObjectsToFormattedString() << std::endl;
124  console << "[DBG] The order of execution is defined by dependency resolution on every element"
125  << std::endl;
126  }
127 }
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:1496
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 &)