Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Prepacing.cpp
Go to the documentation of this file.
5 
6 using namespace Nektar;
7 
8 int main(int argc, char *argv[])
9 {
13  std::string vCellModel;
14  CellModelSharedPtr vCell;
15  std::vector<StimulusSharedPtr> vStimulus;
16  Array<OneD, Array<OneD, NekDouble> > vWsp(1);
17  Array<OneD, Array<OneD, NekDouble> > vSol(1);
18  NekDouble vDeltaT;
19  NekDouble vTime;
20  unsigned int nSteps;
21 
22  // Create a session reader to read pacing parameters
23  vSession = LibUtilities::SessionReader::CreateInstance(argc, argv);
24 
25  try
26  {
27  // Construct a field consisting of a single vertex
29  ::AllocateSharedPtr(3, 0, 0.0, 0.0, 0.0);
31  ::AllocateSharedPtr(vPoint);
32 
33  // Get cell model name and create it
34  vSession->LoadSolverInfo("CELLMODEL", vCellModel, "");
35  ASSERTL0(vCellModel != "", "Cell Model not specified.");
36 
38  vCellModel, vSession, vExp);
39  vCell->Initialise();
40 
41  // Load the stimuli
42  vStimulus = Stimulus::LoadStimuli(vSession, vExp);
43 
44  // Set up solution arrays, workspace and read in parameters
45  vSol[0] = Array<OneD, NekDouble>(1, 0.0);
46  vWsp[0] = Array<OneD, NekDouble>(1, 0.0);
47  vDeltaT = vSession->GetParameter("TimeStep");
48  vTime = 0.0;
49  nSteps = vSession->GetParameter("NumSteps");
50 
52  vSession->GetFunction("InitialConditions", "u");
53  vSol[0][0] = e->Evaluate(0.0, 0.0, 0.0, 0.0);
54 
55  // Time integrate cell model
56  for (unsigned int i = 0; i < nSteps; ++i)
57  {
58  // Compute J_ion
59  vCell->TimeIntegrate(vSol, vWsp, vTime);
60 
61  // Add stimuli J_stim
62  for (unsigned int i = 0; i < vStimulus.size(); ++i)
63  {
64  vStimulus[i]->Update(vWsp, vTime);
65  }
66 
67  // Time-step with forward Euler
68  Vmath::Svtvp(1, vDeltaT, vWsp[0], 1, vSol[0], 1, vSol[0], 1);
69 
70  // Increment time
71  vTime += vDeltaT;
72 
73  // Output current solution to stdout
74  cout << vTime << " " << vSol[0][0] << endl;
75  }
76 
77  for (unsigned int i = 0; i < vCell->GetNumCellVariables(); ++i)
78  {
79  cout << "# " << vCell->GetCellVarName(i) << " "
80  << vCell->GetCellSolution(i)[0] << endl;
81  }
82  }
83  catch (...)
84  {
85  cerr << "An error occured" << endl;
86  }
87 
88  return 0;
89 }