# Implementation of Chord Length Sampling(CLS) Method by Modifying OpenMC Code

**URL:** <https://openmc.discourse.group/t/implementation-of-chord-length-sampling-cls-method-by-modifying-openmc-code/2509>\
**Category:** Development\
**Created:** [November 25, 2022, 12:38pm UTC](https://openmc.discourse.group/t/implementation-of-chord-length-sampling-cls-method-by-modifying-openmc-code/2509 "2022-11-25T12:38:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skyawlker](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@skyawlker](https://openmc.discourse.group/u/skyawlker)\
**Post date:** [November 25, 2022, 12:38pm UTC](https://openmc.discourse.group/t/implementation-of-chord-length-sampling-cls-method-by-modifying-openmc-code/2509/1 "2022-11-25T12:38:29Z")

</div>

Hello,everyone  
For the TRISO problem, I noticed that only explicit modeling can be done in OpenMC. I want to solve the TRISO transport problem by modifying the source code of OpenMC to implement the Chord Length Sampling（CLS） Method.The core idea of Chord Length Sampling is to use probability distribution functions to describe the distance(i.e. the chord length) by which the particles will travel in the matric or in the fuel particles. By using the exponential distribution approximately, the positions of new fuel particles are sampled ‘‘on-the-fly’’ during the tracking process rather than being calculated explicitly（Zimmerman, G., Adams, M., 1991. Algorithms for Monte Carlo particle transport in binary statistical media. Trans. Am. Nucl. Soc. 64, 287–288）.  
For OpenMC, I can only use Python API skillfully, but I have no experience in developing Monte Carlo programs. I do not know how to start, so I want to know what I should to learn if I want to realize this idea.

Any help regarding this topic would be very appreciated.

Skywalker

---

<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:** [December 7, 2022, 4:16am UTC](https://openmc.discourse.group/t/implementation-of-chord-length-sampling-cls-method-by-modifying-openmc-code/2509/2 "2022-12-07T04:16:53Z")

</div>

Hi @skyawlker. This sounds like a very interesting idea. In order to implement something like this, you would need to make modifications to the core C++ code. If you haven’t worked with C++ before, picking up a good book on C++ would be the first place you want to start. Once you have some C++ skills, you’ll need to get a sense of how the code fits together. A good place to start might be the [src/simulation.cpp](https://github.com/openmc-dev/openmc/blob/develop/src/simulation.cpp) source file, in particular the `openmc_next_batch` function.

---

<div class="post-metadata">

**Author:** ![skyawlker](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@skyawlker](https://openmc.discourse.group/u/skyawlker)\
**Post date:** [December 8, 2022, 5:37am UTC](https://openmc.discourse.group/t/implementation-of-chord-length-sampling-cls-method-by-modifying-openmc-code/2509/3 "2022-12-08T05:37:34Z")

</div>

Thank you for your guidance@paulromano

I still have a question that OpenMC mentioned in this paper is written in standard Fortran 2008[1], but in fact the current source code is written in C + +, so openmc was rewritten after this article was published ?

[1]Romano P K, Horelik N E, Herman B R, et al. OpenMC: A state-of-the-art Monte Carlo code for research and development[J]. Annals of Nuclear Energy, 2015, 82: 90-97.

---

<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:** [December 8, 2022, 4:52pm UTC](https://openmc.discourse.group/t/implementation-of-chord-length-sampling-cls-method-by-modifying-openmc-code/2509/4 "2022-12-08T16:52:51Z")

</div>

Correct, the rewrite happened primarily in the 2018–2019 timeframe. If you’re interested in the motivation, you can have a look at the [discussion here](https://github.com/openmc-dev/openmc/issues/603).
