www.mooseframework.org
Public Types | Public Member Functions | Protected Attributes | List of all members
DiscreteNucleationInserter Class Reference

This UserObject manages the insertion and expiration of nuclei in the simulation domain it manages a list of nuclei with their insertion times and their center positions. More...

#include <DiscreteNucleationInserter.h>

Inheritance diagram for DiscreteNucleationInserter:
[legend]

Public Types

using NucleusLocation = std::pair< Real, Point >
 A nucleus has an expiration time and a location. More...
 
using NucleusList = std::vector< NucleusLocation >
 Every MPI task should keep a full list of nuclei (in case they cross domains with their finite radii) More...
 
using NucleusChanges = std::pair< unsigned int, unsigned int >
 

Public Member Functions

 DiscreteNucleationInserter (const InputParameters &parameters)
 
virtual void initialize ()
 
virtual void execute ()
 
virtual void threadJoin (const UserObject &y)
 
virtual void finalize ()
 
const Real & getRate () const
 
virtual bool isMapUpdateRequired () const
 
virtual const NucleusListgetNucleusList () const
 
virtual const NucleusChangesgetInsertionsAndDeletions () const
 

Protected Attributes

const MaterialProperty< Real > & _probability
 Nucleation rate density (should be a material property implementing nucleation theory) More...
 
Real _hold_time
 Duration of time each nucleus is kept active after insertion. More...
 
NucleusList_local_nucleus_list
 the local nucleus list of nuclei centered in the domain of the current processor More...
 
Real _nucleation_rate
 total nucleation rate More...
 
NucleusList_global_nucleus_list
 the global list of all nuclei over all processors More...
 
NucleusChanges _changes_made
 count the number of nucleus insertions and deletions More...
 
bool _update_required
 is a map update required More...
 

Detailed Description

This UserObject manages the insertion and expiration of nuclei in the simulation domain it manages a list of nuclei with their insertion times and their center positions.

A DiscreteNucleationMap is needed to enable the DiscreteNucleation material to look up if a nucleus is present at a given element/qp.

Definition at line 26 of file DiscreteNucleationInserter.h.

Member Typedef Documentation

◆ NucleusChanges

using DiscreteNucleationInserterBase::NucleusChanges = std::pair<unsigned int, unsigned int>
inherited

Definition at line 38 of file DiscreteNucleationInserterBase.h.

◆ NucleusList

Every MPI task should keep a full list of nuclei (in case they cross domains with their finite radii)

Definition at line 35 of file DiscreteNucleationInserterBase.h.

◆ NucleusLocation

using DiscreteNucleationInserterBase::NucleusLocation = std::pair<Real, Point>
inherited

A nucleus has an expiration time and a location.

Definition at line 32 of file DiscreteNucleationInserterBase.h.

Constructor & Destructor Documentation

◆ DiscreteNucleationInserter()

DiscreteNucleationInserter::DiscreteNucleationInserter ( const InputParameters &  parameters)

Definition at line 30 of file DiscreteNucleationInserter.C.

31  : DiscreteNucleationInserterBase(parameters),
32  _probability(getMaterialProperty<Real>("probability")),
33  _hold_time(getParam<Real>("hold_time")),
34  _local_nucleus_list(declareRestartableData("local_nucleus_list", NucleusList(0)))
35 {
36 }
DiscreteNucleationInserterBase(const InputParameters &parameters)
const MaterialProperty< Real > & _probability
Nucleation rate density (should be a material property implementing nucleation theory) ...
std::vector< NucleusLocation > NucleusList
Every MPI task should keep a full list of nuclei (in case they cross domains with their finite radii)...
NucleusList & _local_nucleus_list
the local nucleus list of nuclei centered in the domain of the current processor
Real _hold_time
Duration of time each nucleus is kept active after insertion.

Member Function Documentation

◆ execute()

void DiscreteNucleationInserter::execute ( )
virtual

Definition at line 70 of file DiscreteNucleationInserter.C.

71 {
72  // check each qp for potential nucleation
73  // TODO: we might as well place the nuclei at random positions within the element...
74  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
75  {
76  const Real rate = _probability[qp] * _JxW[qp] * _coord[qp];
77  _nucleation_rate += rate;
78 
79  const Real random = getRandomReal();
80 
81  // We check the random number against the inverse of the zero probability.
82  // for performance reasons we do a quick check against the linearized form of
83  // that probability, which is always strictly larger than the actual probability.
84  // The expression below should short circuit and the expensive exponential
85  // should rarely get evaluated
86  if (random < rate * _fe_problem.dt() && random < (1.0 - std::exp(-rate * _fe_problem.dt())))
87  {
88  _local_nucleus_list.push_back(NucleusLocation(_fe_problem.time() + _hold_time, _q_point[qp]));
89  _changes_made.first++;
90  }
91  }
92 }
NucleusChanges _changes_made
count the number of nucleus insertions and deletions
const MaterialProperty< Real > & _probability
Nucleation rate density (should be a material property implementing nucleation theory) ...
Real _nucleation_rate
total nucleation rate
NucleusList & _local_nucleus_list
the local nucleus list of nuclei centered in the domain of the current processor
Real _hold_time
Duration of time each nucleus is kept active after insertion.
std::pair< Real, Point > NucleusLocation
A nucleus has an expiration time and a location.

◆ finalize()

void DiscreteNucleationInserter::finalize ( )
virtual

Pack the _global_nucleus_list into a simple vector of Real. libMesh's allgather does not portably work on the original _global_nucleus_list data structure!

Definition at line 111 of file DiscreteNucleationInserter.C.

112 {
113  // add the _local_nucleus_list of thread zero
114  _global_nucleus_list.insert(
116 
122  std::vector<Real> comm_buffer(_global_nucleus_list.size() * 4);
123  for (unsigned i = 0; i < _global_nucleus_list.size(); ++i)
124  {
125  comm_buffer[i * 4 + 0] = _global_nucleus_list[i].first;
126  comm_buffer[i * 4 + 1] = _global_nucleus_list[i].second(0);
127  comm_buffer[i * 4 + 2] = _global_nucleus_list[i].second(1);
128  comm_buffer[i * 4 + 3] = _global_nucleus_list[i].second(2);
129  }
130 
131  // combine _global_nucleus_lists from all MPI ranks
132  _communicator.allgather(comm_buffer);
133 
134  // unpack the gathered _global_nucleus_list
135  unsigned int n = comm_buffer.size() / 4;
136  mooseAssert(comm_buffer.size() % 4 == 0,
137  "Communication buffer has an unexpected size (not divisible by 4)");
138  _global_nucleus_list.resize(n);
139  for (unsigned i = 0; i < n; ++i)
140  {
141  _global_nucleus_list[i].first = comm_buffer[i * 4 + 0];
142  _global_nucleus_list[i].second(0) = comm_buffer[i * 4 + 1];
143  _global_nucleus_list[i].second(1) = comm_buffer[i * 4 + 2];
144  _global_nucleus_list[i].second(2) = comm_buffer[i * 4 + 3];
145  }
146 
147  // get the global number of changes (i.e. changes to _global_nucleus_list)
148  gatherSum(_changes_made.first);
149  gatherSum(_changes_made.second);
150 
151  // gather the total nucleation rate
152  gatherSum(_nucleation_rate);
153 
154  _update_required = _changes_made.first > 0 || _changes_made.second > 0;
155 }
NucleusChanges _changes_made
count the number of nucleus insertions and deletions
Real _nucleation_rate
total nucleation rate
NucleusList & _local_nucleus_list
the local nucleus list of nuclei centered in the domain of the current processor
bool _update_required
is a map update required
NucleusList & _global_nucleus_list
the global list of all nuclei over all processors

◆ getInsertionsAndDeletions()

virtual const NucleusChanges& DiscreteNucleationInserterBase::getInsertionsAndDeletions ( ) const
inlinevirtualinherited

Definition at line 42 of file DiscreteNucleationInserterBase.h.

Referenced by DiscreteNucleationData::getValue().

42 { return _changes_made; }
NucleusChanges _changes_made
count the number of nucleus insertions and deletions

◆ getNucleusList()

virtual const NucleusList& DiscreteNucleationInserterBase::getNucleusList ( ) const
inlinevirtualinherited

Definition at line 41 of file DiscreteNucleationInserterBase.h.

41 { return _global_nucleus_list; }
NucleusList & _global_nucleus_list
the global list of all nuclei over all processors

◆ getRate()

const Real& DiscreteNucleationInserter::getRate ( ) const
inlinevirtual

Implements DiscreteNucleationInserterBase.

Definition at line 36 of file DiscreteNucleationInserter.h.

36 { return _nucleation_rate; }
Real _nucleation_rate
total nucleation rate

◆ initialize()

void DiscreteNucleationInserter::initialize ( )
virtual

Definition at line 39 of file DiscreteNucleationInserter.C.

40 {
41  // clear insertion and deletion counter
42  _changes_made = {0, 0};
43 
44  // expire entries from the local nucleus list (if the current time step converged)
45  if (_fe_problem.converged())
46  {
47  unsigned int i = 0;
48  while (i < _local_nucleus_list.size())
49  {
50  if (_local_nucleus_list[i].first <= _fe_problem.time())
51  {
52  // remove entry (by replacing with last element and shrinking size by one)
54  _local_nucleus_list.pop_back();
55  _changes_made.second++;
56  }
57  else
58  ++i;
59  }
60  }
61 
62  // we reassemble this list at every time step
63  _global_nucleus_list.clear();
64 
65  // clear total nucleation rate
66  _nucleation_rate = 0.0;
67 }
NucleusChanges _changes_made
count the number of nucleus insertions and deletions
Real _nucleation_rate
total nucleation rate
NucleusList & _local_nucleus_list
the local nucleus list of nuclei centered in the domain of the current processor
NucleusList & _global_nucleus_list
the global list of all nuclei over all processors

◆ isMapUpdateRequired()

virtual bool DiscreteNucleationInserterBase::isMapUpdateRequired ( ) const
inlinevirtualinherited

◆ threadJoin()

void DiscreteNucleationInserter::threadJoin ( const UserObject &  y)
virtual

Definition at line 95 of file DiscreteNucleationInserter.C.

96 {
97  // combine _local_nucleus_list entries from all threads on the current process
98  const DiscreteNucleationInserter & uo = static_cast<const DiscreteNucleationInserter &>(y);
99  _global_nucleus_list.insert(
100  _global_nucleus_list.end(), uo._local_nucleus_list.begin(), uo._local_nucleus_list.end());
101 
102  // sum up insertion and deletion counts
103  _changes_made.first += uo._changes_made.first;
104  _changes_made.second += uo._changes_made.second;
105 
106  // integrate total nucleation rate
108 }
NucleusChanges _changes_made
count the number of nucleus insertions and deletions
This UserObject manages the insertion and expiration of nuclei in the simulation domain it manages a ...
Real _nucleation_rate
total nucleation rate
NucleusList & _local_nucleus_list
the local nucleus list of nuclei centered in the domain of the current processor
NucleusList & _global_nucleus_list
the global list of all nuclei over all processors

Member Data Documentation

◆ _changes_made

NucleusChanges DiscreteNucleationInserterBase::_changes_made
protectedinherited

◆ _global_nucleus_list

NucleusList& DiscreteNucleationInserterBase::_global_nucleus_list
protectedinherited

the global list of all nuclei over all processors

Definition at line 48 of file DiscreteNucleationInserterBase.h.

Referenced by finalize(), DiscreteNucleationInserterBase::getNucleusList(), initialize(), DiscreteNucleationFromFile::initialize(), and threadJoin().

◆ _hold_time

Real DiscreteNucleationInserter::_hold_time
protected

Duration of time each nucleus is kept active after insertion.

Definition at line 43 of file DiscreteNucleationInserter.h.

Referenced by execute().

◆ _local_nucleus_list

NucleusList& DiscreteNucleationInserter::_local_nucleus_list
protected

the local nucleus list of nuclei centered in the domain of the current processor

Definition at line 46 of file DiscreteNucleationInserter.h.

Referenced by execute(), finalize(), initialize(), and threadJoin().

◆ _nucleation_rate

Real DiscreteNucleationInserter::_nucleation_rate
protected

total nucleation rate

Definition at line 49 of file DiscreteNucleationInserter.h.

Referenced by execute(), finalize(), getRate(), initialize(), and threadJoin().

◆ _probability

const MaterialProperty<Real>& DiscreteNucleationInserter::_probability
protected

Nucleation rate density (should be a material property implementing nucleation theory)

Definition at line 40 of file DiscreteNucleationInserter.h.

Referenced by execute().

◆ _update_required

bool DiscreteNucleationInserterBase::_update_required
protectedinherited

The documentation for this class was generated from the following files: