openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
ionics.cc
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: LicenseRef-APL-1.1
3 
12 #include "ionics.h"
13 
14 #include "SF_init.h"
15 
16 namespace opencarp {
17 
19 {
20  double t1, t2;
21  get_time(t1);
22 
24 
25  double comp_time = timing(t2, t1);
26  this->compute_time += comp_time;
27 
28  comp_stats.calls++;
29  comp_stats.tot_time += comp_time;
30 
33 }
34 
36 {
37  miif->free_MIIF();
38 }
39 
41 {}
42 
44 {
45  double t1, t2;
46  get_time(t1);
47 
48  set_dir(OUTPUT);
49 
50  // initialize generic logger for ODE timings per time_dt
51  comp_stats.init_logger("ODE_stats.dat");
52 
53  double tstart = 0.;
54  sf_mesh & mesh = get_mesh(ion_domain);
55  limpet::node_count_t loc_size = mesh.pl.num_algebraic_idx();
56 
57  // create ionic current vector and register it
58  sf_vec *IIon;
59  sf_vec *Vmv;
60  SF::init_vector(&IIon, mesh, 1, sf_vec::algebraic);
61  SF::init_vector(&Vmv, mesh, 1, sf_vec::algebraic);
62  register_data(IIon, iion_vec);
63  register_data(Vmv, vm_vec);
64 
65  // setup miif
66  miif = new limpet::MULTI_IF();
67  // hand down the physics log file, so that what MULTI_IF reports while setting up and
68  // restoring state is recorded rather than only echoed to the console
69  miif->logger = logger;
70  // store IIF_IDs and Plugins in arrays
71  miif->name = "myocardium";
72  miif->gdata[limpet::Vm] = Vmv;
73  miif->gdata[limpet::Iion] = IIon;
74 
75  int rank = get_rank();
76 
77  SF::vector<RegionSpecs> rs(param_globals::num_imp_regions);
78  for (size_t i = 0; i < rs.size(); i++ ) {
79  rs[i].nsubregs = param_globals::imp_region[i].num_IDs;
80  rs[i].subregtags = param_globals::imp_region[i].ID;
81  for (int j=0;j<rs[i].nsubregs;j++) {
82  if(rs[i].subregtags[j]==-1 && rank==0)
83  log_msg(NULL,3,ECHO, "Warning: not all %u IDs provided for imp_region[%u]!\n", rs[i].nsubregs, i);
84  }
85  }
86 
87  SF::vector<int> reg_mask;
88  region_mask(ion_domain, rs, reg_mask, false, "imp_region");
89 
90  int purkfLen = 1;
91  tstart = setup_MIIF(loc_size, param_globals::num_imp_regions, param_globals::imp_region,
92  reg_mask.data(), param_globals::start_statef, param_globals::num_adjustments,
93  param_globals::adjustment, param_globals::dt, purkfLen > 0);
94 
95  miif->extUpdateVm = !param_globals::operator_splitting;
96 
97  // if we start at a non-zero time (i.e. we have restored a state), we notify the
98  // timer manager
99  if(tstart > 0.) {
100  log_msg(logger, 0, 0, "Changing simulation start time to %.2lf", tstart);
101  user_globals::tm_manager->setup(param_globals::dt, tstart, param_globals::tend);
103  }
104 
105  set_dir(INPUT);
106 
107  this->initialize_time += timing(t2, t1);
108 }
109 
110 double Ionics::setup_MIIF(limpet::node_count_t nnodes, int nreg, IMPregion* impreg, int* mask,
111  const char *start_fn, int numadjust, IMPVariableAdjustment *adjust,
112  double time_step, bool close)
113 {
114  double tstart = 0;
115 
116  miif->N_IIF = nreg;
117  miif->numNode = nnodes;
118  miif->iontypes = {};
119  miif->numplugs = (int*)calloc( miif->N_IIF, sizeof(int));
120  miif->plugtypes = std::vector<limpet::IonTypeList>(miif->N_IIF);
121  miif->targets = std::vector<limpet::Target>(miif->N_IIF, limpet::Target::AUTO);
122 
123  log_msg(logger,0,ECHO, "\nSetting up ionic models and plugins\n" \
124  "-----------------------------------\n\n" \
125  "Assigning IMPS to tagged regions:" );
126 
127  for (int i=0;i<miif->N_IIF;i++) {
128  auto pT = limpet::get_ion_type(std::string(impreg[i].im));
129  if (pT != NULL)
130  {
131  miif->iontypes.push_back(*pT);
132  log_msg(logger, 0, ECHO|NONL, "\tIonic model: %s to tag region(s)", impreg[i].im);
133 
134  if(impreg[i].num_IDs > 0) {
135  for(int j = 0; j < impreg[i].num_IDs; j++)
136  log_msg(logger,0,ECHO|NONL, " [%d],", impreg[i].ID[j]);
137  log_msg(logger,0,ECHO,"\b.");
138  }
139  else {
140  log_msg(logger,0,ECHO, " [0] (implicitely)");
141  }
142  }
143  else {
144  log_msg(NULL,5,ECHO, "Illegal IM specified: %s\n", impreg[i].im );
145  log_msg(NULL,5,ECHO, "Run bench --list-imps for a list of all available models.\n" );
146  EXIT(1);
147  }
148  if (limpet::get_plug_flag( impreg[i].plugins, &miif->numplugs[i], miif->plugtypes[i]))
149  {
150  if(impreg[i].plugins[0] != '\0') {
151  log_msg(logger,0, ECHO|NONL, "\tPlug-in(s) : %s to tag region(s)", impreg[i].plugins);
152 
153  for(int j = 0; j < impreg[i].num_IDs; j++)
154  log_msg(logger,0,ECHO|NONL, " [%d],", impreg[i].ID[j]);
155  log_msg(logger,0,ECHO,"\b.");
156  }
157  }
158  else {
159  log_msg(NULL,5,ECHO,"Illegal plugin specified: %s\n", impreg[i].plugins);
160  log_msg(NULL,5,ECHO, "Run bench --list-imps for a list of all available plugins.\n" );
161  EXIT(1);
162  }
163  }
164 
166 
167  // The mask is a nodal vector with the region IDs of each node.
168  // It is already reduced during the region_mask call to guarantee unique values
169  // for overlapping interface nodes
170  if (mask) {
171  for (limpet::node_index_t i=0; i<miif->numNode; i++)
172  miif->IIFmask[i] = (limpet::IIF_Mask_t) mask[i];
173  }
174 
176 
177  for(int i=0; i<miif->N_IIF; i++)
178  if(!miif->IIF[i]->cgeom().SVratio)
179  miif->IIF[i]->cgeom().SVratio = param_globals::imp_region[i].cellSurfVolRatio;
180 
181  for (int i=0;i<miif->N_IIF;i++) {
182  // the IMP tuning does not handle spaces well, thus we remove them here
183  remove_char(impreg[i].im_param, strlen(impreg[i].im_param), ' ');
184  miif->IIF[i]->tune(impreg[i].im_param, impreg[i].plugins, impreg[i].plug_param);
185  }
186 
187  set_dir(INPUT);
188  miif->initialize_currents(time_step, param_globals::ode_fac);
189 
190  // overriding initial values goes here
191  // read in single cell state vector and spread it out over the entire region
192  set_dir(INPUT);
193  for (int i=0;i<miif->N_IIF;i++) {
194  if (impreg[i].im_sv_init && strlen(impreg[i].im_sv_init) > 0)
195  if (read_sv(miif, i, impreg[i].im_sv_init)) {
196  log_msg(NULL, 5, ECHO|FLUSH, "State vector initialization failed for %s.\n", impreg[i].name);
197  EXIT(-1);
198  }
199  }
200 
201  if( !start_fn || strlen(start_fn)>0 )
202  tstart = (double) miif->restore_state(start_fn, ion_domain, close);
203 
204  for (int i=0; i<numadjust; i++)
205  {
206  set_dir(INPUT);
207 
208  SF::vector<SF_int> indices;
209  SF::vector<SF_real> values;
210  bool restrict_to_algebraic = true;
211 
212  sf_mesh & imesh = get_mesh(ion_domain);
213  std::map<std::string,std::string> metadata;
214  read_metadata(adjust[i].file, metadata, PETSC_COMM_WORLD);
215 
216  SF::SF_nbr nbr = SF::NBR_REF;
217  if(metadata.count("grid") && metadata["grid"].compare("intra") == 0) {
218  nbr = SF::NBR_SUBMESH;
219  }
220  read_indices_with_data(indices, values, adjust[i].file, imesh, nbr, restrict_to_algebraic, 1, PETSC_COMM_WORLD);
221 
222  int rank = get_rank();
223 
224  for(size_t gi = 0; gi < indices.size(); gi++)
225  indices[gi] = SF::local_nodal_to_local_petsc<mesh_int_t,mesh_real_t>(imesh, rank, indices[gi]);
226 
227  // debug, output parameters on global intracellular vector
228  if(adjust[i].dump) {
229  sf_vec* adjPars;
230  SF::init_vector(&adjPars, imesh, 1, sf_vec::algebraic);
231  adjPars->set(indices, values, false, true);
232 
233  set_dir(OUTPUT);
234  char fname[2085];
235  snprintf(fname, sizeof fname, "adj_%s_perm.dat", adjust[i].variable);
236  adjPars->write_ascii(fname, false);
237 
238  // get the scattering to the canonical permutation
240  if(sc == NULL) {
241  log_msg(0,3,0, "%s warning: PETSC_TO_CANONICAL permutation needed registering!", __func__);
243  }
244 
245  (*sc)(*adjPars, true);
246  snprintf(fname, sizeof fname, "adj_%s_canonical.dat", adjust[i].variable);
247  adjPars->write_ascii(fname, false);
248  }
249 
250  int nc = miif->adjust_MIIF_variables(adjust[i].variable, indices, values);
251  log_msg(logger, 0, 0, "Adjusted %d values for %s", nc, adjust[i].variable);
252  }
253 
254  return tstart;
255 }
256 
268  const char* gridname, const char* reglist)
269 {
270  bool AllTagsExist = true;
271 
273  tagset.insert(tags.begin(), tags.end());
274 
275  // cycle through all user-specified regions
276  for (size_t reg=0; reg<regspec.size(); reg++)
277  // cycle through all tags which belong to the region
278  for (int k=0; k<regspec[reg].nsubregs; k++) {
279  // check whether this tag exists in element list
280  int n = 0;
281  if(tagset.count(regspec[reg].subregtags[k])) n++;
282  // globalize n
283  int N = get_global(n, MPI_SUM);
284  if (N==0) {
285  if(strcmp(reglist, "gregion_vol"))
286  log_msg(NULL, 3, ECHO,
287  "%s[%d] references tag %d, but no element in the %s grid carries this tag — region will have no elements.\n",
288  reglist, reg, regspec[reg].subregtags[k], gridname);
289  AllTagsExist = false;
290  }
291  }
292 
293  if (!AllTagsExist) {
294  log_msg(NULL, 4, ECHO,"One or more configured regions are empty. Check that region tag IDs match the tags in your mesh or tagfile.\n");
295  }
296 
297  return AllTagsExist;
298 }
299 
301  const char* gridname, const char* reglist,
302  bool warn_on_default_tags)
303 {
304  if(!warn_on_default_tags) return;
305 
306  // build the set of tags covered by configured regions (1..N-1; region 0 is the implicit default)
308  for (size_t reg = 1; reg < regspec.size(); reg++)
309  for (int k = 0; k < regspec[reg].nsubregs; k++)
310  configured.insert(regspec[reg].subregtags[k]);
311 
312  SF::vector<mesh_int_t> unmatched;
313  long int n_defaulted = 0;
314  for (const mesh_int_t & t : tags) {
315  if (!configured.count(t)) {
316  unmatched.push_back(t);
317  n_defaulted++;
318  }
319  }
320 
321  n_defaulted = get_global(n_defaulted, MPI_SUM);
322  if (!n_defaulted) return;
323 
324  binary_sort(unmatched);
325  unique_resize(unmatched);
326  make_global(unmatched, PETSC_COMM_WORLD);
327  binary_sort(unmatched);
328  unique_resize(unmatched);
329 
330  std::string taglist;
331  for (size_t i = 0; i < unmatched.size(); i++) {
332  if (i) taglist += ", ";
333  taglist += std::to_string(unmatched[i]);
334  }
335 
336  log_msg(NULL, 3, ECHO,
337  "%s: %ld element(s) in %s grid carry tags {%s} not assigned to any "
338  "%s region; these elements default to region 0.\n",
339  __func__, n_defaulted, gridname, taglist.c_str(), reglist);
340 }
341 
342 void region_mask(mesh_t meshspec, SF::vector<RegionSpecs> & regspec,
343  SF::vector<int> & regionIDs, bool mask_elem, const char* reglist,
344  bool warn_on_default_tags)
345 {
346  if(regspec.size() == 1) return;
347 
348  sf_mesh & mesh = get_mesh(meshspec);
350 
351  // initialize the list with the default regionID, 0
352  size_t rIDsize = mask_elem ? mesh.l_numelem : mesh.l_numpts;
353 
354  size_t nelem = mesh.l_numelem;
355  const SF::vector<mesh_int_t> & tags = mesh.tag;
356 
357  // check whether all specified tags exist in the element list
358  check_tags_in_elems(tags, regspec, mesh.name.c_str(), reglist);
359  check_unassigned_tags(tags, regspec, mesh.name.c_str(), reglist, warn_on_default_tags);
360 
361  regionIDs.assign(rIDsize, 0);
363 
364  // we generate a map from tags to region IDs. This has many benefits, mainly we can check
365  // whether a tag is assigned to multiple regions and simplify our regionIDs filling loop
366  for (size_t reg=1; reg < regspec.size(); reg++) {
367  int err = 0;
368  for (int k=0; k < regspec[reg].nsubregs; k++) {
369  int curtag = regspec[reg].subregtags[k];
370  if(tag_to_reg.count(curtag)) err++;
371 
372  if(get_global(err, MPI_SUM))
373  log_msg(0,4,0, "%s warning: Tag idx %d is assigned to multiple regions!\n"
374  "Its final assignment will be to the highest assigned region ID!",
375  __func__, curtag);
376 
377  tag_to_reg[curtag] = reg;
378  }
379  }
380 
381  SF::vector<int> mx_tag(regionIDs.size(), -1);
382 
383  // cycle through the element list
384  for(size_t i=0; i<nelem; i++) {
385  const mesh_int_t & cur_tag = tags[i];
386  // check if current element tag has a custom region ID
387  if (tag_to_reg.count(cur_tag))
388  {
389  int reg = tag_to_reg[cur_tag];
390 
391  if (mask_elem) regionIDs[i] = reg;
392  else {
393  eview.set_elem(i);
394 
395  for (int j=0; j < eview.num_nodes(); j++) {
396  mesh_int_t n = eview.node(j);
397  if (cur_tag > mx_tag[n]) mx_tag[n] = cur_tag;
398  }
399  }
400  }
401  }
402 
403  if(mask_elem) return;
404 
405  // The tie between the tags meeting at a node must be broken on the tags themselves.
406  // Reducing the region IDs instead would let the highest region win at nodes shared
407  // between ranks while the highest tag wins everywhere else, making the assignment
408  // depend on the partitioning whenever the tags are not listed in ascending order.
409  mesh.pl.reduce(mx_tag, "max");
410 
411  for(size_t i=0; i < regionIDs.size(); i++)
412  if(mx_tag[i] >= 0) regionIDs[i] = tag_to_reg[mx_tag[i]];
413 
414  const SF::vector<mesh_int_t> & alg_nod = mesh.pl.algebraic_nodes();
416 
417  SF::vector<int> alg_reg(alg_nod.size());
418  SF::vector<int> gids (alg_nod.size());
419 
420  for(size_t i=0; i<alg_nod.size(); i++) {
421  alg_reg[i] = regionIDs[alg_nod[i]];
422  gids[i] = nbr[alg_nod[i]];
423  }
424 
425  regionIDs = alg_reg;
426 
427  if(param_globals::dump_imp_region) {
428  set_dir(OUTPUT);
429  write_data_ascii(PETSC_COMM_WORLD, gids, regionIDs, std::string(reglist)+".dat");
430  }
431 }
432 
435 double Ionics::timer_val(const int timer_id)
436 {
437  double val = std::nan("NaN");
438  return val;
439 }
440 
443 std::string Ionics::timer_unit(const int timer_id)
444 {
445  std::string s_unit;
446  return s_unit;
447 }
448 
450 {
451  if (impdata[limpet::Iion] != NULL)
452  impdata[limpet::Iion][n] = 0;
453 
454  pIF.for_each([&](limpet::IonIfBase& imp) {
455  update_ts(&imp.get_tstp());
456  imp.compute(n, n + 1, impdata);
457  });
458 }
459 
471 void* find_SV_in_IMP(limpet::MULTI_IF* miif, const int idx, const char *IMP, const char *SV,
472  int* offset, int* sz, int* plugin_idx)
473 {
474  *plugin_idx = -1;
475 
476  if(strcmp(IMP, miif->iontypes[idx].get().get_name().c_str()) == 0) {
477  return (void*) miif->iontypes[idx].get().get_sv_offset(SV, offset, sz);
478  }
479  else {
480  for(int k=0; k<miif->numplugs[idx]; k++)
481  if(strcmp(IMP, miif->plugtypes[idx][k].get().get_name().c_str()) == 0) {
482  *plugin_idx = k;
483  return (void*) miif->plugtypes[idx][k].get().get_sv_offset(SV, offset, sz);
484  }
485  }
486 
487  return NULL;
488 }
489 
490 
500 void alloc_gvec_data(const int nGVcs, const int nRegs,
501  GVecs *prmGVecs, gvec_data &glob_vecs)
502 {
503  glob_vecs.nRegs = nRegs;
504 
505  if (nGVcs) {
506  glob_vecs.vecs.resize(nGVcs);
507  glob_vecs.plugin_idx.resize(nGVcs);
508 
509  for (size_t i = 0; i < glob_vecs.vecs.size(); i++) {
510  sv_data &gvec = glob_vecs.vecs[i];
511 
512  gvec.name = dupstr(prmGVecs[i].name);
513  gvec.units = dupstr(prmGVecs[i].units);
514  gvec.bogus = prmGVecs[i].bogus;
515 
516  gvec.imps = (char**) calloc(nRegs, sizeof(char *));
517  gvec.svNames = (char**) calloc(nRegs, sizeof(char *));
518  gvec.svSizes = (int*) calloc(nRegs, sizeof(int));
519  gvec.svOff = (int*) calloc(nRegs, sizeof(int));
520  gvec.getsv = (void**) calloc(nRegs, sizeof(limpet::SVgetfcn));
521 
522  for (int j = 0; j < nRegs; j++) {
523  if (strlen(prmGVecs[i].imp)) gvec.imps[j] = dupstr(prmGVecs[i].imp);
524 #ifdef WITH_PURK
525  else if (j < param_globals::num_imp_regions)
526  gvec.imps[j] = dupstr(param_globals::imp_region[j].im);
527  else
528  gvec.imps[j] = dupstr(param_globals::PurkIon[j - param_globals::num_imp_regions].im);
529 #else
530  else if (j < param_globals::num_imp_regions)
531  gvec.imps[j] = dupstr(param_globals::imp_region[j].im);
532 #endif
533  gvec.svNames[j] = dupstr(prmGVecs[i].ID[j]);
534  }
535  }
536  }
537 }
538 
552  igb_output_manager & output_manager)
553 {
554  GVs.inclPS = false;
555  // int num_purk_regions = GVs->inclPS ? purk->ion.N_IIF : 0;
556  int num_purk_regions = 0;
557  int nRegs = param_globals::num_imp_regions + num_purk_regions;
558 
559  alloc_gvec_data(param_globals::num_gvecs, nRegs, param_globals::gvec, GVs);
560 
561 #ifdef WITH_PURK
562  if (GVs->inclPS) sample_PS_ionSVs(purk);
563 #endif
564 
565  for (unsigned int i = 0; i < GVs.vecs.size(); i++) {
566  sv_data & gv = GVs.vecs[i];
567  int noSV = 0;
568 
569  for (int j = 0; j < miif->N_IIF; j++) {
570  gv.getsv[j] = find_SV_in_IMP(miif, j, gv.imps[j], gv.svNames[j], gv.svOff + j, gv.svSizes + j, &GVs.plugin_idx[i]);
571 
572  if (gv.getsv[j] == NULL) {
573  log_msg(NULL, 3, ECHO, "\tWarning: SV(%s) not found in region %d\n", gv.svNames[j], j);
574  noSV++;
575  }
576  }
577 
578  SF::init_vector(&gv.ordered, &tmpl);
579  output_manager.register_output(gv.ordered, intra_elec_msh, 1, gv.name, gv.units);
580 
581 #ifdef WITH_PURK
582  // same procedure for Purkinje
583  if (GVs->inclPS) {
584  IF_PURK_PROC(purk) {
585  MULTI_IF* pmiif = &purk->ion;
586  for (int j = miif->N_IIF; j < nRegs; j++) {
587  gv.getsv[j] = find_SV_in_IMP(pmiif, j - miif->N_IIF, gv.imps[j],
588  gv.svNames[j], gv.svOff + j, gv.svSizes + j);
589 
590  if (gv.getsv[j] == NULL) {
591  LOG_MSG(NULL, 3, ECHO, "\tWarning: state variable \"%s\" not found in region %d\n", gv.svNames[j], j);
592  noSV++;
593  }
594  }
595  RVector_dup(purk->vm_pt, &gv.orderedPS_PS);
596  MYO_COMM(purk);
597  }
598  RVector_dup(purk->vm_pt_over, &gv.orderedPS);
599  initialize_grid_output(grid, NULL, tmo, intra_elec_msh, GRID_WRITE, 0., 1., gv.units, gv.orderedPS,
600  1, gv.GVcName, -purk->npt, param_globals::output_level);
601  }
602 #endif
603 
604  if (noSV == nRegs) {
605  log_msg(NULL, 5, ECHO, "\tError: no state variables found for global vector %d\n", i);
606  log_msg(NULL, 5, ECHO, "Run bench --imp=YourModel --imp-info to get a list of all parameters.\\n");
607  exit(1);
608  }
609  }
610 }
611 
623 {
624  for(size_t i=0; i<gvecs.vecs.size(); i++ ) {
625  sv_data & gv = gvecs.vecs[i];
626  int plugin_idx = gvecs.plugin_idx[i];
627 
628  // set to the defalt value
629  gv.ordered->set(gv.bogus);
630  SF_int start, stop;
631  gv.ordered->get_ownership_range(start, stop);
632 
633  for( int n = 0; n<miif->N_IIF; n++ ) {
634  if( !gv.getsv[n] ) continue;
635 
636  SF::vector<SF_real> data (miif->N_Nodes[n]);
637  SF::vector<SF_int> indices(miif->N_Nodes[n]);
638 
639  limpet::IonIfBase* base_im = miif->IIF[n];
640  limpet::IonIfBase* imp = plugin_idx > -1 ? base_im->plugins()[plugin_idx] : base_im;
641 
642  for( limpet::node_index_t j=0; j<miif->N_Nodes[n]; j++ ) {
643  indices[j] = miif->NodeLists[n][j] + start;
644  data[j] = ((limpet::SVgetfcn)(gv.getsv[n]))( *miif->IIF[n], j, gv.svOff[n]);
645  }
646 
647  bool add = false;
648  gv.ordered->set(indices, data, add);
649  }
650  }
651 }
652 
653 
654 } // namespace opencarp
opencarp::local_index_t mesh_int_t
Definition: SF_container.h:31
opencarp::global_index_t SF_int
Global algebraic index type.
Definition: SF_globals.h:17
#define FLUSH
Definition: basics.h:304
#define ECHO
Definition: basics.h:301
#define NONL
Definition: basics.h:305
virtual void get_ownership_range(T &start, T &stop) const =0
virtual void set(const vector< T > &idx, const vector< S > &vals, const bool additive=false, const bool local=false)=0
Comfort class. Provides getter functions to access the mesh member variables more comfortably.
Definition: SF_fem_utils.h:689
const T & node(short nidx) const
Access the connectivity information.
Definition: SF_fem_utils.h:778
void set_elem(size_t eidx)
Set the view to a new element.
Definition: SF_fem_utils.h:716
T num_nodes() const
Getter function for the number of nodes.
Definition: SF_fem_utils.h:746
overlapping_layout< T > pl
nodal parallel layout
Definition: SF_container.h:414
size_t l_numelem
local number of elements
Definition: SF_container.h:384
std::string name
the mesh name
Definition: SF_container.h:392
size_t l_numpts
local number of points
Definition: SF_container.h:386
vector< T > & get_numbering(SF_nbr nbr_type)
Get the vector defining a certain numbering.
Definition: SF_container.h:449
vector< T > tag
element tag
Definition: SF_container.h:402
Container for a PETSc VecScatter.
A vector storing arbitrary data.
Definition: SF_vector.h:28
size_t size() const
The current size of the vector.
Definition: SF_vector.h:89
void resize(size_t n)
Resize a vector.
Definition: SF_vector.h:194
const T * end() const
Pointer to the vector's end.
Definition: SF_vector.h:113
void assign(InputIterator s, InputIterator e)
Assign a memory range.
Definition: SF_vector.h:146
const T * begin() const
Pointer to the vector's start.
Definition: SF_vector.h:101
T * data()
Pointer to the vector's start.
Definition: SF_vector.h:76
T & push_back(T val)
Definition: SF_vector.h:268
hm_int count(const K &key) const
Check if key exists.
Definition: hashmap.hpp:612
Custom unordered_set implementation.
Definition: hashmap.hpp:739
hm_int count(const K &key) const
Definition: hashmap.hpp:1067
void insert(InputIterator first, InputIterator last)
Definition: hashmap.hpp:1037
Represents the ionic model and plug-in (IMP) data structure.
Definition: ION_IF.h:168
std::vector< IonIfBase * > & plugins()
Returns a vector containing the plugins of this IMP.
Definition: ION_IF.cc:174
void compute(node_index_t start, node_index_t end, GlobalData_t **data)
Perform ionic model computation for 1 time step.
Definition: ION_IF.cc:258
ts & get_tstp()
Gets the time stepper.
Definition: ION_IF.cc:198
void for_each(const std::function< void(IonIfBase &)> &consumer)
Executes the consumer functions on this IMP and each of its plugins.
Definition: ION_IF.cc:526
bool extUpdateVm
flag indicating update function for Vm
Definition: MULTI_ION_IF.h:204
std::vector< IonIfBase * > IIF
array of IIF's
Definition: MULTI_ION_IF.h:198
opencarp::sf_vec * gdata[NUM_IMP_DATA_TYPES]
data used by all IMPs
Definition: MULTI_ION_IF.h:212
node_count_t numNode
local number of nodes
Definition: MULTI_ION_IF.h:206
int * numplugs
number of plugins for each region
Definition: MULTI_ION_IF.h:205
std::vector< Target > targets
target for each region
Definition: MULTI_ION_IF.h:209
std::vector< IonTypeList > plugtypes
plugins types for each region
Definition: MULTI_ION_IF.h:211
IonTypeList iontypes
type for each region
Definition: MULTI_ION_IF.h:208
void initialize_currents(double, int)
float restore_state(const char *, opencarp::mesh_t gid, bool)
int N_IIF
how many different IIF's
Definition: MULTI_ION_IF.h:207
void compute_ionic_current(bool flag_send=1, bool flag_receive=1)
GPU kernel to emulate the add_scaled call made to adjust the Vm values when the update to Vm is not m...
node_count_t * N_Nodes
#nodes for each IMP
Definition: MULTI_ION_IF.h:196
opencarp::FILE_SPEC logger
Definition: MULTI_ION_IF.h:213
node_index_t ** NodeLists
local partitioned node lists for each IMP stored
Definition: MULTI_ION_IF.h:197
IIF_Mask_t * IIFmask
region for each node
Definition: MULTI_ION_IF.h:210
int adjust_MIIF_variables(const char *variable, const SF::vector< SF_int > &indices, const SF::vector< SF_real > &values)
std::string name
name for MIIF region
Definition: MULTI_ION_IF.h:194
FILE_SPEC logger
The logger of the physic, each physic should have one.
Definition: physics_types.h:49
const char * name
The name of the physic, each physic should have one.
Definition: physics_types.h:47
void output_step()
Definition: ionics.cc:40
mesh_t ion_domain
Definition: ionics.h:53
generic_timing_stats comp_stats
Definition: ionics.h:55
limpet::MULTI_IF * miif
Definition: ionics.h:52
void compute_step()
Definition: ionics.cc:18
void initialize()
Definition: ionics.cc:43
void destroy()
Definition: ionics.cc:35
std::string timer_unit(const int timer_id)
figure out units of a signal linked to a given timer
Definition: ionics.cc:443
double timer_val(const int timer_id)
figure out current value of a signal linked to a given timer
Definition: ionics.cc:435
void register_output(sf_vec *inp_data, const mesh_t inp_meshid, const int dpn, const char *name, const char *units, const SF::vector< mesh_int_t > *idx=NULL, bool elem_data=false)
Register a data vector for output.
Definition: sim_utils.cc:2850
void setup(double inp_dt, double inp_start, double inp_end)
Initialize the timer_manager.
Definition: timer_utils.cc:21
void reset_timers()
Reset time in timer_manager and then reset registered timers.
Definition: timer_utils.h:101
Electrical ionics functions and LIMPET wrappers.
void write_data_ascii(const MPI_Comm comm, const vector< T > &idx, const vector< S > &data, std::string file, short dpn=1)
void make_global(const vector< T > &vec, vector< T > &out, MPI_Comm comm)
make a parallel vector global
Definition: SF_network.h:210
void unique_resize(vector< T > &_P)
Definition: SF_sort.h:338
void init_vector(SF::abstract_vector< T, S > **vec)
Definition: SF_init.h:110
void binary_sort(vector< T > &_V)
Definition: SF_sort.h:274
SF_nbr
Enumeration encoding the different supported numberings.
Definition: SF_container.h:185
@ NBR_PETSC
PETSc numbering of nodes.
Definition: SF_container.h:188
@ NBR_REF
The nodal numbering of the reference mesh (the one stored on HD).
Definition: SF_container.h:186
@ NBR_SUBMESH
Submesh nodal numbering: The globally ascending sorted reference indices are reindexed.
Definition: SF_container.h:187
int get_plug_flag(char *plgstr, int *out_num_plugins, IonTypeList &out_plugins)
@ AUTO
Definition: target.h:31
IonType * get_ion_type(const std::string &name)
SF_real GlobalData_t
Definition: limpet_types.h:12
GlobalData_t(* SVgetfcn)(IonIfBase &, node_index_t, int)
Definition: ion_type.h:33
void update_ts(ts *ptstp)
Definition: ION_IF.cc:575
opencarp::local_index_t node_count_t
Definition: limpet_types.h:14
int read_sv(MULTI_IF *, int, const char *)
char IIF_Mask_t
Definition: ion_type.h:35
opencarp::local_index_t node_index_t
Definition: limpet_types.h:13
std::map< int, std::string > units
Definition: stimulate.cc:26
timer_manager * tm_manager
a manager for the various physics timers
Definition: main.cc:40
void compute_IIF(limpet::IonIfBase &pIF, limpet::GlobalData_t **impdata, limpet::node_index_t n)
Definition: ionics.cc:449
void * find_SV_in_IMP(limpet::MULTI_IF *miif, const int idx, const char *IMP, const char *SV, int *offset, int *sz, int *plugin_idx)
Definition: ionics.cc:471
@ iotm_console
Definition: timer_utils.h:29
sf_mesh & get_mesh(const mesh_t gt)
Get a mesh by specifying the gridID.
Definition: sf_interface.cc:18
SF::scattering * get_permutation(const int mesh_id, const int perm_id, const int dpn)
Get the PETSC to canonical permutation scattering for a given mesh and number of dpn.
void region_mask(mesh_t meshspec, SF::vector< RegionSpecs > &regspec, SF::vector< int > &regionIDs, bool mask_elem, const char *reglist, bool warn_on_default_tags)
classify elements/points as belonging to a region
Definition: ionics.cc:342
SF::meshdata< mesh_int_t, mesh_real_t > sf_mesh
Definition: sf_interface.h:33
int set_dir(IO_t dest)
Definition: sim_utils.cc:1615
void read_metadata(const std::string filename, std::map< std::string, std::string > &metadata, MPI_Comm comm)
Read metadata from the header.
Definition: fem_utils.cc:57
int get_rank(MPI_Comm comm=PETSC_COMM_WORLD)
Definition: basics.h:269
T get_global(T in, MPI_Op OP, MPI_Comm comm=PETSC_COMM_WORLD)
Do a global reduction on a variable.
Definition: basics.h:218
void check_unassigned_tags(const SF::vector< mesh_int_t > &tags, SF::vector< RegionSpecs > &regspec, const char *gridname, const char *reglist, bool warn_on_default_tags)
Definition: ionics.cc:300
SF::scattering * register_permutation(const int mesh_id, const int perm_id, const int dpn)
Register a permutation between two orderings for a mesh.
void register_data(sf_vec *dat, datavec_t d)
Register a data vector in the global registry.
Definition: sim_utils.cc:2090
@ OUTPUT
Definition: sim_utils.h:39
void init_sv_gvec(gvec_data &GVs, limpet::MULTI_IF *miif, sf_vec &tmpl, igb_output_manager &output_manager)
Definition: ionics.cc:551
void assemble_sv_gvec(gvec_data &gvecs, limpet::MULTI_IF *miif)
Definition: ionics.cc:622
char * dupstr(const char *old_str)
Definition: basics.cc:29
bool check_tags_in_elems(const SF::vector< mesh_int_t > &tags, SF::vector< RegionSpecs > &regspec, const char *gridname, const char *reglist)
Check whether the tags in the region spec struct matches with an array of tags.
Definition: ionics.cc:267
void log_msg(FILE_SPEC out, int level, unsigned char flag, const char *fmt,...)
Definition: basics.cc:57
mesh_t
The enum identifying the different meshes we might want to load.
Definition: sf_interface.h:44
@ intra_elec_msh
Definition: sf_interface.h:45
void alloc_gvec_data(const int nGVcs, const int nRegs, GVecs *prmGVecs, gvec_data &glob_vecs)
Definition: ionics.cc:500
void get_time(double &tm)
Definition: basics.h:429
SF::abstract_vector< SF_int, SF_real > sf_vec
Definition: sf_interface.h:35
void remove_char(char *buff, const int buffsize, const char c)
Definition: basics.h:349
void read_indices_with_data(SF::vector< T > &idx, SF::vector< S > &dat, const std::string filename, const hashmap::unordered_map< mesh_int_t, mesh_int_t > &dd_map, const int dpn, MPI_Comm comm)
like read_indices, but with associated data for each index
Definition: fem_utils.h:254
V timing(V &t2, const V &t1)
Definition: basics.h:441
#define PETSC_TO_CANONICAL
Permute algebraic data from PETSC to canonical ordering.
Definition: sf_interface.h:64
void log_stats(double tm, bool cflg)
Definition: timers.cc:96
void init_logger(const char *filename)
Definition: timers.cc:80
int calls
# calls for this interval, this is incremented externally
Definition: timers.h:73
double tot_time
total time, this is incremented externally
Definition: timers.h:75
SF::vector< int > plugin_idx
if we use a plugin, its index in the plugins list of the IMP will be stored here, else -1.
Definition: ionics.h:135
SF::vector< sv_data > vecs
store sv dump indices for global vectors
Definition: ionics.h:134
unsigned int nRegs
number of imp regions
Definition: ionics.h:132
bool inclPS
include PS if exists
Definition: ionics.h:133
float bogus
value indicating sv not in region
Definition: ionics.h:128
void ** getsv
functions to retrieve sv
Definition: ionics.h:125
char * name
Name of global composite sv vector.
Definition: ionics.h:118
int * svOff
sv size in bytes
Definition: ionics.h:123
char ** svNames
sv names of components forming global vector
Definition: ionics.h:120
int * svSizes
sv size in bytes
Definition: ionics.h:122
char ** imps
Name of imp to which sv belongs.
Definition: ionics.h:119
char * units
units of sv
Definition: ionics.h:127
sf_vec * ordered
vector in which to place ordered data
Definition: ionics.h:126