Skip to content

Commit

Permalink
Merging Sachetto changes/There is a bug in the free memory stage when…
Browse files Browse the repository at this point in the history
… we use the (update_monodomain_default) function
  • Loading branch information
bergolho committed Mar 14, 2019
2 parents d1cf4bb + 6240b68 commit dc3c634
Show file tree
Hide file tree
Showing 68 changed files with 33,903 additions and 31,345 deletions.
2 changes: 1 addition & 1 deletion .idea/MonoAlg3D.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ IF(EXISTS "/etc/manjaro-release")
set(CMAKE_CXX_COMPILER "/opt/cuda/bin/g++")
ENDIF(EXISTS "/etc/manjaro-release")

IF(EXISTS "/etc/debconf.conf")
set(CMAKE_C_COMPILER "/usr/bin/gcc-6")
set(CMAKE_CXX_COMPILER "/usr/bin/g++-6")
ENDIF(EXISTS "/etc/debconf.conf")
#IF(EXISTS "/etc/debconf.conf")
# set(CMAKE_C_COMPILER "/usr/bin/gcc-6")
# set(CMAKE_CXX_COMPILER "/usr/bin/g++-6")
#ENDIF(EXISTS "/etc/debconf.conf")


cmake_minimum_required(VERSION 3.0.1)
Expand Down Expand Up @@ -84,7 +84,7 @@ ENDIF(CUDA_FOUND)
SET(OpenGL_GL_PREFERENCE "GLVND")
FIND_PACKAGE(OpenGL)

IF(OPENGL_FOUND AND OPENMP_FOUND)
IF(NOT MSVC AND OPENGL_FOUND AND OPENMP_FOUND)
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOMPILE_OPENGL")
ENDIF()

Expand All @@ -97,7 +97,7 @@ ADD_SUBDIRECTORY(src/config)
ADD_SUBDIRECTORY(src/graph)
ADD_SUBDIRECTORY(src/vtk_utils)

IF(OPENGL_FOUND AND OPENMP_FOUND)
IF(NOT MSVC AND OPENGL_FOUND AND OPENMP_FOUND)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_GAMES OFF CACHE BOOL "" FORCE)
ADD_SUBDIRECTORY(src/raylib/src)
Expand Down Expand Up @@ -162,7 +162,9 @@ ADD_SUBDIRECTORY(src/linear_system_solver_library)
ADD_SUBDIRECTORY(src/save_mesh_library)
ADD_SUBDIRECTORY(src/save_state_library)
ADD_SUBDIRECTORY(src/restore_state_library)
ADD_SUBDIRECTORY(src/update_monodomain_library)

SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests_bin )

ADD_SUBDIRECTORY(src/tests)

1 change: 0 additions & 1 deletion ToDo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Sachetto
- Convert my internal libraries to single header libraries
- Rewrite the flags parsing using: https://github.com/kgabis/kgflags/blob/master/examples/full_api.c
- Correct the domain version that sets the two scars and the fibrosis from file (maybe the error is on extra-data)
- Compare the mesh with the mesh from the scientific reports paper
Expand Down
16 changes: 14 additions & 2 deletions clean_project.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#!/bin/bash
cd build; rm -r *; cd ..
cd bin; rm *

BUILD_DIR="build"

if [[ "$#" -eq 1 ]]; then
BUILD_DIR=$1
fi

if [[ ! -d "${BUILD_DIR}" ]]; then
echo "Directory ${BUILD_DIR} does not exist"
exit
fi

rm -fr ${BUILD_DIR}/*
rm -fr bin/*
5 changes: 4 additions & 1 deletion example_configs/elnaz_plain_mesh_tentusscher.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[main]
num_threads=2
dt_pde=0.02
simulation_time=500.0
simulation_time=10.0
abort_on_no_activity=false
use_adaptivity=false

Expand All @@ -14,6 +14,9 @@ save_pvd=true
;//////////////////
file_prefix=V

[update_monodomain]
function=update_monodomain_default

[assembly_matrix]
sigma_x=0.0000176
sigma_y=0.0001334
Expand Down
2 changes: 2 additions & 0 deletions example_configs/plain_mesh_ddm_2d.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ save_pvd=true
;//////////////////
file_prefix=V

[update_monodomain]
function=update_monodomain_ddm

[assembly_matrix]
sigma_x=0.00176
Expand Down
3 changes: 3 additions & 0 deletions example_configs/simple_purkinje_example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ file_prefix=V
binary=false
compress=false

[update_monodomain]
function=update_monodomain_default

[assembly_matrix]
sigma_x=0.0000176
sigma_y=0.0001334
Expand Down
21 changes: 20 additions & 1 deletion recompile_project.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
#!/bin/bash
cd build; cmake ..; make

BUILD_DIR="build"
BUILD_TYPE="Release"

if [[ "$#" -eq 1 ]]; then
BUILD_DIR=$1
fi

if [[ "$#" -eq 2 ]]; then
BUILD_DIR=$1
BUILD_TYPE=$2
fi


if [[ ! -d "${BUILD_DIR}" ]]; then
echo "Directory ${BUILD_DIR} does not exist. Creating."
mkdir ${BUILD_DIR}
fi

cd ${BUILD_DIR}; cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ..; make
2 changes: 1 addition & 1 deletion scripts/animations/convert_png_to_mp4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ OUTPUT_VIDEO_FILENAME="video/ddm_3d"
RESOLUTION="1020x720"

# Execute the converting command using FFMPEG
ffmpeg -r $FRAME_RATE -f image2 -s $RESOLUTION -start_number 1 -i $FILENAME.%04d.png -vframes $END_FRAME -vcodec libx264 -crf 25 -pix_fmt yuv420p $OUTPUT_VIDEO_FILENAME.mp4
ffmpeg -r ${FRAME_RATE} -f image2 -s ${RESOLUTION} -start_number 1 -i ${FILENAME}.%04d.png -vframes ${END_FRAME} -vcodec libx264 -crf 25 -pix_fmt yuv420p ${OUTPUT_VIDEO_FILENAME}.mp4
11 changes: 7 additions & 4 deletions scripts/calc_APD.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import sys


def forwarddiff(y, h):
n = len(y)
res = []
i = 1

for i in range(1,n):
res.append((y[i] - y[i-1]) / h);
for i in range(1, n):
res.append((y[i] - y[i-1]) / h)

return res


def slope_start(data, start=0, epsilon=0.0001, h=1.0):

d = data[start:]
Expand All @@ -19,6 +20,7 @@ def slope_start(data, start=0, epsilon=0.0001, h=1.0):
if abs(d[i] - d[i-1]/h) > epsilon:
return i+start


def slope_end(data, start=0, epsilon=0.0001, h=1.0):

d = data[start:]
Expand All @@ -40,11 +42,12 @@ def max_index(data, start, end):

return max_index


def index_activation(data, start=0):
d = data[start:]

for i, v in enumerate(d):
if d[i+start] < 0.0 and d[i+start+1] > 0.0:
if d[i + start] < 0.0 < d[i + start + 1]:
return i+start

def main ():
Expand Down
3 changes: 2 additions & 1 deletion scripts/getAps.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env bash
AP_DIR=$1
AP_PREFIX=$2
AP_LINE=$3
AP_OUT=$4
CELL_ID=$5

if [ "$#" -ne 5 ]; then
if [[ "$#" -ne 5 ]]; then
echo "-------------------------------------------------------------------"
echo "Usage:> $0 <AP_DIR> <AP_PREFIX> <AP_LINE> <AP_OUT> <CELL_ID>"
echo "-------------------------------------------------------------------"
Expand Down
6 changes: 3 additions & 3 deletions scripts/get_number_lines_from_file_in_vtk_folder.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ "$#" -ne 2 ]; then
if [[ "$#" -ne 2 ]]; then
echo "-------------------------------------------------------------------"
echo "Usage:> $0 <AP_DIR> <AP_PREFIX>"
echo "-------------------------------------------------------------------"
Expand All @@ -17,7 +17,7 @@ AP_DIR=$1
AP_PREFIX=$2

FIRST_FILE=$(ls -1v ${AP_DIR}/${AP_PREFIX}_it_0_*)
NUMBER_OF_LINES=$(wc $FIRST_FILE | awk -F ' ' '{print $1}')
NUMBER_OF_LINES=$(wc ${FIRST_FILE} | awk -F ' ' '{print $1}')
NUMBER_OF_LINES=$((NUMBER_OF_LINES+1))
echo $NUMBER_OF_LINES
echo ${NUMBER_OF_LINES}

12 changes: 7 additions & 5 deletions scripts/plot_potential.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import sys
import numpy as np
import matplotlib.pyplot as plt


def read_transmembrane_potential (input_file,dt,print_rate):
data = np.genfromtxt(input_file)
n = len(data)
Expand All @@ -12,19 +12,20 @@ def read_transmembrane_potential (input_file,dt,print_rate):

return timesteps, vms


def plot_transmembrane_potential (t,v):
plt.grid()
plt.plot(t,v,label="Vm",c="black",linewidth=3.0)
plt.plot(t, v, label="Vm", c="black", linewidth=3.0)
plt.xlabel("t (ms)",fontsize=15)
plt.ylabel("V (mV)",fontsize=15)
plt.title("Action potential",fontsize=14)
plt.legend(loc=2,fontsize=14)
plt.show()
#plt.savefig("ap.pdf")


def main ():

if (len(sys.argv) != 4):
if len(sys.argv) != 4:
print("-------------------------------------------------------------------------")
print("Usage:> python %s <input_file> <dt> <print_rate>" % sys.argv[0])
print("-------------------------------------------------------------------------")
Expand All @@ -41,6 +42,7 @@ def main ():
t, vm = read_transmembrane_potential(input_file,dt,print_rate)

plot_transmembrane_potential(t,vm)



if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions scripts/run_valgrind.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#!/usr/bin/env bash
valgrind --xml=yes --xml-file=val.xml --suppressions=scripts/valgrind.supp --leak-check=full --leak-check=yes $@
8 changes: 4 additions & 4 deletions src/alg/grid/grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ void clean_grid(struct grid *the_grid) {

struct cell_node *grid_cell = NULL;

// TODO: Think about this function
// TODO: Think about this function when the coupling happens ...
// Delete nodes from the Purkinje network
if (the_grid->the_purkinje_network->list_nodes == NULL)
if (the_grid->the_purkinje_network->list_nodes != NULL)
{

// First free the Purkinje mesh structure
Expand Down Expand Up @@ -293,12 +293,12 @@ void clean_grid(struct grid *the_grid) {

if(the_grid->refined_this_step)
{
arrsetlen(the_grid->refined_this_step, 0);
arrreset(the_grid->refined_this_step);
}

if(the_grid->free_sv_positions)
{
arrsetlen(the_grid->free_sv_positions, 0);
arrreset(the_grid->free_sv_positions);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/alg/grid/grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct grid {
uint32_t *free_sv_positions;
uint32_t *refined_this_step;

struct cell_node* *active_cells;
struct cell_node **active_cells;
bool adaptive;

struct graph *the_purkinje_network;
Expand Down
2 changes: 1 addition & 1 deletion src/alg/grid/grid_refinement.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool refine_grid_with_bound(struct grid *the_grid, double refinement_bound, doub

uint32_t *free_sv_pos = the_grid->free_sv_positions;

arrsetlen(the_grid->refined_this_step, 0);
arrreset(the_grid->refined_this_step);

while(continue_refining) {
continue_refining = false;
Expand Down
2 changes: 1 addition & 1 deletion src/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(SOURCE_FILES_CONFIG
save_mesh_config.c save_mesh_config.h
save_state_config.c save_state_config.h
restore_state_config.c restore_state_config.h
update_monodomain_config.c update_monodomain_config.h
)

ADD_LIBRARY(config STATIC ${SOURCE_FILES_CONFIG})
Expand All @@ -18,5 +19,4 @@ IF(MSVC)
TARGET_LINK_LIBRARIES(config string getopt utils dl)
ELSE()
TARGET_LINK_LIBRARIES(config string utils dl)

ENDIF()
4 changes: 4 additions & 0 deletions src/config/config_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

#include <stddef.h>
#include "config_common.h"
#ifdef _MSC_VER
#include "../dlfcn-win32/dlfcn.h"
#else
#include <dlfcn.h>
#endif

#include "../single_file_libraries/stb_ds.h"

Expand Down
32 changes: 31 additions & 1 deletion src/config/config_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static const struct option long_options[] = {
{"save_state", required_argument, NULL, SAVE_STATE_OPT}, //Complex option
{"restore_state", required_argument, NULL, RESTORE_STATE_OPT}, //Complex option
{"linear_system_solver", required_argument, NULL, LINEAR_SYSTEM_SOLVER_OPT}, //Complex option
{"update_monodomain", required_argument, NULL, UPDATE_MONODOMAIN_SOLVER_OPT}, //Complex option
{"visualize", no_argument, NULL, DRAW_OPT},
{"visualization_max_v", required_argument, NULL, MAX_V_OPT},
{"visualization_min_v", required_argument, NULL, MIN_V_OPT},
Expand Down Expand Up @@ -195,6 +196,7 @@ struct user_options *new_user_options() {
user_args->save_mesh_config = NULL;
user_args->save_state_config = NULL;
user_args->restore_state_config = NULL;
user_args->update_monodomain_config = NULL;

user_args->draw = false;
user_args->max_v = 40.0f;
Expand Down Expand Up @@ -785,6 +787,13 @@ void parse_options(int argc, char **argv, struct user_options *user_args) {
}
set_config(optarg, user_args->linear_system_solver_config, user_args->config_file, "linear_system_solver");
break;
case UPDATE_MONODOMAIN_SOLVER_OPT:
if(user_args->update_monodomain_config == NULL) {
print_to_stdout_and_file("Creating new update_monodomain config from command line!\n");
user_args->update_monodomain_config = new_update_monodomain_config();
}
set_config(optarg, user_args->update_monodomain_config, user_args->config_file, "update_monodomain");
break;
case EXTRA_DATA_OPT:
if(user_args->extra_data_config == NULL) {
print_to_stdout_and_file("Creating new extra data config from command line!\n");
Expand Down Expand Up @@ -1069,7 +1078,25 @@ int parse_config_file(void *user, const char *section, const char *name, const c
} else {
shput(pconfig->assembly_matrix_config->config_data.config, name, strdup(value));
}
} else if(MATCH_SECTION(LINEAR_SYSTEM_SOLVER_SECTION)) {
}
else if(MATCH_SECTION(UPDATE_MONODOMAIN_SECTION)) {

if(pconfig->update_monodomain_config == NULL) {
pconfig->update_monodomain_config = new_update_monodomain_config();
}

if(MATCH_NAME("function")) {
pconfig->update_monodomain_config->config_data.function_name = strdup(value);
pconfig->update_monodomain_config->config_data.function_name_was_set = true;

} else if(MATCH_NAME("library_file")) {
pconfig->update_monodomain_config->config_data.library_file_path = strdup(value);
pconfig->update_monodomain_config->config_data.library_file_path_was_set = true;
} else {
shput(pconfig->update_monodomain_config->config_data.config, name, strdup(value));
}
}
else if(MATCH_SECTION(LINEAR_SYSTEM_SOLVER_SECTION)) {

if(pconfig->linear_system_solver_config == NULL) {
pconfig->linear_system_solver_config = new_linear_system_solver_config();
Expand Down Expand Up @@ -1201,5 +1228,8 @@ void free_user_options(struct user_options *s) {
if(s->save_state_config)
free_save_state_config(s->save_state_config);

if(s->update_monodomain_config)
free_update_monodomain_config(s->update_monodomain_config);

free(s);
}
Loading

0 comments on commit dc3c634

Please sign in to comment.