Skip to content

Commit

Permalink
Cleaner vector/array initializations (Exawind#1062)
Browse files Browse the repository at this point in the history
* Cleaner vector/array initializations
* Better initialization for RealArray, the default constructor will fill in 0 for the rest of the array
  • Loading branch information
moprak-nrel authored May 23, 2024
1 parent 6ba000b commit 2c00d88
Show file tree
Hide file tree
Showing 55 changed files with 110 additions and 118 deletions.
2 changes: 1 addition & 1 deletion amr-wind/boundary_conditions/wall_models/WallFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ WallFunction::WallFunction(CFDSim& sim)
{
{
amrex::ParmParse pp("BodyForce");
amrex::Vector<amrex::Real> body_force{{0.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> body_force{0.0, 0.0, 0.0};
pp.getarr("magnitude", body_force);
m_log_law.utau_mean = std::sqrt(std::sqrt(
body_force[0] * body_force[0] + body_force[1] * body_force[1]));
Expand Down
6 changes: 3 additions & 3 deletions amr-wind/equation_systems/icns/source_terms/ABLForcing.H
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private:
int m_n_band{2};

//! ABL forcing terms
amrex::RealArray m_abl_forcing{{0.0, 0.0, 0.0}};
amrex::RealArray m_abl_forcing{0.0};

//! File name for velocity forcing time table
std::string m_vel_timetable;
Expand All @@ -114,10 +114,10 @@ private:
amrex::Vector<amrex::Real> m_direction_table;

//! Target velocity
amrex::Vector<amrex::Real> m_target_vel{{0.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> m_target_vel{0.0, 0.0, 0.0};

//! Current mean vel
amrex::RealArray m_mean_vel{{0.0, 0.0, 0.0}};
amrex::RealArray m_mean_vel{0.0};

//! Height at which the velocities are forcing
amrex::Real m_forcing_height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public:
private:
const amrex::AmrCore& m_mesh;

amrex::Vector<amrex::Real> m_gravity{{0.0, 0.0, -9.81}};
amrex::Vector<amrex::Real> m_gravity{0.0, 0.0, -9.81};

amrex::Gpu::DeviceVector<amrex::Real> m_theta_ht;
amrex::Gpu::DeviceVector<amrex::Real> m_theta_vals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void ABLMeanBoussinesq::operator()(
const amrex::Real T0 = m_ref_theta;
const amrex::Real beta = m_beta;
const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> gravity{
{m_gravity[0], m_gravity[1], m_gravity[2]}};
m_gravity[0], m_gravity[1], m_gravity[2]};

// Mean temperature profile used to compute background forcing term
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void ABLMesoForcingMom::mean_velocity_heights(
// First the index in time
m_idx_time = closest_index(ncfile->meso_times(), currtime);

amrex::Array<amrex::Real, 2> coeff_interp{{0.0, 0.0}};
amrex::Array<amrex::Real, 2> coeff_interp{0.0, 0.0};

amrex::Real denom =
ncfile->meso_times()[m_idx_time + 1] - ncfile->meso_times()[m_idx_time];
Expand Down Expand Up @@ -172,7 +172,7 @@ void ABLMesoForcingMom::mean_velocity_heights(
// First the index in time
m_idx_time = closest_index(ncfile->meso_times(), currtime);

amrex::Array<amrex::Real, 2> coeff_interp{{0.0, 0.0}};
amrex::Array<amrex::Real, 2> coeff_interp{0.0, 0.0};

amrex::Real denom =
ncfile->meso_times()[m_idx_time + 1] - ncfile->meso_times()[m_idx_time];
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/equation_systems/icns/source_terms/BodyForce.H
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private:
const amrex::AmrCore& m_mesh;

//! Forcing source term (pressure gradient)
amrex::Vector<amrex::Real> m_body_force{{0.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> m_body_force{0.0, 0.0, 0.0};

//! Body Force Type
std::string m_type{"uniform_constant"};
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/equation_systems/icns/source_terms/BodyForce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void BodyForce::operator()(
} else {

amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> forcing{
{m_body_force[0], m_body_force[1], m_body_force[2]}};
m_body_force[0], m_body_force[1], m_body_force[2]};

if (!m_utt_file.empty()) {
// Populate forcing from file if supplied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private:
const Field& m_temperature;
const Field* m_vof;

amrex::Vector<amrex::Real> m_gravity{{0.0, 0.0, -9.81}};
amrex::Vector<amrex::Real> m_gravity{0.0, 0.0, -9.81};

//! Reference temperature (Kelvin)
amrex::Real m_ref_theta{300.0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void BoussinesqBuoyancy::operator()(
const amrex::Real T0 = m_ref_theta;
const amrex::Real beta = m_beta;
const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> gravity{
{m_gravity[0], m_gravity[1], m_gravity[2]}};
m_gravity[0], m_gravity[1], m_gravity[2]};

const bool ivf = is_vof;
const auto& vof_arr = (*m_vof)(lev).const_array(mfi);
Expand Down
6 changes: 3 additions & 3 deletions amr-wind/equation_systems/icns/source_terms/CoriolisForcing.H
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ private:
///@{
/** Orientation of the grid w.r.t. to planetary coordinate system
*/
amrex::Vector<amrex::Real> m_east{{1.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> m_north{{0.0, 1.0, 0.0}};
amrex::Vector<amrex::Real> m_up{{0.0, 0.0, 1.0}};
amrex::Vector<amrex::Real> m_east{1.0, 0.0, 0.0};
amrex::Vector<amrex::Real> m_north{0.0, 1.0, 0.0};
amrex::Vector<amrex::Real> m_up{0.0, 0.0, 1.0};
///@}

//! Latitude where the Coriolis forcing is computed (+ve northern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ void CoriolisForcing::operator()(
const amrex::Array4<amrex::Real>& src_term) const
{
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> east{
{m_east[0], m_east[1], m_east[2]}};
m_east[0], m_east[1], m_east[2]};
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> north{
{m_north[0], m_north[1], m_north[2]}};
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> up{
{m_up[0], m_up[1], m_up[2]}};
m_north[0], m_north[1], m_north[2]};
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> up{m_up[0], m_up[1], m_up[2]};

const auto sinphi = m_sinphi;
const auto cosphi = m_cosphi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public:
const amrex::Array4<amrex::Real>& vel_forces) const override;

private:
amrex::Vector<amrex::Real> m_gravity{{0.0, 0.0, -9.81}};
amrex::Vector<amrex::Real> m_gravity{0.0, 0.0, -9.81};

amrex::Real rho_0{1.0};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void DensityBuoyancy::operator()(
{
const amrex::Real density_0 = rho_0;
const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> gravity{
{m_gravity[0], m_gravity[1], m_gravity[2]}};
m_gravity[0], m_gravity[1], m_gravity[2]};

FieldState den_state = field_impl::phi_state(fstate);
const auto& density = m_density.state(den_state)(lev).const_array(mfi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ private:
int m_n_band{2};

//! Target velocity
amrex::Vector<amrex::Real> m_target_vel{{0.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> m_target_vel{0.0, 0.0, 0.0};

//! Forcing source term (pressure gradient)
amrex::Vector<amrex::Real> m_g_forcing{{0.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> m_g_forcing{0.0, 0.0, 0.0};

bool m_is_horizontal{false};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void GeostrophicForcing::operator()(
const auto& problo = m_mesh.Geom(lev).ProbLoArray();
const auto& dx = m_mesh.Geom(lev).CellSizeArray();
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> forcing{
{m_g_forcing[0], m_g_forcing[1], m_g_forcing[2]}};
m_g_forcing[0], m_g_forcing[1], m_g_forcing[2]};

// Calculate forcing values if target velocity is a function of time
if (!m_vel_timetable.empty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public:
const amrex::Array4<amrex::Real>& vel_forces) const override;

private:
amrex::Vector<amrex::Real> m_gravity{{0.0, 0.0, -9.81}};
amrex::Vector<amrex::Real> m_gravity{0.0, 0.0, -9.81};

Field* m_rho{nullptr};
Field* m_rho0{nullptr};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void GravityForcing::operator()(
const amrex::Array4<amrex::Real>& vel_forces) const
{
const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> gravity{
{m_gravity[0], m_gravity[1], m_gravity[2]}};
m_gravity[0], m_gravity[1], m_gravity[2]};

const auto& rho_arr =
((*m_rho).state(field_impl::phi_state(fstate)))(lev).const_array(mfi);
Expand Down
6 changes: 3 additions & 3 deletions amr-wind/equation_systems/icns/source_terms/RayleighDamping.H
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private:
const Field& m_velocity;

//! Reference velocity defined as an input
amrex::Vector<amrex::Real> m_ref_vel{{15.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> m_ref_vel{15.0, 0.0, 0.0};

//! Full length of the damping layer
amrex::Real m_dRD{500.};
Expand All @@ -47,9 +47,9 @@ private:
amrex::Real m_tau{5.0};

//! Which coordinate directions are forced
amrex::Vector<int> m_fcoord{{1, 1, 1}};
amrex::Vector<int> m_fcoord{1, 1, 1};
};

} // namespace amr_wind::pde::icns

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void RayleighDamping::operator()(

const amrex::Real tau = m_tau;
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> ref_vel{
{m_ref_vel[0], m_ref_vel[1], m_ref_vel[2]}};
m_ref_vel[0], m_ref_vel[1], m_ref_vel[2]};
const auto& vel =
m_velocity.state(field_impl::dof_state(fstate))(lev).const_array(mfi);

Expand Down Expand Up @@ -76,4 +76,4 @@ void RayleighDamping::operator()(
});
}

} // namespace amr_wind::pde::icns
} // namespace amr_wind::pde::icns
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ amrex::Real ABLMesoForcingTemp::mean_temperature_heights(
// First the index in time
m_idx_time = closest_index(ncfile->meso_times(), currtime);

amrex::Array<amrex::Real, 2> coeff_interp{{0.0, 0.0}};
amrex::Array<amrex::Real, 2> coeff_interp{0.0, 0.0};

amrex::Real denom =
ncfile->meso_times()[m_idx_time + 1] - ncfile->meso_times()[m_idx_time];
Expand Down Expand Up @@ -159,7 +159,7 @@ amrex::Real ABLMesoForcingTemp::mean_temperature_heights(
// First the index in time
m_idx_time = closest_index(ncfile->meso_times(), currtime);

amrex::Array<amrex::Real, 2> coeff_interp{{0.0, 0.0}};
amrex::Array<amrex::Real, 2> coeff_interp{0.0, 0.0};

amrex::Real denom =
ncfile->meso_times()[m_idx_time + 1] - ncfile->meso_times()[m_idx_time];
Expand Down
4 changes: 2 additions & 2 deletions amr-wind/immersed_boundary/bluff_body/BluffBody.H
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ struct BluffBodyBaseData

bool has_wall_model{false};

amrex::Vector<amrex::Real> vel_bc{{0.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> vel_bc{0.0, 0.0, 0.0};

//! Total integrated forces on the immersed body
amrex::Vector<amrex::Real> frc{{0.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> frc{0.0, 0.0, 0.0};
};

struct BluffBodyType : public IBType
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/mesh_mapping_models/ChannelFlowMap.H
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public:

private:
//! User input parameters
amrex::Vector<amrex::Real> m_beta{{0.0, 3.0, 0.0}};
amrex::Vector<amrex::Real> m_beta{0.0, 3.0, 0.0};

amrex::Real m_eps{1e-11};
};
Expand Down
20 changes: 10 additions & 10 deletions amr-wind/mesh_mapping_models/ChannelFlowMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ void ChannelFlowMap::create_map(int lev, const amrex::Geometry& geom)
void ChannelFlowMap::create_cell_node_map(int lev, const amrex::Geometry& geom)
{
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> beta{
{m_beta[0], m_beta[1], m_beta[2]}};
m_beta[0], m_beta[1], m_beta[2]};
const auto eps = m_eps;

const auto& dx = geom.CellSizeArray();
const auto& prob_lo = geom.ProbLoArray();
const auto& prob_hi = geom.ProbHiArray();

amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> len{
{prob_hi[0] - prob_lo[0], prob_hi[1] - prob_lo[1],
prob_hi[2] - prob_lo[2]}};
prob_hi[0] - prob_lo[0], prob_hi[1] - prob_lo[1],
prob_hi[2] - prob_lo[2]};

for (amrex::MFIter mfi((*m_mesh_scale_fac_cc)(lev)); mfi.isValid(); ++mfi) {

Expand Down Expand Up @@ -138,16 +138,16 @@ void ChannelFlowMap::create_cell_node_map(int lev, const amrex::Geometry& geom)
void ChannelFlowMap::create_face_map(int lev, const amrex::Geometry& geom)
{
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> beta{
{m_beta[0], m_beta[1], m_beta[2]}};
m_beta[0], m_beta[1], m_beta[2]};
const auto eps = m_eps;

const auto& dx = geom.CellSizeArray();
const auto& prob_lo = geom.ProbLoArray();
const auto& prob_hi = geom.ProbHiArray();

amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> len{
{prob_hi[0] - prob_lo[0], prob_hi[1] - prob_lo[1],
prob_hi[2] - prob_lo[2]}};
prob_hi[0] - prob_lo[0], prob_hi[1] - prob_lo[1],
prob_hi[2] - prob_lo[2]};

for (amrex::MFIter mfi((*m_mesh_scale_fac_xf)(lev)); mfi.isValid(); ++mfi) {

Expand Down Expand Up @@ -253,7 +253,7 @@ void ChannelFlowMap::create_face_map(int lev, const amrex::Geometry& geom)
void ChannelFlowMap::create_non_uniform_mesh(
int lev, const amrex::Geometry& geom)
{
amrex::Vector<amrex::Real> probhi_physical{{0.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> probhi_physical{0.0, 0.0, 0.0};
{
amrex::ParmParse pp("geometry");
if (pp.contains("prob_hi_physical")) {
Expand All @@ -266,16 +266,16 @@ void ChannelFlowMap::create_non_uniform_mesh(
}

amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> beta{
{m_beta[0], m_beta[1], m_beta[2]}};
m_beta[0], m_beta[1], m_beta[2]};
const auto eps = m_eps;

const auto& dx = geom.CellSizeArray();
const auto& prob_lo = geom.ProbLoArray();
const auto& prob_hi = geom.ProbHiArray();

amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> len{
{probhi_physical[0] - prob_lo[0], probhi_physical[1] - prob_lo[1],
probhi_physical[2] - prob_lo[2]}};
probhi_physical[0] - prob_lo[0], probhi_physical[1] - prob_lo[1],
probhi_physical[2] - prob_lo[2]};

for (amrex::MFIter mfi((*m_non_uniform_coord_cc)(lev)); mfi.isValid();
++mfi) {
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/mesh_mapping_models/ConstantMap.H
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public:

private:
//! Factor to scale the mesh by
amrex::Vector<amrex::Real> m_fac{{1.0, 1.0, 1.0}};
amrex::Vector<amrex::Real> m_fac{1.0, 1.0, 1.0};
};

} // namespace amr_wind::const_map
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/physics/BoussinesqBubbleFieldInit.H
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public:

private:
//! Initial bubble location
amrex::Vector<amrex::Real> m_loc{{0.25, 0.25, 0.5}};
amrex::Vector<amrex::Real> m_loc{0.25, 0.25, 0.5};

//! Initial density field
amrex::Real m_rho{1.0};
Expand Down
6 changes: 3 additions & 3 deletions amr-wind/physics/ChannelFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ChannelFlow::ChannelFlow(CFDSim& sim)
pp.query("C1", m_C1);
{
amrex::ParmParse ppb("BodyForce");
amrex::Vector<amrex::Real> body_force{{0.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> body_force{0.0, 0.0, 0.0};
ppb.queryarr("magnitude", body_force);
m_dpdx = -body_force[0];
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
Expand Down Expand Up @@ -231,7 +231,7 @@ amrex::Real ChannelFlow::compute_error(const IndexSelector& idxOp)

amrex::Real dpdx = 0;
{
amrex::Vector<amrex::Real> body_force{{0.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> body_force{0.0, 0.0, 0.0};
amrex::ParmParse pp("BodyForce");
pp.queryarr("magnitude", body_force, 0, AMREX_SPACEDIM);
dpdx = body_force[flow_dir];
Expand All @@ -240,7 +240,7 @@ amrex::Real ChannelFlow::compute_error(const IndexSelector& idxOp)
const auto& problo = m_mesh.Geom(0).ProbLoArray();
amrex::Real ht = 0.0;
{
amrex::Vector<amrex::Real> probhi_physical{{0.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> probhi_physical{0.0, 0.0, 0.0};
amrex::ParmParse pp("geometry");
if (pp.contains("prob_hi_physical")) {
pp.getarr("prob_hi_physical", probhi_physical);
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/physics/EkmanSpiral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ EkmanSpiral::EkmanSpiral(const CFDSim& sim)

{
amrex::ParmParse pp("GeostrophicForcing");
amrex::Vector<amrex::Real> gwind{{15.0, 0.0, 0.0}};
amrex::Vector<amrex::Real> gwind{15.0, 0.0, 0.0};
pp.getarr("geostrophic_wind", gwind);
m_vel = gwind[0];

Expand Down
Loading

0 comments on commit 2c00d88

Please sign in to comment.