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

WasteStream._get_property, WasteStream.mol inaccuracy #100

Open
joyxyz1994 opened this issue Mar 24, 2023 · 10 comments
Open

WasteStream._get_property, WasteStream.mol inaccuracy #100

joyxyz1994 opened this issue Mar 24, 2023 · 10 comments

Comments

@joyxyz1994
Copy link
Member

Need to add WasteStream-specific methods for molar flow and related thermodynamic properties. Generally, Component can be measured as something other than the chemical itself (e.g., COD, N). But this difference is not yet taken into account when getting thermodynamic properties of a WasteStream as a mixture of components.

@yalinli2
Copy link
Member

@joyxyz1994 is this fixed now with the recent merge related with bsm2?

@joyxyz1994
Copy link
Member Author

Not yet

@BenGillen1998
Copy link

Hi, as I mentioned in office hours the other week, I have been looking into this problem. To my understanding, components with unknown composition are set to a molar weight of 1. Therefore, inserting the following code into _waste_stream.py should throw an error whenever someone tries to get the molar flow of a component with this incorrect molar weight.

def get_flow(self, units: str, key: Optional[Sequence[str]|str]=...):
    name, factor = self._get_flow_name_and_factor(units)
    if name == 'mol':
        for chem in self.available_chemicals:
            if chem.chem_MW == 1:
                raise ValueError(f"The component {chem.CAS} does not have a molar mass")
    return super().get_flow(units = units, key = key)

Is this the intended functionality? Also, do we know the other functions and thermodynamic properties that need to be fixed?

@yalinli2
Copy link
Member

yalinli2 commented Nov 15, 2024

Hi @BenGillen1998 , thanks for looking into this. You are correct that we default the MW to 1 if it's not provided, but sometimes we also intentionally set the MW of a component to 1 (for things we don't really care about the mass), so we don't get an error when calculating some properties. So it probably won't work if we just throw an error to a MW of 1.

@joyxyz1994 , is the key issue here getting the correct molar flow? Can we just look at if i_C, i_N, etc., is set and calculate moles accordingly?

@joyxyz1994
Copy link
Member Author

I was thinking to allow users to get molar flow but give a warning if it involves components that are not pure chemicals and thus don't have a legitimate MW (e.g., "readily biodegradable substrate"). They typically would be given a MW of 1. I don't think using i_C, i_N etc would work though. Not all elements are tracked (e.g., H, O). And if there's sufficient information there, defining MW shouldn't be a problem to begin with.

For components that have MW but are measured as something else, e.g., ammonium measured as N, I was planning on adding algorithms to use <Component>.i_mass to convert N mass flow back to NH4 mass flow and then use chem_MW or MW to calculate molar flow.

@yalinli2
Copy link
Member

@joyxyz1994 good point, I'm thinking of throwing an error by default, unless intentionally set preference/provide an additional input arg, because there are many warnings issued during the simulation (a lot of which are related to cost algorithms) and people may just ignore the warnings... what do you think?

@joyxyz1994
Copy link
Member Author

@yalinli2 Yea that's certainly a valid concern. A lot of times though, the molar flows rather than mass flows are accessed by default in thermosteam to calculate a Stream's thermodynamic properties like LHV. So, if it raises an error by default, would it automatically disable a lot of Stream's built-in functionalities? Not sure how to best deal with that..

@yalinli2
Copy link
Member

indeed I think molar flow is foundation in biosteam, let's chat about this at Monday's office hour

first office hour with an agenda lol

@BenGillen1998
Copy link

It is also my understanding that Stream stores everything in terms of molar flow. I chose the get_flow method to edit because it is not called anywhere else in the class so calling other methods would not be messed up. However, generalizing this solution to all other methods that rely on molar flow may be problematic.

I will be sure to attend Monday's office hour to help where I can.

@yalinli2
Copy link
Member

just to throw a note while I still remember, the idea is to:

  1. in Components.compile, add a check on measured_as
  2. throw an error when any components have measured_as, unless the users acknowledge (by setting some kwarg like ignore_measured_as_property_inaccuracy=True (by default this kwarg will be False) that they know some calculated properties won't be accurate with measured_as set for some components.
  3. in the error message, let the users know (i) how to avoid this error, (ii) what properties will be incorrect, and (iii) include a link to the doc (could be the FAQ page, or the measured_as attr) where an example is given showing how to correctly calculated the properties (using biogas an example, I forgot the name of that component in process models, s_ch4?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants