mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Formatting updates
Use American English consistently. A small tweak to a brace in the SerializedSource.
This commit is contained in:
parent
175d57c126
commit
7770010cf1
3 changed files with 11 additions and 12 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# Building a Serialised Custom Source
|
||||
# Building a Serialized Custom Source
|
||||
|
||||
To run this example, you first need to compile the custom source library, which
|
||||
requires headers from OpenMC. A CMakeLists.txt file has been set up for you that
|
||||
|
|
@ -10,7 +10,7 @@ library, you can run:
|
|||
make
|
||||
|
||||
After this, you can build the model by running `python build_xml.py`. In the XML
|
||||
files that are created, you should see a reference to build/libserialised_source.so,
|
||||
files that are created, you should see a reference to build/libserialized_source.so,
|
||||
the custom source library that was built by CMake, and the path to the serialized
|
||||
representation of the source in serialized_source.xml. The model is also set up with a
|
||||
mesh tally of the flux, so once you run `openmc`, you will get a statepoint file
|
||||
|
|
@ -19,5 +19,5 @@ results from the statepoint file and display them. If all worked well, you
|
|||
should see a ring "imprint" as well as a higher flux to the right side (since
|
||||
the custom source has all particles moving in the positive x direction).
|
||||
|
||||
Once built, you can edit the serialised_source.xml file to change the radius of the
|
||||
Once built, you can edit the serialized_source.xml file to change the radius of the
|
||||
sampled ring or the energy of the sampled particles.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import openmc
|
||||
|
||||
# Define the serialised source
|
||||
# Define the serialized source
|
||||
serialized_source = """<Source>
|
||||
<Radius>1.5</Radius>
|
||||
<Energy>1e3</Energy>
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
#include "openmc/particle.h"
|
||||
#include "pugixml.hpp"
|
||||
|
||||
class SerialisedSource {
|
||||
class SerializedSource {
|
||||
protected:
|
||||
double radius_;
|
||||
double energy_;
|
||||
|
||||
// Protect the constructor so that the class can only be created by serialisation.
|
||||
SerialisedSource(double radius, double energy) {
|
||||
SerializedSource(double radius, double energy) {
|
||||
radius_ = radius;
|
||||
energy_ = energy;
|
||||
}
|
||||
|
|
@ -25,21 +25,20 @@ class SerialisedSource {
|
|||
// in the input XML document.
|
||||
// Note that the source will have already been read from file, so what will be passed
|
||||
// in here is a string-like serialized value (not the path to the serialized value).
|
||||
static SerialisedSource from_xml(char* serialised_source) {
|
||||
static SerializedSource from_xml(char* serialized_source) {
|
||||
pugi::xml_document doc;
|
||||
doc.load_string(serialised_source);
|
||||
doc.load_string(serialized_source);
|
||||
pugi::xml_node root_node = doc.root().child("Source");
|
||||
double radius = root_node.child("Radius").text().as_double();
|
||||
double energy = root_node.child("Energy").text().as_double();
|
||||
return SerialisedSource(radius, energy);
|
||||
return SerializedSource(radius, energy);
|
||||
}
|
||||
};
|
||||
|
||||
// you must have external C linkage here otherwise
|
||||
// dlopen will not find the file
|
||||
extern "C" openmc::Particle::Bank sample_source(uint64_t* seed, char* serialised_source)
|
||||
{
|
||||
SerialisedSource source = SerialisedSource::from_xml(serialised_source);
|
||||
extern "C" openmc::Particle::Bank sample_source(uint64_t* seed, char* serialized_source) {
|
||||
SerializedSource source = SerializedSource::from_xml(serialized_source);
|
||||
|
||||
openmc::Particle::Bank particle;
|
||||
// wgt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue