BioDynaMo  v1.05.120-25dc9790
param.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_PARAM_PARAM_H_
16 #define CORE_PARAM_PARAM_H_
17 
18 #include <cinttypes>
19 #include <map>
20 #include <memory>
21 #include <set>
22 #include <string>
23 #include <unordered_map>
24 #include <vector>
25 #include "core/analysis/style.h"
26 #include "core/param/param_group.h"
27 #include "core/real_t.h"
28 #include "core/util/root.h"
29 #include "core/util/type.h"
30 
31 namespace bdm {
32 
33 class Simulation;
34 
35 struct Param {
36  static void RegisterParamGroup(ParamGroup* param);
37 
38  Param();
39 
40  ~Param();
41 
42  Param(const Param& other);
43 
44  void Restore(Param&& other);
45 
50  std::string ToJsonString() const;
51 
56  void MergeJsonPatch(const std::string& patch);
57 
58  template <typename TParamGroup>
59  const TParamGroup* Get() const {
60  if (groups_.find(TParamGroup::kUid) != groups_.end()) {
61  return bdm_static_cast<const TParamGroup*>(groups_.at(TParamGroup::kUid));
62  } else {
63  Log::Error("TParamGroup::Get",
64  "Couldn't find the requested group parameter.");
65  return nullptr;
66  }
67  }
68 
69  template <typename TParamGroup>
70  TParamGroup* Get() {
71  if (groups_.find(TParamGroup::kUid) != groups_.end()) {
72  return bdm_static_cast<TParamGroup*>(groups_.at(TParamGroup::kUid));
73  } else {
74  Log::Error("TParamGroup::Get",
75  "Couldn't find the requested group parameter.");
76  return nullptr;
77  }
78  }
79 
80  // simulation values ---------------------------------------------------------
90  uint64_t random_seed = 4357;
91 
99  std::vector<std::string> unschedule_default_operations;
100 
103  enum NumericalODESolver { kEuler = 1, kRK4 = 2 };
104  NumericalODESolver numerical_ode_solver = NumericalODESolver::kEuler;
105 
113  std::string output_dir = "output";
114 
122  std::string environment = "uniform_grid";
123 
131  uint32_t nanoflann_depth = 10;
132 
140  uint32_t unibn_bucketsize = 16;
141 
150 
159  std::string backup_file = "";
160 
169  std::string restore_file = "";
170 
177  uint32_t backup_interval = 1800;
178 
186 
195 
198  kOpen = 0,
210  };
211 
219 
228 
237 
244  std::string diffusion_boundary_condition = "Neumann";
245 
256 
257  std::string diffusion_method = "euler";
258 
265  bool calculate_gradients = true;
266 
274 
282  ThreadSafetyMechanism::kUserSpecified;
283 
284  // visualization values ------------------------------------------------------
285 
293  std::string visualization_engine = "paraview";
294 
304  bool insitu_visualization = false;
305 
312  bool export_visualization = false;
313 
320  bool root_visualization = false;
321 
328  std::string pv_insitu_pipeline =
329  Concat(std::getenv("BDMSYS"),
330  "/include/core/visualization/paraview/default_insitu_pipeline.py");
331 
343  std::string pv_insitu_pipelinearguments = "";
344 
354 
363 
385  std::map<std::string, std::set<std::string>>
387 
389  std::string name;
390  bool concentration = true;
391  bool gradient = false;
392  };
393 
416  std::vector<VisualizeDiffusion> visualize_diffusion;
417 
428 
429  // performance values --------------------------------------------------------
430 
437  uint64_t scheduling_batch_size = 1000;
438 
440 
457  ExecutionOrder execution_order = ExecutionOrder::kForEachAgentForEachOp;
458 
470  bool detect_static_agents = false;
471 
480  bool cache_neighbors = false;
481 
487  bool use_bdm_mem_mgr = true;
488 
500 
509 
523 
537 
546 
556  MappedDataArrayMode::kZeroCopy;
557 
558  // development values --------------------------------------------------------
568  bool statistics = false;
569 
575 #ifdef USE_LIBGIT2
576  bool track_git_changes = true;
577 #endif // USE_LIBGIT2
578 
586  bool debug_numa = false;
587 
595  uint64_t show_simulation_step = 0;
596 
607  bool use_progress_bar = false;
608 
614  std::string progress_bar_time_unit = "s";
615 
616  // ---------------------------------------------------------------------------
617  // experimental group
618 
625  std::string compute_target = "cpu";
626 
633  bool opencl_debug = false;
634 
641  int preferred_gpu = -1;
642 
645  bool plot_memory_layout = false;
646 
648  void AssignFromConfig(const std::shared_ptr<cpptoml::table>&);
649 
650  private:
652  static std::unordered_map<ParamGroupUid, std::unique_ptr<ParamGroup>>
654  std::unordered_map<ParamGroupUid, ParamGroup*> groups_;
656 };
657 
658 } // namespace bdm
659 
660 #endif // CORE_PARAM_PARAM_H_
bdm::Param::VisualizeDiffusion
Definition: param.h:388
bdm::Param::visualization_engine
std::string visualization_engine
Definition: param.h:293
bdm::Param::use_progress_bar
bool use_progress_bar
Definition: param.h:607
bdm::Param::remove_output_dir_contents
bool remove_output_dir_contents
Definition: param.h:149
bdm::Param::kAutomatic
@ kAutomatic
Definition: param.h:273
style.h
bdm::Param::kNone
@ kNone
Definition: param.h:273
bdm::Param::kForEachOpForEachAgent
@ kForEachOpForEachAgent
Definition: param.h:439
bdm::Param::mapped_data_array_mode
Param::MappedDataArrayMode mapped_data_array_mode
Definition: param.h:555
bdm::Param::groups_
std::unordered_map< ParamGroupUid, ParamGroup * > groups_
Definition: param.h:654
bdm::Param::Param
Param()
Definition: param.cc:42
bdm::Param::detect_static_agents
bool detect_static_agents
Definition: param.h:470
bdm
Definition: agent.cc:39
bdm::Param::Get
TParamGroup * Get()
Definition: param.h:70
bdm::Param::kForEachAgentForEachOp
@ kForEachAgentForEachOp
Definition: param.h:439
bdm::Param::insitu_visualization
bool insitu_visualization
Definition: param.h:304
param_group.h
bdm::Param::debug_numa
bool debug_numa
Definition: param.h:586
bdm::Param::visualize_agents
std::map< std::string, std::set< std::string > > visualize_agents
JSON_object.
Definition: param.h:386
bdm::Param::ToJsonString
std::string ToJsonString() const
Definition: param.cc:108
bdm::Param::NumericalODESolver
NumericalODESolver
Definition: param.h:103
bdm::Param::mem_mgr_aligned_pages_shift
uint64_t mem_mgr_aligned_pages_shift
Definition: param.h:499
bdm::Param::use_bdm_mem_mgr
bool use_bdm_mem_mgr
Definition: param.h:487
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::Param::unibn_bucketsize
uint32_t unibn_bucketsize
Definition: param.h:140
bdm::Param::cache_neighbors
bool cache_neighbors
Definition: param.h:480
bdm::Param::kCache
@ kCache
Definition: param.h:545
bdm::Param::DiffusionTest_CopyOldData_Test
friend class DiffusionTest_CopyOldData_Test
Definition: param.h:651
bdm::Param::BoundSpaceMode
BoundSpaceMode
Definition: param.h:196
bdm::Param::export_visualization
bool export_visualization
Definition: param.h:312
bdm::Param::kEuler
@ kEuler
Definition: param.h:103
bdm::Param::show_simulation_step
uint64_t show_simulation_step
Definition: param.h:595
bdm::Param::diffusion_boundary_condition
std::string diffusion_boundary_condition
Definition: param.h:244
bdm::Param::kTorus
@ kTorus
Definition: param.h:209
bdm::Param::progress_bar_time_unit
std::string progress_bar_time_unit
Definition: param.h:614
type.h
bdm::Param::backup_file
std::string backup_file
Definition: param.h:159
bdm::Param::RegisterParamGroup
static void RegisterParamGroup(ParamGroup *param)
Definition: param.cc:37
bdm::Param::VisualizeDiffusion::gradient
bool gradient
Definition: param.h:391
bdm::Param::mem_mgr_max_mem_per_thread_factor
uint64_t mem_mgr_max_mem_per_thread_factor
Definition: param.h:522
bdm::Param::numerical_ode_solver
NumericalODESolver numerical_ode_solver
Definition: param.h:104
bdm::Param::kRK4
@ kRK4
Definition: param.h:103
bdm::Param::Get
const TParamGroup * Get() const
Definition: param.h:59
bdm::Param::MappedDataArrayMode
MappedDataArrayMode
Definition: param.h:545
bdm::Param::kCopy
@ kCopy
Definition: param.h:545
bdm::Param::minimize_memory_while_rebalancing
bool minimize_memory_while_rebalancing
Definition: param.h:536
bdm::Param::compute_target
std::string compute_target
Definition: param.h:625
bdm::Param::BDM_CLASS_DEF_NV
BDM_CLASS_DEF_NV(Param, 1)
bdm::Param::mem_mgr_growth_rate
real_t mem_mgr_growth_rate
Definition: param.h:508
bdm::Param::backup_interval
uint32_t backup_interval
Definition: param.h:177
bdm::Param::opencl_debug
bool opencl_debug
Definition: param.h:633
bdm::Param::diffusion_method
std::string diffusion_method
Definition: param.h:257
bdm::Param::max_bound
real_t max_bound
Definition: param.h:236
bdm::Param::unschedule_default_operations
std::vector< std::string > unschedule_default_operations
Definition: param.h:99
bdm::Param::pv_insitu_pipelinearguments
std::string pv_insitu_pipelinearguments
Definition: param.h:343
bdm::Param::registered_groups_
static std::unordered_map< ParamGroupUid, std::unique_ptr< ParamGroup > > registered_groups_
Definition: param.h:653
bdm::Param::simulation_time_step
real_t simulation_time_step
Definition: param.h:185
bdm::Param::plot_memory_layout
bool plot_memory_layout
Definition: param.h:645
bdm::Param::scheduling_batch_size
uint64_t scheduling_batch_size
Definition: param.h:437
root.h
bdm::Param::kOpen
@ kOpen
The simulation space grows to encapsulate all agents.
Definition: param.h:198
bdm::Param::kClosed
@ kClosed
Definition: param.h:203
bdm::Param::VisualizeDiffusion::name
std::string name
Definition: param.h:389
bdm::Param::visualization_compress_pv_files
bool visualization_compress_pv_files
Definition: param.h:427
bdm::Param::min_bound
real_t min_bound
Definition: param.h:227
bdm::Param::ExecutionOrder
ExecutionOrder
Definition: param.h:439
bdm::ParamGroup
Interface for parameter groups.
Definition: param_group.h:45
bdm::Concat
std::string Concat(const Args &... parts)
Concatenates all arguments into a string. Equivalent to streaming all arguments into a stringstream a...
Definition: string.h:70
bdm::Param::execution_order
ExecutionOrder execution_order
Definition: param.h:457
bdm::Param::MergeJsonPatch
void MergeJsonPatch(const std::string &patch)
Definition: param.cc:126
bdm::Param::~Param
~Param()
Definition: param.cc:50
bdm::Log::Error
static void Error(const std::string &location, const Args &... parts)
Prints error message.
Definition: log.h:79
bdm::Param::simulation_max_displacement
real_t simulation_max_displacement
Definition: param.h:194
bdm::Param::AssignFromConfig
void AssignFromConfig(const std::shared_ptr< cpptoml::table > &)
Assign values from config file to variables.
Definition: param.cc:220
bdm::Param::random_seed
uint64_t random_seed
Definition: param.h:90
bdm::Param::environment
std::string environment
Definition: param.h:122
bdm::Param::ThreadSafetyMechanism
ThreadSafetyMechanism
Definition: param.h:273
bdm::Param::root_visualization
bool root_visualization
Definition: param.h:320
bdm::Param::bound_space
BoundSpaceMode bound_space
Definition: param.h:218
real_t.h
bdm::Param::visualization_interval
uint32_t visualization_interval
Definition: param.h:353
bdm::Param::output_dir
std::string output_dir
Definition: param.h:113
bdm::Param::calculate_gradients
bool calculate_gradients
Definition: param.h:265
bdm::Param::pv_insitu_pipeline
std::string pv_insitu_pipeline
Definition: param.h:328
bdm::Param::thread_safety_mechanism
ThreadSafetyMechanism thread_safety_mechanism
Definition: param.h:281
bdm::Param::VisualizeDiffusion::concentration
bool concentration
Definition: param.h:390
bdm::Param::preferred_gpu
int preferred_gpu
Definition: param.h:641
bdm::Param::restore_file
std::string restore_file
Definition: param.h:169
bdm::Param::visualize_diffusion
std::vector< VisualizeDiffusion > visualize_diffusion
Definition: param.h:416
bdm::Param
Definition: param.h:35
bdm::Param::kUserSpecified
@ kUserSpecified
Definition: param.h:273
bdm::Param::kZeroCopy
@ kZeroCopy
Definition: param.h:545
bdm::Param::visualization_export_generate_pvsm
bool visualization_export_generate_pvsm
Definition: param.h:362
bdm::Param::statistics
bool statistics
Definition: param.h:568
bdm::Param::Restore
void Restore(Param &&other)
Definition: param.cc:57
bdm::Param::nanoflann_depth
uint32_t nanoflann_depth
Definition: param.h:131