-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from NCAR/adding_solver
Added creating solver interface
- Loading branch information
Showing
23 changed files
with
292 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
target_sources(musica-fortran | ||
PUBLIC | ||
interface.F90 | ||
micm_mod.F90 | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
interface | ||
function create_micm_c(config_path) bind(C, name="create_micm") | ||
use iso_c_binding | ||
implicit none | ||
type(c_ptr) :: create_micm_c | ||
character(len=1, kind=C_CHAR), intent(in) :: config_path(*) | ||
end function | ||
|
||
subroutine delete_micm_c(micm_t) bind(C, name="delete_micm") | ||
use iso_c_binding | ||
implicit none | ||
type(c_ptr), value :: micm_t | ||
end subroutine | ||
|
||
function micm_create_solver_c(micm_t) bind(C, name="micm_create_solver") | ||
use iso_c_binding | ||
implicit none | ||
integer(c_int) :: micm_create_solver_c ! TODO(jiwon) return value? | ||
type(c_ptr), intent(in), value :: micm_t | ||
end function | ||
|
||
subroutine micm_solve_c(micm_t, temperature, pressure, time_step, concentrations, num_concentrations) bind(C, name="micm_solve") | ||
use iso_c_binding | ||
implicit none | ||
type(c_ptr), intent(in), value :: micm_t | ||
real(c_double), value :: temperature | ||
real(c_double), value :: pressure | ||
real(c_double), value :: time_step | ||
real(c_double), dimension(*), intent(inout) :: concentrations | ||
integer(c_size_t), value, intent(in) :: num_concentrations | ||
end subroutine | ||
end interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module micm | ||
use iso_c_binding | ||
implicit none | ||
|
||
private | ||
public :: micm_t | ||
|
||
include "micm_c_def.F90" | ||
|
||
type micm_t | ||
private | ||
type(c_ptr) :: ptr | ||
contains | ||
procedure :: create_solver => micm_create_solver | ||
procedure :: solve => micm_solve | ||
final :: delete_micm | ||
end type | ||
|
||
interface micm_t | ||
procedure create_micm | ||
end interface | ||
|
||
contains | ||
function create_micm(config_path) | ||
type(micm_t) :: create_micm | ||
character(len=*), intent(in) :: config_path | ||
character(len=1, kind=C_CHAR) :: c_config_path(len_trim(config_path) + 1) | ||
integer :: N, i | ||
|
||
! Converting Fortran string to C string | ||
N = len_trim(config_path) | ||
do i = 1, N | ||
c_config_path(i) = config_path(i:i) | ||
end do | ||
c_config_path(N + 1) = C_NULL_CHAR | ||
|
||
create_micm%ptr = create_micm_c(c_config_path) | ||
end function | ||
|
||
subroutine delete_micm(this) | ||
type(micm_t) :: this | ||
call delete_micm_c(this%ptr) | ||
end subroutine | ||
|
||
integer function micm_create_solver(this) | ||
class(micm_t), intent(in) :: this | ||
micm_create_solver = micm_create_solver_c(this%ptr) | ||
end function | ||
|
||
subroutine micm_solve(this, temperature, pressure, time_step, concentrations, num_concentrations) | ||
class(micm_t), intent(in) :: this | ||
real(c_double), intent(in) :: temperature | ||
real(c_double), intent(in) :: pressure | ||
real(c_double), intent(in) :: time_step | ||
real(c_double), dimension(*), intent(inout) :: concentrations | ||
integer(c_size_t), intent(in) :: num_concentrations | ||
call micm_solve_c(this%ptr, temperature, pressure, time_step, concentrations, num_concentrations) | ||
end subroutine | ||
|
||
end module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"camp-data": [{"name": "Chapman", "type": "MECHANISM", "reactions": [{"type": "ARRHENIUS", "reactants": {"spec_0": {}, "spec_1": {}, "spec_2": {}}, "products": {"spec_3": {"yield": 0.7}, "spec_4": {"yield": 0.6}, "spec_5": {"yield": 0.4}, "spec_6": {"yield": 0.1}}, "MUSICA name": "reaction_0", "A": 0.06307742014373313, "C": -4.580502916806157}, {"type": "ARRHENIUS", "reactants": {"spec_7": {}, "spec_8": {}}, "products": {"spec_9": {"yield": 1.4}}, "MUSICA name": "reaction_1", "A": 0.04349975747486285, "C": 0.9227077653687363}, {"type": "ARRHENIUS", "reactants": {"spec_3": {}, "spec_6": {}, "spec_8": {}}, "products": {"spec_5": {"yield": 1.2}, "spec_0": {"yield": 0.5}, "spec_7": {"yield": 0.6}, "spec_8": {"yield": 0.3}}, "MUSICA name": "reaction_2", "A": 0.06852791722073094, "C": 3.2487346324460002}, {"type": "ARRHENIUS", "reactants": {"spec_8": {}, "spec_4": {}}, "products": {"spec_9": {"yield": 0.5}, "spec_1": {"yield": 0.7}, "spec_6": {"yield": 1.1}, "spec_8": {"yield": 1.3}, "spec_4": {"yield": 1.2}, "spec_3": {"yield": 0.4}}, "MUSICA name": "reaction_3", "A": 0.25712668426775886, "C": -1.6984663902168808}, {"type": "ARRHENIUS", "reactants": {"spec_9": {}, "spec_1": {}}, "products": {"spec_5": {"yield": 0.6}}, "MUSICA name": "reaction_4", "A": 0.09981506051562195, "C": 4.434345327828195}, {"type": "ARRHENIUS", "reactants": {"spec_8": {}, "spec_1": {}, "spec_3": {}}, "products": {"spec_0": {"yield": 0.7}}, "MUSICA name": "reaction_5", "A": 0.04095822066544459, "C": -0.9768070373515956}, {"type": "ARRHENIUS", "reactants": {"spec_1": {}, "spec_7": {}}, "products": {"spec_8": {"yield": 1.1}, "spec_1": {"yield": 1.5}}, "MUSICA name": "reaction_6", "A": 0.05421274033990674, "C": -2.8281780970323145}, {"type": "ARRHENIUS", "reactants": {"spec_3": {}}, "products": {"spec_5": {"yield": 0.8}, "spec_8": {"yield": 0.6}}, "MUSICA name": "reaction_7", "A": 0.48935553510912033, "C": -4.956655119700008}, {"type": "ARRHENIUS", "reactants": {"spec_3": {}}, "products": {"spec_7": {"yield": 0.9}, "spec_3": {"yield": 1.0}, "spec_2": {"yield": 1.3}}, "MUSICA name": "reaction_8", "A": 0.18950947076801095, "C": 0.04442551245927007}, {"type": "ARRHENIUS", "reactants": {"spec_6": {}}, "products": {"spec_4": {"yield": 0.7}, "spec_9": {"yield": 0.5}, "spec_3": {"yield": 0.8}, "spec_1": {"yield": 0.6}, "spec_5": {"yield": 0.2}}, "MUSICA name": "reaction_9", "A": 0.021971337763203702, "C": -2.81627531289537}]}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"camp-data": [{"name": "spec_0", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_1", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_2", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_3", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_4", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_5", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_6", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_7", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_8", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_9", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
program test_musica_api | ||
use iso_c_binding | ||
use micm | ||
program test | ||
use iso_c_binding | ||
use micm | ||
implicit none | ||
type(micm_t) :: m | ||
|
||
character(len=5, kind=c_char) :: c_filepath | ||
type(c_funptr) :: csolver_func_pointer | ||
c_filepath = 'asdf' | ||
csolver_func_pointer = get_solver(c_filepath) | ||
real(c_double) :: temperature | ||
real(c_double) :: pressure | ||
real(c_double) :: time_step | ||
real(c_double), dimension(10) :: concentrations | ||
integer(c_size_t) :: num_concentrations | ||
|
||
end program test_musica_api | ||
temperature = 10d0 | ||
pressure = 20d0 | ||
time_step = 1d0 | ||
concentrations = (/ 1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0, 10d0 /) | ||
num_concentrations = 10 | ||
|
||
write(*,*) " * [Fortran] Creating MICM" | ||
m = micm_t("micm_config") | ||
|
||
write(*,*) " * [Fortran] Creating solver" | ||
write(*,*) " * [Fortran] Solver creating status indicates ", m%create_solver(), " (1 is success, else failure) " | ||
|
||
write(*,*) " * [Fortran] Initial temp", temperature | ||
write(*,*) " * [Fortran] Initial pressure", pressure | ||
write(*,*) " * [Fortran] Initial time_step", time_step | ||
write(*,*) " * [Fortran] Initial concentrations", concentrations | ||
write(*,*) " * [Fortran] Initial number of concentrations", num_concentrations | ||
|
||
write(*,*) " * [Fortran] Starting to solve" | ||
call m%solve(temperature, pressure, time_step, concentrations, num_concentrations) | ||
write(*,*) " * [Fortran] After solving, concentrations", concentrations | ||
|
||
write(*,*) " * [Fortran] Calling destructor for MICM" | ||
call m%delete | ||
|
||
end program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <cstddef> | ||
|
||
#include <micm/solver/rosenbrock.hpp> | ||
#include <micm/util/sparse_matrix_vector_ordering.hpp> | ||
#include <micm/util/vector_matrix.hpp> | ||
|
||
|
||
class MICM | ||
{ | ||
public: | ||
MICM(const std::string& config_path); | ||
~MICM(); | ||
|
||
// TODO(jiwon): can return type indicate error? | ||
int create_solver(); | ||
void solve(double temperature, double pressure, double time_step, double*& concentrations, size_t num_concentrations); | ||
|
||
private: | ||
static constexpr size_t NUM_GRID_CELLS = 1; // TODO(jiwon) | ||
|
||
std::string config_path_; | ||
|
||
// TODO(jiwon) - currently hard coded | ||
std::vector<double> v_concentrations_; | ||
|
||
// TODO(jiwon) - currently hard coded | ||
template <class T = double> | ||
using Vector1MatrixParam = micm::VectorMatrix<T, 1>; | ||
template <class T = double> | ||
using Vector1SparseMatrixParam = micm::SparseMatrix<T, micm::SparseMatrixVectorOrdering<1>>; | ||
typedef micm::RosenbrockSolver<Vector1MatrixParam, Vector1SparseMatrixParam> VectorRosenbrockSolver; | ||
VectorRosenbrockSolver* solver_; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <cstddef> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
class MICM; | ||
typedef MICM Micm; | ||
#endif | ||
|
||
Micm* create_micm(const char* config_path); | ||
void delete_micm(const Micm* micm); | ||
int micm_create_solver(Micm* micm); | ||
void micm_solve(Micm* micm, double temperature, double pressure, double time_step, | ||
double* concentrations, size_t num_concentrations); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
target_sources(musica | ||
PRIVATE | ||
interface.cpp | ||
micm_c_api.cpp | ||
micm.cpp | ||
) |
Oops, something went wrong.