Nektar++
Prepacing.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Prepacing.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description:
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
37 #include <MultiRegions/ExpList.h>
39 
40 using namespace std;
41 using namespace Nektar;
42 
43 int main(int argc, char *argv[])
44 {
48  std::string vCellModel;
49  CellModelSharedPtr vCell;
50  std::vector<StimulusSharedPtr> vStimulus;
53  NekDouble vDeltaT;
54  NekDouble vTime;
55  unsigned int nSteps;
56 
57  // Create a session reader to read pacing parameters
58  vSession = LibUtilities::SessionReader::CreateInstance(argc, argv);
59  vSession->InitSession();
60 
61  try
62  {
63  // Construct a field consisting of a single vertex
65  3, 0, 0.0, 0.0, 0.0);
67 
68  // Get cell model name and create it
69  vSession->LoadSolverInfo("CELLMODEL", vCellModel, "");
70  ASSERTL0(vCellModel != "", "Cell Model not specified.");
71 
72  vCell =
73  GetCellModelFactory().CreateInstance(vCellModel, vSession, vExp);
74  vCell->Initialise();
75 
76  // Load the stimuli
77  vStimulus = Stimulus::LoadStimuli(vSession, vExp);
78 
79  // Set up solution arrays, workspace and read in parameters
80  vSol[0] = Array<OneD, NekDouble>(1, 0.0);
81  vWsp[0] = Array<OneD, NekDouble>(1, 0.0);
82  vDeltaT = vSession->GetParameter("TimeStep");
83  vTime = 0.0;
84  nSteps = vSession->GetParameter("NumSteps");
85 
87  vSession->GetFunction("InitialConditions", "u");
88  vSol[0][0] = e->Evaluate(0.0, 0.0, 0.0, 0.0);
89 
90  cout << "#";
91  for (unsigned int i = 0; i < vCell->GetNumCellVariables(); ++i)
92  {
93  cout << " " << vCell->GetCellVarName(i);
94  }
95  cout << endl;
96 
97  // Time integrate cell model
98  for (unsigned int i = 0; i < nSteps; ++i)
99  {
100  // Compute J_ion
101  vCell->TimeIntegrate(vSol, vWsp, vTime);
102 
103  // Add stimuli J_stim
104  for (unsigned int i = 0; i < vStimulus.size(); ++i)
105  {
106  vStimulus[i]->Update(vWsp, vTime);
107  }
108 
109  // Time-step with forward Euler
110  Vmath::Svtvp(1, vDeltaT, vWsp[0], 1, vSol[0], 1, vSol[0], 1);
111 
112  // Increment time
113  vTime += vDeltaT;
114 
115  // Output current solution to stdout
116  cout << vTime << " " << vSol[0][0];
117  for (unsigned int j = 0; j < vCell->GetNumCellVariables(); ++j)
118  {
119  cout << " " << vCell->GetCellSolution(j)[0];
120  }
121  cout << endl;
122  }
123 
124  for (unsigned int i = 0; i < vCell->GetNumCellVariables(); ++i)
125  {
126  cout << "# " << vCell->GetCellVarName(i) << " "
127  << vCell->GetCellSolution(i)[0] << endl;
128  }
129  }
130  catch (...)
131  {
132  cerr << "An error occured" << endl;
133  }
134 
135  return 0;
136 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
int main(int argc, char *argv[])
Definition: Prepacing.cpp:43
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:129
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:59
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
CellModelFactory & GetCellModelFactory()
Definition: CellModel.cpp:46
std::shared_ptr< CellModel > CellModelSharedPtr
A shared pointer to an EquationSystem object.
Definition: CellModel.h:55
double NekDouble
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector plus vector): z = alpha*x + y
Definition: Vmath.cpp:622