bool Entities::is_ghost(const Uint idx) const { cf3_assert_desc(to_str(idx)+">="+to_str(size()),idx < size()); cf3_assert(size() == m_rank->size()); cf3_assert(idx<m_rank->size()); return (*m_rank)[idx] != PE::Comm::instance().rank(); }
OPTION_TYPE& add (const boost::shared_ptr<OPTION_TYPE>& option) { cf3_assert_desc ( "Class has already property with name " + option->name(), this->store.find(option->name()) == store.end() ); store.insert( std::make_pair(option->name(), option ) ); return *option; }
typename SelectOptionType<T>::type& add (const std::string& name, const T& default_value = T()) { cf3_assert_desc ( "Class already has an option with same name", this->store.find(name) == store.end() ); typedef typename SelectOptionType<T>::type OptionType; boost::shared_ptr<OptionType> opt ( new OptionType(name, default_value) ); store.insert( std::make_pair(name, opt ) ); return *opt; }
std::string class_name_from_typeinfo (const std::type_info & info) { TypeInfo& ti = TypeInfo::instance(); std::map<std::string, std::string>::const_iterator it = ti.portable_types.find(info.name()); cf3_assert_desc(common::demangle(info.name()).c_str(), it != ti.portable_types.end() ); return it->second; }
std::string class_name () { TypeInfo& ti = TypeInfo::instance(); std::map<std::string, std::string>::const_iterator it = ti.portable_types.find(typeid(TYPE).name()); cf3_assert_desc("type "+demangle(typeid(TYPE).name())+" not registered", it != ti.portable_types.end() ); return it->second; }
void Map<KEY,DATA>::sort_keys() { if (!m_sorted) { std::sort(begin(), end(), LessThan()); m_sorted = true; cf3_assert_desc ("multiple keys in the map are detected. Not allowed in this map" , std::unique (begin(), end(), unique_key ) - begin() == (int) size() ); } }
inline typename Map<KEY,DATA>::const_iterator Map<KEY,DATA>::find(const key_type& key) const { if(m_vectorMap.empty()) return end(); cf3_assert_desc ("Trying to sort Map is not allowed in find() \"const\". use sort_keys() apriori", m_sorted ); const_iterator itr = std::lower_bound(begin(),end(),key,Compare()); if (itr != end()) if (itr->first != key) return end(); return itr; }
/// Erase the given iterator from the map /// @param[in] itr The iterator to delete /// @pre the map must be sorted void erase (iterator itr) { cf3_assert_desc ( "Map internal structure must be sorted" , m_sorted); m_vectorMap.erase(itr); m_sorted = false; }
void ComputeUpdateCoefficient::execute() { link_fields(); if (is_null(m_wave_speed)) throw SetupError(FromHere(), "WaveSpeed field was not set"); if (is_null(m_update_coeff)) throw SetupError(FromHere(), "UpdateCoeff Field was not set"); Field& wave_speed = *m_wave_speed; Field& update_coeff = *m_update_coeff; Real cfl = options().value<Real>("cfl"); if (options().value<bool>("time_accurate")) // global time stepping { if (is_null(m_time)) throw SetupError(FromHere(), "Time component was not set"); Time& time = *m_time; cf3_assert_desc("Fields not compatible: "+to_str(update_coeff.size())+"!="+to_str(wave_speed.size()),update_coeff.size() == wave_speed.size()); /// compute time step // ----------------- /// - take user-defined time step Real dt = time.options().value<Real>("time_step"); if (dt==0.) dt = math::Consts::real_max(); /// - Make time step stricter through the CFL number Real min_dt = dt; Real max_dt = 0.; RealVector ws(wave_speed.row_size()); for (Uint i=0; i<wave_speed.size(); ++i) { if (wave_speed[i][0] > 0) { dt = cfl/wave_speed[i][0]; min_dt = std::min(min_dt,dt); max_dt = std::max(max_dt,dt); } } Real glb_min_dt; PE::Comm::instance().all_reduce(PE::min(), &min_dt, 1, &glb_min_dt); dt = glb_min_dt; /// - Make sure we reach milestones and final simulation time Real tf = limit_end_time(time.current_time(), time.options().value<Real>("end_time")); if( time.current_time() + dt + m_tolerance > tf ) dt = tf - time.current_time(); /// Calculate the update_coefficient // -------------------------------- /// For Forward Euler: update_coefficient = @f$ \Delta t @f$. /// @f[ Q^{n+1} = Q^n + \Delta t \ R @f] for (Uint i=0; i<update_coeff.size(); ++i) { update_coeff[i][0] = dt ; } // Update the new time step time.dt() = dt; } else // local time stepping { if (is_not_null(m_time)) m_time->dt() = 0.; // Calculate the update_coefficient = CFL/wave_speed RealVector ws(wave_speed.row_size()); for (Uint i=0; i<wave_speed.size(); ++i) { if (wave_speed[i][0] > 0) update_coeff[i][0] = cfl/wave_speed[i][0]; } } }
void ImposeCFL::execute() { if (is_null(m_wave_speed)) throw SetupError(FromHere(), "wave_speed was not configured"); if (is_null(m_time_step)) throw SetupError(FromHere(), "time_step Field was not set"); if (is_null(m_time)) throw SetupError(FromHere(), "Time component was not set"); Field& wave_speed = *m_wave_speed; Field& time_step = *m_time_step; std::vector<Real> args(3); args[0] = m_time->iter(); args[1] = m_time->current_time(); args[2] = m_cfl; m_cfl = m_cfl_function(args); if (options().value<bool>("time_accurate")) // global time stepping { Time& time = *m_time; cf3_assert_desc("Fields not compatible: "+to_str(time_step.size())+"!="+to_str(wave_speed.size()),time_step.size() == wave_speed.size()); /// compute time step // ----------------- /// - take user-defined time step Real dt = time.options().value<Real>("time_step"); if (dt==0.) dt = math::Consts::real_max(); /// - Make time step stricter through the CFL number Real min_dt = dt; Real max_dt = 0.; for (Uint i=0; i<wave_speed.size(); ++i) { if (wave_speed[i][0] > 0.) { dt = m_cfl/wave_speed[i][0]; min_dt = std::min(min_dt,dt); max_dt = std::max(max_dt,dt); } } Real glb_min_dt; PE::Comm::instance().all_reduce(PE::min(), &min_dt, 1, &glb_min_dt); dt = glb_min_dt; /// - Make sure we reach final simulation time Real tf = time.options().value<Real>("end_time"); if( time.current_time() + dt*(1+sqrt(eps()))> tf ) dt = tf - time.current_time(); /// Calculate the time_step // ----------------------- /// For Forward Euler: time_step = @f$ \Delta t @f$. /// @f[ Q^{n+1} = Q^n + \Delta t \ R @f] for (Uint i=0; i<time_step.size(); ++i) { time_step[i][0] = dt ; } // Update the new time step time.dt() = dt; // UNCOMMENTING THIS WILL FIX THE UPPER-LIMIT OF THE WAVESPEED FOREVER :( // DUE TO LINE 88 // // Fix wave-speed for visualization // Real glb_max_dt; // PE::Comm::instance().all_reduce(PE::min(), &max_dt, 1, &glb_max_dt); // for (Uint i=0; i<wave_speed.size(); ++i) // { // if (wave_speed[i][0] == 0.) // { // wave_speed[i][0] = cfl/glb_max_dt; // } // } } else // local time stepping { if (is_not_null(m_time)) m_time->dt() = 0.; // Check for a minimum value for the wave speeds Real min_wave_speed = math::Consts::real_max(); for (Uint i=0; i<wave_speed.size(); ++i) { if (wave_speed[i][0] > 0.) { min_wave_speed = std::min(min_wave_speed,wave_speed[i][0]); } } PE::Comm::instance().all_reduce(PE::min(), &min_wave_speed, 1, &min_wave_speed); if (min_wave_speed == 0.) throw common::BadValue(FromHere(), "Minimum wave-speed cannot be zero!"); // Calculate the time_stepicient = CFL/wave_speed for (Uint i=0; i<wave_speed.size(); ++i) { if (wave_speed[i][0] == 0.) { wave_speed[i][0] = min_wave_speed; } time_step[i][0] = m_cfl/wave_speed[i][0]; } } }