static Real BzZero(const Real R, const Real phi, const Real z) { Real Arg, bz, H0, n, Rs, I; H0 = sqrt(2.0)*Iso_csound/Omega(R0); Arg = 2.0*PI*(R-R0)/H0; n = floor( (R-1.2)/H0 ); Rs = 1.3 + n*H0; I = ChiMag(R); bz = I*sin(Arg)*(Rs/R)*Omega(Rs); return bz; }
void Bayes::init(const ublas::matrix<double>& _x, const int _n, const int _p, const int _k) { Py_BEGIN_ALLOW_THREADS // data x = _x; n = _n; p = _p; k = _k; current = 0.0; loglik = -1e100; ml_pi = ublas::zero_vector<double>(k); ml_mu.resize(k); for (int i=0; i<k; ++i) ml_mu(i) = ublas::zero_vector<double>(p); ml_Omega.resize(k); for (int i=0; i<k; ++i) { ml_Omega(i).resize(p, p); ml_Omega(i) = ublas::zero_matrix<double>(p, p); } probx.resize(k, n); for (int i=0; i<k; ++i) for (int j=0; j<n; ++j) probx(i, j) = 0.0; // INITIALISE EXTERNALLY pi.resize(k); // assign equal weight for (int i=0; i<k; ++i) pi(i) = 1.0/k; // assign omega to be identity matrix * some scaling factor Omega.resize(k); ml_Omega.resize(k); for (int i=0; i<k; ++i) { Omega(i).resize(p, p); Omega(i) = 0.01*ublas::identity_matrix<double>(p, p); } // assign mu with kmeans mu = kmeans(x, n, k, p, 1e-6); // assign random indices to z z.resize(n); for (size_t i=0; i<z.size(); ++i) z(i) = std::rand() % k; Py_END_ALLOW_THREADS }
static Real BzNet(const Real R, const Real phi, const Real z) { Real bz, I; I = ChiMag(R); bz = I*Omega(R); return bz; }
void ExplicitUnitary ( ElementalMatrix<F>& APre, bool thinQR, const QRCtrl<Base<F>>& ctrl ) { DEBUG_CSE DistMatrixReadWriteProxy<F,F,MC,MR> AProx( APre ); auto& A = AProx.Get(); const Grid& g = A.Grid(); DistMatrix<F,MD,STAR> householderScalars(g); DistMatrix<Base<F>,MD,STAR> signature(g); if( ctrl.colPiv ) { DistPermutation Omega(g); QR( A, householderScalars, signature, Omega, ctrl ); } else QR( A, householderScalars, signature ); if( thinQR ) { A.Resize( A.Height(), householderScalars.Height() ); ExpandPackedReflectors ( LOWER, VERTICAL, CONJUGATED, 0, A, householderScalars ); DiagonalScale( RIGHT, NORMAL, signature, A ); } else { auto ACopy = A; // TODO: Use an extension of ExpandPackedReflectors to make this faster Identity( A, A.Height(), A.Height() ); qr::ApplyQ( LEFT, NORMAL, ACopy, householderScalars, signature, A ); } }
void RigidBody::operator()(const RigidBody::InternalState &x, RigidBody::InternalState &dxdt, const double /* t */) { Eigen::Vector3d x_dot, v_dot, omega_dot; Eigen::Vector4d q_dot; Eigen::Vector4d q(attitude.x(), attitude.y(), attitude.z(), attitude.w()); Eigen::Vector3d omega = angularVelocity; Eigen::Matrix4d omegaMat = Omega(omega); x_dot = velocity; v_dot = force/mass; q_dot = 0.5*omegaMat*q; omega_dot = inertia.inverse() * (torque - omega.cross(inertia*omega)); dxdt[0] = x_dot(0); dxdt[1] = x_dot(1); dxdt[2] = x_dot(2); dxdt[3] = v_dot(0); dxdt[4] = v_dot(1); dxdt[5] = v_dot(2); dxdt[6] = q_dot(0); dxdt[7] = q_dot(1); dxdt[8] = q_dot(2); dxdt[9] = q_dot(3); dxdt[10] = omega_dot(0); dxdt[11] = omega_dot(1); dxdt[12] = omega_dot(2); }
double cosmology::Mcaustic_from_Mvir(double mvir0,double z0){ if(!bool_pe_rho_rdelta_phys_Zhao || mvir0!=Mvir_for_pe || z0!=z_for_pe){ std::cout<<"# Initializing physical density profile for "<<mvir0<<" at z="<<z0<<std::endl<<std::endl; init_pe_rho_rdelta_phys_Zhao(mvir0,z0); } double eps=1.0e-2; double z1=z0*(1.+eps); /// Calculate the total mass evolution double Mvir1=gsl_spline_eval(mah_Zhao_spline,z1,mah_Zhao_acc); double z1step=pow(10.,log10(1.+z1)+0.2)-1.0; double Mvir1_step=gsl_spline_eval(mah_Zhao_spline,z1step,mah_Zhao_acc); double dlogMdloga_1=-(log10(Mvir1)-log10(Mvir1_step))/( log10(1.+z1) - log10(1.+z1step) ); // First calculate concentration of these halos double conc1= gsl_spline_eval(cvir_mah_Zhao_spline,z1,cvir_mah_Zhao_acc); //conc(Mvir1,z1); // Get the c200_mean of these halos double c200m_1=getcDel(conc1,z1,200.0); // Normalization factor for the Rt-R200m relation, based on Benedikt's new // fitting formulae double norm_1=0.42+0.40*Omega(z1); double c_caustic_1=c200m_1*norm_1*( 1.+2.15*exp(-dlogMdloga_1/1.96) ); double Mcaustic1=Mvir1*mu(c_caustic_1)/mu(conc1); return Mcaustic1; }
int main() { ifstream iNodes("Mathematica/Generate Mesh/nodes.dat"), iTriangles("Mathematica/Generate Mesh/triangles.dat"), iNeighbors("Mathematica/Generate Mesh/neighbors.dat"); ofstream oXi("Mathematica/Draw Logo/xi.dat"), oDirichletNodes("Mathematica/Draw Logo/DirichletNodes.dat"), oNodes("Mathematica/Draw Logo/nodes.dat"), oTriangles("Mathematica/Draw Logo/triangles.dat"); try { // import kitty mesh Triangulation Omega(iNodes, iTriangles, iNeighbors); DiffusionReactionEqn PoissonEqn(oneFunc, zeroFunc, f); BoundaryConditions BCs({ make_shared<DirichletBC>(oneFunc, fixedBoundary), make_shared<NeumannBC>() // free bndry on right half of kitty’s face }); // solve vector<double> soln = FEM::computeDiscreteSolution(PoissonEqn, Omega, BCs); // save the result oXi << soln; Boundary bndry = Omega.computeBoundary(); oDirichletNodes << FEM::computeBoundaryNodes(Omega, bndry, fixedBoundary); Omega.save(oNodes, oTriangles); } catch (exception const & e) { cout << e.what() << endl; } }
void Foam::fv::tabulatedAccelerationSource::addSup ( const RhoFieldType& rho, fvMatrix<vector>& eqn, const label fieldi ) { Vector<vector> acceleration(motion_.acceleration()); // If gravitational force is present combine with the linear acceleration if (mesh_.foundObject<uniformDimensionedVectorField>("g")) { uniformDimensionedVectorField& g = mesh_.lookupObjectRef<uniformDimensionedVectorField>("g"); const uniformDimensionedScalarField& hRef = mesh_.lookupObject<uniformDimensionedScalarField>("hRef"); g = g0_ - dimensionedVector("a", dimAcceleration, acceleration.x()); dimensionedScalar ghRef ( mag(g.value()) > SMALL ? g & (cmptMag(g.value())/mag(g.value()))*hRef : dimensionedScalar("ghRef", g.dimensions()*dimLength, 0) ); mesh_.lookupObjectRef<volScalarField>("gh") = (g & mesh_.C()) - ghRef; mesh_.lookupObjectRef<surfaceScalarField>("ghf") = (g & mesh_.Cf()) - ghRef; } // ... otherwise include explicitly in the momentum equation else { eqn -= rho*dimensionedVector("a", dimAcceleration, acceleration.x()); } dimensionedVector Omega ( "Omega", dimensionSet(0, 0, -1, 0, 0), acceleration.y() ); dimensionedVector dOmegaDT ( "dOmegaDT", dimensionSet(0, 0, -2, 0, 0), acceleration.z() ); eqn -= ( rho*(2*Omega ^ eqn.psi()) // Coriolis force + rho*(Omega ^ (Omega ^ mesh_.C())) // Centrifugal force + rho*(dOmegaDT ^ mesh_.C()) // Angular tabulatedAcceleration force ); }
void Bayes::sample_zpi() { //! sample classification // ublas::matrix<double> probx(k, n); for (int i=0; i<k; ++i) { row(probx, i).assign(pi(i) * mvnormpdf(x, mu(i), Omega(i))); } // print out likelihood for (int i=0; i<n; ++i) { double tmpsum = sum(column(probx, i)); if (tmpsum > 0) { current += log(tmpsum); } } if (loglik < current && current < 0) { loglik = current; ml_pi.assign(pi); ml_mu.assign(mu); ml_Omega.assign(Omega); } current = 0.0; ublas::vector<int> nz(k); for (int i=0; i<k; ++i) nz(i) = 0; for (int i=0; i<n; ++i) { column(probx, i) /= sum(column(probx, i)); z(i) = rdisc(column(probx, i)); } // calculate counts and complete data log likelihood for (int i=0; i<k; ++i) for (int j=0; j<n; ++j) if (z[j] == i) { nz(i) += 1; } pi = dirichlet_rnd(nz); // get indices sorted in reverse order std::vector<int> idx(argsort(pi)); std::reverse(idx.begin(), idx.end()); ublas::indirect_array<> u_idx(idx.size()); for (size_t i=0; i<idx.size(); ++i) u_idx(i) = idx[i]; pi = project(pi, u_idx); mu = project(mu, u_idx); Omega = project(Omega, u_idx); ublas::vector<int> oldz(z); for (int i=0; i<k; ++i) for (size_t j=0; j<oldz.size(); ++j) if (i == oldz[j]) z[j] = idx[i]; }
void CAST256::Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &) { AssertValidKeyLength(keylength); word32 kappa[8]; GetUserKey(BIG_ENDIAN_ORDER, kappa, 8, userKey, keylength); for(int i=0; i<12; ++i) { Omega(2*i,kappa); Omega(2*i+1,kappa); K[8*i]=kappa[0] & 31; K[8*i+1]=kappa[2] & 31; K[8*i+2]=kappa[4] & 31; K[8*i+3]=kappa[6] & 31; K[8*i+4]=kappa[7]; K[8*i+5]=kappa[5]; K[8*i+6]=kappa[3]; K[8*i+7]=kappa[1]; } if (!IsForwardTransformation()) { for(int j=0; j<6; ++j) { for(int i=0; i<4; ++i) { int i1=8*j+i; int i2=8*(11-j)+i; assert(i1<i2); std::swap(K[i1],K[i2]); std::swap(K[i1+4],K[i2+4]); } } } memset(kappa, 0, sizeof(kappa)); }
/// Get the cDel for a given cvir double cosmology::getcDel(double cvir, double z, double Delta) { int status; int iter = 0, max_iter = 100; double res; const gsl_root_fsolver_type *T; gsl_root_fsolver *s; double c_lo = 0.01*cvir, c_hi = 10.0*cvir; gsl_function F; cDel_params p; p.cptr = this; p.cvir = &cvir; double omz=Omega(z); double dcz=Delta_crit(z); p.omegaz=&omz; p.dcz=&dcz; p.Delta=Δ F.function = &findcDel; F.params = &p; T = gsl_root_fsolver_brent; s = gsl_root_fsolver_alloc (T); gsl_root_fsolver_set (s, &F, c_lo, c_hi); do { iter++; status = gsl_root_fsolver_iterate (s); res = gsl_root_fsolver_root (s); c_lo = gsl_root_fsolver_x_lower (s); c_hi = gsl_root_fsolver_x_upper (s); status = gsl_root_test_interval (c_lo, c_hi,0, 1e-6); if (status == GSL_SUCCESS) { //std::cout<<"# "<<"zcollapse:Brent converged after "<< iter<<" iterations"<<std::endl; } }while (status == GSL_CONTINUE && iter < max_iter); gsl_root_fsolver_free (s); return res; }
void ExplicitTriang( ElementalMatrix<F>& A, const QRCtrl<Base<F>>& ctrl ) { DEBUG_CSE DistMatrix<F,MD,STAR> householderScalars(A.Grid()); DistMatrix<Base<F>,MD,STAR> signature(A.Grid()); if( ctrl.colPiv ) { DistPermutation Omega(A.Grid()); BusingerGolub( A, householderScalars, signature, Omega, ctrl ); } else Householder( A, householderScalars, signature ); A.Resize( householderScalars.Height(), A.Width() ); MakeTrapezoidal( UPPER, A ); }
void ExplicitTriang( ElementalMatrix<F>& A, const QRCtrl<Base<F>>& ctrl ) { DEBUG_ONLY(CSE cse("qr::ExplicitTriang")) DistMatrix<F,MD,STAR> t(A.Grid()); DistMatrix<Base<F>,MD,STAR> d(A.Grid()); if( ctrl.colPiv ) { DistPermutation Omega(A.Grid()); BusingerGolub( A, t, d, Omega, ctrl ); } else Householder( A, t, d ); A.Resize( t.Height(), A.Width() ); MakeTrapezoidal( UPPER, A ); }
void Explicit ( ElementalMatrix<F>& APre, ElementalMatrix<F>& R, bool thinQR, const QRCtrl<Base<F>>& ctrl ) { DEBUG_ONLY(CSE cse("qr::Explicit")) DistMatrixReadWriteProxy<F,F,MC,MR> AProx( APre ); auto& A = AProx.Get(); const Grid& g = A.Grid(); DistMatrix<F,MD,STAR> t(g); DistMatrix<Base<F>,MD,STAR> d(g); if( ctrl.colPiv ) { DistPermutation Omega(g); QR( A, t, d, Omega, ctrl ); } else QR( A, t, d ); const Int m = A.Height(); const Int n = A.Width(); const Int numIts = t.Height(); auto AT = A( IR(0,numIts), IR(0,n) ); Copy( AT, R ); MakeTrapezoidal( UPPER, R ); if( thinQR ) { A.Resize( m, numIts ); ExpandPackedReflectors( LOWER, VERTICAL, CONJUGATED, 0, A, t ); DiagonalScale( RIGHT, NORMAL, d, A ); } else { auto ACopy = A; // TODO: Use an extension of ExpandPackedReflectors to make this faster Identity( A, A.Height(), A.Height() ); qr::ApplyQ( LEFT, NORMAL, ACopy, t, d, A ); } }
/// Radii are in physical units here, so be careful void cosmology::modelNFWhalo(double m200,double z,double &Mvir, double &Rvir, double &cvir, double &R200, double &c200) { Mvir=getMvir(m200,z); Rvir=0.169*pow(Mvir/1.e12,1./3.); Rvir*=pow(Delta_crit(z)/178.0,-1.0/3.0); Rvir*=pow(Eofz(z),-2./3.); double Delta=200.; R200=pow( 1.0e12/(4./3.*Delta*3e4*0.3/(8*gee)),1./3.); R200*=pow(m200/1.e12,1./3.); R200*=pow(Omega(z)/0.3,-1.0/3.0); R200*=pow(Eofz(z),-2./3.); cvir=conc(Mvir,z); c200=getc200(cvir,z); }
void Explicit ( ElementalMatrix<F>& APre, ElementalMatrix<F>& R, ElementalMatrix<Int>& OmegaFull, bool thinQR, const QRCtrl<Base<F>>& ctrl ) { DEBUG_CSE DistMatrixReadWriteProxy<F,F,MC,MR> AProx( APre ); auto& A = AProx.Get(); const Grid& g = A.Grid(); DistMatrix<F,MD,STAR> householderScalars(g); DistMatrix<Base<F>,MD,STAR> signature(g); DistPermutation Omega(g); QR( A, householderScalars, signature, Omega, ctrl ); const Int m = A.Height(); const Int n = A.Width(); const Int numIts = householderScalars.Height(); auto AT = A( IR(0,numIts), IR(0,n) ); Copy( AT, R ); MakeTrapezoidal( UPPER, R ); if( thinQR ) { A.Resize( m, numIts ); ExpandPackedReflectors ( LOWER, VERTICAL, CONJUGATED, 0, A, householderScalars ); DiagonalScale( RIGHT, NORMAL, signature, A ); } else { auto ACopy = A; // TODO: Use an extension of ExpandPackedReflectors to make this faster Identity( A, A.Height(), A.Height() ); qr::ApplyQ( LEFT, NORMAL, ACopy, householderScalars, signature, A ); } Omega.ExplicitMatrix( OmegaFull ); }
std::string Node::thirdString() const { std::string res = "2 "; res += string2string(satelliteNumber(), 5) + " "; res += double2string(normalizeAngle(i()), 8, 4, false, false, false) + " "; res += double2string(normalizeAngle(Omega()), 8, 4, false, false, false) + " "; res += double2string(e(), 7, 7, false, true, false) + " "; res += double2string(normalizeAngle(omega()), 8, 4, false, false, false) + " "; res += double2string(normalizeAngle(M()), 8, 4, false, false, false) + " "; res += double2string(n(), 11, 8, false, false, false); res += int2string(revolutionNumber(), 5, false); // Checksum int sum = checksum(res); res += int2string(sum, 1); return res; }
/// Delta_crit(z) a'la Bryan and Norman '98 double cosmology::Delta_crit(double z) { double result; double x=Omega(z)-1.; if (Omega0<1.&&Omegal==0.0) { result=18.0 * M_PI*M_PI + 60.0*x - 32.0 * x*x; } else if (fabs(Omega0+Omegal-1.0)<1.e-4) { result=18.0 * M_PI*M_PI + 82.0*x - 39.0 * x*x; } else { std::cout<<"# Aborting as Delta_Crit not defined for this cosmology."<<std::endl; exit(0); } return result; }
void Node::parseAll() { n(); dn(); d2n(); i(); Omega(); omega(); M(); e(); bstar(); satelliteNumber(); satelliteName(); designator(); classification(); ephemerisType(); elementNumber(); revolutionNumber(); preciseEpoch(); }
void EstimatorPredictor::PropagateState(const Eigen::Vector3d &omega_m, const Eigen::Vector3d &a_m) { Matrix3d C_q_i_w_old = q_i_w.toQuat().toRotationMatrix(); Vector3d v_i_w_old = v_i_w; Vector3d p_i_w_old = p_i_w; QuaternionAd q_i_w_old = q_i_w; // (eye(4) - Delta_t/4*Omega(omega_m - b_omega))*q_i_w_new == (eye(4) + Delta_t/4*Omega( omega_m_old - b_omega))*q_i_w_old Vector3d tmp = Delta_t/4.0*(omega_m - b_omega); Matrix4d Q1; // eye(4) - Delta_t/4*Omega(omega_m - b_omega) Q1 << 1, tmp(0), tmp(1), -tmp(2), -tmp(0), 1, tmp(2), tmp(1), -tmp(1), -tmp(2), 1, -tmp(0), tmp(2), -tmp(1), tmp(2), 1; tmp = Delta_t/4.0*(omega_m_old - b_omega); Matrix4d Q2; // eye(4) + Delta_t/4*Omega( omega_m_old - b_omega) Q2 << 1, tmp(0), tmp(1), -tmp(2), -tmp(0), 1, tmp(2), tmp(1), -tmp(1), -tmp(2), 1, -tmp(0), tmp(2), -tmp(1), tmp(2), 1; //q_i_w.coeffs() = Q1.lu().solve(Q2*q_i_w_old.coeffs()); //q_i_w.normalize(); tmp = Delta_t*(omega_m_old - b_omega)/2.0; Quaterniond Omega( 0, tmp(0), tmp(1), tmp(2) ); q_i_w.q.coeffs() += (Omega.conjugate()*q_i_w.toQuat()).conjugate().coeffs(); q_i_w.normalize(); Matrix3d C_q_i_w = q_i_w.toQuat().toRotationMatrix(); v_i_w += ( C_q_i_w_old.transpose()*(a_m_old - b_a) - g + C_q_i_w.transpose()*(a_m - b_a) - g )*Delta_t/2.0; p_i_w += (v_i_w_old + v_i_w)*Delta_t/2.0; omega_m_old = omega_m; a_m_old = a_m; }
void Model::predict(std::vector<double> &choice_probability, const Eigen::MatrixXd &M, const Parameter ¶meter) { if (parameter.stopping_time < 0) { std::runtime_error("Stopping Time has to be non-negative."); } n_alternatives = M.rows(); n_dimensions = M.cols(); choice_probability.resize(n_alternatives); std::fill(begin(choice_probability), end(choice_probability), 0.0); Eigen::MatrixXd S(n_alternatives, n_alternatives); construct_feedback_matrix(S, M, parameter); // unsigned int res = check_feedback_matrix(S); // // if (res == 0) { Eigen::MatrixXd C(n_alternatives, n_alternatives); construct_contrast_matrix(C); Eigen::VectorXd W(n_dimensions); construct_weight_vector(W); Eigen::VectorXd Eta(n_alternatives); Eigen::MatrixXd Omega(n_alternatives, n_alternatives); construct_preference_and_covariance(Eta, Omega, C, M, W, S, parameter); Eigen::MatrixXd L(n_alternatives - 1, n_alternatives); for (unsigned int i = 0; i < n_alternatives; i++) { construct_L_matrix(L, i); choice_probability.at(i) = compute_choice_probability(L, Eta, Omega); } // } }
/// Radii are in comoving units here void cosmology::modelNFWhalo_com_ext(double mDel,double z,double &Mvir, double &Rvir, double &cvir, double &RDel, double &cDel,double Del) { //std::cout<<Delta_crit(z)<<std::endl;exit(0); Mvir=getMvir(mDel,z,Del); Rvir=0.169*pow(Mvir/1.e12,1./3.); Rvir*=pow(Delta_crit(z)/178.0,-1.0/3.0); Rvir*=pow(Eofz(z),-2./3.); double Delta=Del; RDel=pow( 1.0e12/(4./3.*Delta*3e4*0.3/(8*gee)),1./3.); RDel*=pow(mDel/1.e12,1./3.); RDel*=pow(Omega(z)/0.3,-1.0/3.0); RDel*=pow(Eofz(z),-2./3.); cvir=conc(Mvir,z); cDel=getcDel(cvir,z,Delta); Rvir=Rvir*(1.+z); RDel=RDel*(1.+z); }
double cosmology::dMcaustic_dMvir(double mvir0,double z0,double z1,double z2){ if(!bool_pe_rho_rdelta_phys_Zhao || mvir0!=Mvir_for_pe || z0!=z_for_pe){ std::cout<<"# Initializing physical density profile for "<<mvir0<<" at z="<<z0<<std::endl<<std::endl; init_pe_rho_rdelta_phys_Zhao(mvir0,z0); } if(z0>z1 || z0>z2){ std::cout<<"# z0 should be smaller than z1 and z2\n"; return 0; } if(z2<z1){ std::cout<<"# z1 should be smaller than z2\n"; return 0; } /// Calculate the total mass evolution double Mvir1=gsl_spline_eval(mah_Zhao_spline,z1,mah_Zhao_acc); double z1step=pow(10.,log10(1.+z1)+0.2)-1.0; double Mvir1_step=gsl_spline_eval(mah_Zhao_spline,z1step,mah_Zhao_acc); double dlogMdloga_1=-(log10(Mvir1)-log10(Mvir1_step))/( log10(1.+z1) - log10(1.+z1step) ); double Mvir2=gsl_spline_eval(mah_Zhao_spline,z2,mah_Zhao_acc); double z2step=pow(10.,log10(1.+z2)+0.2)-1.0; double Mvir2_step=gsl_spline_eval(mah_Zhao_spline,z2step,mah_Zhao_acc); double dlogMdloga_2=-(log10(Mvir2)-log10(Mvir2_step))/( log10(1.+z2) - log10(1.+z2step) ); //printf("z1:%e z1step:%e z2:%e z2step:%e\n",z1,z1step,z2,z2step); //mofz=(Mvir1+Mvir2)/2.; /* double Rvir1=rvir_from_mvir(Mvir1,z1); Rvir1=Rvir1/(1+z1); double Rvir2=rvir_from_mvir(Mvir2,z2); Rvir2=Rvir2/(1+z2); */ double dMvir=Mvir1-Mvir2; // First calculate concentration of these halos double conc1= gsl_spline_eval(cvir_mah_Zhao_spline,z1,cvir_mah_Zhao_acc); //conc(Mvir1,z1); double conc2= gsl_spline_eval(cvir_mah_Zhao_spline,z2,cvir_mah_Zhao_acc); //conc(Mvir2,z2); // Get the c200_mean of these halos double c200m_1=getcDel(conc1,z1,200.0); double c200m_2=getcDel(conc2,z2,200.0); // Normalization factor for the Rt-R200m relation, based on Benedikt's new // fitting formulae double norm_1=0.42+0.40*Omega(z1); double norm_2=0.42+0.40*Omega(z2); double c_caustic_1=c200m_1*norm_1*( 1.+2.15*exp(-dlogMdloga_1/1.96) ); double c_caustic_2=c200m_2*norm_2*( 1.+2.15*exp(-dlogMdloga_2/1.96) ); double Mcaustic1=Mvir1*mu(c_caustic_1)/mu(conc1); double Mcaustic2=Mvir2*mu(c_caustic_2)/mu(conc2); //printf("dlogMdloga_1:%e log10 Mvir1:%e z1:%e Mcaustic1:%e dlogMdloga_1:%e log10 Mvir2:%e z2:%e Mcaustic2:%e\n",dlogMdloga_1,log10(Mvir1),z1,Mcaustic1,dlogMdloga_2,log10(Mvir2),z2,Mcaustic2); double dMcaustic=(Mcaustic1-Mcaustic2); //fprintf(stderr,"# Mvir1:%e Mvir2:%e Mpe:%e dMvir:%e M4rs1:%e M4rs2:%e dM4rs:%e\n",Mvir1,Mvir2,Mpe,dMvir,M4rs1,M4rs2,dM4rs); if(dMcaustic<0) return -1.0; else return dMcaustic/dMvir; }
double OmegaRad( double centuryTime) { return DEG2RAD(Omega(centuryTime)); }
void run() { Environment::changeRepository( boost::format( "/testsuite/feeldiscr/%1%/P%2%/" ) % Environment::about().appName() % OrderPoly ); /* change parameters below */ const int nDim = 2; const int nOrderPoly = OrderPoly; const int nOrderGeo = 1; //------------------------------------------------------------------------------// typedef Mesh< Simplex<nDim, 1,nDim> > mesh_type; typedef Mesh< Simplex<nDim, 1,nDim> > mesh_bis_type; double meshSize = option("hsize").as<double>(); double meshSizeBis = option("hsize-bis").as<double>(); // mesh GeoTool::Node x1( 0,0 ); GeoTool::Node x2( 4,1 ); GeoTool::Rectangle Omega( meshSize,"Omega",x1,x2 ); Omega.setMarker( _type="line",_name="Entree",_marker4=true ); Omega.setMarker( _type="line",_name="Sortie",_marker2=true ); Omega.setMarker( _type="line",_name="Paroi",_marker1=true,_marker3=true ); Omega.setMarker( _type="surface",_name="Fluid",_markerAll=true ); auto mesh = Omega.createMesh(_mesh=new mesh_type,_name="omega_"+ mesh_type::shape_type::name() ); LOG(INFO) << "created mesh\n"; GeoTool::Rectangle OmegaBis( meshSizeBis,"Omega",x1,x2 ); OmegaBis.setMarker( _type="line",_name="Entree",_marker4=true ); OmegaBis.setMarker( _type="line",_name="Sortie",_marker2=true ); OmegaBis.setMarker( _type="line",_name="Paroi",_marker1=true,_marker3=true ); OmegaBis.setMarker( _type="surface",_name="Fluid",_markerAll=true ); auto meshBis = OmegaBis.createMesh(_mesh=new mesh_bis_type,_name="omegaBis_"+ mesh_type::shape_type::name() ); //auto meshBis= mesh->createP1mesh(); LOG(INFO) << "created meshBis\n"; typedef Lagrange<nOrderPoly,Scalar,Continuous,PointSetFekete> basis_type; typedef FunctionSpace<mesh_type, bases<basis_type> > space_type; auto Xh = space_type::New( mesh ); auto u = Xh->element(); auto v = Xh->element(); auto u2 = Xh->element(); LOG(INFO) << "created space and elements\n"; auto mybackend = backend(); //--------------------------------------------------------------// auto A = mybackend->newMatrix( Xh, Xh ); auto F = mybackend->newVector( Xh ); auto pi = cst( M_PI ); auto u_exact = cos( pi*Px() )*sin( pi*Py() ); auto dudx = -pi*sin( pi*Px() )*sin( pi*Py() ); auto dudy = pi*cos( pi*Px() )*cos( pi*Py() ); auto grad_u_uexact = vec( dudx,dudy ); auto lap = -2*pi*pi*cos( pi*Px() )*sin( pi*Py() ); //auto lap = -pi*pi*cos(pi*Px())*sin(pi*Py()) // -pi*pi*cos(pi*Px())*sin(pi*Py()); LOG(INFO) << "created exact data and matrix/vector\n"; auto f = -lap;//cst(1.); double gammabc=10; // assemblage form2( Xh, Xh, A, _init=true ) = integrate( elements( mesh ), //_Q<15>(), + gradt( u )*trans( grad( v ) ) ); form2( Xh, Xh, A ) += integrate( boundaryfaces( mesh ), - gradt( u )*N()*id( v ) + gammabc*idt( u )*id( v )/hFace() ); form1( Xh, F, _init=true ) = integrate( elements( mesh ), // _Q<10>(), trans( f )*id( v ) ); form1( Xh, F ) += integrate( boundaryfaces( mesh ), + gammabc*u_exact*id( v )/hFace() ); LOG(INFO) << "A,F assembled\n"; //form2( Xh, Xh, A ) += // on( boundaryfaces(mesh) , u, F, u_exact ); // solve system mybackend->solve( A,u,F ); LOG(INFO) << "A u = F solved\n"; //--------------------------------------------------------------// auto a2 = form2( _test=Xh, _trial=Xh ); auto f2 = form1( _test=Xh ); LOG(INFO) << "created form2 a2 and form1 F2\n"; // assemblage a2 = integrate( elements( meshBis ), + gradt( u2 )*trans( grad( v ) ), _Q<10>() ); LOG(INFO) << "a2 grad.grad term\n"; a2 += integrate( boundaryfaces( meshBis ), - gradt( u2 )*N()*id( v ) + gammabc*idt( u2 )*id( v )/hFace(), _Q<10>() ); LOG(INFO) << "a2 weak dirichlet terms\n"; f2 = integrate( elements( meshBis ), trans( f )*id( v ), _Q<10>() ); LOG(INFO) << "f2 source term\n"; f2 += integrate( boundaryfaces( meshBis ), + gammabc*u_exact*id( v )/hFace(), _Q<10>() ); LOG(INFO) << "f2 dirichlet terms\n"; LOG(INFO) << "a2,f2 assembled\n"; //form2( Xh, Xh, A2 ) += // on( boundaryfaces(mesh) , u2, F2, u_exact ); #if 0 for ( size_type i = 0 ; i< F->size() ; ++i ) { auto errOnF = std::abs( ( *F )( i )-( *F2 )( i ) ); if ( errOnF > 1e-8 ) std::cout << "\nerrOnF : " << errOnF; } std::cout << "\nFin errOnF !!!!\n"; #endif // solve system a2.solve( _rhs=f2, _solution=u2 ); auto diff = std::sqrt( integrate( elements( mesh ), ( idv( u )-idv( u2 ) )*( idv( u )-idv( u2 ) ) ).evaluate()( 0,0 ) ); #if 0 auto int1 = integrate( elements( mesh ), abs( idv( u ) ) ).evaluate()( 0,0 ); auto int2 = integrate( elements( mesh ), abs( idv( u2 ) ) ).evaluate()( 0,0 ); std::cout << "\nThe diff : " << diff << " int1 :" << int1 << " int2 :" << int2 << "\n"; #endif #if USE_BOOST_TEST BOOST_CHECK_SMALL( diff,1e-2 ); #endif //--------------------------------------------------------------// if ( option("exporter.export").as<bool>() ) { // export auto ex = exporter( _mesh=mesh ); ex->add( "u", u ); ex->add( "ubis", u2 ); ex->save(); } }
void fourier_harmonic_3D(std::vector<Real> harmonics, Real lc, Real R, std::string output_name,int verbose){ ////=============================================================//// ////======================= Mesh building =====================//// ////=============================================================//// if (verbose>0){ std::cout<<"Construction du maillage"<<std::endl; } gmsh_sphere(("sphere_"+NbrToStr(lc)).c_str(),R,lc,verbose); ////=============================================================//// ////======================= Mesh loading ======================//// ////=============================================================//// if (verbose>0){ std::cout<<"Chargement du maillage"<<std::endl; } Real kappa=1.; geometry geom; load_node_gmsh(geom,("sphere_"+NbrToStr(lc)).c_str()); mesh_2D Omega(geom); load_elt_gmsh(Omega,0); //gmsh_clean(("sphere_"+NbrToStr(lc)).c_str()); ////=============================================================//// ////================== Calcul de la normale =====================//// ////=============================================================//// nrml_2D n_(Omega); ////=============================================================//// ////================ Assemblage de la matrice ===================//// ////=============================================================//// if (verbose>0){ std::cout<<"Assemblage operateurs integraux"<<std::endl; } int nbelt = nb_elt(Omega); P1_2D dof(Omega); int nbdof = nb_dof(dof); if (verbose>0){ std::cout<<"Matrice de taille: "; std::cout<<nbdof<< std::endl; std::cout<<"Nel: "; std::cout<<nbelt<< std::endl; } gmm_dense V(nbdof,nbdof),W(nbdof,nbdof),K(nbdof,nbdof),M(nbdof,nbdof); bem<P1_2D,P1_2D, SLP_3D> Vop (kappa,n_,n_); bem<P1_2D,P1_2D, HSP_3D> Wop (kappa,n_,n_); bem<P1_2D,P1_2D, DLP_3D> Kop (kappa,n_,n_); progress bar("assembly", nbelt*nbelt,verbose); for(int j=0; j<nbelt; j++){ const elt_2D& tj = Omega[j]; const N3& jj = dof[j]; for(int k=0; k<nbelt; k++,bar++){ const elt_2D& tk = Omega[k]; const N3& kk = dof[k]; V (jj,kk) += Vop (tj,tk); W (jj,kk) += Wop (tj,tk); K (jj,kk) += Kop (tj,tk); } M(jj,jj) += MassP1(tj); } bar.end(); // for (int l=0;l<harmonics.size();l++){ // Real p = harmonics[l]; // ////=============================================================//// // ////================== Harmonique de Fourier ====================//// // ////=============================================================//// // vect<Cplx> Ep;resize(Ep,nbdof);fill(Ep,0.); // for (int j=0 ; j<nbelt ; j++){ // const elt_2D& seg = Omega[j]; // const N3& I = dof[j]; // R3 X0; X0[0] = seg[0][0];X0[1]=seg[0][1]; X0[2]=seg[0][2]; // R3 X1; X1[0] = seg[1][0];X1[1]=seg[1][1]; X1[2]=seg[1][2]; // R3 X2; X2[0] = seg[2][0];X2[1]=seg[2][1]; X2[2]=seg[2][2]; // Real phi0 = atan2(X0[1],X0[0]); // Real phi1 = atan2(X1[1],X1[0]); // Real phi2 = atan2(X2[1],X2[0]); // Real theta0 = acos(X0[2]); // Real theta1 = acos(X1[2]); // Real theta2 = acos(X2[2]); // if (phi0<0){ // phi0 += 2 * M_PI; // } // if (phi1<0){ // phi1 += 2 * M_PI; // } // if (phi2<0){ // phi2 += 2 * M_PI; // } // C3 Vinc; // Vinc[0] = boost::math::spherical_harmonic(p,p,theta0,phi0); // Vinc[1] = boost::math::spherical_harmonic(p,p,theta1,phi1); // Vinc[2] = boost::math::spherical_harmonic(p,p,theta2,phi2); // Ep[I] = Vinc; // } // vect<Cplx> Eph;resize(Eph,nbdof);fill(Eph,0.); // mv_prod(Eph,M,Ep); // ////=============================================================//// // ////================== Calcul valeurs propres ===================//// // ////=============================================================//// // ////===================================//// // ////===== Test avec orthogonalité =====//// // Cplx val =0; // Cplx err =0; // for(int j=0; j<nbdof; j++){ // val += Ep[j]*conj(Eph[j]); // } // err = abs(val)-1; // std::cout<<"PS : "<<err<<std::endl; // ////===================================//// // ////=========== Test avec V ===========//// // val =0; // Real err_V =0; // Cplx j_p = boost::math::sph_bessel(p, kappa*R); // Cplx y_p = boost::math::sph_neumann(p, kappa*R); // Cplx h_p = boost::math::sph_hankel_1(p, kappa*R); // Cplx j_p_prime = boost::math::sph_bessel_prime(p, kappa*R); // Cplx y_p_prime = boost::math::sph_neumann_prime(p, kappa*R); // Cplx h_p_prime = j_p_prime + iu * y_p_prime; // Cplx ref = iu * kappa * j_p * h_p; // vect<Cplx> Temp;resize(Temp,nbdof);fill(Temp,0.); // mv_prod(Temp,V,Ep); // for(int j=0; j<nbdof; j++){ // val += conj(Ep[j])*Temp[j]; // } // // // err_V = abs(val-ref) /abs(ref); // if (verbose>0){ // std::cout<<"V : "<<err_V<<std::endl; // } // ////===================================//// // ////=========== Test avec W ===========//// // val =0; // Real err_W =0; // ref = - iu * pow(kappa,3) * j_p_prime * h_p_prime; // fill(Temp,0.); // mv_prod(Temp,W,Ep); // for(int j=0; j<nbdof; j++){ // val += conj(Ep[j])*Temp[j]; // } // err_W = abs(val-ref) /abs(ref); // if (verbose>0){ // std::cout<<"W : "<<err_W<<std::endl; // } // ////===================================//// // ////=========== Test avec K ===========//// // val =0; // Real err_K =0; // ref = iu /2. * kappa*kappa * (j_p_prime * h_p + j_p * h_p_prime); // fill(Temp,0.); // mv_prod(Temp,K,Ep); // for(int j=0; j<nbdof; j++){ // val += conj(Ep[j])*Temp[j]; // } // err_K = abs(val-ref) /abs(ref); // if (verbose>0){ // std::cout<<"K : "<<err_K<<std::endl; // } // ////=============================================================//// // ////======================== Sauvegardes ========================//// // ////=============================================================//// // std::ofstream output((output_name+"_"+NbrToStr<Real>(p)+".txt").c_str(),std::ios::app); // if (!output){ // std::cerr<<"Output file cannot be created"<<std::endl; // exit(1); // } // else{ // output<<lc<<" "<<err_V<<" "<<err_W<<" "<<err_K<<std::endl; // } // output.close(); // if (l == 0) // { // std::cout << p << "P" << std::endl; // } // } }
bool Reed_Solomon::decode(const bvec &coded_bits, const ivec &erasure_positions, bvec &decoded_message, bvec &cw_isvalid) { bool decoderfailure, no_dec_failure; int j, i, kk, l, L, foundzeros, iterations = floor_i(static_cast<double>(coded_bits.length()) / (n * m)); bvec mbit(m * k); decoded_message.set_size(iterations * k * m, false); cw_isvalid.set_length(iterations); GFX rx(q, n - 1), cx(q, n - 1), mx(q, k - 1), ex(q, n - 1), S(q, 2 * t), Xi(q, 2 * t), Gamma(q), Lambda(q), Psiprime(q), OldLambda(q), T(q), Omega(q); GFX dummy(q), One(q, (char*)"0"), Omegatemp(q); GF delta(q), tempsum(q), rtemp(q), temp(q), Xk(q), Xkinv(q); ivec errorpos; if ( erasure_positions.length() ) { it_assert(max(erasure_positions) < iterations*n, "Reed_Solomon::decode: erasure position is invalid."); } no_dec_failure = true; for (i = 0; i < iterations; i++) { decoderfailure = false; //Fix the received polynomial r(x) for (j = 0; j < n; j++) { rtemp.set(q, coded_bits.mid(i * n * m + j * m, m)); rx[j] = rtemp; } // Fix the Erasure polynomial Gamma(x) // and replace erased coordinates with zeros rtemp.set(q, -1); ivec alphapow = - ones_i(2); Gamma = One; for (j = 0; j < erasure_positions.length(); j++) { rx[erasure_positions(j)] = rtemp; alphapow(1) = erasure_positions(j); Gamma *= (One - GFX(q, alphapow)); } //Fix the syndrome polynomial S(x). S.clear(); for (j = 1; j <= 2 * t; j++) { S[j] = rx(GF(q, b + j - 1)); } // calculate the modified syndrome polynomial Xi(x) = Gamma * (1+S) - 1 Xi = Gamma * (One + S) - One; // Apply Berlekam-Massey algorithm if (Xi.get_true_degree() >= 1) { //Errors in the received word // Iterate to find Lambda(x), which hold all error locations kk = 0; Lambda = One; L = 0; T = GFX(q, (char*)"-1 0"); while (kk < 2 * t) { kk = kk + 1; tempsum = GF(q, -1); for (l = 1; l <= L; l++) { tempsum += Lambda[l] * Xi[kk - l]; } delta = Xi[kk] - tempsum; if (delta != GF(q, -1)) { OldLambda = Lambda; Lambda -= delta * T; if (2 * L < kk) { L = kk - L; T = OldLambda / delta; } } T = GFX(q, (char*)"-1 0") * T; } // Find the zeros to Lambda(x) errorpos.set_size(Lambda.get_true_degree()); foundzeros = 0; for (j = q - 2; j >= 0; j--) { if (Lambda(GF(q, j)) == GF(q, -1)) { errorpos(foundzeros) = (n - j) % n; foundzeros += 1; if (foundzeros >= Lambda.get_true_degree()) { break; } } } if (foundzeros != Lambda.get_true_degree()) { decoderfailure = true; } else { // Forney algorithm... //Compute Omega(x) using the key equation for RS-decoding Omega.set_degree(2 * t); Omegatemp = Lambda * (One + Xi); for (j = 0; j <= 2 * t; j++) { Omega[j] = Omegatemp[j]; } //Find the error/erasure magnitude polynomial by treating them the same Psiprime = formal_derivate(Lambda*Gamma); errorpos = concat(errorpos, erasure_positions); ex.clear(); for (j = 0; j < errorpos.length(); j++) { Xk = GF(q, errorpos(j)); Xkinv = GF(q, 0) / Xk; // we calculate ex = - error polynomial, in order to avoid the // subtraction when recunstructing the corrected codeword ex[errorpos(j)] = (Xk * Omega(Xkinv)) / Psiprime(Xkinv); if (b != 1) { // non-narrow-sense code needs corrected error magnitudes int correction_exp = ( errorpos(j)*(1-b) ) % n; ex[errorpos(j)] *= GF(q, correction_exp + ( (correction_exp < 0) ? n : 0 )); } } //Reconstruct the corrected codeword. // instead of subtracting the error/erasures, we calculated // the negative error with 'ex' above cx = rx + ex; //Code word validation S.clear(); for (j = 1; j <= 2 * t; j++) { S[j] = cx(GF(q, b + j - 1)); } if (S.get_true_degree() >= 1) { decoderfailure = true; } } } else { cx = rx; decoderfailure = false; } //Find the message polynomial mbit.clear(); if (decoderfailure == false) { if (cx.get_true_degree() >= 1) { // A nonzero codeword was transmitted if (systematic) { for (j = 0; j < k; j++) { mx[j] = cx[j]; } } else { mx = divgfx(cx, g); } for (j = 0; j <= mx.get_true_degree(); j++) { mbit.replace_mid(j * m, mx[j].get_vectorspace()); } } } else { //Decoder failure. // for a systematic code it is better to extract the undecoded message // from the received code word, i.e. obtaining a bit error // prob. p_b << 1/2, than setting all-zero (p_b = 1/2) if (systematic) { mbit = coded_bits.mid(i * n * m, k * m); } else { mbit = zeros_b(k); } no_dec_failure = false; } decoded_message.replace_mid(i * m * k, mbit); cw_isvalid(i) = (!decoderfailure); } return no_dec_failure; }
int main( int argc, char* argv[] ) { El::Environment env( argc, argv ); try { typedef double Real; typedef El::Complex<Real> Scalar; const El::Int m = El::Input("--height","height of matrix",20); const El::Int n = El::Input("--width","width of matrix",100); const El::Int r = El::Input("--rank","rank of matrix",5); const El::Int maxSteps = El::Input("--maxSteps","max # of steps of QR",10); const Real tol = El::Input("--tol","tolerance for ID",Real(-1)); const bool print = El::Input("--print","print matrices?",false); const bool smallestFirst = El::Input("--smallestFirst","smallest norm first?",false); El::ProcessInput(); El::PrintInputReport(); El::mpi::Comm comm = El::mpi::COMM_WORLD; const El::Grid& grid = El::Grid::Default(); El::DistMatrix<Scalar> U(grid), V(grid), A(grid); El::Uniform( U, m, r ); El::Uniform( V, n, r ); El::Gemm( El::NORMAL, El::ADJOINT, Scalar(1), U, V, A ); const Real frobA = El::FrobeniusNorm( A ); if( print ) El::Print( A, "A" ); El::DistPermutation Omega(grid); El::DistMatrix<Scalar,El::STAR,El::VR> Z(grid); El::QRCtrl<Real> ctrl; ctrl.boundRank = true; ctrl.maxRank = maxSteps; if( tol != -1. ) { ctrl.adaptive = true; ctrl.tol = tol; } ctrl.smallestFirst = smallestFirst; El::Timer timer; if( El::mpi::Rank(comm) == 0 ) timer.Start(); El::ID( A, Omega, Z, ctrl ); if( El::mpi::Rank(comm) == 0 ) timer.Stop(); const El::Int rank = Z.Height(); if( print ) { El::DistMatrix<El::Int> OmegaFull(grid); Omega.ExplicitMatrix( OmegaFull ); El::Print( OmegaFull, "Omega" ); El::Print( Z, "Z" ); } // Pivot A and form the matrix of its (hopefully) dominant columns El::Timer permTimer("permTimer"); permTimer.Start(); Omega.PermuteCols( A ); permTimer.Stop(); auto hatA( A ); hatA.Resize( m, rank ); if( print ) { El::Print( A, "A Omega^T" ); El::Print( hatA, "\\hat{A}" ); } // Check || A Omega^T - \hat{A} [I, Z] ||_F / || A ||_F El::DistMatrix<Scalar> AL(grid), AR(grid); El::PartitionRight( A, AL, AR, rank ); El::Zero( AL ); { El::DistMatrix<Scalar,El::MC,El::STAR> hatA_MC_STAR(grid); El::DistMatrix<Scalar,El::STAR,El::MR> Z_STAR_MR(grid); hatA_MC_STAR.AlignWith( AR ); Z_STAR_MR.AlignWith( AR ); hatA_MC_STAR = hatA; Z_STAR_MR = Z; El::LocalGemm ( El::NORMAL, El::NORMAL, Scalar(-1), hatA_MC_STAR, Z_STAR_MR, Scalar(1), AR ); } const Real frobError = El::FrobeniusNorm( A ); if( print ) El::Print( A, "A Omega^T - \\hat{A} [I, Z]" ); if( El::mpi::Rank(comm) == 0 ) { El::Output(" ID time: ",timer.Total()," secs"); El::Output ("|| A ||_F = ",frobA,"\n", "|| A Omega^T - \\hat{A} [I, Z] ||_F / || A ||_F = ", frobError/frobA); } } catch( std::exception& e ) { El::ReportException(e); } return 0; }
void MR::propagateCavityFields() { Real sum_even, sum_odd; Real maxdev; size_t maxruns = 1000; for( size_t i = 0; i < G.nrNodes(); i++ ) bforeach( const Neighbor &j, G.nb(i) ) M[i][j.iter] = 0.1; size_t run=0; do { maxdev=0.0; run++; for( size_t i = 0; i < G.nrNodes(); i++ ) { bforeach( const Neighbor &j, G.nb(i) ) { size_t _j = j.iter; size_t _i = G.findNb(j,i); DAI_ASSERT( G.nb(j,_i) == i ); Real newM = 0.0; if( props.updates == Properties::UpdateType::FULL ) { // find indices in nb(j) that do not correspond with i sub_nb _nbj_min_i(G.nb(j).size()); _nbj_min_i.set(); _nbj_min_i.reset(_i); // find indices in nb(i) that do not correspond with j sub_nb _nbi_min_j(G.nb(i).size()); _nbi_min_j.set(); _nbi_min_j.reset(_j); sum_subs(j, _nbj_min_i, &sum_even, &sum_odd); newM = (tanh(theta[j]) * sum_even + sum_odd) / (sum_even + tanh(theta[j]) * sum_odd); sum_subs(i, _nbi_min_j, &sum_even, &sum_odd); Real denom = sum_even + tanh(theta[i]) * sum_odd; Real numer = 0.0; for(size_t _k=0; _k < G.nb(i).size(); _k++) if(_k != _j) { sub_nb _nbi_min_jk(_nbi_min_j); _nbi_min_jk.reset(_k); sum_subs(i, _nbi_min_jk, &sum_even, &sum_odd); numer += tJ[i][_k] * cors[i][_j][_k] * (tanh(theta[i]) * sum_even + sum_odd); } newM -= numer / denom; } else if( props.updates == Properties::UpdateType::LINEAR ) { newM = T(j,_i); for(size_t _l=0; _l<G.nb(i).size(); _l++) if( _l != _j ) newM -= Omega(i,_j,_l) * tJ[i][_l] * cors[i][_j][_l]; for(size_t _l1=0; _l1<G.nb(j).size(); _l1++) if( _l1 != _i ) for( size_t _l2=_l1+1; _l2<G.nb(j).size(); _l2++) if( _l2 != _i) newM += Gamma(j,_i,_l1,_l2) * tJ[j][_l1] * tJ[j][_l2] * cors[j][_l1][_l2]; } Real dev = newM - M[i][_j]; // dev *= 0.02; if( abs(dev) >= maxdev ) maxdev = abs(dev); newM = M[i][_j] + dev; if( abs(newM) > 1.0 ) newM = (newM > 0.0) ? 1.0 : -1.0; M[i][_j] = newM; } } } while((maxdev>props.tol)&&(run<maxruns)); _iters = run; if( maxdev > _maxdiff ) _maxdiff = maxdev; if(run==maxruns){ if( props.verbose >= 1 ) cerr << "MR::propagateCavityFields: Convergence not reached (maxdev=" << maxdev << ")..." << endl; } }
static Real vphi(const Real x1, const Real x2, const Real x3) { return x1*Omega(x1); }