Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FilterCheckpoint.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File FilterCheckpoint.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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Outputs solution fields during time-stepping.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 
38 namespace Nektar
39 {
40  namespace SolverUtils
41  {
43 
46  const std::map<std::string, std::string> &pParams) :
47  Filter(pSession)
48  {
49  if (pParams.find("OutputFile") == pParams.end())
50  {
51  m_outputFile = m_session->GetSessionName();
52  }
53  else
54  {
55  ASSERTL0(!(pParams.find("OutputFile")->second.empty()),
56  "Missing parameter 'OutputFile'.");
57  m_outputFile = pParams.find("OutputFile")->second;
58  }
59  ASSERTL0(pParams.find("OutputFrequency") != pParams.end(),
60  "Missing parameter 'OutputFrequency'.");
61  m_outputFrequency = atoi(pParams.find("OutputFrequency")->second.c_str());
62  m_outputIndex = 0;
63  m_index = 0;
65 
66  }
67 
69  {
70 
71  }
72 
73  void FilterCheckpoint::v_Initialise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
74  {
75  m_index = 0;
76  m_outputIndex = 0;
77  }
78 
79  void FilterCheckpoint::v_Update(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
80  {
81  m_index++;
82  if (m_index % m_outputFrequency > 0)
83  {
84  return;
85  }
86 
87  std::stringstream vOutputFilename;
88  vOutputFilename << m_outputFile << "_" << m_outputIndex << ".chk";
89 
90  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
91  = pFields[0]->GetFieldDefinitions();
92  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
93 
94  // copy Data into FieldData and set variable
95  for(int j = 0; j < pFields.num_elements(); ++j)
96  {
97  for(int i = 0; i < FieldDef.size(); ++i)
98  {
99  // Could do a search here to find correct variable
100  FieldDef[i]->m_fields.push_back(m_session->GetVariable(j));
101  pFields[0]->AppendFieldData(FieldDef[i], FieldData[i], pFields[j]->UpdateCoeffs());
102  }
103  }
104  m_fld->Write(vOutputFilename.str(),FieldDef,FieldData);
105  m_outputIndex++;
106  }
107 
108  void FilterCheckpoint::v_Finalise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
109  {
110 
111  }
112 
114  {
115  return true;
116  }
117  }
118 }