Nektar++
FilterCheckpointCellModel.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: FilterCheckpointCellModel.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
36
37namespace Nektar
38{
41 "CheckpointCellModel", FilterCheckpointCellModel::create);
42
45 const std::weak_ptr<SolverUtils::EquationSystem> &pEquation,
46 const ParamMap &pParams)
47 : Filter(pSession, pEquation)
48{
49 // OutputFile
50 auto it = pParams.find("OutputFile");
51 if (it == pParams.end())
52 {
53 m_outputFile = m_session->GetSessionName();
54 }
55 else
56 {
57 ASSERTL0(it->second.length() > 0, "Missing parameter 'OutputFile'.");
58 m_outputFile = it->second;
59 }
60
61 // OutputFrequency
62 it = pParams.find("OutputFrequency");
63 ASSERTL0(it != pParams.end(), "Missing parameter 'OutputFrequency'.");
64 LibUtilities::Equation equ(m_session->GetInterpreter(), it->second);
65 m_outputFrequency = floor(equ.Evaluate());
66
67 m_outputIndex = 0;
68 m_index = 0;
70}
71
73{
74}
75
78 [[maybe_unused]] const NekDouble &time)
79{
80 ASSERTL0(m_cell.get(),
81 "Cell model has not been set by EquationSystem "
82 "class. Use SetCellModel on this filter to achieve this.");
83
84 m_index = 0;
85 m_outputIndex = 0;
86
87 v_Update(pFields, 0.0);
88}
89
92 const NekDouble &time)
93{
94 if (m_index++ % m_outputFrequency > 0)
95 {
96 return;
97 }
98
99 std::stringstream vOutputFilename;
100 vOutputFilename << m_outputFile << "_" << m_outputIndex << ".chk";
101
102 SpatialDomains::MeshGraphSharedPtr vGraph = pFields[0]->GetGraph();
103
104 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
105 pFields[0]->GetFieldDefinitions();
106 std::vector<std::vector<NekDouble>> FieldData(FieldDef.size());
107
108 // copy Data into FieldData and set variable
109 std::string varName;
110 for (size_t j = 1; j < m_cell->GetNumCellVariables(); ++j)
111 {
112 varName = m_cell->GetCellVarName(j);
113
114 for (size_t i = 0; i < FieldDef.size(); ++i)
115 {
116 // Retrieve data from cell model
117 Array<OneD, NekDouble> data = m_cell->GetCellSolutionCoeffs(j);
118
119 // Could do a search here to find correct variable
120 FieldDef[i]->m_fields.push_back(varName);
121 pFields[0]->AppendFieldData(FieldDef[i], FieldData[i], data);
122 }
123 }
124
125 // Update time in field info if required
126 LibUtilities::FieldMetaDataMap fieldMetaDataMap;
127 fieldMetaDataMap["Time"] = boost::lexical_cast<std::string>(time);
128
129 m_fld->Write(vOutputFilename.str(), FieldDef, FieldData, fieldMetaDataMap);
131}
132
135 &pFields,
136 [[maybe_unused]] const NekDouble &time)
137{
138}
139
141{
142 return true;
143}
144} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FilterCheckpointCellModel(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< SolverUtils::EquationSystem > &pEquation, const ParamMap &pParams)
void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
static std::string className
Name of the class.
void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
LibUtilities::FieldIOSharedPtr m_fld
void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
static SolverUtils::FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< SolverUtils::EquationSystem > &pEquation, const ParamMap &pParams)
Creates an instance of this class.
static std::shared_ptr< FieldIO > CreateDefault(const LibUtilities::SessionReaderSharedPtr session)
Returns an object for the default FieldIO method.
Definition: FieldIO.cpp:195
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:83
std::map< std::string, std::string > ParamMap
Definition: Filter.h:65
std::map< std::string, std::string > FieldMetaDataMap
Definition: FieldIO.h:50
std::shared_ptr< SessionReader > SessionReaderSharedPtr
FilterFactory & GetFilterFactory()
Definition: Filter.cpp:39
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
double NekDouble