5#ifndef DIFFUSION_HELPFUNCTIONSDIFFUSION_HPP
6#define DIFFUSION_HELPFUNCTIONSDIFFUSION_HPP
19template <
typename gr
id_type,
typename T>
25 sum += (T)1.0 / (T)(
grid.spacing(d) *
grid.spacing(d));
28 return 1.0 / ((T)4.0 * k_max *
sum);
43T get_smooth_sigmoidal(T x, T x_shift, T x_stretch, T y_min, T y_max)
45 return y_min + y_max / (1.0 + exp(- (x_shift + x_stretch * x)));
55template <
size_t Prop,
typename gr
id_type>
59 auto dom =
grid.getDomainIterator();
63 sum +=
grid.template getProp<Prop>(key);
66 auto &v_cl = create_vcluster();
84template <
size_t Conc,
typename gr
id_type,
typename T,
typename T_mass>
85void monitor_total_mass(
grid_type &
grid,
const T_mass m_initial,
const T p_volume,
const T t,
const size_t i,
86 const std::string & path_output,
const std::string & filename=
"total_mass.csv")
88 auto &v_cl = create_vcluster();
97 T m_total = sum_prop_over_grid<Conc>(
grid) * p_volume;
98 T m_diff = m_total - m_initial;
99 T m_max = get_max_val<Conc>(
grid) * p_volume;
101 if (v_cl.rank() == 0)
103 std::string outpath = path_output +
"/" + filename;
105 std::ofstream outfile;
106 outfile.open(outpath, std::ios_base::app);
110 outfile <<
"Time, Total mass, Mass difference, Max mass" << std::endl;
147template <
size_t Conc,
typename gr
id_type,
typename T>
148void monitor_total_concentration(
grid_type &
grid,
const T t,
const size_t i,
149 const std::string & path_output,
const std::string & filename=
"total_conc.csv")
151 auto &v_cl = create_vcluster();
152 T c_total = sum_prop_over_grid<Conc>(
grid);
154 if (v_cl.rank() == 0)
156 std::string outpath = path_output +
"/" + filename;
158 std::ofstream outfile;
159 outfile.open(outpath, std::ios_base::app);
163 outfile <<
"Time, Total concentration" << std::endl;
185template <
size_t Conc,
size_t Emission,
typename gr
id_type,
typename key_vector_type,
typename T>
186void adapt_emission(
grid_type &
grid, key_vector_type & keys, T threshold)
188 for (
int i = 0; i < keys.size(); ++i)
190 auto key = keys.get(i);
191 if (
grid.template getProp<Conc>(key) > threshold)
grid.template getProp<Emission>(key) = 0.0;
Header file containing help-functions that perform on OpenFPM-grids.
std::string to_string_with_precision(const T myValue, const size_t n=6)
Converts value into string maintaining a desired precision.
Header file containing functions for creating files and folders.
static void create_file_if_not_exist(std::string path)
Creates a file if not already existent.
This is a distributed grid.
static const unsigned int dims
Number of dimensions.
It model an expression expr1 + ... exprn.