Nektar++
FilterCellHistoryPoints.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: FilterCellHistoryPoints.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 values at specific points during time-stepping.
32//
33///////////////////////////////////////////////////////////////////////////////
34
37#include <boost/format.hpp>
38#include <iomanip>
39
40using namespace std;
41
42namespace Nektar
43{
44
47 "CellHistoryPoints", FilterCellHistoryPoints::create);
48
49/**
50 *
51 */
54 const std::weak_ptr<SolverUtils::EquationSystem> &pEquation,
55 const ParamMap &pParams)
56 : FilterHistoryPoints(pSession, pEquation, pParams)
57{
58}
59
60/**
61 *
62 */
64{
65}
66
67/**
68 *
69 */
72 const NekDouble &time)
73{
74 // Only output every m_outputFrequency.
75 if ((m_index++) % m_outputFrequency)
76 {
77 return;
78 }
79
80 const size_t numPoints = m_historyPoints.size();
81 const size_t numFields = m_cell->GetNumCellVariables();
82 LibUtilities::CommSharedPtr vComm = pFields[0]->GetComm();
83 Array<OneD, NekDouble> data(numPoints * numFields, 0.0);
84 Array<OneD, NekDouble> gloCoord(3, 0.0);
87
88 // Pull out data values field by field
89 for (size_t j = 0; j < numFields; ++j)
90 {
92 {
93 // Number of points per plane
94 const int nppp = pFields[0]->GetPlane(0)->GetTotPoints();
95
96 for (auto &x : m_historyList)
97 {
98 locCoord = std::get<1>(x);
99 const int indx = std::get<2>(x);
100 const int expId = std::get<3>(x);
101
102 physvals = m_cell->GetCellSolution(j) + m_outputPlane * nppp +
103 pFields[j]->GetPhys_Offset(expId);
104
105 // interpolate point
106 data[indx * numFields + j] =
107 pFields[0]->GetExp(expId)->StdPhysEvaluate(locCoord,
108 physvals);
109 }
110 }
111 else
112 {
113 for (auto &x : m_historyList)
114 {
115 locCoord = std::get<1>(x);
116 const int indx = std::get<2>(x);
117 const int expId = std::get<3>(x);
118
119 physvals = m_cell->GetCellSolution(j) +
120 pFields[0]->GetPhys_Offset(expId);
121
122 // interpolate point
123 data[indx * numFields + j] =
124 pFields[0]->GetExp(expId)->StdPhysEvaluate(locCoord,
125 physvals);
126 }
127 }
128 }
129
130 // Exchange history data
131 // This could be improved to reduce communication but works for now
132 vComm->AllReduce(data, LibUtilities::ReduceSum);
133 v_WriteData(vComm->GetRank(), data, numFields, time);
134}
135
137 const Array<OneD, NekDouble> &data,
138 const int &numFields,
139 const NekDouble &time)
140{
141 // Only the root process writes out history data
142 if (rank > 0)
143 {
144 return;
145 }
146
147 Array<OneD, NekDouble> gloCoord(3, 0.0);
148 if (!m_outputOneFile || m_index == 1)
149 {
150 std::stringstream vOutputFilename;
151 if (m_outputOneFile)
152 {
153 vOutputFilename << m_outputFile << ".his";
154 }
155 else
156 {
157 vOutputFilename << m_outputFile << "_" << m_outputIndex << ".his";
158 }
160 if (m_adaptive)
161 {
162 m_outputStream.open(vOutputFilename.str().c_str(), ofstream::app);
163 }
164 else
165 {
166 m_outputStream.open(vOutputFilename.str().c_str());
167 }
168 // m_outputStream << "# History data for variables (:";
169
170 // for (int i = 0; i < numFields; ++i)
171 //{
172 // m_outputStream << m_session->GetVariable(i) <<",";
173 // }
174
176 {
177 m_outputStream << ") at points:" << endl;
178 }
179 else
180 {
181 m_outputStream << ") at points:" << endl;
182 }
183
184 for (int i = 0; i < m_historyPoints.size(); ++i)
185 {
186 gloCoord = m_historyPoints[i];
187
188 m_outputStream << "# " << boost::format("%6.0f") % i;
189 m_outputStream << " " << boost::format("%15.9e") % gloCoord[0];
190 m_outputStream << " " << boost::format("%15.9e") % gloCoord[1];
191 m_outputStream << " " << boost::format("%15.9e") % gloCoord[2];
192 m_outputStream << endl;
193 }
194
196 {
197 if (m_waveSpace)
198 {
199 m_outputStream << "# (in Wavespace)" << endl;
200 }
201 }
202 }
203
204 // Write data values point by point
205 for (int k = 0; k < m_historyPoints.size(); ++k)
206 {
207 m_outputStream << boost::format("%15.9e") % time;
208 for (int j = 0; j < numFields; ++j)
209 {
210 m_outputStream << " "
211 << boost::format("%15.9e") % data[k * numFields + j];
212 }
213 m_outputStream << endl;
214 }
215
216 if (!m_outputOneFile)
217 {
218 m_outputStream.close();
219 }
220}
221
222} // namespace Nektar
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::string className
Name of the class.
virtual void v_WriteData(const int &rank, const Array< OneD, NekDouble > &data, const int &numFields, const NekDouble &time)
FilterCellHistoryPoints(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< SolverUtils::EquationSystem > &pEquation, const ParamMap &pParams)
void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
Array< OneD, Array< OneD, const NekDouble > > m_historyPoints
int m_outputPlane
plane to take history point from if using a homogeneous1D expansion
std::list< std::tuple< Array< OneD, const NekDouble >, Array< OneD, const NekDouble >, int, int > > m_historyList
std::map< std::string, std::string > ParamMap
Definition: Filter.h:65
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
FilterFactory & GetFilterFactory()
Definition: Filter.cpp:39
double NekDouble