Implementation of time distribution for the source

This commit is contained in:
Olaf Schumann 2021-12-28 12:30:15 +01:00
parent d12e390f1a
commit d93df33dfb
3 changed files with 48 additions and 8 deletions

View file

@ -42,13 +42,13 @@ public:
};
//==============================================================================
//! Source composed of independent spatial, angle, and energy distributions
//! Source composed of independent spatial, angle, energy, and time distributions
//==============================================================================
class IndependentSource : public Source {
public:
// Constructors
IndependentSource(UPtrSpace space, UPtrAngle angle, UPtrDist energy);
IndependentSource(UPtrSpace space, UPtrAngle angle, UPtrDist energy, UPtrDist time);
explicit IndependentSource(pugi::xml_node node);
//! Sample from the external source distribution
@ -64,6 +64,7 @@ public:
SpatialDistribution* space() const { return space_.get(); }
UnitSphereDistribution* angle() const { return angle_.get(); }
Distribution* energy() const { return energy_.get(); }
Distribution* time() const { return time_.get(); }
private:
ParticleType particle_ {ParticleType::neutron}; //!< Type of particle emitted
@ -71,6 +72,7 @@ private:
UPtrSpace space_; //!< Spatial distribution
UPtrAngle angle_; //!< Angular distribution
UPtrDist energy_; //!< Energy distribution
UPtrDist time_; //!< Time distribution
};
//==============================================================================

View file

@ -22,6 +22,8 @@ class Source:
Angular distribution of source sites
energy : openmc.stats.Univariate
Energy distribution of source sites
time : openmc.stats.Univariate
time distribution of source sites
filename : str
Source file from which sites should be sampled
library : str
@ -43,6 +45,8 @@ class Source:
Angular distribution of source sites
energy : openmc.stats.Univariate or None
Energy distribution of source sites
time : openmc.stats.Univariate or None
time distribution of source sites
file : str or None
Source file from which sites should be sampled
library : str or None
@ -56,11 +60,12 @@ class Source:
"""
def __init__(self, space=None, angle=None, energy=None, filename=None,
def __init__(self, space=None, angle=None, energy=None, time=None, filename=None,
library=None, parameters=None, strength=1.0, particle='neutron'):
self._space = None
self._angle = None
self._energy = None
self._time = None
self._file = None
self._library = None
self._parameters = None
@ -71,6 +76,8 @@ class Source:
self.angle = angle
if energy is not None:
self.energy = energy
if time is not None:
self.time = time
if filename is not None:
self.file = filename
if library is not None:
@ -104,6 +111,10 @@ class Source:
def energy(self):
return self._energy
@property
def time(self):
return self._time
@property
def strength(self):
return self._strength
@ -142,6 +153,11 @@ class Source:
cv.check_type('energy distribution', energy, Univariate)
self._energy = energy
@time.setter
def time(self, time):
cv.check_type('time distribution', time, Univariate)
self._time = time
@strength.setter
def strength(self, strength):
cv.check_type('source strength', strength, Real)
@ -178,6 +194,8 @@ class Source:
element.append(self.angle.to_xml_element())
if self.energy is not None:
element.append(self.energy.to_xml_element('energy'))
if self.time is not None:
element.append(self.time.to_xml_element('time'))
return element
@classmethod
@ -229,6 +247,11 @@ class Source:
if energy is not None:
source.energy = Univariate.from_xml_element(energy)
time = elem.find('time')
if time is not None:
source.time = Univariate.from_xml_element(time)
return source

View file

@ -46,11 +46,12 @@ vector<unique_ptr<Source>> external_sources;
// IndependentSource implementation
//==============================================================================
IndependentSource::IndependentSource(
UPtrSpace space, UPtrAngle angle, UPtrDist energy)
: space_ {std::move(space)}, angle_ {std::move(angle)}, energy_ {
std::move(energy)}
{}
IndependentSource::IndependentSource(UPtrSpace space, UPtrAngle angle, UPtrDist energy, UPtrDist time)
: space_{std::move(space)},
angle_{std::move(angle)},
energy_{std::move(energy)},
time_{std::move(time)}
{ }
IndependentSource::IndependentSource(pugi::xml_node node)
{
@ -140,6 +141,17 @@ IndependentSource::IndependentSource(pugi::xml_node node)
// Default to a Watt spectrum with parameters 0.988 MeV and 2.249 MeV^-1
energy_ = UPtrDist {new Watt(0.988e6, 2.249e-6)};
}
// Determine external source time distribution
if (check_for_node(node, "time")) {
pugi::xml_node node_dist = node.child("time");
time_ = distribution_from_xml(node_dist);
} else {
// Default to a Constant time T=0
double T[] {0.0};
double p[] {1.0};
time_ = UPtrDist {new Discrete{T, p, 1}};
}
}
}
@ -224,6 +236,9 @@ SourceSite IndependentSource::sample(uint64_t* seed) const
break;
}
// Sample particle creation time
site.time = time_->sample(seed);
return site;
}