Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new plane average that works on fine levels #667

Merged
merged 10 commits into from
Aug 22, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ void ABLMeanBoussinesq::mean_temperature_update(const FieldPlaneAveraging& tavg)
void ABLMeanBoussinesq::read_temperature_profile(std::string profile_file_name)
{

m_axis = 2; // Fix to be z-direction for now
amrex::Vector<amrex::Real> theta_ht, theta_vals;
std::ifstream infile;
int n_hts;
Expand Down
1 change: 1 addition & 0 deletions amr-wind/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ target_sources(${amr_wind_lib_name}
console_io.cpp
IOManager.cpp
FieldPlaneAveraging.cpp
FieldPlaneAveragingFine.cpp
SecondMomentAveraging.cpp
ThirdMomentAveraging.cpp

Expand Down
6 changes: 6 additions & 0 deletions amr-wind/utilities/DirectionSelector.H
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct DirectionSelector<0>
{
return i;
};
int odir1 = 1;
int odir2 = 2;
};

template <>
Expand All @@ -35,6 +37,8 @@ struct DirectionSelector<1>
{
return j;
};
int odir1 = 0;
int odir2 = 2;
};

template <>
Expand All @@ -45,6 +49,8 @@ struct DirectionSelector<2>
{
return k;
};
int odir1 = 0;
int odir2 = 1;
};

using XDir = DirectionSelector<0>;
Expand Down
153 changes: 153 additions & 0 deletions amr-wind/utilities/FieldPlaneAveragingFine.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#ifndef FieldPlaneAveragingFine_H
#define FieldPlaneAveragingFine_H

#include "amr-wind/utilities/DirectionSelector.H"
#include "amr-wind/CFDSim.H"
#include "amr-wind/core/Field.H"
#include "amr-wind/core/SimTime.H"

/**
* \defgroup statistics Field statistics
* Field statistics
*
* This group contains utilities for performing turbulence averaging and
* outputting statistics during wind simulations.
*
* \ingroup utilities
*/

namespace amr_wind {

/** Output average of a field on planes normal to a given direction
* \ingroup statistics we_abl
*
* The user can choose a direction (x, y, or z), the default value is the
* z-direction. The field is then averaged on planes at the cell-centers at
* level 0 (coarsest level) along the specified direction.
*/

template <typename FType>
class FPlaneAveragingFine
{
public:
/**
* \param field_in [in] Field to be averaged
* \param time [in] Time instance to determine output frequencies
* \param axis_in [in] Direction along which planes are computed
* \param compute_deriv [in] Should the derivative of the averages be
* computed
*/
FPlaneAveragingFine(
const FType& field_in, const amr_wind::SimTime& time, int axis_in);

~FPlaneAveragingFine() = default;

void operator()();

void convert_x_to_ind(amrex::Real x, int& ind, amrex::Real& c) const;

/** evaluate line average at specific location for any average component */
amrex::Real line_average_interpolated(amrex::Real x, int comp) const;
/** evaluate line average at specific cell for any average component */
amrex::Real line_average_cell(int ind, int comp) const;

void output_line_average_ascii(
const std::string& filename, int step, amrex::Real time);
void output_line_average_ascii(int step, amrex::Real time);

/** change precision of text file output */
void set_precision(int p) { m_precision = p; };

int axis() const { return m_axis; };
int ncomp() const { return m_ncomp; };
int ncell_line() const { return m_ncell_line; };
int last_updated_index() const { return m_last_updated_index; };

const amrex::Vector<amrex::Real>& line_average() const
{
return m_line_average;
};
void line_average(int comp, amrex::Vector<amrex::Real>& l_vec);
const amrex::Vector<amrex::Real>& line_centroids() const
{
return m_line_xcentroid;
};

const FType& field() const { return m_field; };

protected:
int m_ncomp; /** number of average components */

amrex::Vector<amrex::Real>
m_line_average; /** line storage for the average velocity and tracer
variables */

amrex::Vector<amrex::Real> m_line_xcentroid; /** line storage for centroids
of each cell along a line*/

amrex::Real m_dx; /** mesh spacing in axis direction*/
amrex::Real m_xlo; /** bottom of line */
amrex::Real m_xhi; /** top of line */

int m_ncell_line; /** number of cells along line */

int m_precision = 6; /** precision for line plot text file */
int m_last_updated_index = -1; /** keep track of the last time index that
the operator was called */

const FType& m_field;
const SimTime& m_time;
const int m_axis;

public: // public for GPU
/** fill line storage with averages */
template <typename IndexSelector>
void compute_averages(const IndexSelector& idxOp);
};

using FieldPlaneAveragingFine = FPlaneAveragingFine<Field>;
using ScratchFieldPlaneAveragingFine = FPlaneAveragingFine<ScratchField>;

/** Specific application of FieldPlaneAveraging to the velocity field
* \ingroup statistics we_abl
*/
class VelPlaneAveragingFine : public FieldPlaneAveragingFine
{
public:
VelPlaneAveragingFine(CFDSim& sim, int axis_in);

~VelPlaneAveragingFine() = default;

void operator()();

private:
amrex::Vector<amrex::Real>
m_line_hvelmag_average; /** line storage for the average horizontal
velocity magnitude */
amrex::Vector<amrex::Real>
m_line_Su_average; /** line storage for the average horizontal
velocity magnitude time x-velocity */

amrex::Vector<amrex::Real>
m_line_Sv_average; /** line storage for the average horizontal
velocity magnitude time y-velocity */

public: // public for GPU
/** fill line storage with horizontal velocity magnitude averages */
template <typename IndexSelector>
void compute_hvelmag_averages(const IndexSelector& idx_op);

/** evaluate line haverage at specific location for horizontal velocity
* magnitude */
amrex::Real line_hvelmag_average_interpolated(amrex::Real x) const;
/** evaluate line haverage at specific location for horizontal velocity
* magnitude times x-velocity */
amrex::Real line_Su_average_interpolated(amrex::Real x) const;
/** evaluate line haverage at specific location for horizontal velocity
* magnitude times y-velocity */
amrex::Real line_Sv_average_interpolated(amrex::Real x) const;
};

} // namespace amr_wind

#endif /* FieldPlaneAveraging_H */
Loading