Open theodoreOnzGit opened 2 years ago
Great videos! Thanks for taking your time to deep dive into this package! It is very helpful for us to get the feedback you provide on youtube. I might make a HowTo on making your own costume units. You are just the first to ask for it. If you are missing some units that you feel should be a part if this package, then feel free to ask for them and I will add them for you.
In short you got the underlaying mathematic correct, you just needed the correct symbol.
You could do it this way in C#:
var unit1 = new UnitSystem(EnergyUnit.Kilojoule/AmountOfSubstanceUnit.Kilomole, $"{EnergyUnit.Kilojoule}/{AmountOfSubstanceUnit.Kilomole}");
var unit2 = new UnitSystem(EnergyUnit.SI/AmountOfSubstanceUnit.SI, $"{EnergyUnit.SI}/{AmountOfSubstanceUnit.SI}");
Printout:
kJ/kmol
J/mol
To answer some of your questions from your videos:
The BaseUnit
class it not really meant to be used directly by the users, but as you can see it can be used.
The UnknownUnit
Class is a unit that is not yet Cast to a specific unit
//Creating a unit that is not yet cast to a specific unit
UnknownUnit unknown = Energy.FromSI(10) / Duration.FromSI(10);
// {1 W}
//You could cast it to BaseUnit but you lose the nice looking symbols
BaseUnit baseunit = (BaseUnit)unknown;
// {1 kgm²/s³}
//Casting it to a specifig unit. It runs the check and will throw an error if the user set it to a wrong unit
Power power = unknown;
//{1 W}
//Trying to cast to a wrong unit
Energy energy = unknown;
//WrongUnitException
Hello MadsKirkFoged,
Thank you for getting back to me promptly! Appreciate your answers
Yeah i think for fluids mechanics and heat transfer, heat capacity is good. Thought I saw that entropy has the same units in another issue post.
However, units for empirical correlations can take any kind of form. They aren't standard per se. For example, temperature correlations for Therminol VP-1 are temperature related, or for air as well. Heat capacity correlations can be cubic as shown in the video.
Also, for equations of state such as peng robinson and soave redlich kwong, the constants used have units, but are not standard units as well.
I don't know if adding the units of these constants in is worth your time really. Because as you would know, the correlations in engineering can take so many forms. So having the howto guide on making custom units is perhaps the thing i'd ask for.
How to typecast those custom units, and convert them back to say heat capacity or viscosity etc...
The alternative is to have the user use the BaseUnit Class directly as i was doing. It provides a convenient return type since almost every engineeringUnit derives from it.
I was making an IEnumerable
Let me know what you think?
Hi MadsKirkFoged,
jumping onto this issue as you mentioned above that you wanted to add a HowTo on creating custom units without inheriting from BaseUnit... are you still planning to do that?
I was using some custom units that I thought were probably not necessary for your average user and/or would have needed a little more work from your side to add in a clean way (see below), so I never wanted to open a request to add those. I was able to define these without any issues by inheriting from BaseUnit and taking inspiration from the generated code of existing units. After the recent code changes however, this is no longer possible as easily as some used methods are now internal. I got everything to work by cloning your repo, adding these units in there and using my own custom dll, but as you can imagine, this can get a little tedious...
So this is what I was doing:
I had a model where the result would among other things be a cost effectiveness comparison. E.g. you want to know the energy specific cost of a power plant in say M$/GWh, an input parameter to the model might be the mass specific cost of a certain material needed for construction, say in $/kg, etc.
For this, I created a new base unit Cost
Cost.zip as well as several combined units like EnergySpecificCost.zip. All quite straight forward.
The reason I didn't ask for this to be added was that I think it is probably not great to hard-code this to be Dollar-based. You certainly don't want to deal with currency conversions but maybe there is an easy way to let the user choose the currency to be used for all cost-based calculations. If so (or if you think it's fine to hard-code Dollars for now), then maybe you could add these new units (with "SI" units): Cost ($)
, EnergySpecificCost ($/J)
, PowerSpecificCost ($/W)
, MassSpecificCost ($/kg)
, LenghtSpecificCost ($/m)
, AreaSpecificCost ($/m^2)
, VolumeSpecificCost ($/m^3)
.
Looking forward to hearing your thoughts. Let me know if you want to discuss Cost in a separate issue.
@mschmitz2
I really like your implementation of Cost
!
I have created a new issue for Cost #39 and one for creating a Howto #40
Hello, thanks for making this great package,
I'm trying to make custom units for heat capacity using BaseUnit Class
I find that when i do:
Console.WriteLine(EnergyUnit.Kilojoule/AmountOfSubstanceUnit.Kilomole) Console.WriteLine(EnergyUnit.SI/AmountOfSubstanceUNit.SI)
They are not equivalent.
I'm making a video guide on how to use your unit package, but the bug is at https://youtu.be/R_2DvEKXpac 12:00 approx onwards.
I will stick to SI for now, but could you check this out? Thank you so much!