Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve algorithm and typing of ActorNeutronics #167

Merged
merged 1 commit into from
Oct 12, 2022
Merged

Conversation

bclyons12
Copy link
Member

No description provided.

@@ -19,16 +19,18 @@ function Zcoord(n::neutron_particle)
n.z
end

mutable struct ActorNeutronics <: PlasmaAbstractActor
dd::IMAS.dd
mutable struct ActorNeutronics{T} <: PlasmaAbstractActor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bclyons12 you raise a good point here about the type of IMAS.dd. This is something I had not originally caught!

In addition of having to define the actors constructors as you have done, we should do the same for all functions that use type annotations. That is ~500 hits across 58 files. Doable but still annoying.

I'll merge this, and actually remove the {T} from the constructor (I just don't like to have the source of an actor being different than the others. I'll open a separate issue specifically to discuss this and decide a course of action.

Copy link
Member Author

@bclyons12 bclyons12 Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orso82 You need to do this for structs, since IMAS.dd is abstract. You don't need to do it for function arguments though. Since IMAS.dd{T} <: IMAS.dd, having ::IMAS.dd will allow the compiler will dispatch on each separately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok! you are right! Phew 😅

What threw me off is that you added this constructor.

ActorNeutronics(dd::IMAS.dd{T}, par::ParametersActor; kw...) where {T} = ActorNeutronics{T}(dd, par; kw...)

Is this really necessary? shouldn't ActorNeutronics pick up the right {T} already based on the concrete IMAS.dd type that is passed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if you don't override the default inner constructor. You have here (something I advocate against 😃 ), so it doesn't make the default outer constructor either.

Here's the relevant bit from https://docs.julialang.org/en/v1/manual/constructors/ :
Screen Shot 2022-10-11 at 9 25 45 PM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You actually might need the inner constructor here, since you use it to accept keywords and Julia doesn't multiple dispatch on keywords. If you made that as an outer constructor, it couldn't distinguish between that and the default inner constructor...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's also something I had not caught.

As you noted, all actors that only have dd and par as their structure need to use a inner constructor to accept keywords arguments. For all other actors I have defined an outer constructor.

@orso82 orso82 merged commit c12db29 into master Oct 12, 2022
@orso82 orso82 deleted the neutronics_update branch October 12, 2022 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants