Skip to content

Commit 18921d8

Browse files
committed
chore: clean up code
1 parent 05c5e13 commit 18921d8

File tree

12 files changed

+124
-50
lines changed

12 files changed

+124
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ compile_commands.json
88
# Env
99
.bmc_info
1010
results/
11+
results
1112
cma_data/
1213
*.h5
1314
#Benchs

apps/core/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dep_core = [
1111
simulation_lib_dependency,
1212
eigen_dep,
1313
blas,
14-
cma_utils_dependency,
14+
cma_utils_lib_dependency,
1515
]
1616

1717
if highfive_found

apps/core/src/global_initaliser.cpp

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "cma_utils/alias.hpp"
12
#include <algorithm>
23
#include <biocma_cst_config.hpp>
34
#include <cassert>
@@ -45,7 +46,6 @@ namespace
4546
std::vector<double>({0, 0.}),
4647
std::vector<size_t>({0}));
4748

48-
// TODO Move elsewhere
4949
double get_time_step(double user_deta_time,
5050
const CmaUtils::TransitionnerPtrType& iterator)
5151
{
@@ -56,40 +56,12 @@ namespace
5656
// that the fluid movement between two steps is accurately represented
5757
// without losing flow information.
5858
double delta_time = user_deta_time;
59-
59+
Kokkos::printf("up %f\r\n", delta_time);
6060
if (delta_time <= 0)
6161
{
6262

63-
const std::size_t n_states = iterator->size();
64-
double min_residence_time = std::numeric_limits<double>::max();
65-
for (std::size_t i_state = 0; i_state < n_states; ++i_state)
66-
{
67-
// Naive min-research, as COO is not sorted we can´t do better without
68-
// convert COO to CSR/CSC or sort
69-
// + function exececuted only once
70-
const auto state = iterator->get_at(i_state);
71-
const auto liquid = state->get_liquid();
72-
const auto coo_matrix = liquid->transition();
73-
const auto liquid_volumes = liquid->volume();
74-
const auto data = coo_matrix->values();
75-
const auto rows = coo_matrix->row_indices();
76-
const auto cols = coo_matrix->col_indices();
77-
for (std::size_t k = 0; k < data.size(); ++k)
78-
{
79-
// Only way to find diagonal with not sorted COO
80-
if (rows[k] == cols[k])
81-
{
82-
const auto volume = liquid_volumes[rows[k]];
83-
if (volume != 0.)
84-
{
85-
double residence_time =
86-
-data[k] / volume; // minus cause transition has negative
87-
// diagonal (leaving flow)
88-
min_residence_time = std::min(residence_time, min_residence_time);
89-
}
90-
}
91-
}
92-
}
63+
const auto min_residence_time =
64+
CmaUtils::get_min_residence_time(iterator);
9365

9466
if (min_residence_time != std::numeric_limits<double>::max() &&
9567
min_residence_time != 0.)

apps/core/src/host_export_handler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,14 @@ bool ExportHandler::operator()(
138138
Core::PartialExporter& partial_exporter,
139139
const CmaUtils::TransitionnerPtrType& transitioner)
140140
{
141-
PROFILE_SECTION("host:handle_export")
142141

143142
// Only proceed if the dump interval is reached
144143
if (++dump_counter != dump_interval)
145144
{
146145
return false;
147146
}
147+
// Declare profiling here to count only if we actually export
148+
PROFILE_SECTION("host:handle_export")
148149

149150
// Prepare event span if event counter is enabled
150151
const auto event_span = prepareEventSpan(simulation);

apps/libs/cma_utils/meson.build

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#cma_utils_src = run_command('sh', '-c', f'find ./src -type f -name *.cpp', check: true).stdout().splitlines()
1+
cma_utils_src = run_command('sh', '-c', f'find ./src -type f -name *.cpp', check: true).stdout().splitlines()
22
lib_name = f'@project_name@_cma_utils'
33
public = include_directories('public')
44
private = include_directories('includes')
@@ -8,7 +8,7 @@ deps = [cma_dep, blas, kokkos, common_dependecy]
88

99
cma_utils = static_library(
1010
lib_name,
11-
# cma_utils_src,
11+
cma_utils_src,
1212
include_directories: [public, private],
1313
dependencies: [deps],
1414
# pic: true,
@@ -18,8 +18,14 @@ cma_utils = static_library(
1818
cpp_args: [],
1919
)
2020

21-
2221
cma_utils_dependency = declare_dependency(
2322
include_directories: [public],
23+
link_with:cma_utils,
24+
dependencies: [cma_dep ,kokkos, common_dependecy],
25+
)
26+
27+
cma_utils_lib_dependency = declare_dependency(
28+
include_directories: [public],
29+
link_with:cma_utils,
2430
dependencies: [cma_dep ,kokkos, common_dependecy],
2531
)

apps/libs/cma_utils/public/cma_utils/alias.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,29 @@
77

88
namespace CmaUtils
99
{
10+
/** @brief Opaque type for flowmap transitioner
11+
@note: underlying type is rust box which has to be considered as a
12+
non-movable unique_ptr
13+
*/
1014
using TransitionnerPtrType = rust::Box<TransitionerWrapper>;
15+
16+
/** @brief Opaque type for iteration state
17+
@note: underlying type is rust box which has to be considered as a
18+
non-movable unique_ptr
19+
*/
1120
using IterationStatePtrType = ::rust::Box<::IterationStateWrapper>;
21+
22+
/** @brief Opaque type for Naive COO matrix
23+
@note: underlying type is rust box which has to be considered as a
24+
non-movable unique_ptr
25+
*/
1226
using StateCooMatrixType = ::rust::Box<::CooMatrixWrap>;
1327

28+
/** @brief Determine the smallest compartment residence time
29+
For cases with multiple flowmaps, all the different states are taken into
30+
account*/
31+
double get_min_residence_time(const TransitionnerPtrType& iterator) noexcept;
32+
1433
} // namespace CmaUtils
1534

1635
#endif

apps/libs/cma_utils/src/utils.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <algorithm>
2+
#include <cma_utils/alias.hpp>
3+
#include <limits>
4+
namespace CmaUtils
5+
{
6+
7+
// double get_min_residence_time(const TransitionnerPtrType& iterator)
8+
// {
9+
// const std::size_t n_states = iterator->size();
10+
// double min_residence_time = std::numeric_limits<double>::max();
11+
// for (std::size_t i_state = 0; i_state < n_states; ++i_state)
12+
// {
13+
// // Naive min-research, as COO is not sorted we can´t do better
14+
// without
15+
// // convert COO to CSR/CSC or sort
16+
// // + function exececuted only once
17+
// const auto state = iterator->get_at(i_state);
18+
// const auto liquid = state->get_liquid();
19+
// const auto coo_matrix = liquid->transition();
20+
// const auto liquid_volumes = liquid->volume();
21+
// const auto data = coo_matrix->values();
22+
// const auto rows = coo_matrix->row_indices();
23+
// const auto cols = coo_matrix->col_indices();
24+
25+
// for (std::size_t k = 0; k < data.size(); ++k)
26+
// {
27+
// // Only way to find diagonal with not sorted COO
28+
// if (rows[k] == cols[k])
29+
// {
30+
// const auto volume = liquid_volumes[rows[k]];
31+
// if (volume != 0.)
32+
// {
33+
// double residence_time =
34+
// -data[k] / volume; // minus cause transition has negative
35+
// // diagonal (leaving flow)
36+
// min_residence_time = std::min(residence_time,
37+
// min_residence_time);
38+
// }
39+
// }
40+
// }
41+
// }
42+
// return min_residence_time;
43+
// }
44+
45+
// Does this function should be moved into RCMTool ?
46+
double get_min_residence_time(const TransitionnerPtrType& iterator) noexcept
47+
{
48+
/*
49+
This new implementation only determine minimum residence time defined as
50+
min(tau)=min(qi/vi) where qi=sum(flow) in compartment i First impl
51+
determined the smaller flow min(flowi/vi) which leads to smaller value
52+
*/
53+
const std::size_t n_states = iterator->size();
54+
double min_residence_time = std::numeric_limits<double>::max();
55+
for (std::size_t i_state = 0; i_state < n_states; ++i_state)
56+
{
57+
const auto state = iterator->get_at(i_state);
58+
const auto liquid = state->get_liquid();
59+
const auto out_flows = liquid->out_flows();
60+
const auto liquid_volumes = liquid->volume();
61+
KOKKOS_ASSERT(liquid_volumes.size() == out_flows.size());
62+
for (std::size_t k = 0; k < out_flows.size(); ++k)
63+
{
64+
const auto volume = liquid_volumes[k];
65+
if (volume > 0.)
66+
{
67+
const double residence_time = out_flows[k] / volume;
68+
min_residence_time = std::min(residence_time, min_residence_time);
69+
}
70+
}
71+
}
72+
return min_residence_time;
73+
}
74+
75+
} // namespace CmaUtils

devutils/udf_build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
CXX="clang++-18"
1515
#TARGET="fdist"
1616
TARGET="cullum_vicente"
17-
BUILD_DIR="./builddir/test"
17+
BUILD_DIR="./builddir/host"
1818

19-
SRC_BD="/home_pers/casale/Documents/thesis/udf_models"
19+
SRC_BD=$1
2020
SRC="$SRC_BD/$TARGET.cpp"
2121
OUT="$BUILD_DIR/libudf_model_$TARGET.so"
2222

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(
22
'biocma_mcst',
33
'cpp',
4-
version: '0.9.8',
4+
version: '0.9.75',
55
meson_version: '>= 1.3.0',
66
default_options: ['warning_level=3', 'b_colorout=always', 'cpp_std=c++20'],
77
)

tools/cases.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<cases>
33
<control name="debug">
4-
<!-- <cma_case_path >/home_pers/casale/Documents/thesis/cfd/bench/</cma_case_path> -->
5-
<cma_case_path>./cma_data/0d_gas/</cma_case_path>
6-
<!-- <cma_case_path >/home_pers/casale/Documents/thesis/cfd/sanofi/</cma_case_path> -->
4+
<!-- <cma_case_path >/home_pers/casale/Documents/thesis/cfd/bench/</cma_case_path> -->
5+
<!-- <cma_case_path>./cma_data/0d_gas/</cma_case_path> -->
6+
<cma_case_path >/home_pers/casale/Documents/thesis/cfd/sanofi/</cma_case_path>
77
<!-- <cma_case_path >/home-local/casale/Documents/thesis/cfd-cma/cma_data/sanofi/</cma_case_path> -->
88

9-
<final_time>1</final_time>
10-
<number_particle>600000</number_particle>
11-
<delta_time>0.01</delta_time>
9+
<final_time>5</final_time>
10+
<number_particle>6000000</number_particle>
11+
<delta_time>0</delta_time>
1212
<results_file_name>debug</results_file_name>
1313
<number_exported_result>10</number_exported_result>
1414
<model_name>monod</model_name>
15-
<initialiser_path>./cma_data/0d_4s_init.h5</initialiser_path>
15+
<!--<initialiser_path>./cma_data/0d_4s_init.h5</initialiser_path> -->
1616
<!-- <initialiser_path>./cma_data/n14_init.h5</initialiser_path> -->
17-
<!-- <initialiser_path>./cma_data/sanofi_init.h5</initialiser_path> -->
17+
<initialiser_path>./cma_data/sanofi_init.h5</initialiser_path>
1818
</control>
1919

2020

0 commit comments

Comments
 (0)