Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable fortran preprocessor for fortran interface and then add same l… #308

Merged
merged 22 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ade7a10
Enable fortran preprocessor for fortran interface and then add same l…
dholladay00 Oct 12, 2023
7c9edcc
Actually enabled fortran preprocessor.
dholladay00 Oct 12, 2023
f6349e3
Merge branch 'main' into dholladay00/fpp
dholladay00 Oct 12, 2023
1f0e6a0
Fix of intel compiler error. Thanks Richard for the fixgit add singul…
dholladay00 Oct 18, 2023
c0e11fd
Add more precision to catch info.
dholladay00 Oct 18, 2023
f50b422
fix PTE when downstream code defines its own variant
jdolence Oct 10, 2023
47790a5
formatting
jdolence Oct 10, 2023
ff608ee
make get a host device function
jdolence Oct 10, 2023
fbf8cd8
split test_eos_unit into multiple, easier to read, faster to compile …
jonahm-LANL Oct 12, 2023
d1ba3cb
add CATCH_CONFIG_FAST_COMPILE and split executable into 3
jonahm-LANL Oct 12, 2023
9e47c88
remove some unneeded headers
jonahm-LANL Oct 12, 2023
9f0dabf
shrink the variant in all the translation units
jonahm-LANL Oct 12, 2023
b77437d
formatting and changelog
jonahm-LANL Oct 12, 2023
aea1e95
update docs to reflect changes to test infrastructure
jonahm-LANL Oct 12, 2023
d0df5ab
contributing
jonahm-LANL Oct 12, 2023
429cc0f
Add eos_sap_polynomial to list of headers for install
pbrady Oct 16, 2023
4790958
The golds were not calculated to enough precision. They have been upd…
dholladay00 Oct 23, 2023
8c79d39
merge main.
dholladay00 Oct 23, 2023
653cc14
format.
dholladay00 Oct 23, 2023
67327b7
Modify a currently unbuilt fortran interface test file to test the fo…
dholladay00 Oct 31, 2023
67a2ad6
fix gnu issues that did not appear with intel.
dholladay00 Oct 31, 2023
cc23a92
Modified changelog.
dholladay00 Oct 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [[PR228]](https://github.com/lanl/singularity-eos/pull/228) added untracked header files in cmake
- [[PR215]](https://github.com/lanl/singularity-eos/pull/215) and [[PR216]](https://github.com/lanl/singularity-eos/pull/216) fix duplicate definition of EPS and fix CI
- [[PR232]](https://github.com/lanl/singularity-eos/pull/228) Fixed uninitialized cmake path variables
- [[PR308]](https://github.com/lanl/singularity-eos/pull/308) spack builds +fortran now compile via correct blocking out of interfaces via preprocessor ifdef

### Added (new features/APIs/variables/...)
- [[PR306]](https://github.com/lanl/singularity-eos/pull/306) Added generic Evaluate method
Expand Down Expand Up @@ -48,10 +49,12 @@
- [[PR234]](https://github.com/lanl/singularity-eos/pull/234) update ports-of-call to correct for undefined behavior in error handling
- [[PR219]](https://github.com/lanl/singularity-eos/pull/219) Removed static analysis from re-git pipeline
- [[PR233]](https://github.com/lanl/singularity-eos/pull/233) Exposed entropy for the EOS type (now required for future EOS)
- [[PR308]](https://github.com/lanl/singularity-eos/pull/308) Fortran initialization interface functions no longer require modifier arrays, they are optional parameters.

### Infrastructure (changes irrelevant to downstream codes)
- [[PR190]](https://github.com/lanl/singularity-eos/pull/190) update CI on re-git
- [[PR245]](https://github.com/lanl/singularity-eos/pull/245) Separating get_sg_eos to other files. Build/compilation improvements, warning fixes/suppression.
- [[PR308]](https://github.com/lanl/singularity-eos/pull/308) Added a fortran test.

### Removed (removing behavior/API/varaibles/...)
- [[PR293]](https://github.com/lanl/singularity-eos/pull/293) Removing PTofRE function. This will no longer be callable downstream.
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ if(SINGULARITY_USE_FORTRAN)
target_include_directories(
singularity-eos INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include/singularity-eos/eos>)
set_target_properties(singularity-eos PROPERTIES Fortran_PREPROCESS ON)
endif() # SINGULARITY_USE_FORTRAN

target_include_directories(
Expand Down
6 changes: 3 additions & 3 deletions singularity-eos/eos/modifiers/ramps_eos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ void pAlpha2BilinearRampParams(const T &eos, const Real alpha0, const Real Pe,
template <typename T>
class BilinearRampEOS : public EosBase<BilinearRampEOS<T>> {
public:
// Vector functions that overload the scalar versions declared here.
SG_ADD_BASE_CLASS_USINGS(BilinearRampEOS<T>)

// move semantics ensures dynamic memory comes along for the ride
BilinearRampEOS(T &&t, const Real r0, const Real a, const Real b, const Real c)
: t_(std::forward<T>(t)), r0_(r0), a_(a), b_(b), c_(c),
Expand Down Expand Up @@ -425,9 +428,6 @@ class BilinearRampEOS : public EosBase<BilinearRampEOS<T>> {
t_.ValuesAtReferenceState(rho, temp, sie, press, cv, bmod, dpde, dvdt, lambda);
}

// Vector functions that overload the scalar versions declared here.
SG_ADD_BASE_CLASS_USINGS(BilinearRampEOS<T>)

inline constexpr bool IsModified() const { return true; }

inline constexpr T UnmodifyOnce() { return t_; }
Expand Down
224 changes: 174 additions & 50 deletions singularity-eos/eos/singularity_eos.f90

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ if(SINGULARITY_USE_SPINER)
target_link_libraries(profile_eos singularity-eos::singularity-eos)
endif()

if(SINGULARITY_USE_FORTRAN)
add_executable(ftn_interface test_f_iface.f90)
target_link_libraries(ftn_interface singularity-eos::singularity-eos)
set_target_properties(ftn_interface PROPERTIES LINKER_LANGUAGE Fortran)
add_test(test_fortran_interface ftn_interface)
endif()

if(SINGULARITY_USE_EOSPAC
AND SINGULARITY_TEST_SESAME
AND NOT SINGULARITY_USE_CUDA)
Expand Down
14 changes: 12 additions & 2 deletions test/eos_unit_test_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <cstdio>
#include <cstdlib>

#include <iomanip>
#include <limits>
#include <sstream>

// typename demangler
#ifdef __GNUG__
#include <cstdlib>
Expand Down Expand Up @@ -64,9 +68,15 @@ PORTABLE_INLINE_FUNCTION Real myAtan(Real x, Real shift, Real scale, Real offset
template <typename X, typename Y, typename Z, typename ZT, typename XN, typename YN>
inline void array_compare(int num, X &&x, Y &&y, Z &&z, ZT &&ztrue, XN xname, YN yname,
Real tol = 1e-12) {
assert(num > 0);
using underlying_t =
typename std::remove_cv<typename std::remove_reference<decltype(x[0])>::type>::type;
for (int i = 0; i < num; i++) {
INFO("i: " << i << ", " << xname << ": " << x[i] << ", " << yname << ": " << y[i]
<< ", Value: " << z[i] << ", True Value: " << ztrue[i]);
auto s = std::ostringstream{};
s << std::setprecision(std::numeric_limits<underlying_t>::max_digits10)
<< std::scientific << "i: " << i << ", " << xname << ": " << x[i] << ", " << yname
<< ": " << y[i] << ", Value: " << z[i] << ", True Value: " << ztrue[i];
INFO(s.str());
CHECK(isClose(z[i], ztrue[i], 1e-12));
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_eos_gruneisen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ SCENARIO("Gruneisen EOS density limit") {
INFO("FillEos bmod: " << bmod << ", Lookup bmod: " << bmod_true);
CHECK(bmod == bmod_true);
INFO("FillEos pressure: " << P << ", Lookup pressure: " << pres_true);
CHECK(P == pres_true);
CHECK(isClose(P, pres_true, 1.e-14));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_eos_stellar_collapse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SCENARIO("Test 3D reinterpolation to fast log grid", "[StellarCollapse]") {
constexpr int N2 = 100;
constexpr int N1 = 101;
constexpr int N0 = 102;
StellarCollapse::Grid_t g2(0, 1, N2);
StellarCollapse::Grid_t g2(1.0 / N2, 1, N2);
StellarCollapse::Grid_t g1(1, 3, N1);
StellarCollapse::Grid_t g0(2, 4, N0);
StellarCollapse::DataBox db(N2, N1, N0);
Expand Down
12 changes: 6 additions & 6 deletions test/test_eos_stiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ SCENARIO("StiffGas1", "[StiffGas][StiffGas1]") {

// Gold standard values for a subset of lookups
constexpr std::array<Real, num> pressure_true{
1.0132500000019073e+06, 3.4450500000000000e+07, 6.7887750000001907e+07,
1.0132500000000000e+08};
1.01324999999964016e+06, 3.44504999999983162e+07, 6.78877500000010729e+07,
1.01324999999999583e+08};
constexpr std::array<Real, num> bulkmodulus_true{
2.3502381137500000e+10, 2.3580958675000000e+10, 2.3659536212500004e+10,
2.3738113750000004e+10};
2.35023811375000000e+10, 2.35809586749999962e+10, 2.36595362125000038e+10,
2.37381137500000000e+10};
constexpr std::array<Real, num> temperature_true{
2.9814999999999998e+02, 1.5320999999999999e+03, 2.7660500000000002e+03,
4.0000000000000000e+03};
2.98149999999999920e+02, 1.53209999999999968e+03, 2.76605000000000064e+03,
3.99999999999999955e+03};
constexpr std::array<Real, num> gruneisen_true{1.35, 1.35, 1.35, 1.35};

#ifdef PORTABILITY_STRATEGY_KOKKOS
Expand Down
85 changes: 17 additions & 68 deletions test/test_f_iface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,81 +12,30 @@
! publicly and display publicly, and to permit others to do so.
!------------------------------------------------------------------------------

program test
use bedroom_door_eos
integer :: res, nmat, ncell, i, j, matid
type(bd_eos_ary_t) :: eos
integer, allocatable, dimension(:) :: offsets
real(kind=8), allocatable, dimension(:) :: spvol, sie_tot, vsum, press, pmax
real(kind=8), allocatable, dimension(:) :: temp, bmod, dpde, cv
real(kind=8), allocatable, dimension(:,:) :: frac_mass, frac_vol, frac_sie
real(kind=8) :: vsumint
character(len=64) :: filename
program test_sg_fortran_interface
! modules
use singularity_eos_types
use singularity_eos
! no implicit vars
implicit none
! variable declaration
integer :: nmat, res
type(sg_eos_ary_t) :: eos

ncell = 1
! set test parameters
nmat = 3
filename = "../data/materials.sp5"

! allocate arrays
allocate(spvol(ncell), sie_tot(ncell), temp(ncell), press(ncell), vsum(ncell))
allocate(bmod(ncell), dpde(ncell), cv(ncell), pmax(ncell))
allocate(offsets(ncell))
allocate(frac_mass(ncell, nmat))
allocate(frac_vol(ncell, nmat), frac_sie(ncell, nmat))
! initialize eos's
res = init_bd_eos_f(nmat, eos)
! allocate and initialize eos's
res = init_sg_eos_f(nmat, eos)

res = init_Gruneisen_f(1, eos, 394000.d0, 1.489d0, 0.d0, 0.d0, 2.02d0, 0.47d0,&
res = init_sg_Gruneisen_f(1, eos, 394000.d0, 1.489d0, 0.d0, 0.d0, 2.02d0, 0.47d0,&
8.93d0, 297.0d0, 1.0d6, 0.383d7)
res = init_DavisReactants_f(2, eos, 1.890d0, 4.115d10, 1.0d6, 297.0d0, 1.8d0,&
res = init_sg_DavisReactants_f(2, eos, 1.890d0, 4.115d10, 1.0d6, 297.0d0, 1.8d0,&
4.6d0, 0.34d0, 0.56d0,0.d0, 0.4265d0, 0.001074d10)
res = init_DavisProducts_f(3, eos, 0.798311d0, 0.58d0, 1.35d0, 2.66182d0,&
res = init_sg_DavisProducts_f(3, eos, 0.798311d0, 0.58d0, 1.35d0, 2.66182d0,&
0.75419d0, 3.2d10, 0.001072d10, 0.d0)
!matid = 4272
!res = init_SpinerDependsRhoT_f(2, eos, filename, matid)
!matid = 5030
!res = init_SpinerDependsRhoT_f(3, eos, filename, matid)
! initialize state variables
call srand(10)
press = 0.d0
do i=1,ncell
vsum(i) = 1.0d-2
frac_mass(i,1) = 8.93d0*vsum(i)*0.33
frac_mass(i,2) = 1.89d0*vsum(i)*.033
frac_mass(i,3) = 2.5d0*vsum(i)*0.34
sie_tot(i) = 0.d0
spvol(i) = 0.d0
!vsum(i) = 0.d0
offsets(i) = i
frac_sie(i,1) = 1.16049000000000000d+09
frac_sie(i,2) = 4.50111706015744858d+10
frac_sie(i,3) = 3.29477034927098885d+10
temp(i) = 0.d0
! frac_vols will be normalized in eos call
do j=1,nmat
frac_vol(i,j) = 0.d0
enddo
do j=1,nmat
spvol(i) = spvol(i) + frac_mass(i,j)
sie_tot(i) = sie_tot(i) + frac_mass(i,j)*frac_sie(i,j)
frac_sie(i,j) = frac_sie(i,j)*frac_mass(i,j) ! needs to be energy
enddo
sie_tot(i) = sie_tot(i)/spvol(i)
spvol(i) = vsum(i)/spvol(i)
enddo

!write(*,*) 'spvol', spvol
write(*,*) frac_mass, frac_vol, frac_sie
! calculate PTE eos
res = get_bd_eos_f(nmat, ncell, ncell, 0, eos, offsets, press, pmax, vsum,&
spvol, sie_tot, temp, bmod, dpde, cv, frac_mass, frac_vol,&
frac_sie)

write(*,*) press, cv, bmod, temp
write(*,*) frac_mass, frac_vol, frac_sie
! cleanup
res = finalize_bd_eos_f(nmat, eos)
res = finalize_sg_eos_f(nmat, eos)

deallocate(vsum, sie_tot, spvol, frac_mass, temp, press, frac_vol, frac_sie)
deallocate(bmod, dpde, cv, offsets, pmax)
end program test
end program test_sg_fortran_interface
Loading