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