openmc-dev / openmc

OpenMC Monte Carlo Code
https://docs.openmc.org
Other
699 stars 444 forks source link

update math function unit test with catch2 #2955

Open lhchg opened 2 weeks ago

lhchg commented 2 weeks ago

Description

Some interfaces do not need to be exposed to the python API, except for unit testing, so move math unit tests to C++ unit tests, which implemented in python before

Fixes #2943

Checklist

lhchg commented 2 weeks ago

Sorry, seems some error will be introduced. I'm checking

lhchg commented 1 week ago

Hi @paulromano @gridley

I updated the code to use hardcode for the reference part. And I think if included a python script to generate the reference part, maybe this would introduce new python package dependencies when running the catch2 unit tests?

What do you think of this hardcode approach?

If you think it would be better to include a python script, I will continue to modify it.

lhchg commented 5 days ago

There seems to be some dependency on the python math api

self = <openmc.polynomial.ZernikeRadial object at 0x7fe6bfe0dc90>, r = 0.196

    def __call__(self, r):
        import openmc.lib as lib
        if isinstance(r, Iterable):
            return [np.sum(self._norm_coef * lib.calc_zn_rad(self.order, r_i / self.radius))
                    for r_i in r]
        else:
>           return np.sum(self._norm_coef * lib.calc_zn_rad(self.order, r / self.radius))
E           AttributeError: module 'openmc.lib' has no attribute 'calc_zn_rad'

openmc/polynomial.py:82: AttributeError

I have fixed it