15 #ifndef CORE_MODEL_INITIALIZER_H_
16 #define CORE_MODEL_INITIALIZER_H_
18 #include <Math/DistFunc.h>
31 class EulerDepletionGrid;
52 template <
typename Function>
54 Function agent_builder) {
58 auto* ctxt = sim->GetExecutionContext();
61 for (
size_t x = 0; x < agents_per_dim; x++) {
62 auto x_pos = x * space;
63 for (
size_t y = 0; y < agents_per_dim; y++) {
64 auto y_pos = y * space;
65 for (
size_t z = 0; z < agents_per_dim; z++) {
66 auto* new_agent = agent_builder({x_pos, y_pos, z * space});
67 ctxt->AddAgent(new_agent);
91 template <
typename Function>
92 static void Grid3D(
const std::array<size_t, 3>& agents_per_dim,
real_t space,
93 Function agent_builder) {
97 auto* ctxt = sim->GetExecutionContext();
100 for (
size_t x = 0; x < agents_per_dim[0]; x++) {
101 auto x_pos = x * space;
102 for (
size_t y = 0; y < agents_per_dim[1]; y++) {
103 auto y_pos = y * space;
104 for (
size_t z = 0; z < agents_per_dim[2]; z++) {
105 auto* new_agent = agent_builder({x_pos, y_pos, z * space});
106 ctxt->AddAgent(new_agent);
121 template <
typename Function>
123 Function agent_builder) {
127 auto* ctxt = sim->GetExecutionContext();
130 for (
size_t i = 0; i < positions.size(); i++) {
132 agent_builder({positions[i][0], positions[i][1], positions[i][2]});
133 ctxt->AddAgent(new_agent);
150 template <
typename Function>
152 Function agent_builder,
157 auto* ctxt = sim->GetExecutionContext();
158 auto* random = sim->GetRandom();
161 for (uint64_t i = 0; i < num_agents; i++) {
162 if (rng !=
nullptr) {
164 bool in_range =
false;
166 pos = rng->Sample3();
167 in_range = (pos[0] >= min) && (pos[0] <= max) && (pos[1] >= min) &&
168 (pos[1] <= max) && (pos[2] >= min) && (pos[2] <= max);
170 auto* new_agent = agent_builder(pos);
171 ctxt->AddAgent(new_agent);
173 auto* new_agent = agent_builder(random->UniformArray<3>(min, max));
174 ctxt->AddAgent(new_agent);
213 template <
typename Function>
218 Function agent_builder) {
222 auto* ctxt = sim->GetExecutionContext();
225 static_cast<uint64_t
>(std::floor((xmax - xmin) / deltax));
227 static_cast<uint64_t
>(std::floor((ymax - ymin) / deltay));
230 for (uint64_t xit = 0; xit < xiterations; ++xit) {
231 real_t x = xmin + xit * deltax;
232 for (uint64_t yit = 0; yit < yiterations; ++yit) {
233 real_t y = ymin + yit * deltay;
235 pos[2] = f(pos.
data(), fn_params.
data());
236 ctxt->AddAgent(agent_builder(pos));
273 template <
typename Function>
277 real_t ymin,
real_t ymax, uint64_t num_agents, Function agent_builder) {
281 auto* ctxt = sim->GetExecutionContext();
282 auto* random = sim->GetRandom();
285 for (uint64_t i = 0; i < num_agents; ++i) {
286 Real3 pos = {random->Uniform(xmin, xmax), random->Uniform(ymin, ymax)};
287 pos[2] = f(pos.
data(), fn_params.
data());
288 ctxt->AddAgent(agent_builder(pos));
304 template <
typename Function>
307 Function agent_builder) {
311 auto* ctxt = sim->GetExecutionContext();
312 auto* random = sim->GetRandom();
315 for (uint64_t i = 0; i < num_agents; i++) {
316 auto pos = random->Sphere(radius) + center;
317 auto* new_agent = agent_builder(pos);
318 ctxt->AddAgent(new_agent);
334 template <
typename Function>
337 Function agent_builder) {
345 auto radial_pdf_sphere = [](
const double* x,
const double* params) {
348 if (r > 0.0 && r <= R) {
349 return 3.0 * std::pow(r, 2.0) / std::pow(R, 3.0);
363 std::vector<real_t> random_radius;
364 random_radius.resize(num_agents);
365 for (
size_t i = 0; i < num_agents; i++) {
366 random_radius[i] = rng.
Sample();
368 #pragma omp parallel shared(random_radius)
371 #pragma omp for schedule(static)
372 for (uint64_t i = 0; i < num_agents; i++) {
373 auto pos = random->Sphere(random_radius[i]) + center;
374 auto* new_agent = agent_builder(pos);
375 ctxt_tl->AddAgent(new_agent);
393 int substance_id,
const std::string& substance_name,
394 real_t diffusion_coeff,
real_t decay_constant,
int resolution = 10,
395 const std::vector<real_t>& binding_coefficients = {},
396 const std::vector<int>& binding_substances = {});
398 template <
typename F>
401 auto* rm = sim->GetResourceManager();
402 auto diffusion_grid = rm->GetDiffusionGrid(substance_id);
403 diffusion_grid->AddInitializer(
function);
413 std::unique_ptr<BoundaryCondition> bc) {
415 const auto* rm = sim->GetResourceManager();
416 auto diffusion_grid = rm->GetDiffusionGrid(substance_id);
417 diffusion_grid->SetBoundaryConditionType(bc_type);
418 diffusion_grid->SetBoundaryCondition(std::move(bc));
424 #endif // CORE_MODEL_INITIALIZER_H_