Line data Source code
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 : 10 : #include "ComputeInitialConditionThread.h" 11 : #include "FEProblem.h" 12 : #include "DisplacedProblem.h" 13 : #include "Assembly.h" 14 : #include "InitialCondition.h" 15 : 16 58410 : ComputeInitialConditionThread::ComputeInitialConditionThread(FEProblemBase & fe_problem) 17 58410 : : _fe_problem(fe_problem) 18 : { 19 58410 : } 20 : 21 4762 : ComputeInitialConditionThread::ComputeInitialConditionThread(ComputeInitialConditionThread & x, 22 4762 : Threads::split /*split*/) 23 4762 : : _fe_problem(x._fe_problem) 24 : { 25 4762 : } 26 : 27 : void 28 63172 : ComputeInitialConditionThread::operator()(const ConstElemRange & range) 29 : { 30 63172 : ParallelUniqueId puid; 31 63172 : _tid = puid.id; 32 63172 : const auto current_ic_state = _fe_problem.getCurrentICState(); 33 : 34 63172 : const InitialConditionWarehouse & warehouse = _fe_problem.getInitialConditionWarehouse(); 35 63172 : printGeneralExecutionInformation(); 36 : 37 : // Iterate over all the elements in the range 38 10441634 : for (const auto & elem : range) 39 : { 40 10378469 : 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 10378469 : std::set<SubdomainID> block_ids; 45 68106110 : for (unsigned int n = 0; n < n_nodes; n++) 46 : { 47 57727641 : auto node = elem->node_ptr(n); 48 57727641 : const auto & ids = _fe_problem.mesh().getNodeBlockIds(*node); 49 57727641 : 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 10378469 : 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 10378469 : std::map<MooseVariableFEBase *, std::vector<std::shared_ptr<InitialConditionBase>>> groups; 65 21375546 : for (auto id : block_ids) 66 10997077 : if (warehouse.hasActiveBlockObjects(id, _tid)) 67 4090098 : for (auto ic : warehouse.getActiveBlockObjects(id, _tid)) 68 : { 69 5172174 : if ((id != elem->subdomain_id() && !ic->variable().isNodal()) || 70 2538801 : ic->getState() != current_ic_state) 71 94572 : continue; 72 2538801 : order.push_back(&(ic->variable())); 73 2538801 : groups[&(ic->variable())].push_back(ic); 74 2633373 : } 75 : 76 10378469 : _fe_problem.setCurrentSubdomainID(elem, _tid); 77 10378469 : _fe_problem.prepare(elem, _tid); 78 10378469 : _fe_problem.reinitElem(elem, _tid); 79 : 80 12917263 : for (auto var : order) 81 : { 82 2538801 : DenseVector<Real> Ue; 83 2538801 : 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 2538801 : DependencyResolverInterface::sort<std::shared_ptr<InitialConditionBase>>(vec); 91 : } 92 0 : catch (CyclicDependencyException<std::shared_ptr<InitialConditionBase>> & e) 93 : { 94 0 : DependencyResolverInterface::cyclicDependencyError<std::shared_ptr<InitialConditionBase>>( 95 : e, "Cyclic dependency detected in object ordering"); 96 0 : } 97 : 98 4989748 : for (auto ic : vec) 99 2450954 : ic->compute(); 100 2538794 : vec.clear(); 101 : 102 : // Now that all dofs are set for this variable, solemnize the solution. 103 2538794 : var->insert(var->sys().solution()); 104 2538794 : } 105 10378462 : } 106 63165 : } 107 : 108 : void 109 4762 : ComputeInitialConditionThread::join(const ComputeInitialConditionThread & /*y*/) 110 : { 111 4762 : } 112 : 113 : void 114 63172 : ComputeInitialConditionThread::printGeneralExecutionInformation() const 115 : { 116 63172 : const auto & ic_wh = _fe_problem.getInitialConditionWarehouse(); 117 63172 : if (_fe_problem.shouldPrintExecution(_tid) && ic_wh.hasActiveObjects()) 118 : { 119 80 : const auto & console = _fe_problem.console(); 120 80 : const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag(); 121 80 : console << "[DBG] Executing initial conditions on elements on " << execute_on << std::endl; 122 80 : console << "[DBG] Unordered list:" << std::endl; 123 80 : console << ic_wh.activeObjectsToFormattedString() << std::endl; 124 80 : console << "[DBG] The order of execution is defined by dependency resolution on every element" 125 80 : << std::endl; 126 : } 127 63172 : }