From 5ed03935142e96085ee5d00b442010e3f3d8644b Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Thu, 24 Sep 2020 11:03:32 +0200 Subject: [PATCH] Replaced initialization loops and trivial computations with STL algorithms --- proteus/mprans/ArgumentsDict.cpp | 2 +- proteus/mprans/RANS2P2D.h | 114 ++++++++++++------------------- 2 files changed, 43 insertions(+), 73 deletions(-) diff --git a/proteus/mprans/ArgumentsDict.cpp b/proteus/mprans/ArgumentsDict.cpp index 0934af1b98..655e2c2a3e 100644 --- a/proteus/mprans/ArgumentsDict.cpp +++ b/proteus/mprans/ArgumentsDict.cpp @@ -119,7 +119,7 @@ namespace proteus }); // IMPORTANT: keep the scalar overloads AFTER the pyarray overloads, // because numpy array containing a single elements can be implicitly - // converted to scalars. If the scalar overload is define before the + // converted to scalars. If the scalar overload is defined before the // pyarray overload, it is chosen by pybind11 and the array ends up // in the wrong dictionary. cl.def("__setitem__", diff --git a/proteus/mprans/RANS2P2D.h b/proteus/mprans/RANS2P2D.h index a490ad70df..af2a8af139 100644 --- a/proteus/mprans/RANS2P2D.h +++ b/proteus/mprans/RANS2P2D.h @@ -24,6 +24,16 @@ const double DM3=1.0;//1-point-wise divergence, 0-point-wise rate of volume cha const double inertial_term=1.0; namespace proteus { + namespace detail + { + template + inline std::array make_array(const T& t) + { + std::array res; + std::fill_n(res.begin(), N, t); + } + } + template using GeneralizedFunctions = equivalent_polynomials::GeneralizedFunctions_mix; @@ -1617,7 +1627,7 @@ namespace proteus xt::pyarray& forcex = args.array("forcex"); xt::pyarray& forcey = args.array("forcey"); xt::pyarray& forcez = args.array("forcez"); - int use_ball_as_particle = args.scalar("use_ball_as_particle"); + int use_ball_as_particle = args.scalar("use_ball_as_particle"); xt::pyarray& ball_center = args.array("ball_center"); xt::pyarray& ball_radius = args.array("ball_radius"); xt::pyarray& ball_velocity = args.array("ball_velocity"); @@ -1680,36 +1690,21 @@ namespace proteus /* <<"Ball Info: velocity "<(0.0); + auto elementResidual_p_check = detail::make_array(0.0); + auto elementResidual_mesh = detail::make_array(0.0); + auto elementResidual_u = detail::make_array(0.0); + auto elementResidual_v = detail::make_array(0.0); + auto pelementResidual_u = detail::make_array(0.0); + auto pelementResidual_v = detail::make_array(0.0); + auto velocityErrorElement = detail::make_array(0.0); + double eps_rho, eps_mu; bool element_active=false; elementIsActive[eN]=false; const double* elementResidual_w(NULL); double mesh_volume_conservation_element=0.0, mesh_volume_conservation_element_weak=0.0; - for (int i=0;i 0) { @@ -1925,6 +1920,7 @@ namespace proteus dmass_ham_u_s=0.0, dmass_ham_v_s=0.0, dmass_ham_w_s=0.0; + //get jacobian, etc for mapping reference element gf_s.set_quad(k); gf.set_quad(k); @@ -1965,18 +1961,11 @@ namespace proteus //get the trial function gradients ck.gradTrialFromRef(&p_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,p_grad_trial); ck_v.gradTrialFromRef(&vel_grad_trial_ref.data()[k*nDOF_v_trial_element*nSpace],jacInv,vel_grad_trial); - for (int i=0; i < nDOF_trial_element; i++) - { - p_trial[i] = p_trial_ref.data()[k*nDOF_trial_element + i]; - p_grad_trial_ib[i*nSpace + 0] = p_grad_trial[i*nSpace+0]; - p_grad_trial_ib[i*nSpace + 1] = p_grad_trial[i*nSpace+1]; - } - for (int i=0; i < nDOF_v_trial_element; i++) - { - vel_trial[i] = vel_trial_ref.data()[k*nDOF_v_trial_element + i]; - vel_grad_trial_ib[i*nSpace + 0] = vel_grad_trial[i*nSpace+0]; - vel_grad_trial_ib[i*nSpace + 1] = vel_grad_trial[i*nSpace+1]; - } + std::copy_n(p_trial_ref.data() + k*nDOF_trial_element, nDOF_trial_element, p_trial); + std::copy_n(p_grad_trial, nDOF_trial_element*nSpace, p_grad_trial_ib); + std::copy_n(vel_trial_ref.data() + k*nDOF_v_trial_element, nDOF_v_trial_element, vel_trial); + std::copy_n(vel_grad_trial, nDOF_v_trial_element*nSpace, vel_grad_trial_ib); + if (icase == 0) { #ifdef IFEMBASIS @@ -2092,42 +2081,23 @@ namespace proteus if (PRESSURE_PROJECTION_STABILIZATION) ck.DOFaverage(p_dof.data(), &p_l2g.data()[eN_nDOF_trial_element],p_element_avg); //precalculate test function products with integration weights + auto dv_lambda = [dV](double arg) { return arg * dV; }; #ifdef IFEMGALERKIN - for (int j=0;j