Giter Club home page Giter Club logo

Comments (6)

yalinli2 avatar yalinli2 commented on August 28, 2024

(Additional questions related to this thread)
I noticed biosteam has some cool functions - copylike and copyflow, which appeared in the units module in the cornstover biorefinery (e.g., when creating the PretreatmentReactorSystem
unit class, starting line 114):
PretreatmentReactorSystem

I tried to use similar codes when creating the FakeTank unit:
FakeTank2

This time, I got an error suggesting 'Outs' has no attribute 'copylike'
Error2

How should I use the copylike function?

Additionally, what does the "_linkedstreams = True" do? I added that line because that appears in cornstover codes, and I thought that could be used to link outs to ins.

Also, I noticed some codes used the "link_streams" function, what will this do?

As a summary to my above questions, what is the simplest way to make a unit that has the same outs as ins?

Thanks!!!

from biosteam.

yalinli2 avatar yalinli2 commented on August 28, 2024

(More questions related to this thread on the factories module)
I noticed some really cool codes the cornstover biorefinery used to batch-create units using the factories module of biosteam and an Excel spreadsheet:
Batch-create units

Can you explain how this works? I couldn't really understand the raw codes in the factories module and additionally, I was baffled by the fact that/I wanted to know:

  • Seems like not all units in the spreadsheet were used
  • Only some units were created this way, was this intended to be a quick way for simple units?
  • Is there anyway for me to check what units were created this way in the console?

Sorry I have a ton of questions... I tried to look at the tutorial but still couldn't figure these out. Let me know if the answers were somewhere in the tutorial , thanks!!!

from biosteam.

yoelcortes avatar yoelcortes commented on August 28, 2024

Nicee, its cool to see people trying to implement their own Unit subclass. Here is the explanation/fix to your bugs:

  1. I noticed you replaced the purchase_cost and installation_cost, these are not abstract properties. Best if you do not replace them! Your purchase/installation cost will be 0 anyways if you don't add any purchase costs to the _Cost dictionary.

  2. Comment 1: BioSTEAM doesn't let you directly set ins or outs because these are actually important objects that manage the source and sink of Stream objects. The reference to the source and sink are what allow flowsheets to be created. You should use copylike instead (good job!).

  3. Comment 2: The ins and outs attribute are actually lists of streams, so you would need to write:

...
def _run(self):
    # Notice the commas
    feed, = self.ins 
    effluent, = self.outs
    # This should work
    effluent.copylike(feed) 
  1. About linked streams... The _linkedstreams attribute is deprecated, you might be looking at older versions of BioSTEAM. The link_streams method of Static unit operations makes the input and output stream share data on the flow rates. The _run method in Static objects just copies T, P and phase from upstream to downstream, and the flow rates of both are always the same (so its faster!). Note that you can subclass from Static and replace the _run method, but the feed/effluent stream flow rates will always be linked. I'll use your fake tank as an example:
from biosteam import *
from biosteam.units.decorators import cost

# Create Unit subclass
@cost(basis='Flow rate', units='kg/hr', cost=0, CE=522, n=0.6)
class FakeTank(units.Static): pass

Now lets test it:

>>> Stream.species = Species('Water', 'Ethanol')
>>> feed = Stream('feed', Water=1, Ethanol=1)
>>> T1 = FakeTank('T1', ins=feed, outs='effluent')
>>> T1.show()
FakeTank: T1
ins...
[0] feed
    phase: 'l', T: 298.15 K, P: 101325 Pa
    flow (kmol/hr): Water    1
                    Ethanol  1
outs...
[0] effluent
    phase: 'l', T: 298.15 K, P: 101325 Pa
    flow (kmol/hr): Water    1
                    Ethanol  1

Also, notice that the flow rates are the same array:

>>> T1.ins[0].mol is T1.outs[0].mol
True

Hope this helps!

from biosteam.

yalinli2 avatar yalinli2 commented on August 28, 2024

Great! Now it works!

I found _linkedstream in comment codes in biosteam BTW, so should have known it's not up to date

Only one thing, I do need to keep the line:
_N_outs = 1

Otherwise I will get two out streams and trigger an error when simulating the unit:
Two outs

Error

However I don't necessarily need to add:
_N_ins = 1

By adding a comma after feed/effluent, I can understand that two streams will be created for outs, but why there is only 1 ints? Is this because of some default setting?

Thanks!!!

from biosteam.

yoelcortes avatar yoelcortes commented on August 28, 2024

Ahh, yes, old commented code that shouldn't be there. Good catch, I'll remove it in the next BioSTEAM update.

As for the number of streams, I think you figured it out already:

>>> from biosteam import Unit
>>> Unit._N_ins
1
>>> Unit._N_outs
2

from biosteam.

yalinli2 avatar yalinli2 commented on August 28, 2024

Got it, thanks!!!

from biosteam.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.