object_ptr<InnerWidget::ListWidget> InnerWidget::setupList( RpWidget *parent, not_null<PeerListController*> controller) const { auto result = object_ptr<ListWidget>( parent, controller, st::infoCommonGroupsList); result->scrollToRequests( ) | rpl::start_with_next([this](Ui::ScrollToRequest request) { auto addmin = (request.ymin < 0) ? 0 : st::infoCommonGroupsMargin.top(); auto addmax = (request.ymax < 0) ? 0 : st::infoCommonGroupsMargin.top(); _scrollToRequests.fire({ request.ymin + addmin, request.ymax + addmax }); }, result->lifetime()); result->moveToLeft(0, st::infoCommonGroupsMargin.top()); parent->widthValue( ) | rpl::start_with_next([list = result.data()](int newWidth) { list->resizeToWidth(newWidth); }, result->lifetime()); result->heightValue( ) | rpl::start_with_next([parent](int listHeight) { auto newHeight = st::infoCommonGroupsMargin.top() + listHeight + st::infoCommonGroupsMargin.bottom(); parent->resize(parent->width(), newHeight); }, result->lifetime()); return result; }
void ManagePeerBox::setupContent() { auto content = Ui::CreateChild<Ui::VerticalLayout>(this); FillManageBox(controller(), _channel, content); widthValue( ) | rpl::start_with_next([=](int width) { content->resizeToWidth(width); }, content->lifetime()); content->heightValue( ) | rpl::start_with_next([=](int height) { setDimensions(st::boxWidth, height); }, content->lifetime()); }
GifsListWidget::GifsListWidget( QWidget *parent, not_null<Window::Controller*> controller) : Inner(parent, controller) , _section(Section::Gifs) , _updateInlineItems([=] { updateInlineItems(); }) , _previewTimer([=] { showPreview(); }) { setMouseTracking(true); setAttribute(Qt::WA_OpaquePaintEvent); _inlineRequestTimer.setSingleShot(true); connect(&_inlineRequestTimer, &QTimer::timeout, this, [this] { sendInlineRequest(); }); Auth().data().savedGifsUpdated( ) | rpl::start_with_next([this] { refreshSavedGifs(); }, lifetime()); subscribe(Auth().downloaderTaskFinished(), [this] { update(); }); subscribe(controller->gifPauseLevelChanged(), [this] { if (!this->controller()->isGifPausedAtLeastFor(Window::GifPauseReason::SavedGifs)) { update(); } }); }
InnerDropdown::InnerDropdown( QWidget *parent, const style::InnerDropdown &st) : RpWidget(parent) , _st(st) , _scroll(this, _st.scroll) { _hideTimer.setSingleShot(true); connect(&_hideTimer, SIGNAL(timeout()), this, SLOT(onHideAnimated())); connect(_scroll, SIGNAL(scrolled()), this, SLOT(onScroll())); hide(); shownValue( ) | rpl::filter([](bool shown) { return shown; }) | rpl::take(1) | rpl::map([=] { // We can't invoke this before the window is created. // So instead we start handling them on the first show(). return macWindowDeactivateEvents(); }) | rpl::flatten_latest( ) | rpl::filter([=] { return !isHidden(); }) | rpl::start_with_next([=] { leaveEvent(nullptr); }, lifetime()); }
Car::Car(QString name, CarManager *parent) : QObject(parent), _manager(parent), _name(name), _nbtire(0),_buyingprice(0),_sellingprice(0),_lifetime(0) { this->db_init(); db_loading=false; while(this->db_get_version() < DB_VERSION) { qDebug() << "Update configuation database " << this->db_get_version() << " >> " << DB_VERSION; if(this->db_get_version() < 2) { db_upgrade_to_2(); } if(this->db_get_version() < 3) { db_upgrade_to_3(); } if(this->db_get_version() < 4) { db_upgrade_to_4(); } } qDebug() << "Database version " << this->db_get_version(); this->db_load(); this->_stationlist.append(new Station); qSort(_stationlist.begin(), _stationlist.end(), sortStationByQuantity); this->_fueltypelist.append(new Fueltype); qSort(_fueltypelist.begin(), _fueltypelist.end(), sortFueltypeById); this->_costtypelist.append(new Costtype); qSort(_costtypelist.begin(), _costtypelist.end(), sortCosttypeById); nbtire(); buyingprice(); sellingprice(); lifetime(); }
void PeerListBox::prepare() { setContent(setInnerWidget( object_ptr<PeerListContent>( this, _controller.get(), st::peerListBox), st::boxLayerScroll)); content()->resizeToWidth(st::boxWideWidth); _controller->setDelegate(this); setDimensions(st::boxWideWidth, st::boxMaxListHeight); if (_select) { _select->finishAnimating(); Ui::SendPendingMoveResizeEvents(_select); _scrollBottomFixed = true; onScrollToY(0); } content()->scrollToRequests( ) | rpl::start_with_next([this](Ui::ScrollToRequest request) { onScrollToY(request.ymin, request.ymax); }, lifetime()); if (_init) { _init(this); } }
FadeWrap<RpWidget> *FadeWrap<RpWidget>::toggleOn( rpl::producer<bool> &&shown) { std::move( shown ) | rpl::start_with_next([this](bool shown) { toggle(shown, anim::type::normal); }, lifetime()); finishAnimating(); return this; }
Controller::Controller(not_null<MainWindow*> window) : _window(window) { Auth().data().animationPlayInlineRequest( ) | rpl::start_with_next([this](auto item) { if (const auto video = roundVideo(item)) { video->pauseResume(); } else { startRoundVideo(item); } }, lifetime()); }
UpdateStateRow::UpdateStateRow(QWidget *parent) : RpWidget(parent) , _check(this, lang(lng_settings_check_now)) , _restart(this, lang(lng_settings_update_now)) { connect(_check, SIGNAL(clicked()), this, SLOT(onCheck())); connect(_restart, SIGNAL(clicked()), this, SIGNAL(restart())); _versionText = lng_settings_current_version_label(lt_version, currentVersionText()); Core::UpdateChecker checker; checker.checking() | rpl::start_with_next([=] { onChecking(); }, lifetime()); checker.isLatest() | rpl::start_with_next([=] { onLatest(); }, lifetime()); checker.progress( ) | rpl::start_with_next([=](Core::UpdateChecker::Progress progress) { onDownloading(progress.already, progress.size); }, lifetime()); checker.failed() | rpl::start_with_next([=] { onFailed(); }, lifetime()); checker.ready() | rpl::start_with_next([=] { onReady(); }, lifetime()); switch (checker.state()) { case Core::UpdateChecker::State::Download: setState(State::Download, true); setDownloadProgress(checker.already(), checker.size()); break; case Core::UpdateChecker::State::Ready: setState(State::Ready, true); break; default: setState(State::None, true); break; } }
BlockWidget::BlockWidget(QWidget *parent, UserData *self, const QString &title) : RpWidget(parent) , _content(this) , _self(self) , _title(title) { _content->heightValue( ) | rpl::start_with_next([this](int contentHeight) { resize( width(), contentTop() + contentHeight + st::settingsBlockMarginBottom); }, lifetime()); }
Float::Float( QWidget *parent, not_null<Window::Controller*> controller, not_null<HistoryItem*> item, Fn<void(bool visible)> toggleCallback, Fn<void(bool closed)> draggedCallback) : RpWidget(parent) , _controller(controller) , _item(item) , _toggleCallback(std::move(toggleCallback)) , _draggedCallback(std::move(draggedCallback)) { auto media = _item->media(); Assert(media != nullptr); auto document = media->document(); Assert(document != nullptr); Assert(document->isVideoMessage()); auto margin = st::mediaPlayerFloatMargin; auto size = 2 * margin + st::mediaPlayerFloatSize; resize(size, size); prepareShadow(); Auth().data().itemRepaintRequest( ) | rpl::start_with_next([this](auto item) { if (_item == item) { repaintItem(); } }, lifetime()); Auth().data().itemRemoved( ) | rpl::start_with_next([this](auto item) { if (_item == item) { detach(); } }, lifetime()); setCursor(style::cur_pointer); }
void Controller::init() { session().data().animationPlayInlineRequest( ) | rpl::start_with_next([=](auto item) { if (const auto video = roundVideo(item)) { video->pauseResume(); } else { startRoundVideo(item); } }, lifetime()); if (session().supportMode()) { initSupportMode(); } }
void Controller::initSupportMode() { session().supportHelper().registerWindow(this); Shortcuts::Requests( ) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) { using C = Shortcuts::Command; request->check(C::SupportHistoryBack) && request->handle([=] { return chatEntryHistoryMove(-1); }); request->check(C::SupportHistoryForward) && request->handle([=] { return chatEntryHistoryMove(1); }); }, lifetime()); }
void CoverWidget::showSetPhotoBox(const QImage &img) { if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) { Ui::show(Box<InformBox>(lang(lng_bad_photo))); return; } auto peer = _self; auto box = Ui::show(Box<PhotoCropBox>(img, peer)); box->ready( ) | rpl::start_with_next([=](QImage &&image) { Messenger::Instance().uploadProfilePhoto( std::move(image), peer->id); }, box->lifetime()); subscribe(box->boxClosing, [this] { onPhotoUploadStatusChanged(); }); }
void NotificationItem::saveState(QSettings* settings) const { settings->setValue("SoundCollectionPath", Utils::PathUtils().RemoveDataPath(getSoundCollectionPath())); settings->setValue(QLatin1String("CurrentLanguage"), getCurrentLanguage()); settings->setValue(QLatin1String("ObjectField"), getObjectField()); settings->setValue(QLatin1String("DataObject"), getDataObject()); settings->setValue(QLatin1String("RangeLimit"), getCondition()); settings->setValue(QLatin1String("Value1"), singleValue()); settings->setValue(QLatin1String("Value2"), valueRange2()); settings->setValue(QLatin1String("Sound1"), getSound1()); settings->setValue(QLatin1String("Sound2"), getSound2()); settings->setValue(QLatin1String("Sound3"), getSound3()); settings->setValue(QLatin1String("SayOrder"), getSayOrder()); settings->setValue(QLatin1String("Repeat"), retryValue()); settings->setValue(QLatin1String("ExpireTimeout"), lifetime()); settings->setValue(QLatin1String("Mute"), mute()); }
FloatingIcon::FloatingIcon( RpWidget *parent, const style::icon &icon, QPoint position, const Tag &) : RpWidget(parent) , _icon(&icon) , _point(position) { resize( _point.x() + _icon->width(), _point.y() + _icon->height()); setAttribute(Qt::WA_TransparentForMouseEvents); parent->widthValue( ) | rpl::start_with_next( [this] { moveToLeft(0, 0); }, lifetime()); }
void Panel::showCriticalError(const QString &error) { auto container = base::make_unique_q<Ui::PaddingWrap<Ui::FlatLabel>>( _widget.get(), object_ptr<Ui::FlatLabel>( _widget.get(), error, Ui::FlatLabel::InitType::Simple, st::passportErrorLabel), style::margins(0, st::passportPanelSize.height() / 3, 0, 0)); container->widthValue( ) | rpl::start_with_next([label = container->entity()](int width) { label->resize(width, label->height()); }, container->lifetime()); _widget->showInner(std::move(container)); setBackAllowed(false); }
InnerWidget::InnerWidget( QWidget *parent, not_null<Controller*> controller, not_null<UserData*> user) : RpWidget(parent) , _controller(controller) , _user(user) , _listController(std::make_unique<ListController>(controller, _user)) , _list(setupList(this, _listController.get())) { setContent(_list.data()); _listController->setDelegate(static_cast<PeerListDelegate*>(this)); _controller->searchFieldController()->queryValue( ) | rpl::start_with_next([this](QString &&query) { peerListScrollToTop(); content()->searchQueryChanged(std::move(query)); }, lifetime()); }
Widget::Widget( QWidget *parent, not_null<Controller*> controller) : ContentWidget(parent, controller) { controller->setSearchEnabledByContent(false); _inner = setInnerWidget(object_ptr<InnerWidget>( this, controller)); _inner->move(0, 0); _inner->scrollToRequests( ) | rpl::start_with_next([this](Ui::ScrollToRequest request) { if (request.ymin < 0) { scrollTopRestore( qMin(scrollTopSave(), request.ymax)); } else { scrollTo(request); } }, lifetime()); }
void PeerListBox::createMultiSelect() { Expects(_select == nullptr); auto entity = object_ptr<Ui::MultiSelect>(this, st::contactsMultiSelect, langFactory(lng_participant_filter)); _select.create(this, std::move(entity)); _select->heightValue( ) | rpl::start_with_next( [this] { updateScrollSkips(); }, lifetime()); _select->entity()->setSubmittedCallback([this](bool chtrlShiftEnter) { content()->submitted(); }); _select->entity()->setQueryChangedCallback([this](const QString &query) { searchQueryChanged(query); }); _select->entity()->setItemRemovedCallback([this](uint64 itemId) { if (auto peer = App::peerLoaded(itemId)) { if (auto row = peerListFindRow(peer->id)) { content()->changeCheckState(row, false, PeerListRow::SetStyle::Animated); update(); } _controller->itemDeselectedHook(peer); } }); _select->resizeToWidth(st::boxWideWidth); _select->moveToLeft(0, 0); }
int bin_time_interval(int IMFi, double f0, double time, double end_time, double Step_Prec, double *times, double *delta_times) { double m, delta_time; double Left, Right, timed_frac; double next_notBH_sup, next_notBH_inf; int BHi, i, limit; for(m = dying_mass(time), BHi = 0; (BHi < IMFs[IMFi].N_notBH_ranges) && (m <= IMFs[IMFi].notBH_ranges.inf[BHi]); BHi++) ; next_notBH_sup = lifetime(IMFs[IMFi].notBH_ranges.inf[BHi]); next_notBH_inf = lifetime(IMFs[IMFi].notBH_ranges.sup[BHi]); i = 1; /* initial guess for delta_time */ modf(log10(time) + 9, &delta_time); delta_time = pow(10, delta_time) / 1e9; /* cycle to calculate time steps */ while(time < end_time) { timed_frac = 1; Left = Right = limit = 0; while((timed_frac / f0 < Step_Prec * 0.9 || timed_frac / f0 > Step_Prec * 1.1) && !limit) { if(time + delta_time > end_time) delta_time = end_time - time; if(time + delta_time > next_notBH_sup) delta_time = next_notBH_sup - time; timed_frac = IntegrateIMF_byNum(dying_mass(time + delta_time), dying_mass(time), &IMFs[IMFi], INC_BH); if(timed_frac / f0 < Step_Prec * 0.9) { if(!(limit = (time + delta_time == end_time))) { Left = max(Left, delta_time); if(Right == 0) delta_time *= 2; else delta_time = (Left + Right) / 2; } } if(timed_frac / f0 > Step_Prec * 1.1) { if(Right == 0) Right = delta_time; else Right = min(Right, delta_time); if(Left == 0) delta_time /= 2; else delta_time = (Left + Right) / 2; } } if(timed_frac / f0 < Step_Prec / 2 && limit) delta_times[i - 1] += delta_time; else { times[i] = time; delta_times[i] = delta_time; i++; } if((time += delta_time) == next_notBH_sup) { if(BHi < IMFs[IMFi].N_notBH_ranges) { BHi++; delta_time = lifetime(IMFs[IMFi].notBH_ranges.sup[BHi]) - next_notBH_sup; next_notBH_sup = lifetime(IMFs[IMFi].notBH_ranges.inf[BHi]); next_notBH_inf = lifetime(IMFs[IMFi].notBH_ranges.sup[BHi]); } else { limit = 1; time = end_time; } } } return i; }
void setup_SF_related(int mySFi) /* * | RHOth indep. of Z | RHOth dep. on Z * ========================================================================================================== * | | | * | A calc. RHOth using Mth @ a given | F calculate RHOth using the given Mth for each Z | * | Z using metal cooling | | * | | | * RHOth from | ................................ | | * parameters | | | * | B calc. RHOth using Mth not using | | * | the metal cooling | | * ========================================================================================================== * | | | * | C calc. Mth @ a given metallicity | G calculate Mth @ | * | keep Mth for all Z | a given Z | * RHOth set | ............................... | \ | * to a given | D calc. Mth not using the metal cool | --> keep Mth for all Z --> calc. RHOth | * value | -------------------------------------- | / | * | | H set Mth to a given value | * | E set Mth to a given value for all Z | | * =========================================================================================================== * */ { int IMFi, j, k, filecount, set; double num_snII; double myPhysDensTh, myFEVP, m; double left, right; double feedbackenergyinergs; double *dummies, dummy, frac; int PATH; int exist_eff_model_file; char buffer[200]; IMFi = SFs[mySFi].IMFi; IMFp = &IMFs[IMFi]; if(SFs[mySFi].MaxSfrTimescale_rescale_by_densityth > 1) SFs[mySFi].MaxSfrTimescale /= 1.2 * sqrt(SFs[mySFi].MaxSfrTimescale_rescale_by_densityth); if(SFs[mySFi].MaxSfrTimescale_rescale_by_densityth < 1 && SFs[mySFi].MaxSfrTimescale_rescale_by_densityth > 0) SFs[mySFi].MaxSfrTimescale *= 0.8 * sqrt(SFs[mySFi].MaxSfrTimescale_rescale_by_densityth); if(SFs[mySFi].egyShortLiv_MassTh > 0) /* * Mth has been specified, check that it stays * within boundaries. * then translate it in a time threshold and calculate * beta and egyspecSN. */ { /* checks that the defined mass th does not fall in a BH mass range */ j = not_in_BHrange(IMFi, &SFs[mySFi].egyShortLiv_MassTh); if(j == 0) { if(ThisTask == 0) { fprintf(FdWarn, "incorrect IRA limit set by your parameters: out of range\n" " your inf IRA mass is %9.7g vs [%9.7g : %9.7g] Msun limits for the IMF\n" " better to stop here\n", SFs[mySFi].egyShortLiv_MassTh, IMFs[IMFi].Mm, IMFs[IMFi].MU); fflush(FdWarn); printf("incorrect IRA limit set by your parameters: out of range\n" " your inf IRA mass is %9.7g vs [%9.7g : %9.7g] Msun limits for the IMF\n" " better to stop here\n", SFs[mySFi].egyShortLiv_MassTh, IMFs[IMFi].Mm, IMFs[IMFi].MU); fflush(stdout); } endrun(19001); } else if(j < 0) { j *= -1; if(IMFs[IMFi].N_notBH_ranges > j) SFs[mySFi].metShortLiv_MassTh = IMFs[IMFi].notBH_ranges.inf[j]; else SFs[mySFi].metShortLiv_MassTh = IMFs[IMFi].notBH_ranges.sup[j - 1]; if(ThisTask == 0) { fprintf(FdWarn, "The Short-Living mass limit has been set to %g in order to match" " the non-BH range %d\n", SFs[mySFi].egyShortLiv_MassTh, j); fflush(FdWarn); printf("The Short-Living mass limit has been set to %g in order to match" " the non-BH range %d\n", SFs[mySFi].egyShortLiv_MassTh, j); fflush(stdout); } } /* set the time th accordingly */ SFs[mySFi].egyShortLiv_TimeTh = lifetime(SFs[mySFi].egyShortLiv_MassTh); calculate_ShortLiving_related((SF_Type *) & SFs[mySFi], 1); } if(SFs[mySFi].SFTh_Zdep == 1) /* * if metallicity dependence is on, check whether the * thresholds' file does exist */ { #ifdef LT_METAL_COOLING if(ThisTask == 0) { exist_eff_model_file = 0; if(RestartFlag == 2) { filecount = atoi(All.InitCondFile + strlen(All.InitCondFile) - 3); exist_eff_model_file = read_eff_model(filecount, mySFi); } if(exist_eff_model_file == 0) /* if restartflag is 2 but the eff model file for the snapshot is not * present (j = 0), the code try again searching for the initial file */ exist_eff_model_file = read_eff_model(-1, mySFi); if(exist_eff_model_file == 0) { reading_thresholds_for_thermal_instability(); for(j = 0; j < ZBins; j++) { ThInst_onset[j] = pow(10, ThInst_onset[j]); SFs[mySFi].FEVP[j] = All.TempSupernova / ThInst_onset[j]; } } } /* in case that the threshold file does not exist, the array will however be set to zero */ MPI_Bcast((void *) &exist_eff_model_file, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast((void *) &SFs[mySFi].PhysDensThresh[0], ZBins * sizeof(double), MPI_BYTE, 0, MPI_COMM_WORLD); MPI_Bcast((void *) &SFs[mySFi].FEVP[0], ZBins * sizeof(double), MPI_BYTE, 0, MPI_COMM_WORLD); MPI_Bcast((void *) ThInst_onset, ZBins * sizeof(double), MPI_BYTE, 0, MPI_COMM_WORLD); #endif } else { ThInst_onset[0] = 1e5; // SFs[mySFi].FEVP = &All.FactorEVP; SFs[mySFi].FEVP[0] = All.TempSupernova / ThInst_onset[0]; } PATH = (SFs[mySFi].SFTh_Zdep == 1); PATH |= ((SFs[mySFi].egyShortLiv_MassTh > 0) << 1); PATH |= ((SFs[mySFi].PhysDensThresh[0] > 0) << 2); if(PATH < 2) { printf ("neither the Mass Threshold for the energy release nor the Density Threshold for the Star Formation have been specified..\n" "I do feel difficult to continue. Better to think about a bit more..\n"); endrun(LT_ERR_NOT_ENOUGH_PARAM_FOR_SF); } if(PATH < 4) /* * egyShortLiv_MassTh is specified * PhysDensThresh is not specified */ { if(SFs[mySFi].SFTh_Zdep == 1) /* PATH = 3 */ { /* * metal dependence is on but the thresholds' file does not * exist. */ MPI_Barrier(MPI_COMM_WORLD); init_clouds_cm(2, SFs[mySFi].PhysDensThresh, SFs[mySFi].FEVP, SFs[mySFi].EgySpecSN, SFs[mySFi].FactorSN, SFs[mySFi].MaxSfrTimescale, ZBins, &CoolZvalue[0]); } else /* PATH = 2 */ { init_clouds(2, SFs[mySFi].EgySpecSN, SFs[mySFi].FactorSN, SFs[mySFi].MaxSfrTimescale, SFs[mySFi].referenceZ_toset_SF_DensTh, SFs[mySFi].PhysDensThresh, SFs[mySFi].FEVP); } PATH = 8; } if(PATH < 6) /* * egyShortLiv_MassTh is not specified * PhysDensThresh is specified */ { /* initial guess for Mth */ SFs[mySFi].egyShortLiv_MassTh = All.Mup * 1.1; set = IMFs[IMFi].YSet; SD.Zbin = 0; SD.MArray = IIMbins[set]; SD.Mdim = IIMbins_dim[set]; SD.Y = SnIIEj[set]; get_Egy_and_Beta(SFs[mySFi].egyShortLiv_TimeTh, &SFs[mySFi].EgySpecSN, &SFs[mySFi].FactorSN, &SFs[mySFi]); init_clouds(2, SFs[mySFi].EgySpecSN, SFs[mySFi].FactorSN, SFs[mySFi].MaxSfrTimescale, SFs[mySFi].referenceZ_toset_SF_DensTh, &myPhysDensTh, &myFEVP); while((fabs(myPhysDensTh - SFs[mySFi].PhysDensThresh[0]) / SFs[mySFi].PhysDensThresh[0] > 1e-2) && SFs[mySFi].egyShortLiv_MassTh > All.Mup && SFs[IMFi].egyShortLiv_MassTh < IMFs[IMFi].notBH_ranges.sup[0]) /* note: because of using get_Egy_an_Beta, this calculations automatically * exclude BH ranges */ { if((myPhysDensTh - SFs[mySFi].PhysDensThresh[0]) < 0) { left = SFs[mySFi].egyShortLiv_TimeTh; if(right == 0) SFs[mySFi].egyShortLiv_MassTh *= 0.8; else SFs[mySFi].egyShortLiv_MassTh = (SFs[mySFi].egyShortLiv_MassTh + right) / 2; } else { right = SFs[mySFi].egyShortLiv_MassTh; if(left == 0) SFs[mySFi].egyShortLiv_MassTh *= 1.2; else SFs[mySFi].egyShortLiv_MassTh = (SFs[mySFi].egyShortLiv_MassTh + left) / 2; } if(SFs[mySFi].egyShortLiv_MassTh < All.Mup) SFs[mySFi].egyShortLiv_MassTh = All.Mup; else if(SFs[mySFi].egyShortLiv_MassTh > IMFs[IMFi].notBH_ranges.sup[0]) /* this prevent to fall in the last BH range: if it extend up to MU, * we would obtain zero energy. If the energy is still not sufficient, * the cycle will interrupt anyway due to the 3rd head condition */ SFs[mySFi].egyShortLiv_MassTh = IMFs[IMFi].notBH_ranges.sup[0]; get_Egy_and_Beta(SFs[mySFi].egyShortLiv_MassTh, &SFs[mySFi].EgySpecSN, &SFs[mySFi].FactorSN, &SFs[mySFi]); init_clouds(2, SFs[mySFi].EgySpecSN, SFs[mySFi].FactorSN, SFs[mySFi].MaxSfrTimescale, SFs[mySFi].referenceZ_toset_SF_DensTh, &myPhysDensTh, &myFEVP); } /* checks that found mass does not fall in a BH mass range */ for(j = 0; (j < IMFs[IMFi].N_notBH_ranges) && (SFs[mySFi].egyShortLiv_MassTh <= IMFs[IMFi].notBH_ranges.inf[j]); j++) ; if(j < IMFs[IMFi].N_notBH_ranges) if(SFs[mySFi].egyShortLiv_MassTh > IMFs[IMFi].notBH_ranges.sup[j]) /* this case can arise only when at least 1 BH interval lives * between 2 nom-BH intervals: then, j shold be > 0. */ SFs[mySFi].egyShortLiv_MassTh = IMFs[IMFi].notBH_ranges.sup[j - 1]; if((myPhysDensTh - SFs[mySFi].PhysDensThresh[0]) / SFs[mySFi].PhysDensThresh[0] > 1e-2 && ThisTask == 0) { if(SFs[mySFi].egyShortLiv_MassTh == All.Mup) { fprintf(FdWarn, " . warning: the needed Mass Threshold for a star to be\n" " short--living would be lower that %5.3f Msun.\n" " we set it to %5.3f Msun; pls check sfrrate.txt\n", All.Mup, All.Mup); fflush(stdout); } else if(SFs[mySFi].egyShortLiv_MassTh == IMFs[IMFi].MU) { fprintf(FdWarn, " . warning: the needed Mass Threshold for a star to be\n" " short--living would be larger that %5.3f Msun.\n" " we set it to %5.3f Msun; pls check sfrrate.txt\n", IMFs[IMFi].MU, IMFs[IMFi].MU); fflush(stdout); } else { fprintf(FdWarn, " . warning: Mass Threshold for a star to be short-living is\n" " %5.3f Msun; this would set a physical density threshold for\n" " the star formation different than that you set in paramfile.\n" " pls, check sfrrate.txt\n", SFs[mySFi].egyShortLiv_MassTh); fflush(stdout); } } calculate_ShortLiving_related(&SFs[mySFi], 1); PATH |= 2; } if(PATH == 7) /* if PATH == 6 nothing is left to be done */ /* * egyShortLiv_MassTh is specified * PhysDensThresh is specified */ { if(SFs[mySFi].SFTh_Zdep == 1 && /* PATH = 7 */ exist_eff_model_file == 0) /* assume that the variable has been set */ { dummies = (double *) mymalloc("dummies", ZBins * sizeof(double)); dummy = SFs[mySFi].PhysDensThresh[0]; /* calculate expected thresholds for all metallicities, given the mass EgyMassTh */ MPI_Barrier(MPI_COMM_WORLD); init_clouds_cm(2, dummies, SFs[mySFi].FEVP, SFs[mySFi].EgySpecSN, SFs[mySFi].FactorSN, SFs[mySFi].MaxSfrTimescale, ZBins, &CoolZvalue[0]); /* now apply relative variations due to metallicities to the specified rho_threshold */ if(ZBins > 1) { for(j = ZBins - 1; (j > 0) && (SFs[mySFi].referenceZ_toset_SF_DensTh < CoolZvalue[j]); j--) ; if(j == ZBins - 1) j--; if(SFs[mySFi].referenceZ_toset_SF_DensTh > CoolZvalue[j] * (1 + 0.01) || SFs[mySFi].referenceZ_toset_SF_DensTh < CoolZvalue[j] * (1 - 0.01)) frac = (SFs[mySFi].referenceZ_toset_SF_DensTh - CoolZvalue[j]) * (dummies[j + 1] - dummies[j]) / (CoolZvalue[j + 1] - CoolZvalue[j]); else frac = dummy / dummies[j]; for(j = 0; j < ZBins; j++) { if(SFs[mySFi].referenceZ_toset_SF_DensTh > CoolZvalue[j] * (1 + 0.01) || SFs[mySFi].referenceZ_toset_SF_DensTh < CoolZvalue[j] * (1 - 0.01)) SFs[mySFi].PhysDensThresh[j] = dummies[j] * frac; else SFs[mySFi].PhysDensThresh[j] = dummy; } } myfree(dummies); } } #ifndef LT_WIND_VELOCITY #ifdef LT_ALL_SNII_EGY_INWINDS feedbackenergyinergs = SFs[mySFi].TOT_erg_per_g / All.UnitMass_in_g * (All.UnitEnergy_in_cgs * SOLAR_MASS); SFs[mySFi].WindEnergy = sqrt(2 * SFs[mySFi].WindEnergyFraction * SFs[mySFi].TOT_erg_per_g / SFs[mySFi].WindEfficiency); #else feedbackenergyinergs = SFs[mySFi].IRA_erg_per_g / All.UnitMass_in_g * (All.UnitEnergy_in_cgs * SOLAR_MASS); SFs[mySFi].WindEnergy = sqrt(2 * SFs[mySFi].WindEnergyFraction * SFs[mySFi].IRA_erg_per_g / SFs[mySFi].WindEfficiency); #endif #else feedbackenergyinergs = All.FeedbackEnergy / All.UnitMass_in_g * (All.UnitEnergy_in_cgs * SOLAR_MASS); SFs[mySFi].WindEnergy = LT_WIND_VELOCITY; #ifdef LT_ALL_SNII_EGY_INWINDS SFs[mySFi].WindEnergyFraction = SFs[mySFi].WindEnergy * SFs[mySFi].WindEnergy * SFs[mySFi].WindEfficiency / (2 * SFs [mySFi].TOT_erg_per_g); #else SFs[mySFi].WindEnergyFraction = SFs[mySFi].WindEnergy * SFs[mySFi].WindEnergy * SFs[mySFi].WindEfficiency / (2 * SFs [mySFi].IRA_erg_per_g); #endif #endif if(ThisTask == 0) { printf("Energy Fraction in Winds= %g\n", SFs[mySFi].WindEnergyFraction); printf("Winds Mass load efficiency= %g\n", SFs[mySFi].WindEfficiency); printf("PhysDensThresh= %g (internal units)\n", SFs[mySFi].PhysDensThresh[0]); fprintf(FdSnInit, "\n[Winds]\nEnergy Fraction in Winds= %g \n", SFs[mySFi].WindEnergyFraction); fprintf(FdSnInit, "Winds Mass load efficiency= %g\n", SFs[mySFi].WindEfficiency); fprintf(FdSnInit, "\n[SF Rho Threshold]\nPhysDensThresh= %g (internal units)\n", SFs[mySFi].PhysDensThresh[0]); } #ifndef LT_METAL_COOLING_WAL if(ThisTask == 0) printf("determining Kennicutt law%c..\n", (SFs[mySFi].SFTh_Zdep ? 's' : ' ')); fflush(stdout); if(SFs[mySFi].SFTh_Zdep == 0) { //SFs[mySFi].FEVP = &All.FactorEVP; if(ThisTask == 0) { sfrrate_filenum = mySFi; init_clouds(0, SFs[mySFi].EgySpecSN, SFs[mySFi].FactorSN, SFs[mySFi].MaxSfrTimescale, SFs[mySFi].referenceZ_toset_SF_DensTh, SFs[mySFi].PhysDensThresh, SFs[mySFi].FEVP); } } else { init_clouds_cm(0, SFs[mySFi].PhysDensThresh, SFs[mySFi].FEVP, SFs[mySFi].EgySpecSN, SFs[mySFi].FactorSN, SFs[mySFi].MaxSfrTimescale, ZBins, &CoolZvalue[0]); if(ThisTask == 0) write_eff_model(-1, mySFi); } #endif MPI_Barrier(MPI_COMM_WORLD); if(ThisTask == 0) { printf("Feedback energy per formed solar mass in stars= %g ergs\n" "Wind Velocity= %g Km/s\n", feedbackenergyinergs, SFs[mySFi].WindEnergy); fprintf(FdSnInit, "Feedback energy per formed solar mass in stars= %g ergs\n" "Wind Velocity= %g Km/s\n", feedbackenergyinergs, SFs[mySFi].WindEnergy); } m = max(IMFs[IMFi].Mm, All.Mup); if(SFs[mySFi].metShortLiv_MassTh <= m) SFs[mySFi].metShortLiv_MassTh = m; else if(SFs[mySFi].metShortLiv_MassTh > IMFs[IMFi].MU) SFs[mySFi].metShortLiv_MassTh = IMFs[IMFi].MU; /* checks that the defined mass th does not fall in a BH mass range */ for(j = 0; (j < IMFs[IMFi].N_notBH_ranges) && (SFs[mySFi].metShortLiv_MassTh <= IMFs[IMFi].notBH_ranges.inf[j]); j++) ; if(j < IMFs[IMFi].N_notBH_ranges) if(SFs[mySFi].metShortLiv_MassTh > IMFs[IMFi].notBH_ranges.sup[j]) { if(j == 0) /* if the mass th falls ini the upper BH range, and that BH range reaches * MU, then it's impossible to correctly adjust the mass th */ { if(ThisTask == 0) { printf("The Short-Living mass limit for metal release that you defined is not\n" "compatible with the BH ranges that you defined. Pls check all that in\n" "param file and in IMF file\n"); endrun(LT_ERR_MISMATCH_ShL_TH_BHranges); } } else { SFs[mySFi].metShortLiv_MassTh = IMFs[IMFi].notBH_ranges.inf[j - 1]; fprintf(FdWarn, "The Short-Living mass limit for metal release has been set to %g in order to match" " with the non-BH range %d\n", SFs[mySFi].egyShortLiv_MassTh, j); } } SFs[mySFi].metShortLiv_TimeTh = lifetime(SFs[mySFi].metShortLiv_MassTh); if(ThisTask == 0) { if(SFs[mySFi].metShortLiv_MassTh < IMFs[IMFi].MU) printf(":: metal IRA is active in the range [%9.7g - %9.7g]Msun <> [%9.7g - %9.7g]Gyr\n", IMFs[IMFi].MU, SFs[mySFi].metShortLiv_MassTh, IMFs[IMFi].inf_lifetime, SFs[mySFi].metShortLiv_TimeTh); else printf(":: metal IRA is not active\n"); } if(SFs[mySFi].metShortLiv_MassTh < IMFs[IMFi].MU) { /* mass fraction involved in SnII */ SFs[mySFi].MassFrac_inIRA = IntegrateIMF_byMass(SFs[mySFi].metShortLiv_MassTh, IMFs[IMFi].MU, &IMFs[IMFi], INC_BH); /* expected number of SnII per initial stellar population mass in units of solar masses IN IRA RANGE */ SFs[mySFi].NumFrac_inIRA = IntegrateIMF_byNum(SFs[mySFi].metShortLiv_MassTh, IMFs[IMFi].MU, &IMFs[IMFi], EXC_BH); /* expected number of SnII per initial stellar population mass in units of solar masses */ num_snII = IntegrateIMF_byNum(max(All.Mup, IMFs[IMFi].Mm), IMFs[IMFi].MU, &IMFs[IMFi], EXC_BH); if(ThisTask == 0) printf(" %.3lg%% of mass in metal IRA tail\n", SFs[mySFi].MassFrac_inIRA * 100); /* ...........: calculates the restored fraction :................... */ if(ThisTask == 0) printf(" metal IRA, calculating restored fraction..\n"); /* ...........: calculates the effective yields :................... */ if(ThisTask == 0) printf(":: calculating effective yields for Short-Living Stars..\n"); SD.Yset = IMFs[IMFi].YSet; sprintf(buffer, "SnII_ShortLiv_Yields_%2d", mySFi); SnII_ShortLiv_Yields[mySFi] = (double **) mymalloc(buffer, LT_NMet * sizeof(double *)); for(k = 0; k < LT_NMet; k++) { sprintf(buffer, "SnII_ShortLiv_Yields_%2d_%d", mySFi, k); SnII_ShortLiv_Yields[mySFi][k] = (double *) mymalloc(buffer, IIZbins_dim[SD.Yset] * sizeof(double)); } /* #if defined (UM_CHEMISTRY) && defined (UM_METAL_COOLING) */ /* IIShLv_AvgFillNDens[IMFi] = (double*)calloc(IIZbins_dim[SD.Yset], sizeof(double)); */ /* #endif */ SFs[mySFi].nonZeroIRA = calculate_effective_yields(SFs[mySFi].metShortLiv_MassTh, IMFs[IMFi].MU, IMFi); for(j = 0; j < IIZbins_dim[SD.Yset]; j++) { if(j == 0) { SD.Zbin = j; SD.MArray = IIMbins[SD.Yset]; SD.Mdim = IIMbins_dim[SD.Yset]; SD.Y = SnIIYields[SD.Yset][FillEl]; SFs[mySFi].metFactorSN = calculate_FactorSN(SFs[mySFi].metShortLiv_MassTh, IMFs[IMFi].MU, &IMFs[IMFi]); /* restored by IRA SnII */ } if(ThisTask == 0) { fprintf(FdSnInit, "\n[Effective Yields for Short-Living stars :: set %03d - Z %8.6g]\n", SD.Yset, (IIZbins_dim[SD.Yset] > 1) ? IIZbins[SD.Yset][j] : 0); fprintf(FdSnInit, " %3s %6s %10s %10s\n", "IMF", "Z", "name", "Yield"); printf(" %3s %6s %10s %10s\n", "IMF", "Z", "name", "Yield"); for(k = 0; k < LT_NMet; k++) { printf(" [%3d][%8.6g] %10s %10.7lg\n", IMFi, (IIZbins_dim[SD.Yset] > 1) ? IIZbins[SD.Yset][j] : 0, MetNames[k], SnII_ShortLiv_Yields[mySFi][k][j]); fprintf(FdSnInit, " [%3d][%8.6g] %10s %10.7lg\n", SD.Yset, (IIZbins_dim[SD.Yset] > 1) ? IIZbins[SD.Yset][j] : 0, MetNames[k], SnII_ShortLiv_Yields[mySFi][k][j]); } } } } else { SFs[mySFi].MassFrac_inIRA = 0; SFs[mySFi].NumFrac_inIRA = 0; SFs[mySFi].nonZeroIRA = 0; num_snII = 0; SnII_ShortLiv_Yields[mySFi] = 0x0; SFs[mySFi].metFactorSN = 0; if(ThisTask == 0) { printf(":: No metals are supposed to be promptly ejected..\n"); fprintf(FdSnInit, "\n[Effective Yields for IRA part]\n" "No metals are supposed to be promptly ejected..\n"); } } if(ThisTask == 0) printf("\n\n"); }
/* static */ void IPv6RouteAdvertiser::createAdvertisementPacket( const Interface* intf, folly::io::RWPrivateCursor* cursor, folly::MacAddress dstMac, const folly::IPAddressV6& dstIP) { const auto* ndpConfig = &intf->getNdpConfig(); // Settings uint8_t hopLimit = ndpConfig->curHopLimit; // Set managed and other bits in router advertisements. // These bits control whether address and other information // (e.g. where to grab the image) is available via DHCP. uint8_t flags = 0; if (ndpConfig->routerAdvertisementManagedBit) { flags |= ND_RA_FLAG_MANAGED; } if (ndpConfig->routerAdvertisementOtherBit) { flags |= ND_RA_FLAG_OTHER; } std::chrono::seconds lifetime(ndpConfig->routerLifetime); std::chrono::seconds reachableTimer(0); std::chrono::seconds retransTimer(0); uint32_t prefixValidLifetime = ndpConfig->prefixValidLifetimeSeconds; uint32_t prefixPreferredLifetime = ndpConfig->prefixPreferredLifetimeSeconds; // Build the list of prefixes to advertise typedef std::pair<IPAddressV6, uint8_t> Prefix; uint32_t mtu = intf->getMtu(); std::set<Prefix> prefixes; foreachAddrToAdvertise(intf, [&]( const std::pair<folly::IPAddress, uint8_t> & addr) { uint8_t mask = addr.second; prefixes.emplace(addr.first.asV6().mask(mask), mask); }); auto serializeBody = [&](RWPrivateCursor* cursor) { cursor->writeBE<uint8_t>(hopLimit); cursor->writeBE<uint8_t>(flags); cursor->writeBE<uint16_t>(lifetime.count()); cursor->writeBE<uint32_t>(reachableTimer.count()); cursor->writeBE<uint32_t>(retransTimer.count()); // Source MAC option cursor->writeBE<uint8_t>(1); // Option type (src link-layer address) cursor->writeBE<uint8_t>(1); // Option length = 1 (x8) cursor->push(intf->getMac().bytes(), MacAddress::SIZE); // Prefix options for (const auto& prefix : prefixes) { cursor->writeBE<uint8_t>(3); // Option type (prefix information) cursor->writeBE<uint8_t>(4); // Option length = 4 (x8) cursor->writeBE<uint8_t>(prefix.second); uint8_t prefixFlags = 0xc0; // on link, autonomous address configuration cursor->writeBE<uint8_t>(prefixFlags); cursor->writeBE<uint32_t>(prefixValidLifetime); cursor->writeBE<uint32_t>(prefixPreferredLifetime); cursor->writeBE<uint32_t>(0); // reserved cursor->push(prefix.first.bytes(), IPAddressV6::byteCount()); } // MTU option cursor->writeBE<uint8_t>(5); // Option type (MTU) cursor->writeBE<uint8_t>(1); // Option length = 1 (x8) cursor->writeBE<uint16_t>(0); // Reserved cursor->writeBE<uint32_t>(mtu); }; auto bodyLength = getAdvertisementPacketBodySize(prefixes.size()); IPAddressV6 srcIP(IPAddressV6::LINK_LOCAL, intf->getMac()); IPv6Hdr ipv6(srcIP, dstIP); ipv6.trafficClass = 0xe0; // CS7 precedence (network control) ipv6.payloadLength = ICMPHdr::SIZE + bodyLength; ipv6.nextHeader = IP_PROTO_IPV6_ICMP; ipv6.hopLimit = 255; ICMPHdr icmp6(ICMPV6_TYPE_NDP_ROUTER_ADVERTISEMENT, 0, 0); icmp6.serializeFullPacket(cursor, dstMac, intf->getMac(), intf->getVlanID(), ipv6, bodyLength, serializeBody); }