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

Return MICM solver state details from MicmSolve() #145

Merged
merged 115 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 113 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
4141b8b
test adding clang tidy
boulderdaze May 23, 2024
2898dc0
add header filter
boulderdaze May 23, 2024
e5d1ba8
add clang tidy
boulderdaze May 23, 2024
d12ba99
test exclude header
boulderdaze May 24, 2024
1407c7d
fix typo
boulderdaze May 24, 2024
eed79aa
test with continue on
boulderdaze May 24, 2024
49894ae
remove exclude header
boulderdaze May 24, 2024
7fc87c4
fix a bug
boulderdaze May 24, 2024
e9c7ee6
change the branch name
boulderdaze May 24, 2024
0f9d32d
revert back
boulderdaze May 24, 2024
7af747e
strating the grids data types and functions
K20shores May 28, 2024
9d3d031
starting to rough out the apis
K20shores May 28, 2024
38c438f
clang tidy
boulderdaze May 28, 2024
4de4be9
Merge branch 'main' into 128-clang-tidy
boulderdaze May 28, 2024
915360f
Merge branch 'main' into 128-clang-tidy
boulderdaze May 28, 2024
4eeb639
fix python bug
boulderdaze May 29, 2024
57a725e
some changes
K20shores May 30, 2024
1f533e9
calling interanl function
K20shores May 30, 2024
73f411c
need to resolve error handling in both tuvx and micm
K20shores May 30, 2024
93304ed
trying to figure out why there's an error
K20shores May 30, 2024
7da894c
removing nullptr argument on tuvx
K20shores May 30, 2024
8ea9e3b
it compiles, one test fails
K20shores May 31, 2024
b15d7b9
disabling bad configuration test until tuvx is fixed
K20shores May 31, 2024
ddc50a6
Merge branch 'main' into 128-clang-tidy
boulderdaze May 31, 2024
5666b54
fix C function name
boulderdaze May 31, 2024
1eb28d5
grid warehouse pointer now in fortran
K20shores May 31, 2024
a48047e
addig comments
K20shores Jun 3, 2024
b7e001b
saving progress
K20shores Jun 3, 2024
1c099f5
merging
K20shores Jun 3, 2024
468a6ba
fix memcheck failure
boulderdaze Jun 4, 2024
801807d
code review fix
boulderdaze Jun 4, 2024
ab02501
git tag
boulderdaze Jun 4, 2024
bcbca11
adding something that almost gets a grid, adding comments, styling
K20shores Jun 4, 2024
99f9ea6
set git tag to main
boulderdaze Jun 4, 2024
9114e7d
fixing pointer assignment
K20shores Jun 4, 2024
419e7bb
saving progress
K20shores Jun 4, 2024
8e02aeb
not use nampespace fs
boulderdaze Jun 5, 2024
09bdb5c
passing by value
K20shores Jun 5, 2024
d718896
Merge branch 'main' into 128-clang-tidy
boulderdaze Jun 5, 2024
96175de
saving progress
K20shores Jun 5, 2024
6a5ed1d
setting edges and midpoints
K20shores Jun 5, 2024
382a6e4
adding comments
K20shores Jun 5, 2024
34144db
deleted grid, grid map
K20shores Jun 5, 2024
c434d8b
merging main
K20shores Jun 5, 2024
b1e403d
handling merge
K20shores Jun 6, 2024
99d75b9
applying style changes
K20shores Jun 6, 2024
5c6fc89
removing mod files
K20shores Jun 7, 2024
77dc123
add solver stats
boulderdaze Jun 12, 2024
ae95ebe
checking that the configuraiton file exists, making delete string c p…
K20shores Jun 12, 2024
cccc12a
updating tuvx tag
K20shores Jun 12, 2024
cc3510e
just passing char* from c++ to fortran
K20shores Jun 12, 2024
a7481c7
serial build
K20shores Jun 12, 2024
013fae0
more serial builds
K20shores Jun 12, 2024
e428cd6
setting fortran compiler
K20shores Jun 12, 2024
030c49b
setting fortran compiler
K20shores Jun 12, 2024
ba31c9c
installing dependencies
K20shores Jun 12, 2024
8004834
setting fortran compiler for clang
K20shores Jun 12, 2024
409cfd6
using a branch that sets PIC on tuvx
K20shores Jun 12, 2024
37b2dee
stubbing tests
K20shores Jun 12, 2024
34c8a33
seeing if the python build is the problem
K20shores Jun 12, 2024
6f0a5e8
removing flags specific to apple that may no longer be necessary?
K20shores Jun 12, 2024
250e1b7
disabling python build
K20shores Jun 12, 2024
d515ecc
update the test
boulderdaze Jun 12, 2024
f725b63
resolve merge conflicts
boulderdaze Jun 12, 2024
d6d4291
trying a new micm tag
K20shores Jun 12, 2024
422d8c5
using new way to construct a solver
K20shores Jun 13, 2024
b4a3027
continue on error
K20shores Jun 13, 2024
14592dd
update python wrapper
boulderdaze Jun 13, 2024
844107f
continue on fail for ubunut
K20shores Jun 13, 2024
d3bab0b
continue on error
K20shores Jun 13, 2024
8db2ab2
fixing some memory leaks
K20shores Jun 13, 2024
0b78e65
fixing some memory leaks
K20shores Jun 14, 2024
f29504e
fixing another memory leak
K20shores Jun 14, 2024
cec4cb6
maybe the last memory error
K20shores Jun 14, 2024
9407452
proper error handling
K20shores Jun 14, 2024
b5a306e
better actions trigger
K20shores Jun 14, 2024
2d92270
better action trigger
K20shores Jun 14, 2024
4cd6877
printing branch name
K20shores Jun 14, 2024
a6b22dd
printing branch
K20shores Jun 14, 2024
2d268f1
Merge branch 'main' into 43-add-run-function-to-tuv-x-wrapper
K20shores Jun 14, 2024
91831c8
copying tuvx data
K20shores Jun 14, 2024
2b39c7e
trying to correct the fortran things
K20shores Jun 14, 2024
eafa650
parallel builds, removing unused github actions steps
K20shores Jun 14, 2024
92cf5a1
removing print statements
K20shores Jun 17, 2024
d98510d
changing name in github actions
K20shores Jun 17, 2024
8b998ce
trying to update suppression file to match new names
K20shores Jun 17, 2024
f2d03ba
maybe a different leak kind
K20shores Jun 17, 2024
28efdc0
fixing gcc memory leak, removing 2019 msvc github action
K20shores Jun 17, 2024
6f2ce36
adding back python build on macos
K20shores Jun 17, 2024
657b1d6
enabling tuvx on mac
K20shores Jun 17, 2024
22d18e0
Merge branch '43-add-run-function-to-tuv-x-wrapper' into 83-solver-re…
boulderdaze Jun 17, 2024
46c9243
thirdbody
boulderdaze Jun 17, 2024
0d14d2c
resolve merge conflicts
boulderdaze Jun 18, 2024
91dc9fd
resolve merge issue
boulderdaze Jun 18, 2024
ed4834a
remove solvler results test
boulderdaze Jun 18, 2024
e791a4c
changing cmake module variable
K20shores Jun 18, 2024
2913eb6
remove third body
boulderdaze Jun 18, 2024
2245400
build type
boulderdaze Jun 18, 2024
ad0c0ae
update git tag for fetch content
boulderdaze Jun 18, 2024
e0077b3
make solver stats public
boulderdaze Jun 18, 2024
e9b6712
solver stats initialization
boulderdaze Jun 18, 2024
18e515b
add constructor
boulderdaze Jun 18, 2024
2b849de
add default constructor
boulderdaze Jun 18, 2024
7cd638e
update constructor
boulderdaze Jun 18, 2024
1d95571
changing to projest specific variables
K20shores Jun 20, 2024
8550280
fetch content from src for testing
boulderdaze Jun 20, 2024
8424dd3
Merge branch 'fixing_fetch_content_tests' into 83-solver-result
boulderdaze Jun 20, 2024
6371208
handling copy tuvx data by cmake
boulderdaze Jun 21, 2024
f7e4f2c
code cleanup
boulderdaze Jun 21, 2024
19b6a05
fix a bug
boulderdaze Jun 21, 2024
e752ca0
seperate solver state from solver result stats
boulderdaze Jun 21, 2024
3d13cea
update fortran wrapper
boulderdaze Jun 21, 2024
9031a53
clang format
boulderdaze Jun 21, 2024
2d4e56a
resolve stash conflict
boulderdaze Jun 24, 2024
7116a7f
merge main
boulderdaze Jun 24, 2024
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(
VERSION 0.6.1
)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH};${CMAKE_CURRENT_LIST_DIR}/cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH};${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_MODULE_PATH}/SetDefaults.cmake)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

Expand Down
6 changes: 3 additions & 3 deletions cmake/summary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ else()
endif()

# Configure musica.settings file
configure_file("${CMAKE_SOURCE_DIR}/cmake/musica.settings.in"
"${CMAKE_BINARY_DIR}/musica.settings"
configure_file("${PROJECT_SOURCE_DIR}/cmake/musica.settings.in"
"${PROJECT_BINARY_DIR}/musica.settings"
@ONLY)

# Read in settings file, print out.
# Avoid using system-specific calls so that this
# might also work on Windows.
file(READ "${CMAKE_BINARY_DIR}/musica.settings"
file(READ "${PROJECT_BINARY_DIR}/musica.settings"
MUSICA_SETTINGS)
message(STATUS ${MUSICA_SETTINGS})
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM fedora:35

ARG BUILD_TYPE=Release

RUN dnf -y update \
&& dnf -y install \
cmake \
Expand All @@ -23,6 +25,7 @@ COPY . musica
RUN cd musica \
&& cmake -S . \
-B build \
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
&& cd build \
&& make install -j 8

Expand Down
9 changes: 4 additions & 5 deletions docker/Dockerfile.fortran-gcc.integration
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM fedora:35

ARG MUSICA_GIT_TAG=main
ARG BUILD_TYPE=Release

RUN dnf -y update \
&& dnf -y install \
Expand Down Expand Up @@ -37,20 +38,18 @@ COPY . musica
RUN cd musica \
&& cmake -S . \
-B build \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
&& cd build \
&& make install -j

# Build and install MUSICA
RUN cd musica/fortran/test/fetch_content_integration \
&& mkdir build && cd build \
&& cmake .. \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
-D MUSICA_GIT_TAG=${MUSICA_GIT_TAG} \
-D MUSICA_ENABLE_MICM=ON \
-D MUSICA_ENABLE_TUVX=OFF \
&& make -j

WORKDIR musica/fortran/test/fetch_content_integration/build
RUN cp -r /musica/build/_deps/tuvx-src/examples/ .
RUN cp -r /musica/build/_deps/tuvx-src/data/ .
WORKDIR musica/fortran/test/fetch_content_integration/build
4 changes: 1 addition & 3 deletions docker/Dockerfile.fortran-nvhpc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,4 @@ RUN cd musica/fortran/test/fetch_content_integration \
-D MUSICA_GIT_TAG=${MUSICA_GIT_TAG} \
&& make -j

WORKDIR musica/fortran/test/fetch_content_integration/build
RUN cp -r /musica/build/_deps/tuvx-src/examples/ .
RUN cp -r /musica/build/_deps/tuvx-src/data/ .
WORKDIR musica/fortran/test/fetch_content_integration/build
209 changes: 183 additions & 26 deletions fortran/micm.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@
!
module musica_micm
#define ASSERT( expr ) call assert( expr, __FILE__, __LINE__ )
use iso_c_binding, only: c_ptr, c_char, c_int, c_bool, c_double, c_null_char, &
use iso_c_binding, only: c_ptr, c_char, c_int, c_int64_t, c_bool, c_double, c_null_char, &
c_size_t, c_f_pointer, c_funptr, c_null_ptr, c_associated
use musica_util, only: assert, mapping_t
use iso_fortran_env, only: int64
use musica_util, only: assert, mapping_t, string_t, string_t_c
implicit none

public :: get_micm_version, micm_t
public :: micm_t, solver_stats_t, get_micm_version
private

!> Wrapper for c solver stats
type, bind(c) :: solver_stats_t_c
integer(c_int64_t) :: function_calls_ = 0_c_int64_t
integer(c_int64_t) :: jacobian_updates_ = 0_c_int64_t
integer(c_int64_t) :: number_of_steps_ = 0_c_int64_t
integer(c_int64_t) :: accepted_ = 0_c_int64_t
integer(c_int64_t) :: rejected_ = 0_c_int64_t
integer(c_int64_t) :: decompositions_ = 0_c_int64_t
integer(c_int64_t) :: solves_ = 0_c_int64_t
integer(c_int64_t) :: singular_ = 0_c_int64_t
real(c_double) :: final_time_ = 0._c_double
end type solver_stats_t_c

interface
function get_micm_version_c() bind(C, name="get_micm_version")
use musica_util, only: string_t_c
type(string_t_c) :: get_micm_version_c
end function get_micm_version_c

function create_micm_c(config_path, error) bind(C, name="CreateMicm")
use musica_util, only: error_t_c
import c_ptr, c_int, c_char
Expand All @@ -34,9 +42,10 @@ subroutine delete_micm_c(micm, error) bind(C, name="DeleteMicm")
end subroutine delete_micm_c

subroutine micm_solve_c(micm, time_step, temperature, pressure, num_concentrations, concentrations, &
num_user_defined_reaction_rates, user_defined_reaction_rates, error) bind(C, name="MicmSolve")
use musica_util, only: error_t_c
import c_ptr, c_double, c_int
num_user_defined_reaction_rates, user_defined_reaction_rates, solver_state, solver_stats, error) &
bind(C, name="MicmSolve")
use musica_util, only: string_t_c, error_t_c
import c_ptr, c_double, c_int, solver_stats_t_c
type(c_ptr), value, intent(in) :: micm
real(kind=c_double), value, intent(in) :: time_step
real(kind=c_double), value, intent(in) :: temperature
Expand All @@ -45,9 +54,16 @@ subroutine micm_solve_c(micm, time_step, temperature, pressure, num_concentratio
real(kind=c_double), intent(inout) :: concentrations(num_concentrations)
integer(kind=c_int), value, intent(in) :: num_user_defined_reaction_rates
real(kind=c_double), intent(inout) :: user_defined_reaction_rates(num_user_defined_reaction_rates)
type(string_t_c), intent(out) :: solver_state
type(solver_stats_t_c), intent(out) :: solver_stats
type(error_t_c), intent(inout) :: error
end subroutine micm_solve_c

function get_micm_version_c() bind(C, name="MicmVersion")
use musica_util, only: string_t_c
type(string_t_c) :: get_micm_version_c
end function get_micm_version_c

function get_species_property_string_c(micm, species_name, property_name, error) bind(c, name="GetSpeciesPropertyString")
use musica_util, only: error_t_c, string_t_c
import c_ptr, c_char
Expand Down Expand Up @@ -128,6 +144,33 @@ end subroutine delete_mappings_c
procedure constructor
end interface micm_t

!> Solver stats type
type :: solver_stats_t
integer(int64) :: function_calls_
integer(int64) :: jacobian_updates_
integer(int64) :: number_of_steps_
integer(int64) :: accepted_
integer(int64) :: rejected_
integer(int64) :: decompositions_
integer(int64) :: solves_
integer(int64) :: singular_
real :: final_time_
contains
procedure :: function_calls => solver_stats_t_function_calls
procedure :: jacobian_updates => solver_stats_t_jacobian_updates
procedure :: number_of_steps => solver_stats_t_number_of_steps
procedure :: accepted => solver_stats_t_accepted
procedure :: rejected => solver_stats_t_rejected
procedure :: decompositions => solver_stats_t_decompositions
procedure :: solves => solver_stats_t_solves
procedure :: singular => solver_stats_t_singular
procedure :: final_time => solver_stats_t_final_time
end type solver_stats_t

interface solver_stats_t
procedure solver_stats_t_constructor
end interface solver_stats_t

contains

function get_micm_version() result(value)
Expand Down Expand Up @@ -189,24 +232,138 @@ function constructor(config_path, error) result( this )
end function constructor

subroutine solve(this, time_step, temperature, pressure, num_concentrations, concentrations, &
num_user_defined_reaction_rates, user_defined_reaction_rates, error)
use musica_util, only: error_t_c, error_t
class(micm_t) :: this
real(c_double), intent(in) :: time_step
real(c_double), intent(in) :: temperature
real(c_double), intent(in) :: pressure
integer(c_int), intent(in) :: num_concentrations
real(c_double), intent(inout) :: concentrations(*)
integer(c_int), intent(in) :: num_user_defined_reaction_rates
real(c_double), intent(inout) :: user_defined_reaction_rates(*)
type(error_t), intent(out) :: error

type(error_t_c) :: error_c
num_user_defined_reaction_rates, user_defined_reaction_rates, solver_state, solver_stats, error)
use musica_util, only: string_t, string_t_c, error_t_c, error_t
class(micm_t) :: this
real(c_double), intent(in) :: time_step
real(c_double), intent(in) :: temperature
real(c_double), intent(in) :: pressure
integer(c_int), intent(in) :: num_concentrations
real(c_double), intent(inout) :: concentrations(*)
integer(c_int), intent(in) :: num_user_defined_reaction_rates
real(c_double), intent(inout) :: user_defined_reaction_rates(*)
type(string_t), intent(out) :: solver_state
type(solver_stats_t), intent(out) :: solver_stats
type(error_t), intent(out) :: error

type(string_t_c) :: solver_state_c
type(solver_stats_t_c) :: solver_stats_c
type(error_t_c) :: error_c
call micm_solve_c(this%ptr, time_step, temperature, pressure, num_concentrations, concentrations, &
num_user_defined_reaction_rates, user_defined_reaction_rates, error_c)
num_user_defined_reaction_rates, user_defined_reaction_rates, solver_state_c, solver_stats_c, error_c)
solver_state = string_t(solver_state_c)
solver_stats = solver_stats_t(solver_stats_c)
error = error_t(error_c)
end subroutine solve

!> Constructor for solver_stats_t object that takes ownership of solver_stats_t_c
function solver_stats_t_constructor( c_solver_stats ) result( new_solver_stats )
use iso_fortran_env, only: int64
use musica_util, only: string_t
type(solver_stats_t_c), intent(inout) :: c_solver_stats
type(solver_stats_t) :: new_solver_stats

new_solver_stats%function_calls_ = c_solver_stats%function_calls_
new_solver_stats%jacobian_updates_ = c_solver_stats%jacobian_updates_
new_solver_stats%number_of_steps_ = c_solver_stats%number_of_steps_
new_solver_stats%accepted_ = c_solver_stats%accepted_
new_solver_stats%rejected_ = c_solver_stats%rejected_
new_solver_stats%decompositions_ = c_solver_stats%decompositions_
new_solver_stats%solves_ = c_solver_stats%solves_
new_solver_stats%singular_ = c_solver_stats%singular_
new_solver_stats%final_time_ = real( c_solver_stats%final_time_ )

end function solver_stats_t_constructor

!> Get the number of forcing function calls
function solver_stats_t_function_calls( this ) result( function_calls )
use iso_fortran_env, only: int64
class(solver_stats_t), intent(in) :: this
integer(int64) :: function_calls

function_calls = this%function_calls_

end function solver_stats_t_function_calls

!> Get the number of jacobian function calls
function solver_stats_t_jacobian_updates( this ) result( jacobian_updates )
use iso_fortran_env, only: int64
class(solver_stats_t), intent(in) :: this
integer(int64) :: jacobian_updates

jacobian_updates = this%jacobian_updates_

end function solver_stats_t_jacobian_updates

!> Get the total number of internal time steps taken
function solver_stats_t_number_of_steps( this ) result( number_of_steps )
use iso_fortran_env, only: int64
class(solver_stats_t), intent(in) :: this
integer(int64) :: number_of_steps

number_of_steps = this%number_of_steps_

end function solver_stats_t_number_of_steps

!> Get the number of accepted integrations
function solver_stats_t_accepted( this ) result( accepted )
use iso_fortran_env, only: int64
class(solver_stats_t), intent(in) :: this
integer(int64) :: accepted

accepted = this%accepted_

end function solver_stats_t_accepted

!> Get the number of rejected integrations
function solver_stats_t_rejected( this ) result( rejected )
use iso_fortran_env, only: int64
class(solver_stats_t), intent(in) :: this
integer(int64) :: rejected

rejected = this%rejected_

end function solver_stats_t_rejected

!> Get the number of LU decompositions
function solver_stats_t_decompositions( this ) result( decompositions )
use iso_fortran_env, only: int64
class(solver_stats_t), intent(in) :: this
integer(int64) :: decompositions

decompositions = this%decompositions_

end function solver_stats_t_decompositions

!> Get the number of linear solves
function solver_stats_t_solves( this ) result( solves )
use iso_fortran_env, only: int64
class(solver_stats_t), intent(in) :: this
integer(int64) :: solves

solves = this%solves_

end function solver_stats_t_solves

!> Get the number of times a singular matrix is detected
function solver_stats_t_singular( this ) result( singular )
use iso_fortran_env, only: int64
class(solver_stats_t), intent(in) :: this
integer(int64) :: singular

singular = this%function_calls_

end function solver_stats_t_singular

!> Get the final time the solver iterated to
function solver_stats_t_final_time( this ) result( final_time )
class(solver_stats_t), intent(in) :: this
real :: final_time

final_time = this%final_time_

end function solver_stats_t_final_time

function get_species_property_string(this, species_name, property_name, error) result(value)
use musica_util, only: error_t_c, error_t, string_t, string_t_c, to_c_string
class(micm_t), intent(inout) :: this
Expand Down Expand Up @@ -273,4 +430,4 @@ subroutine finalize(this)
ASSERT(error%is_success())
end subroutine finalize

end module musica_micm
end module musica_micm
10 changes: 10 additions & 0 deletions fortran/test/fetch_content_integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,14 @@ if (MUSICA_ENABLE_TUVX)
COMMAND $<TARGET_FILE:test_tuvx_fortran_api>
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)

add_custom_target(
copy_tuvx_examples_dir ALL ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/../../../build/_deps/tuvx-src/examples ${CMAKE_BINARY_DIR}/examples
)

add_custom_target(
copy_tuvx_data_dir ALL ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/../../../build/_deps/tuvx-src/data ${CMAKE_BINARY_DIR}/data
)
endif()
Loading
Loading