MFC icon indicating copy to clipboard operation
MFC copied to clipboard

Unit tests

Open sbryngelson opened this issue 2 years ago • 5 comments

I would be curious to see a PR that attempts to create a unit test for a basic MFC subroutine/feature. Some Fortran packages attempt to automate this process:

  • https://fortranwiki.org/fortran/show/Unit+testing+frameworks
  • https://www.software.ac.uk/blog/2016-09-28-look-fortran-unit-test-frameworks

However I think the easiest solution might be to just write some driver functions/programs that can then call certain subroutines. Some similar arguments are made around the internet, like here:

https://stackoverflow.com/questions/32434904/basic-unit-testing-for-fortran-in-a-locked-down-environment

and

https://groups.google.com/g/comp.lang.fortran/c/CwJdQm1E_iQ

I'm not entirely sure, though, and maybe some package would do the trick.

sbryngelson avatar Jun 07 '23 14:06 sbryngelson

relevant: https://github.com/trixi-framework/HOHQMesh

sbryngelson avatar Nov 12 '23 02:11 sbryngelson

Looking at some of these existing tools and knowing how MFC 'works,' I think using an existing package will be challenging. They often have compiler limitations, introduce a more modern Fortran standard, don't support GPU offload, etc.

It seems like the 'best' solution might be to roll our own. We would need some sort of 'constructor' that creates a data field of the appropriate size. This would take the place of the input data, say the conservative variable fields. Then, these can be inputs to various tests. Many of our subroutines take such fields as inputs (rightfully so, in my view), so it seems these need to be generated a priori.

This would be easier - and not require a constructor - if we used more elemental or pure functions, but I find these to be rather slow on GPU when they are being called so many times per time step.

sbryngelson avatar Nov 13 '23 13:11 sbryngelson

Going to try something here https://github.com/sbryngelson/MFC/tree/unit

sbryngelson avatar Nov 15 '23 03:11 sbryngelson

Starting working on something along these lines. Was curious what other folks are using for unit tests for finite volume schemes. Did not find many examples (at least open source ones). But did find these:

  • https://github.com/thenumbernine/hydro-cl-lua/tree/master/tests
  • https://gitlab.lrz.de/nanoshock/ALPACA/

Overall, not too many unit tests seem obvious here. Some examples I noticed or made up myself are:

  • uniform field gives zero derivatives
  • zero RHS if no source terms and uniform IC
  • making sure equation of state is doing the right thing (giving an expected result)
  • [wip]

sbryngelson avatar Dec 24 '23 05:12 sbryngelson

I sort of ran out of ideas for good unit tests for a CFD solver, especially since MFC wasn't built via TDD. Open to suggestions.

sbryngelson avatar May 01 '24 16:05 sbryngelson

No suggestion for this. Closing for now due to inactivity.

sbryngelson avatar Jul 03 '24 17:07 sbryngelson