Pass serialization as parameter attribute

Changes the implementation of the serialization to be on an attribute of
the source XML element within settings.xml. This removes the need for a
new file containing the serialization.
Parameters are provided as a key-value string, separated by a comma and
a space, although the implementation can change this is required.
Change example values to align with existing custom_source to make
comparisons easier.
Update documentation to be consistent.
This commit is contained in:
Dan Short 2020-08-03 14:24:17 +01:00
parent 1de3d9ddf9
commit 8bb10563c1
11 changed files with 84 additions and 92 deletions

View file

@ -468,14 +468,13 @@ attributes/sub-elements:
*Default*: None
:serialization:
:parameters:
If this attribute is given, it indicates that the source is to be
instantiated from an externally compiled source function, with parameters
defined by a serialized form of the source. The serialized source will be
read from a file in the location provided by this attribute. In this case,
the ``sample_source()`` function must take as input an additional character
array containing the serialization that OpenMC will have read from the
provided file. If the library attribute is not provided then this attribute
defined by the string provided in this attribute. In this case, the
``sample_source()`` function must take as input an additional character
array containing the serialization that OpenMC will have read from this
attribute. If the library attribute is not provided then this attribute
will be ignored. More documentation on how to build serialized sources can
be found in :ref:`serialized_custom_source`.

View file

@ -241,17 +241,17 @@ Custom Serialized Sources
-------------------------
If the custom source may be used with parameters at a variety of values then it
may be necessary to serialize the source to an appropriate format (XML, JSON,
etc.) in order to avoid recompiling the source library for each run. This is
supported by defining the ``source_sampling`` function with an additional
parameter that receives the serialized form of the source:
may be necessary to serialize the source to an appropriate format in order to
avoid recompiling the source library for each run. This is supported by defining
the ``source_sampling`` function with an additional parameter that receives the
parameters used to build the source:
.. code-block:: c++
// you must have external C linkage here
extern "C" openmc::Particle::Bank sample_source(uint64_t* seed, char* serialized_source) {
extern "C" openmc::Particle::Bank sample_source(uint64_t* seed, const char* parameters) {
// function to deserialize the source
SerializedSource source = SerializedSource::from_xml(serialized_source);
SerializedSource source = SerializedSource::from_string(parameters);
openmc::Particle::Bank particle;
// wgt
@ -278,7 +278,7 @@ parameter that receives the serialized form of the source:
The details of the serialization routine, in particular the schema of the source
are to be defined by the implementation of the serializable source class. The
location of the serialized representation of the source to be used must be
provided via the :attr:`openmc.Source.serialization` attribute, along with the
provided via the :attr:`openmc.Source.parameters` attribute, along with the
custom source library location in :attr:`openmc.Source.library`.
When defining a class to be implemented via this deserialization approach, care