Changing Inlet Refpoint / Passing t and dt into Inlet Functions

32 views
Skip to first unread message

Lukas Hof

unread,
Jun 1, 2022, 1:30:12 PM6/1/22
to pysph-users
Hello everyone,

I am using PySPH for a case with an inlet that is moving along the x-,y- and z-axis with the fluid leaving the inlet in the y-direction. I had no trouble moving the inlet in x and z as it simply moves when changing the velocities u and w respectively. However, to make the inlet move in the y-direction, I figured I need to change the reference point of the inlet during the calculation. Changing v alone will obviously only change the speed of the outflow.

I built a function that is called by  "InletBase" in pysph.sph.bc.inlet_outlet_manger.py. In this context the refpoint can be changed. However, when I add the time step "dt" or time "t" they will always be 0 and 0.1 respectively. I couldn't find a reason for this behavior. For equations that are not called by the "InletBase" the time step and time were always available.

I can currently get the time step into the equation by simply passing the value into the function via __init__(). But this workaround will obviously not work when using an adaptive time step.

I would be really happy if you could tell me how I can fix this and pass the current time (step) into the equation. Thank you in advance for your support! If you have a better idea for changing the refpoint during calculation, I am also happy to hear about it! If you need any more information or clarification, let me know!

I really appreciate what you have built here and enjoy using PySPH a lot! I hope it keeps growing and improving!

Regards,
Lukas

Pawan Negi

unread,
Jun 1, 2022, 11:20:34 PM6/1/22
to pysph-users
Hi Lukas,

The refpoint is the point on the inlet-fluid interface which is used to evaluate the distance along the normal of an inlet or fluid particle from the interface. I hope this is clear to you already.

Yes, you can change the reference point once it is passed to an equation by adding v*dt every timestep. In order to do so do not pass timestep (dt) or time (t) in __init__() function. Instead, there are inbuilt parameters including t, dt that you can pass to loop, post_loop or loop_all functions. See the link below describing this


So t and dt here are the current time and timestep. So it will be helpful when you use adaptive timesteps.
I hope this helps.

Regards,
Pawan

Lukas Hof

unread,
Jun 2, 2022, 7:03:54 AM6/2/22
to pysph-users
Hi Pawan,

thank you for your fast response! What you describe is basically what I intend to do. So I am happy that I seem to be on the right track!

I am aware that I should be able to pass 'dt' and 't' into any function of an equation. This worked flawlessly for me before, when writing other equations.

However, when I write or modify an equation that is used in 'InletBase' these two parameters won't be available as they are usually. I wrote an equation like this:

class Test(Equation):
    def py_initialize(self, dst, t, dt):
        print(t, dt)

I then added this equation to 'eqns' in the '_create_io_eval' function in 'InletBase'. The output from this is just '0.0 0.1' for every iteration. 't' doesn't change, and 'dt' is also not set to 0.1. If I print any value from 'dst' (e.g. print(dst.x[5])) I receive values that I would expect. So it seems that only 't' and 'dt' are not passed on correctly, and I don't really understand why.

I hope that provides some clarification on my issue.

Regards,
Lukas

Lukas Hof

unread,
Jun 2, 2022, 3:13:20 PM6/2/22
to pysph-users
Hello everyone,

I just stumbled upon something else that is confusing to me, but it might be somewhat related, so I will post it here as well.

I wrote a test equation to illustrate this second issue:
class Test(Equation):
    def __init__(self, dest, sources):
        self.test = 1.0
        super(Test, self).__init__(dest, sources)

    def py_initialize(self, dst, t, dt):
        self.test = 2.0
        print('py_initialize: '+str(self.test))

    def loop(self):
        print('loop: '+str(self.test))

    def reduce(self, dst, t, dt):
        print('reduce: '+str(self.test))

Ignoring the first iteration, I expected this to output '2.0' for all three functions. Instead, it outputs this:
py_initialize: 2.0
loop: 1.0
(...)
loop: 1.0
reduce: 1.0

So I thought, 'self.test' could only be changed within each function. But when I change the parameter in 'reduce' instead, like so:
class Test(Equation):
    def __init__(self, dest, sources):
        self.test = 1.0
        super(Test, self).__init__(dest, sources)

    def py_initialize(self, dst, t, dt):
        print('py_initialize: '+str(self.test))

    def loop(self):
        print('loop: '+str(self.test))

    def reduce(self, dst, t, dt):
        self.test = 2.0
        print('reduce: '+str(self.test))

The output from the second iteration onwards will be:
py_initialize: 1.0
loop: 2.0
(...)
loop: 2.0
reduce: 2.0

So 'self.test' will stay the same for 'py_initialize', but not for the other two functions. I am a bit confused, is this the expected behavior?

Regards,
Lukas

Prabhu Ramachandran

unread,
Jun 2, 2022, 11:15:04 PM6/2/22
to Lukas Hof, pysph-users
Thanks, this is definitely a bug, the evaluate call is not passing in the time and dt arguments inside the update function.  We will fix this soon.  You can fix this currently by editing:

https://github.com/pypr/pysph/blob/master/pysph/sph/bc/inlet_outlet_manager.py#L599
https://github.com/pypr/pysph/blob/master/pysph/sph/bc/inlet_outlet_manager.py#L723

and pass `time, dt` to the evaluate call.

Regards,
Prabhu
--
You received this message because you are subscribed to the Google Groups "pysph-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pysph-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pysph-users/f35f4c51-304a-4839-a734-9ece0097999fn%40googlegroups.com.

Prabhu Ramachandran

unread,
Jun 3, 2022, 12:56:08 AM6/3/22
to Lukas Hof, pysph-users
This is a subtlety that should be documented better. Basically this py_initialize is a pure Python function that is not transpiled, so it cannot directly affect any attributes on the compiled code.  Supporting that would be quite a bit more work.  Instead only set values or attributes in the particle array's properties or constants instead of the self.attribute.

cheers,
Prabhu
--
You received this message because you are subscribed to the Google Groups "pysph-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pysph-users...@googlegroups.com.

Lukas Hof

unread,
Jun 3, 2022, 3:50:22 PM6/3/22
to pysph-users
Hello Prabhu,

thank you so much! Your suggested fix worked perfectly!

Thank you also for the clarification on py_initialize! When reading the doc, I thought py_initialize and reduce were both pure python, so I was confused by the different behavior.

I appreciate the help a lot!

Regards,
Lukas
Reply all
Reply to author
Forward
0 new messages