Skip to content

Commit

Permalink
Merge pull request #120 from bmad-sim/dcs16/04
Browse files Browse the repository at this point in the history
Added `Species(Null)` to be the same as `Species()`.
  • Loading branch information
DavidSagan authored Jan 7, 2025
2 parents 637c837 + 7a1b119 commit 9867f5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
32 changes: 23 additions & 9 deletions docs/src/species.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ struct Species
kind # the kind of particle.
end;
```
There are 5 kinds of species: `ATOM` `HADRON` `LEPTON` `PHOTON` `NULL`. The kind of species is stored within the `kind` field.
There are 5 kinds of species: `ATOM` `HADRON` `LEPTON` `PHOTON` `NULL`.
The kind of species is stored within the `kind` field.

The fields are stored with a set of units. If the fields are directly accessed, it will return a Unitful value. For example:
The fields are stored with a set of units. If the fields are directly accessed,
it will return a Unitful value. For example:
```julia
julia> Species("electron").mass
0.51099895069 MeV c^-2
Expand All @@ -30,16 +32,27 @@ The default units are:
- `spin`: $\hbar$
- `moment`: J/T

We recommended using our getter functions `massof()` an d `chargeof()` to obtain values in units you prefer. See [this page](constants.md) for more information.
We recommended using our getter functions `massof()` an d `chargeof()` to obtain values
in units you prefer. See [this page](constants.md) for more information.


## Construct a Species

Construct the particle with the constructor `Species(name)`.

### Constructing a Null species

The `Null` species is usful for bookkeeping purposes. For example, as a place holder for a struct
component to indicate that the species has not yet been set. To instantiate use:
```julia
julia> Species("Null")
julia> Species() # Same as above
```

### Constructing Subatomic Species

To construct a subatomic species, put the name of the subatomic species in the field `name`. **Note that the name must be provided exactly.**
To construct a subatomic species, put the name of the subatomic species in the field `name`.
**Note that the name must be provided exactly.**

Example:
```julia
Expand Down Expand Up @@ -95,11 +108,11 @@ Species(name::String, charge::Int, iso::Int)
```
where users can enter charge and mass number as separate parameter.

The parameter `charge` and `iso` are optional and it will use default values if not provided. Defaults are neutral atom and average atom.

**Note**
The parameter `charge` and `iso` are optional and it will use default values if not provided.
Defaults are neutral atom and average atom.

If charge or mass number are also provided in `name`. The charge and mass number in `name` will override the one given in the parameter.
**Note** If charge or mass number are also provided in `name`.
The charge and mass number in `name` will override the one given in the parameter.

Example:
```julia
Expand All @@ -108,7 +121,8 @@ julia> Species("C",charge = 1, iso = 13) #Carbon-13 with a single positive charg

## Species Functions

Species functions take a `Species` as their only parameter and returns a specific property of it. Here is the list of species functions:
Species functions take a `Species` as their only parameter and returns a specific property of it.
Here is the list of species functions:

- `massof()`
- `chargeof()`
Expand Down
2 changes: 1 addition & 1 deletion src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Species
Species() = Species("Null", 0.0u"e", 0.0u"MeV/c^2", 0.0u"h_bar", 0.0u"J/T", 0, Kind.NULL)

function Species(name::String; charge::Int=0, iso::Int=-1)

if name == "Null"; return Species(); end

anti = r"Anti\-|anti\-"
# is the anti-particle in the Subatomic_Particles dictionary?
Expand Down

0 comments on commit 9867f5d

Please sign in to comment.