|
CLASSpp Manual
Cosmology reference and developer manual
|
#include <species_collection.h>
Public Member Functions | |
| void | insert (std::string key, Ptr species) |
| void | freeze () |
| std::unique_ptr< BaseSpecies > & | at (const std::string &key) |
| std::unique_ptr< BaseSpecies > * | find (const std::string &key) |
| std::size_t | index_of (const std::string &key) const |
| bool | has_ncdm () const |
| bool | has_warm_matter () const |
| BaseSpecies * | operator[] (std::size_t i) |
Ordered, named collection of cosmological species.
Mutation is restricted to the construction phase (InputModule::ConstructSpecies). Each species is inserted with an explicit lookup key — today this is the hard-coded class identifier (e.g. "Photons", "CDM", "IDM_DR_IDR"); under the object-based input syntax planned in issue #246 it will be the user-supplied instance name (e.g. "nu1", "ncdm__1"). The key is NOT derived from BaseSpecies::name() because post-#246 several instances may share the same type name (e.g. two "massive_ncdm" instances).
Call freeze() once all species have been inserted; after that the container is sorted by key and the hot-path accessors photons()/baryons() are valid.
Iteration yields Entry&, where Entry exposes .key and .species. The common form for (auto& sp : all_species_) { sp->Foo(); } is supported via an Entry that acts like a unique_ptr<BaseSpecies>& (operator-> and operator* forward to the owned species). Use sp.key when the lookup key is needed; use sp->name() only when the BaseSpecies type name is wanted (these differ once #246 lands).
| void SpeciesCollection::insert | ( | std::string | key, |
| Ptr | species | ||
| ) |
Insert a species under an explicit lookup key. Must be called before freeze(). Duplicate keys abort in debug builds.
| void SpeciesCollection::freeze | ( | ) |
Sort by key and resolve cached Photons/Baryons pointers. Must be called exactly once, after all insert() calls.
| std::unique_ptr< BaseSpecies > & SpeciesCollection::at | ( | const std::string & | key | ) |
Returns the owning unique_ptr, matching std::map::at semantics. Throws std::out_of_range if absent. Call sites typically write *all_species_.at("X") (BaseSpecies&) or all_species_.at("X")->Foo() (forwards through unique_ptr).
| std::unique_ptr< BaseSpecies > * SpeciesCollection::find | ( | const std::string & | key | ) |
Pointer-or-nullptr lookup. Returns the owning unique_ptr (not its payload) so call sites can write if (auto* p = all_species_.find("X")) (*p)->Foo(); (pairing with the at() shape).
|
inline |
Lex-sorted index of an inserted species, or size() if absent. Valid only after freeze(); the lower_bound search relies on the container being sorted. Asserted in debug builds.
|
inline |
True iff the collection holds any NCDM-family species (an NCDMBaseSpecies, or the DNCDM_DR_Species composite). Valid only after freeze().
|
inline |
True iff any species (or composite child) contributes warm matter — clusters in delta_m/P_m but not in delta_cb/P_cb. Gates the _cb sources and spectra: P_cb differs from P_m exactly when this is true. Valid only after freeze().
|
inline |
Index-based access for parallel-vector dispatch (e.g. with perturb_vector::species_layouts). i must be < size().