-
Notifications
You must be signed in to change notification settings - Fork 589
Allowing material making from class constructor #3649
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
base: develop
Are you sure you want to change the base?
Allowing material making from class constructor #3649
Conversation
|
edited this PR |
paulromano
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having objects be in a fully valid state after calling __init__ is a good idea 👍 So, I'm supportive of the change here, but wondering if there was a reason that you didn't also add a components argument that gets passed to add_components while you were at it? That would make it truly complete.
| # Set density if provided | ||
| if (density is not None and density_units is None) or ( | ||
| density is None and density_units is not None | ||
| ): | ||
| raise ValueError( | ||
| "Both density and density_units must be provided together." | ||
| ) | ||
| elif density is not None and density_units is not None: | ||
| self.set_density(density_units, density) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about having density_units default to "g/cm3"? In that case, the first branch of the if could just be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be happy with that density of 'g/cm3'.
If we make 'g/cm3' the default should we also make the the default units when using material.set_density() which I see defaults to None currently?
I wasn't sure if that would be acceptable so I didn't want it blocking the PR. I was not sure if it would be acceptable as adding_components currently needs two additional arguments, one for the dict of components and one for the percent_type. The percent_type is a bigger step as it is not a class attribute currently. So I had a go at reducing components to a single dictionary argument with #3654 but now that PR not going ahead I the way to add components to the init is clearer but it would require adding percent_type as a class attribute. |
|
ok tests are failing, it looks like many tests assumed the density_units were defaulting to Wondering of we should keep density_units to |
Description
It have just added a minimal set of extra options to the Material constructor to allow a material to made from the constructor.
This is useful to myself as I have a json representation of the material and going to a material object is easier with this addition. It also follows on some work @eepeterson and myself were doing trying to allow more classes to be construct-able from the constructor.
Fixes # (issue)
Checklist