Nektar++
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// 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: Outputs solution fields during time-stepping.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#include <boost/core/ignore_unused.hpp>
36
38
39namespace Nektar
40{
41namespace SolverUtils
42{
46
49 const std::weak_ptr<EquationSystem> &pEquation, const ParamMap &pParams)
50 : Filter(pSession, pEquation)
51{
52 // OutputFile
53 auto it = pParams.find("OutputFile");
54 if (it == pParams.end())
55 {
56 m_outputFile = m_session->GetSessionName();
57 }
58 else
59 {
60 ASSERTL0(it->second.length() > 0, "Empty parameter 'OutputFile'.");
61 m_outputFile = it->second;
62 }
63
64 // OutputFrequency
65 it = pParams.find("OutputFrequency");
66 ASSERTL0(it != pParams.end(), "Missing parameter 'OutputFrequency'.");
67 LibUtilities::Equation equ(m_session->GetInterpreter(), it->second);
68 m_outputFrequency = round(equ.Evaluate());
69
70 // Time after which we need to write checkfiles
71 it = pParams.find("OutputStartTime");
72 if (it == pParams.end())
73 {
75 }
76 else
77 {
78 LibUtilities::Equation equ(m_session->GetInterpreter(), it->second);
80 }
81
83}
84
86{
87}
88
91 const NekDouble &time)
92{
93 m_index = 0;
94 m_outputIndex = 0;
95 v_Update(pFields, time);
96}
97
100 const NekDouble &time)
101{
102
103 if (m_index++ % m_outputFrequency > 0 || time < m_outputStartTime)
104 {
105 return;
106 }
107
108 std::stringstream vOutputFilename;
109 vOutputFilename << m_outputFile << "_" << m_outputIndex << ".chk";
110
111 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
112 pFields[0]->GetFieldDefinitions();
113 std::vector<std::vector<NekDouble>> FieldData(FieldDef.size());
114
115 // copy Data into FieldData and set variable
116 for (int j = 0; j < pFields.size(); ++j)
117 {
118 for (int i = 0; i < FieldDef.size(); ++i)
119 {
120 // Could do a search here to find correct variable
121 FieldDef[i]->m_fields.push_back(m_session->GetVariable(j));
122 pFields[0]->AppendFieldData(FieldDef[i], FieldData[i],
123 pFields[j]->UpdateCoeffs());
124 }
125 }
126 m_fld->Write(vOutputFilename.str(), FieldDef, FieldData);
128}
129
132 const NekDouble &time)
133{
134 boost::ignore_unused(pFields, time);
135}
136
138{
139 return true;
140}
141} // namespace SolverUtils
142} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
static std::shared_ptr< FieldIO > CreateDefault(const LibUtilities::SessionReaderSharedPtr session)
Returns an object for the default FieldIO method.
Definition: FieldIO.cpp:197
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
virtual void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
virtual void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
virtual SOLVER_UTILS_EXPORT ~FilterCheckpoint()
LibUtilities::FieldIOSharedPtr m_fld
virtual void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
SOLVER_UTILS_EXPORT FilterCheckpoint(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const std::map< std::string, std::string > &pParams)
Creates an instance of this class.
static std::string className
Name of the class.
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:85
std::map< std::string, std::string > ParamMap
Definition: Filter.h:67
std::shared_ptr< SessionReader > SessionReaderSharedPtr
FilterFactory & GetFilterFactory()
Definition: Filter.cpp:41
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble