Skip to content

Commit 67707e9

Browse files
committed
..
1 parent 6a6b537 commit 67707e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1738
-7
lines changed

models/model_dirac_py/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Build AMICI model
2+
cmake_minimum_required(VERSION 3.22)
3+
cmake_policy(VERSION 3.22...3.31)
4+
5+
project(model_dirac_py)
6+
7+
set(CMAKE_CXX_STANDARD 17)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
10+
11+
include(CheckCXXCompilerFlag)
12+
set(MY_CXX_FLAGS -Wall -Wno-unused-function -Wno-unused-variable)
13+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
14+
list(APPEND MY_CXX_FLAGS -Wno-unused-but-set-variable)
15+
endif()
16+
foreach(flag ${MY_CXX_FLAGS})
17+
unset(CUR_FLAG_SUPPORTED CACHE)
18+
check_cxx_compiler_flag(${flag} CUR_FLAG_SUPPORTED)
19+
if(${CUR_FLAG_SUPPORTED})
20+
string(APPEND CMAKE_CXX_FLAGS " ${flag}")
21+
endif()
22+
endforeach()
23+
24+
if(DEFINED ENV{AMICI_CXXFLAGS})
25+
message(STATUS "Appending flags from AMICI_CXXFLAGS: $ENV{AMICI_CXXFLAGS}")
26+
add_compile_options("$ENV{AMICI_CXXFLAGS}")
27+
endif()
28+
if(DEFINED ENV{AMICI_LDFLAGS})
29+
message(STATUS "Appending flags from AMICI_LDFLAGS: $ENV{AMICI_LDFLAGS}")
30+
link_libraries("$ENV{AMICI_LDFLAGS}")
31+
endif()
32+
33+
find_package(Amici 0.33.0 REQUIRED HINTS
34+
${CMAKE_CURRENT_LIST_DIR}/../../build)
35+
message(STATUS "Found AMICI ${Amici_DIR}")
36+
set_target_properties(Upstream::amici PROPERTIES
37+
MAP_IMPORTED_CONFIG_RELWITHDEBINFO RelWithDebInfo;Release;
38+
MAP_IMPORTED_CONFIG_RELEASE Release
39+
MAP_IMPORTED_CONFIG_DEBUG Debug;RelWithDebInfo;)
40+
41+
# Debug build?
42+
if("$ENV{ENABLE_AMICI_DEBUGGING}" OR "$ENV{ENABLE_GCOV_COVERAGE}")
43+
add_compile_options(-UNDEBUG)
44+
if(MSVC)
45+
add_compile_options(-DEBUG)
46+
else()
47+
add_compile_options(-O0 -g)
48+
endif()
49+
endif()
50+
51+
# coverage options
52+
if($ENV{ENABLE_GCOV_COVERAGE})
53+
string(APPEND CMAKE_CXX_FLAGS_DEBUG " --coverage")
54+
string(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG " --coverage")
55+
endif()
56+
57+
set(MODEL_DIR ${CMAKE_CURRENT_LIST_DIR})
58+
59+
set(SRC_LIST_LIB Jy.cpp
60+
Jy.h
61+
create_splines.cpp
62+
dJydsigma.cpp
63+
dJydy.cpp
64+
dJydy.h
65+
deltaqB.cpp
66+
deltasx.cpp
67+
deltax.cpp
68+
dxdotdp_explicit.cpp
69+
dxdotdp_explicit.h
70+
dxdotdx_explicit.cpp
71+
dxdotdx_explicit.h
72+
dydx.cpp
73+
h.h
74+
model_dirac_py.cpp
75+
model_dirac_py.h
76+
my.h
77+
p.h
78+
root.cpp
79+
sigmay.cpp
80+
sigmay.h
81+
stau.cpp
82+
stau.h
83+
sx.h
84+
w.h
85+
wrapfunctions.cpp
86+
wrapfunctions.h
87+
x.h
88+
xB.h
89+
x_old.h
90+
x_rdata.cpp
91+
x_rdata.h
92+
x_solver.cpp
93+
x_solver.h
94+
xdot.cpp
95+
xdot.h
96+
xdot_old.h
97+
y.cpp
98+
y.h ${MODEL_DIR}/wrapfunctions.cpp)
99+
100+
add_library(${PROJECT_NAME} ${SRC_LIST_LIB})
101+
102+
# ${PROJECT_NAME} might already be "model"
103+
if(NOT TARGET model)
104+
add_library(model ALIAS ${PROJECT_NAME})
105+
endif()
106+
107+
# Some special functions require boost
108+
#
109+
# TODO: set some flag during code generation whether the given model requires
110+
# boost. for now, try to find it, add include directories and link against it.
111+
# let the compiler/linker error if it is required but not found
112+
find_package(Boost)
113+
114+
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
115+
116+
target_link_libraries(
117+
${PROJECT_NAME}
118+
PUBLIC Upstream::amici
119+
PRIVATE $<$<BOOL:${Boost_FOUND}>:Boost::boost>)
120+
121+
if(NOT "${AMICI_PYTHON_BUILD_EXT_ONLY}")
122+
set(SRC_LIST_EXE main.cpp)
123+
add_executable(simulate_${PROJECT_NAME} ${SRC_LIST_EXE})
124+
target_link_libraries(simulate_${PROJECT_NAME} ${PROJECT_NAME})
125+
endif()
126+
127+
# SWIG
128+
option(ENABLE_SWIG "Build swig/python library?" ON)
129+
if(ENABLE_SWIG)
130+
add_subdirectory(swig)
131+
endif()
132+
133+
# <Export cmake configuration>
134+
include(GNUInstallDirs)
135+
install(
136+
TARGETS ${PROJECT_NAME}
137+
EXPORT ${PROJECT_NAME}Targets
138+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
139+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
140+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
141+
INCLUDES
142+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
143+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
144+
export(
145+
EXPORT ${PROJECT_NAME}Targets
146+
FILE ${PROJECT_NAME}Config.cmake
147+
NAMESPACE Upstream::)
148+
# </Export cmake configuration>

models/model_dirac_py/Jy.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "amici/symbolic_functions.h"
2+
#include "amici/defines.h"
3+
#include "sundials/sundials_types.h"
4+
5+
#include <gsl/gsl-lite.hpp>
6+
#include <algorithm>
7+
8+
#include "p.h"
9+
#include "y.h"
10+
#include "sigmay.h"
11+
#include "my.h"
12+
13+
namespace amici {
14+
namespace model_model_dirac_py {
15+
16+
void Jy_model_dirac_py(realtype *Jy, const int iy, const realtype *p, const realtype *k, const realtype *y, const realtype *sigmay, const realtype *my){
17+
switch(iy) {
18+
case 0:
19+
Jy[0] = 0.5*std::log(2*amici::pi*std::pow(sigma_obs_x2, 2)) + 0.5*std::pow(-mobs_x2 + obs_x2, 2)/std::pow(sigma_obs_x2, 2);
20+
break;
21+
}
22+
}
23+
24+
} // namespace model_model_dirac_py
25+
} // namespace amici

models/model_dirac_py/Jy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define Jy0 Jy[0]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "amici/symbolic_functions.h"
2+
#include "amici/defines.h"
3+
#include "sundials/sundials_types.h"
4+
5+
#include <gsl/gsl-lite.hpp>
6+
#include <algorithm>
7+
8+
#include "amici/splinefunctions.h"
9+
#include <vector>
10+
#include "p.h"
11+
12+
namespace amici {
13+
namespace model_model_dirac_py {
14+
15+
std::vector<HermiteSpline> create_splines_model_dirac_py(const realtype *p, const realtype *k){
16+
return {};
17+
}
18+
19+
} // namespace model_model_dirac_py
20+
} // namespace amici
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "amici/symbolic_functions.h"
2+
#include "amici/defines.h"
3+
#include "sundials/sundials_types.h"
4+
5+
#include <gsl/gsl-lite.hpp>
6+
#include <algorithm>
7+
8+
#include "p.h"
9+
#include "y.h"
10+
#include "sigmay.h"
11+
#include "my.h"
12+
13+
namespace amici {
14+
namespace model_model_dirac_py {
15+
16+
void dJydsigma_model_dirac_py(realtype *dJydsigma, const int iy, const realtype *p, const realtype *k, const realtype *y, const realtype *sigmay, const realtype *my){
17+
switch(iy) {
18+
case 0:
19+
dJydsigma[0] = 1.0/sigma_obs_x2 - 1.0*std::pow(-mobs_x2 + obs_x2, 2)/std::pow(sigma_obs_x2, 3);
20+
break;
21+
}
22+
}
23+
24+
} // namespace model_model_dirac_py
25+
} // namespace amici

models/model_dirac_py/dJydy.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include "amici/sundials_matrix_wrapper.h"
2+
#include "sundials/sundials_types.h"
3+
4+
#include <array>
5+
#include <algorithm>
6+
7+
namespace amici {
8+
namespace model_model_dirac_py {
9+
10+
static constexpr std::array<std::array<sunindextype, 2>, 1> dJydy_colptrs_model_dirac_py_ = {{
11+
{0, 1},
12+
}};
13+
14+
void dJydy_colptrs_model_dirac_py(SUNMatrixWrapper &dJydy, int index){
15+
dJydy.set_indexptrs(gsl::make_span(dJydy_colptrs_model_dirac_py_[index]));
16+
}
17+
} // namespace model_model_dirac_py
18+
} // namespace amici
19+
20+
#include "amici/sundials_matrix_wrapper.h"
21+
#include "sundials/sundials_types.h"
22+
23+
#include <array>
24+
#include <algorithm>
25+
26+
namespace amici {
27+
namespace model_model_dirac_py {
28+
29+
static constexpr std::array<std::array<sunindextype, 1>, 1> dJydy_rowvals_model_dirac_py_ = {{
30+
{0},
31+
}};
32+
33+
void dJydy_rowvals_model_dirac_py(SUNMatrixWrapper &dJydy, int index){
34+
dJydy.set_indexvals(gsl::make_span(dJydy_rowvals_model_dirac_py_[index]));
35+
}
36+
} // namespace model_model_dirac_py
37+
} // namespace amici
38+
39+
40+
41+
42+
#include "amici/symbolic_functions.h"
43+
#include "amici/defines.h"
44+
#include "sundials/sundials_types.h"
45+
46+
#include <gsl/gsl-lite.hpp>
47+
#include <algorithm>
48+
49+
#include "p.h"
50+
#include "y.h"
51+
#include "sigmay.h"
52+
#include "my.h"
53+
#include "dJydy.h"
54+
55+
namespace amici {
56+
namespace model_model_dirac_py {
57+
58+
void dJydy_model_dirac_py(realtype *dJydy, const int iy, const realtype *p, const realtype *k, const realtype *y, const realtype *sigmay, const realtype *my){
59+
switch(iy) {
60+
case 0:
61+
dJydy[0] = (-1.0*mobs_x2 + 1.0*obs_x2)/std::pow(sigma_obs_x2, 2);
62+
break;
63+
}
64+
}
65+
66+
} // namespace model_model_dirac_py
67+
} // namespace amici

models/model_dirac_py/dJydy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define dJy0_dobs_x2 dJydy[0]

models/model_dirac_py/deltaqB.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "amici/symbolic_functions.h"
2+
#include "amici/defines.h"
3+
#include "sundials/sundials_types.h"
4+
5+
#include <gsl/gsl-lite.hpp>
6+
#include <algorithm>
7+
8+
#include "x.h"
9+
#include "p.h"
10+
#include "h.h"
11+
#include "xdot.h"
12+
#include "xdot_old.h"
13+
#include "x_old.h"
14+
#include "xB.h"
15+
16+
namespace amici {
17+
namespace model_model_dirac_py {
18+
19+
void deltaqB_model_dirac_py(realtype *deltaqB, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *dx, const int ip, const int ie, const realtype *xdot, const realtype *xdot_old, const realtype *x_old, const realtype *xB){
20+
switch(ie) {
21+
case 0:
22+
switch(ip) {
23+
case 1:
24+
deltaqB[0] = xB0*(-dx1dt + xdot_old0) + xB1*(-dx2dt + xdot_old1);
25+
break;
26+
}
27+
break;
28+
}
29+
}
30+
31+
} // namespace model_model_dirac_py
32+
} // namespace amici

models/model_dirac_py/deltasx.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "amici/symbolic_functions.h"
2+
#include "amici/defines.h"
3+
#include "sundials/sundials_types.h"
4+
5+
#include <gsl/gsl-lite.hpp>
6+
#include <algorithm>
7+
8+
#include "x.h"
9+
#include "p.h"
10+
#include "h.h"
11+
#include "xdot.h"
12+
#include "xdot_old.h"
13+
#include "sx.h"
14+
#include "stau.h"
15+
#include "x_old.h"
16+
17+
namespace amici {
18+
namespace model_model_dirac_py {
19+
20+
void deltasx_model_dirac_py(realtype *deltasx, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w, const int ip, const int ie, const realtype *xdot, const realtype *xdot_old, const realtype *sx, const realtype *stau, const realtype *tcl, const realtype *x_old){
21+
switch(ie) {
22+
case 0:
23+
switch(ip) {
24+
case 0:
25+
case 1:
26+
case 2:
27+
case 3:
28+
deltasx[0] = stau0*(dx1dt - xdot_old0);
29+
deltasx[1] = stau0*(dx2dt - xdot_old1);
30+
break;
31+
}
32+
break;
33+
}
34+
}
35+
36+
} // namespace model_model_dirac_py
37+
} // namespace amici

0 commit comments

Comments
 (0)