# Can I use surf\_source\_write to write neutron going inside a cylinder？

**URL:** <https://openmc.discourse.group/t/can-i-use-surf-source-write-to-write-neutron-going-inside-a-cylinder/2310>\
**Category:** User Support\
**Created:** [September 23, 2022, 11:43am UTC](https://openmc.discourse.group/t/can-i-use-surf-source-write-to-write-neutron-going-inside-a-cylinder/2310 "2022-09-23T11:43:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pun](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@pun](https://openmc.discourse.group/u/pun)\
**Post date:** [September 23, 2022, 11:43am UTC](https://openmc.discourse.group/t/can-i-use-surf-source-write-to-write-neutron-going-inside-a-cylinder/2310/1 "2022-09-23T11:43:21Z")

</div>

Dear Sir

Can I use surf\_source\_write to write neutron going inside a cylinder？

Best Regards,  
Pu

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [September 23, 2022, 1:08pm UTC](https://openmc.discourse.group/t/can-i-use-surf-source-write-to-write-neutron-going-inside-a-cylinder/2310/2 "2022-09-23T13:08:20Z")

</div>

@pun welcome to the OpenMC community! `surf_source_write` is used to write particles to a source file at the point where they cross the surface. Let me know if that still doesn’t answer your question.

---

<div class="post-metadata">

**Author:** ![pun](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@pun](https://openmc.discourse.group/u/pun)\
**Post date:** [September 28, 2022, 7:36am UTC](https://openmc.discourse.group/t/can-i-use-surf-source-write-to-write-neutron-going-inside-a-cylinder/2310/4 "2022-09-28T07:36:19Z")

</div>

Dear Paul  
Thank you for your reply.

I tried to use surf\_source\_write to generate surface source crossing the surface ID 2 in a example pincell. However I got error as follow:

Traceback (most recent call last):  
File “build\_xml.py”, line 72, in  
settings.surf\_source\_write = {‘surfaces\_ids’: [2],‘max\_particles’: 1000000}  
File “/usr/local/lib/python3.8/dist-packages/openmc/settings.py”, line 606, in surf\_source\_write  
cv.check\_value(‘surface source writing key’, key,  
File “/usr/local/lib/python3.8/dist-packages/openmc/checkvalue.py”, line 190, in check\_value  
raise ValueError(msg)  
ValueError: Unable to set “surface source writing key” to “surfaces\_ids” since it is not in “(‘surface\_ids’, ‘max\_particles’)”

Then, I tried to add \<surf\_source\_write\> into setting file to run openmc. In this time, openmc can be run well. There are source particles in the surface source file.  
\<surf\_source\_write\>  
\<surface\_ids\>2\</surface\_ids\>  
\<max\_particles\>1000000\</max\_particles\>  
\</surf\_source\_write\>

However, when I change 2 to -2 in surface id and run openmc, I can not obtain particle in the surface source file.

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [September 29, 2022, 4:25am UTC](https://openmc.discourse.group/t/can-i-use-surf-source-write-to-write-neutron-going-inside-a-cylinder/2310/6 "2022-09-29T04:25:45Z")

</div>

The first problem is that you should have `'surface_id'` as a key in the dictionary, not `'surfaces_id'`:

```python
settings.surf_source_write = {'surfaces_id': [2], 'max_particles': 1000000}

```

> [@pun](#):
>
> when I change 2 to -2 in surface id and run openmc, I can not obtain particle in the surface source file.

Currently you can only specify a surface ID, not a specific side of the surface. If you specify surface 2, all particles that pass surface 2 (from either side) will be captured up the the max particles limit.

---

<div class="post-metadata">

**Author:** ![pun](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@pun](https://openmc.discourse.group/u/pun)\
**Post date:** [September 29, 2022, 11:02am UTC](https://openmc.discourse.group/t/can-i-use-surf-source-write-to-write-neutron-going-inside-a-cylinder/2310/7 "2022-09-29T11:02:26Z")

</div>

> [@paulromano](#):
>
> Currently you can only specify a surface ID, not a specific side of the surface. If you specify surface 2, all particles that pass surface 2 (from either side) will be captured up the the max particles limit.

@paulromano Thank you for your reply. I found my mistake.  
I think particles going into cylinder and go out from other side. Thus, there are no particle recording in out file.

I would like to use OpenMC to couple with other code. Therefore, I need to use a surface source with particle direction inside a cylinder or sphere.  
Look forward to your update version!!!
