openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
ion_type.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // openCARP is an open cardiac electrophysiology simulator.
3 //
4 // Copyright (C) 2020 openCARP project
5 //
6 // This program is licensed under the openCARP Academic Public License (APL)
7 // v1.0: You can use and redistribute it and/or modify it in non-commercial
8 // academic environments under the terms of APL as published by the openCARP
9 // project v1.0, or (at your option) any later version. Commercial use requires
10 // a commercial license (info@opencarp.org).
11 //
12 // This program is distributed without any warranty; see the openCARP APL for
13 // more details.
14 //
15 // You should have received a copy of the openCARP APL along with this program
16 // and can find it online: http://www.opencarp.org/license
17 // ----------------------------------------------------------------------------
18 
19 #ifndef LIMPET_ION_TYPE_H
20 #define LIMPET_ION_TYPE_H
21 
22 #include "limpet_types.h"
23 #include "target.h"
24 #include <string>
25 #include <vector>
26 #include <stdio.h>
27 
28 namespace limpet {
29 
30 template<class T>
31 constexpr inline T max(T a, T b ){ return a > b ? a : b; }
32 template<class T>
33 constexpr inline T min(T a, T b ){ return a < b ? a : b; }
34 
35 /*
36 MODEL SPECIFIC DEFINITIONS
37 
38 Each ionic model must have a model_id, a name and a data structure
39 containing all its adjustable parameters. This data structure is
40 defined in the header files of the respective ionic models.
41 */
42 
43 #include "ION_IF_datatypes.h"
44 
45 class IonIfBase;
46 
47 typedef float Gatetype;
48 typedef GlobalData_t (*SVgetfcn)(IonIfBase&,int,int);
49 typedef void (*SVputfcn)(IonIfBase&,int,int,GlobalData_t);
50 typedef char IIF_Mask_t;
51 
59 class IonType {
60 public:
61  using params_type = void;
62  using state_type = void;
63  using private_type = void;
64  using private_type_vector = void;
65 private:
66  std::string _name;
67  bool _plugin;
68 
69 public:
70  IonType(std::string name, bool plugin) : _name(std::move(name)), _plugin(plugin) {}
71 
77  const std::string& get_name() const;
78 
84  bool is_plugin() const;
85 
91  virtual size_t params_size() const = 0;
92 
99  virtual size_t dlo_vector_size() const = 0;
100 
106  virtual uint32_t reqdat() const = 0;
107 
113  virtual uint32_t moddat() const = 0;
114 
120  virtual void initialize_params(IonIfBase& imp) const = 0;
121 
127  virtual void construct_tables(IonIfBase& imp) const = 0;
128 
136  virtual void destroy(IonIfBase& imp) const = 0;
137 
146  virtual void initialize_sv(IonIfBase& imp, GlobalData_t** data) const = 0;
147 
157  virtual Target select_target(Target target) const = 0;
158 
171  virtual void compute(Target target, int start, int end, IonIfBase& imp, GlobalData_t** data) const = 0;
172 
178  virtual bool has_trace() const = 0;
179 
188  virtual void trace(IonIfBase& imp, int node, FILE* file, GlobalData_t** data) const = 0;
189 
196  virtual void tune(IonIfBase& imp, const char* im_par) const = 0;
197 
205  virtual int read_svs(IonIfBase& imp, FILE* file) const = 0;
206 
214  virtual int write_svs(IonIfBase& imp, FILE* file, int node) const = 0;
215 
228  virtual SVgetfcn get_sv_offset(const char* svname, int* off, int* sz) const = 0;
229 
238  virtual int get_sv_list(char*** list) const = 0;
239 
250  virtual int get_sv_type(const char* svname, int* type, char** type_name) const = 0;
251 
255  virtual void print_params() const = 0;
256 
260  virtual void print_metadata() const = 0;
261 
269  virtual IonIfBase* make_ion_if(Target target, int num_node,
270  const std::vector<std::reference_wrapper<IonType>>& plugins) const = 0;
271 
280  virtual void destroy_ion_if(IonIfBase *imp) const = 0;
281 
282  bool operator==(const IonType& other) const;
283 
284  bool operator!=(const IonType& other) const;
285 };
286 
287 // Shorthand for lists of references to IonTypes
288 using IonTypeList = std::vector<std::reference_wrapper<IonType>>;
289 
290 // TODO: replace with std::optional<std::reference_wrapper<IonType>>
291 // Using std::optional would be nice but requires C++17
292 IonType* get_ion_type(const std::string& name);
293 
294 } // limpet namespace
295 
296 #endif // LIMPET_ION_TYPE_H
constexpr T min(T a, T b)
Definition: ion_type.h:33
GlobalData_t(* SVgetfcn)(IonIfBase &, int, int)
Definition: ion_type.h:48
void state_type
type of this model&#39;s state variable structure
Definition: ion_type.h:62
const std::string & get_name() const
Gets the model name.
Definition: ion_type.cc:23
bool operator!=(const IonType &other) const
Definition: ion_type.cc:35
virtual void print_params() const =0
Prints the parameters of this model.
virtual void initialize_sv(IonIfBase &imp, GlobalData_t **data) const =0
Initializes the state variables of the given IMP.
std::vector< std::reference_wrapper< IonType > > IonTypeList
Definition: ion_type.h:288
constexpr T max(T a, T b)
Definition: ion_type.h:31
float Gatetype
Definition: ion_type.h:45
virtual void trace(IonIfBase &imp, int node, FILE *file, GlobalData_t **data) const =0
Write the values of traced variables to file.
virtual size_t params_size() const =0
Gets the size in bytes needed to represent the parameters of this model.
void(* SVputfcn)(IonIfBase &, int, int, GlobalData_t)
Definition: ion_type.h:49
virtual int get_sv_type(const char *svname, int *type, char **type_name) const =0
Determines the type of a SV.
virtual void initialize_params(IonIfBase &imp) const =0
Initializes the parameters in the given IMP.
virtual int write_svs(IonIfBase &imp, FILE *file, int node) const =0
Write state variable values for one cell to a file/.
virtual int read_svs(IonIfBase &imp, FILE *file) const =0
Reads state variable values for one cell from a file.
virtual void destroy_ion_if(IonIfBase *imp) const =0
Destroy an IonIf object.
virtual void destroy(IonIfBase &imp) const =0
Destroys the given IMP.
virtual uint32_t moddat() const =0
Gets data flags for this IMP&#39;s modified data.
virtual Target select_target(Target target) const =0
Gets a supported target from the given target.
void params_type
type of this model&#39;s parameter structure
Definition: ion_type.h:61
void private_type_vector
Definition: ion_type.h:64
bool operator==(const IonType &other) const
Definition: ion_type.cc:31
Represents the ionic model and plug-in (IMP) data structure.
Definition: ION_IF.h:138
IonType * get_ion_type(const std::string &name)
virtual IonIfBase * make_ion_if(Target target, int num_node, const std::vector< std::reference_wrapper< IonType >> &plugins) const =0
Generate an IonIf object from this type.
virtual void tune(IonIfBase &imp, const char *im_par) const =0
Handles setting of this model&#39;s parameters.
virtual int get_sv_list(char ***list) const =0
Returns a list of SVs.
virtual size_t dlo_vector_size() const =0
Gets the vector size when using data layout optimization (DLO).
char IIF_Mask_t
Definition: ion_type.h:50
virtual uint32_t reqdat() const =0
Gets data flags for this IMP&#39;s required data.
virtual void print_metadata() const =0
Prints the metadata of this model.
virtual void construct_tables(IonIfBase &imp) const =0
Contructs lookup tables.
void private_type
type of this model&#39;s private structure
Definition: ion_type.h:63
Defines valid targets for an ionic model to run on and an allocator for allocating memory on a specif...
Target
enum that represents different targets to run ionic models on.
Definition: target.h:45
IonType(std::string name, bool plugin)
Definition: ion_type.h:70
virtual bool has_trace() const =0
Returns whether the trace method is available or not.
virtual void compute(Target target, int start, int end, IonIfBase &imp, GlobalData_t **data) const =0
Performs computation for 1 time step.
Abstract class representing an ionic model type.
Definition: ion_type.h:59
bool is_plugin() const
Returns whether this model is a plugin or not.
Definition: ion_type.cc:27
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.
SF_real GlobalData_t
Definition: limpet_types.h:27