Dear all, Question on openmc program using custom_source example

Dear all:
I tried to use the openmc program (version 0.12.1) under Ubuntu 18.04 system to run the example of external source——custom_source.

I followed the steps in the manual and produced the libsource.so file.

But when we run the openmc program, the program reports an error, stating that the libsource.so file cannot be opened. The screenshot of the error is as follows.

How to solve this problem?

Best wishes,
William Xia

image

Hi @William_Xia and welcome to the forum! The setup for custom sources did change recently. If you look at the documentation for the developmental branch, you’ll see that it now expects you to write a class that derives from openmc::Source and overrides the source method. In addition, you need to have a function called openmc_create_source that creates a unique pointer to an instance of this class. If you were using the previous convention (a sample_source function that returns a openmc::Particle::Bank) it shouldn’t be too difficult to modify it to what OpenMC expects now.

Dear paul romano,
Thank you very much for your Selfless teaching.
And I have another question on coupling MCNPX and OpenMC(version 0.12.0).
I would like to calculate an ADS problem by coupling MCNPX and OpenMC.
But an example of the external source of OpenMC(version 0.12.0) is cpp file.
Could the OpenMC of version 0.12.0 read the external source sampling wssa file generated by the MCNPX?
Or is there any other way to realize the coupling MCNPX and OpenMC(version 0.12.0)?
Best wishes,
William Xia

Our next release (0.12.1) includes a surface source reading/writing ability that is similar to what appears in MCNP. I think a possible path forward would be to use the SurfSrc class from PyNE to read the MCNP wssa file and then use openmc.write_source_file to create a source file that OpenMC could read.

Dear paul romano,
@paulromano
Thank you very much for your Selfless teaching.
I have read the wssa file using the PyNE SurfSrc class (provided by PyNE), but it cannot directly generate source files readable by openmc.
For the reading of wssa file data, I have used ssw2txt.py in mc-tools (GitHub - kbat/mc-tools: Some Monte Carlo tools) to convert the wssa file into a text file—wssa.txt.
Part of the results of wssa can be seen in the screenshot below.


How to process wssa file into the file needed by openmc.write_source_file?
Should the hexadecimal wssa file be processed directly or the text file wssa.txt?
Is there a related python script?
Best wishes,
William Xia

You’ll need to read the data from that file, create a list of SourceParticle objects, and then use write_source_file. Altogether, it should look something like:

fh = open('wssa.txt', 'r')
next(fh) # skip first line
particles = []
for line in fh:
    values = line.split()
    weight = float(values[2])
    energy = float(values[3])
    x = float(values[4])
    y = float(values[5])
    z = float(values[6])
    ...
    p = openmc.SourceParticle(E=energy, wgt=weight, r=(x, y, z), ...)
    particles.append(p)

openmc.write_source_file(particles, 'source.h5')

Dear @paulromano,
I have generated the source.h5 file according to your suggestions (See the screenshot below for its structure).
image
But the program still does not run successfully. (See the screenshot below for the error).
image
Can you help me find out what the reason is?
The relevant documents are attached, thank you very much.
Best wishes,
William Xia
MUSE4_external_source.py (6.5 KB)
source_8.h5

I suspect the error you’re seeing may be due to the same problem described here:

If you’re recently updated OpenMC, you may need to regenerate the source file using the write_source_file function.