https://mooseframework.inl.gov
InitialConditionWarehouse.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 
12 // MOOSE includes
13 #include "InitialConditionBase.h"
14 #include "MooseVariableFE.h"
15 
18  _boundary_ics(libMesh::n_threads()),
19  _block_ics(libMesh::n_threads())
20 {
21 }
22 
23 void
25 {
27  for (const auto & ic : _active_objects[tid])
28  ic->initialSetup();
29 }
30 
31 void
32 InitialConditionWarehouse::addObject(std::shared_ptr<InitialConditionBase> object,
33  THREAD_ID tid,
34  bool recurse)
35 {
36  // Check that when object is boundary restricted that the variable is nodal
37  const MooseVariableFEBase & var = object->variable();
38  const auto ic_key = std::tuple(var.name(), object->getState());
39 
40  // Boundary Restricted
41  if (object->boundaryRestricted())
42  {
43  if (!var.isNodal())
44  mooseError("You are trying to set a boundary restricted variable on non-nodal variable. That "
45  "is not allowed.");
46 
47  const auto iter = _boundary_ics[tid].find(ic_key);
48  if (iter != _boundary_ics[tid].end() && object->hasBoundary(iter->second))
49  mooseError("The initial condition '",
50  object->name(),
51  "' is being defined on a boundary that already has an initial condition defined "
52  "with the same variable and state.");
53  else
54  _boundary_ics[tid][ic_key].insert(object->boundaryIDs().begin(), object->boundaryIDs().end());
55  }
56 
57  // Block Restricted
58  else if (object->blockRestricted())
59  {
60  auto iter = _block_ics[tid].find(ic_key);
61  if (iter != _block_ics[tid].end() &&
62  (object->hasBlocks(iter->second) ||
63  (iter->second.find(Moose::ANY_BLOCK_ID) != iter->second.end())))
64  mooseError("The initial condition '",
65  object->name(),
66  "' is being defined on a block that already has an initial condition defined "
67  "with the same variable and state.");
68  else
69  _block_ics[tid][ic_key].insert(object->blockIDs().begin(), object->blockIDs().end());
70  }
71 
72  // Non-restricted
73  else
74  {
75  auto iter = _block_ics[tid].find(ic_key);
76  if (iter != _block_ics[tid].end())
77  mooseError("The initial condition '",
78  object->name(),
79  "' is being defined on a block that already has an initial condition defined "
80  "with the same variable and state.");
81  else
82  _block_ics[tid][ic_key].insert(Moose::ANY_BLOCK_ID);
83  }
84 
85  // Add the IC to the storage
87 }
88 
89 std::set<std::string>
91 {
92  std::set<std::string> depend_objects;
93 
94  const auto & ics = getActiveObjects();
95  for (const auto & ic : ics)
96  {
97  const auto & uo = ic->getDependObjects();
98  depend_objects.insert(uo.begin(), uo.end());
99  }
100 
101  return depend_objects;
102 }
void sort(THREAD_ID tid=0)
Sort the objects using the DependencyResolver.
virtual bool isNodal() const
Is this variable nodal.
unsigned int n_threads()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
const std::string & name() const override
Get the variable name.
This class provides an interface for common operations on field variables of both FE and FV types wit...
InitialConditionBase serves as the abstract base class for InitialConditions and VectorInitialConditi...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
void initialSetup(THREAD_ID tid)
Initial setup.
const std::vector< std::shared_ptr< InitialConditionBase > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active all/block/boundary restricted objects for a given thread...
void addObject(std::shared_ptr< InitialConditionBase > object, THREAD_ID tid, bool recurse=true)
Add object to the warehouse.
std::vector< std::map< ic_key_type, std::set< SubdomainID > > > _block_ics
const SubdomainID ANY_BLOCK_ID
Definition: MooseTypes.C:19
std::vector< std::map< ic_key_type, std::set< BoundaryID > > > _boundary_ics
std::set< std::string > getDependObjects() const
Get a list of dependent UserObjects for this exec type.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true)
Adds an object to the storage structure.
std::vector< std::vector< std::shared_ptr< InitialConditionBase > > > _active_objects
All active objects (THREAD_ID on outer vector)
A base storage container for MooseObjects.
unsigned int THREAD_ID
Definition: MooseTypes.h:209