openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
ion_type.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: LicenseRef-APL-1.1
3 
4 #ifndef LIMPET_ION_TYPE_H
5 #define LIMPET_ION_TYPE_H
6 
7 #include "limpet_types.h"
8 #include "target.h"
9 #include <string>
10 #include <vector>
11 #include <stdio.h>
12 
13 namespace limpet {
14 
15 template<class T>
16 constexpr inline T max(T a, T b ){ return a > b ? a : b; }
17 template<class T>
18 constexpr inline T min(T a, T b ){ return a < b ? a : b; }
19 
20 /*
21 MODEL SPECIFIC DEFINITIONS
22 
23 Each ionic model must have a model_id, a name and a data structure
24 containing all its adjustable parameters. This data structure is
25 defined in the header files of the respective ionic models.
26 */
27 
28 #include "ION_IF_datatypes.h"
29 
30 class IonIfBase;
31 
32 typedef float Gatetype;
35 typedef char IIF_Mask_t;
36 
44 class IonType {
45 public:
46  using params_type = void;
47  using state_type = void;
48  using private_type = void;
49  using private_type_vector = void;
50 private:
51  std::string _name;
52  bool _plugin;
53 
54 public:
55  IonType(std::string name, bool plugin) : _name(std::move(name)), _plugin(plugin) {}
56 
62  const std::string& get_name() const;
63 
69  bool is_plugin() const;
70 
76  virtual size_t params_size() const = 0;
77 
84  virtual size_t dlo_vector_size() const = 0;
85 
91  virtual uint32_t reqdat() const = 0;
92 
98  virtual uint32_t moddat() const = 0;
99 
105  virtual void initialize_params(IonIfBase& imp) const = 0;
106 
112  virtual void construct_tables(IonIfBase& imp) const = 0;
113 
121  virtual void destroy(IonIfBase& imp) const = 0;
122 
131  virtual void initialize_sv(IonIfBase& imp, GlobalData_t** data) const = 0;
132 
142  virtual Target select_target(Target target) const = 0;
143 
156  virtual void compute(Target target, node_index_t start, node_index_t end, IonIfBase& imp, GlobalData_t** data) const = 0;
157 
163  virtual bool has_trace() const = 0;
164 
173  virtual void trace(IonIfBase& imp, node_index_t node, FILE* file, GlobalData_t** data) const = 0;
174 
181  virtual void tune(IonIfBase& imp, const char* im_par) const = 0;
182 
190  virtual int read_svs(IonIfBase& imp, FILE* file) const = 0;
191 
199  virtual int write_svs(IonIfBase& imp, FILE* file, node_index_t node) const = 0;
200 
214  virtual SVgetfcn get_sv_offset(const char* svname, int* off, int* sz) const = 0;
215 
224  virtual int get_sv_list(char*** list) const = 0;
225 
236  virtual int get_sv_type(const char* svname, int* type, char** type_name) const = 0;
237 
241  virtual void print_params() const = 0;
242 
246  virtual void print_metadata() const = 0;
247 
255  virtual IonIfBase* make_ion_if(Target target, node_count_t num_node,
256  const std::vector<std::reference_wrapper<IonType>>& plugins) const = 0;
257 
266  virtual void destroy_ion_if(IonIfBase *imp) const = 0;
267 
268  bool operator==(const IonType& other) const;
269 
270  bool operator!=(const IonType& other) const;
271  virtual ~IonType() = default;
272 
273 };
274 
275 // Shorthand for lists of references to IonTypes
276 using IonTypeList = std::vector<std::reference_wrapper<IonType>>;
277 
278 // TODO: replace with std::optional<std::reference_wrapper<IonType>>
279 // Using std::optional would be nice but requires C++17
280 IonType* get_ion_type(const std::string& name);
281 
282 } // limpet namespace
283 
284 #endif // LIMPET_ION_TYPE_H
Represents the ionic model and plug-in (IMP) data structure.
Definition: ION_IF.h:168
Abstract class representing an ionic model type.
Definition: ion_type.h:44
bool is_plugin() const
Returns whether this model is a plugin or not.
Definition: ion_type.cc:12
virtual bool has_trace() const =0
Returns whether the trace method is available or not.
const std::string & get_name() const
Gets the model name.
Definition: ion_type.cc:8
virtual void initialize_params(IonIfBase &imp) const =0
Initializes the parameters in the given IMP.
virtual SVgetfcn get_sv_offset(const char *svname, int *off, int *sz) const =0
Get the offset and size of a state variable of the model, as well as an access function.
virtual int get_sv_list(char ***list) const =0
Returns a list of SVs.
virtual void print_metadata() const =0
Prints the metadata of this model.
virtual uint32_t moddat() const =0
Gets data flags for this IMP's modified data.
virtual int read_svs(IonIfBase &imp, FILE *file) const =0
Reads state variable values for one cell from a file.
virtual ~IonType()=default
virtual void tune(IonIfBase &imp, const char *im_par) const =0
Handles setting of this model's parameters.
void state_type
type of this model's state variable structure
Definition: ion_type.h:47
void private_type_vector
Definition: ion_type.h:49
virtual void print_params() const =0
Prints the parameters of this model.
virtual int get_sv_type(const char *svname, int *type, char **type_name) const =0
Determines the type of a SV.
void params_type
type of this model's parameter structure
Definition: ion_type.h:46
void private_type
type of this model's private structure
Definition: ion_type.h:48
virtual void compute(Target target, node_index_t start, node_index_t end, IonIfBase &imp, GlobalData_t **data) const =0
Performs computation for 1 time step.
bool operator==(const IonType &other) const
Definition: ion_type.cc:16
virtual void initialize_sv(IonIfBase &imp, GlobalData_t **data) const =0
Initializes the state variables of the given IMP.
virtual int write_svs(IonIfBase &imp, FILE *file, node_index_t node) const =0
Write state variable values for one cell to a file/.
virtual uint32_t reqdat() const =0
Gets data flags for this IMP's required data.
virtual Target select_target(Target target) const =0
Gets a supported target from the given target.
virtual void destroy_ion_if(IonIfBase *imp) const =0
Destroy an IonIf object.
virtual size_t params_size() const =0
Gets the size in bytes needed to represent the parameters of this model.
virtual IonIfBase * make_ion_if(Target target, node_count_t num_node, const std::vector< std::reference_wrapper< IonType >> &plugins) const =0
Generate an IonIf object from this type.
bool operator!=(const IonType &other) const
Definition: ion_type.cc:20
virtual void construct_tables(IonIfBase &imp) const =0
Contructs lookup tables.
virtual void trace(IonIfBase &imp, node_index_t node, FILE *file, GlobalData_t **data) const =0
Write the values of traced variables to file.
virtual void destroy(IonIfBase &imp) const =0
Destroys the given IMP.
virtual size_t dlo_vector_size() const =0
Gets the vector size when using data layout optimization (DLO).
IonType(std::string name, bool plugin)
Definition: ion_type.h:55
void(* SVputfcn)(IonIfBase &, node_index_t, int, GlobalData_t)
Definition: ion_type.h:34
float Gatetype
Definition: ion_type.h:30
Target
enum that represents different targets to run ionic models on.
Definition: target.h:30
IonType * get_ion_type(const std::string &name)
SF_real GlobalData_t
Definition: limpet_types.h:12
constexpr T min(T a, T b)
Definition: ion_type.h:18
GlobalData_t(* SVgetfcn)(IonIfBase &, node_index_t, int)
Definition: ion_type.h:33
std::vector< std::reference_wrapper< IonType > > IonTypeList
Definition: ion_type.h:276
constexpr T max(T a, T b)
Definition: ion_type.h:16
opencarp::local_index_t node_count_t
Definition: limpet_types.h:14
char IIF_Mask_t
Definition: ion_type.h:35
opencarp::local_index_t node_index_t
Definition: limpet_types.h:13
Defines valid targets for an ionic model to run on and an allocator for allocating memory on a specif...