MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
AcaPostProcessingRMS< nDim > Class Template Reference

ACA post processing class for calculation of root mean square pressure. More...

#include <acapostprocessing.hpp>

Inheritance diagram for AcaPostProcessingRMS< nDim >:
[legend]
Collaboration diagram for AcaPostProcessingRMS< nDim >:
[legend]

Public Member Functions

void init_ () override
 
void calc (const MInt observerId, const MFloat *const data, const MFloat *const dataComplex=nullptr) override
 
void finish () override
 
 AcaPostProcessing (const MPI_Comm comm)
 
- Public Member Functions inherited from AcaPostProcessing
 AcaPostProcessing (const MPI_Comm comm)
 
virtual ~AcaPostProcessing ()=default
 
virtual void init_ ()=0
 
void init (const MInt noObservers, const MInt noGlobalObservers, const MInt offsetObserver, const MInt noSamples, const MFloat *const coords, const MFloat *const frequencies, const MString outPath)
 
virtual void calc (const MInt observerId, const MFloat *const data, const MFloat *const dataComplex=nullptr)=0
 
virtual void finish ()=0
 

Private Attributes

MString m_fileNameIoParallel
 
MString m_fileNameIoDat
 
std::vector< MFloatm_prms
 

Additional Inherited Members

- Protected Attributes inherited from AcaPostProcessing
MPI_Comm m_mpiComm
 
MInt m_rank
 
MInt m_noObservers = -1
 
MInt m_noGlobalObservers = -1
 
MInt m_offsetObserver = 0
 
MInt m_noSamples = -1
 
MString m_outPath
 
const MFloatm_coords = nullptr
 
const MFloatm_frequencies = nullptr
 

Detailed Description

template<MInt nDim>
class AcaPostProcessingRMS< nDim >

Definition at line 127 of file acapostprocessing.hpp.

Member Function Documentation

◆ AcaPostProcessing()

template<MInt nDim>
AcaPostProcessing::AcaPostProcessing ( const MPI_Comm  comm)
inline

Definition at line 25 of file acapostprocessing.h.

25: m_mpiComm(comm) { MPI_Comm_rank(m_mpiComm, &m_rank); }
MPI_Comm m_mpiComm
MInt m_rank

◆ calc()

template<MInt nDim>
void AcaPostProcessingRMS< nDim >::calc ( const MInt  observerId,
const MFloat *const  data,
const MFloat *const  dataComplex = nullptr 
)
overridevirtual

Implements AcaPostProcessing.

Definition at line 148 of file acapostprocessing.hpp.

149 {
150 // Calculation of root mean square pressure values
151 m_prms[m_offsetObserver + observerId] = 0;
152 for(MInt t = 0; t < m_noSamples; t++) {
153 m_prms[m_offsetObserver + observerId] += POW2(data[t]);
154 }
155 m_prms[m_offsetObserver + observerId] = sqrt(m_prms[m_offsetObserver + observerId] / m_noSamples);
156}
MInt m_offsetObserver
MInt m_noSamples
std::vector< MFloat > m_prms
constexpr Real POW2(const Real x)
Definition: functions.h:119
int32_t MInt
Definition: maiatypes.h:62

◆ finish()

template<MInt nDim>
void AcaPostProcessingRMS< nDim >::finish
overridevirtual

Implements AcaPostProcessing.

Definition at line 159 of file acapostprocessing.hpp.

159 {
160 constexpr MInt rootId = 0;
161 using namespace maia::parallel_io;
162 ParallelIo file(m_fileNameIoParallel, PIO_REPLACE, m_mpiComm);
163 ParallelIo::size_type dimSizesCoordinates[] = {m_noGlobalObservers, nDim};
164 file.defineArray(PIO_FLOAT, "coordinates", 2, &dimSizesCoordinates[0]);
165 file.defineArray(PIO_FLOAT, "rms_pressure", m_noGlobalObservers);
166
167 const MBool isRoot = (m_rank == rootId);
168 file.setOffset((isRoot) ? m_noGlobalObservers : 0, 0, 2);
169 file.writeArray(m_coords, "coordinates");
170 if(isRoot) {
171 MPI_Reduce(MPI_IN_PLACE, m_prms.data(), m_noGlobalObservers, maia::type_traits<MFloat>::mpiType(), MPI_SUM, rootId,
172 m_mpiComm, AT_, "MPI_IN_PLACE", "m_prms");
173 // TODO labels:ACA,totest Check distl, theta, and alpha
174 std::ofstream outfile;
175 outfile.open(m_fileNameIoDat);
176 if constexpr(nDim == 2) {
177 outfile << "# obs:1 x:2 y:3 theta:4 p_rms:5" << std::endl;
178 for(MInt obs = 0; obs < m_noGlobalObservers; obs++) {
179 const MFloat* const obsCoord = &m_coords[nDim * obs];
180 const MFloat theta = atan2(obsCoord[1], obsCoord[0]);
181 outfile << obs << " " << obsCoord[0] << " " << obsCoord[1] << " " << theta << " " << m_prms[obs] << std::endl;
182 }
183 } else if constexpr(nDim == 3) {
184 outfile << "# obs:1 x:2 y:3 z:4 theta:5 alpha:6 p_rms:7" << std::endl;
185 for(MInt obs = 0; obs < m_noGlobalObservers; obs++) {
186 const MFloat* const obsCoord = &m_coords[nDim * obs];
187 const MFloat dist = sqrt(POW2(obsCoord[0]) + POW2(obsCoord[1]) + POW2(obsCoord[2]));
188 const MFloat theta = atan2(obsCoord[2], obsCoord[0]);
189 const MFloat alpha = asin(obsCoord[1] / dist);
190 outfile << obs << " " << obsCoord[0] << " " << obsCoord[1] << " " << obsCoord[2] << " " << theta << " " << alpha
191 << " " << m_prms[obs] << std::endl;
192 }
193 }
194 outfile.close();
195 file.setOffset(m_noGlobalObservers, 0);
196 } else {
197 MPI_Reduce(m_prms.data(), nullptr, m_noGlobalObservers, maia::type_traits<MFloat>::mpiType(), MPI_SUM, rootId,
198 m_mpiComm, AT_, "MPI_IN_PLACE", "m_prms");
199 file.setOffset(0, 0);
200 }
201 file.writeArray(m_prms.data(), "rms_pressure");
202}
MInt m_noGlobalObservers
const MFloat * m_coords
MString m_fileNameIoDat
MString m_fileNameIoParallel
double MFloat
Definition: maiatypes.h:52
bool MBool
Definition: maiatypes.h:58
int MPI_Reduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm, const MString &name, const MString &sndvarname, const MString &rcvvarname)
same as MPI_Reduce
PARALLELIO_DEFAULT_BACKEND ParallelIo
Definition: parallelio.h:292
MFloat dist(const Point< DIM > &p, const Point< DIM > &q)
Definition: pointbox.h:54

◆ init_()

template<MInt nDim>
void AcaPostProcessingRMS< nDim >::init_
overridevirtual

Implements AcaPostProcessing.

Definition at line 141 of file acapostprocessing.hpp.

141 {
142 m_fileNameIoParallel = m_outPath + "RMSpressure" + ParallelIo::fileExt();
143 m_fileNameIoDat = m_outPath + "RMS.dat";
144 m_prms.resize(m_noGlobalObservers, 0.0);
145}
MString m_outPath

Member Data Documentation

◆ m_fileNameIoDat

template<MInt nDim>
MString AcaPostProcessingRMS< nDim >::m_fileNameIoDat
private

Definition at line 130 of file acapostprocessing.hpp.

◆ m_fileNameIoParallel

template<MInt nDim>
MString AcaPostProcessingRMS< nDim >::m_fileNameIoParallel
private

Definition at line 129 of file acapostprocessing.hpp.

◆ m_prms

template<MInt nDim>
std::vector<MFloat> AcaPostProcessingRMS< nDim >::m_prms
private

Definition at line 131 of file acapostprocessing.hpp.


The documentation for this class was generated from the following file: