Is it possible to change the input rate of the model from a constant mass flow rate to a sinusoidal input of particles?
Hi -
You should be able to do this using a UDF.
See the Conveyor Belt tutorial for an example of varying belt speeds. You can do a similar thing to set the variable BC_MASSFLOW_S
.
You don’t need to use the key data approach if you just want to hard-code a simple sinusoid in usr1_des.f
. If you do that you will just need to rebuild the solver when you change the parameters.
– Charles
Ok. What do you mean by the key data approach vs hard code?
What I want to do is run the whole model with a simple sinusoidal particle input instead of the constant mass inflow rate I currently have. I know the equation for the sinusoid I just want to implement this into MFiX in the best way.
Hi -
I referred you to the conveyor belt example because it has a time-varying belt speed, which is analagous to your time-varying input rate.
If you examine the conveyor belt example you will see that uses a data file to specify the belt velocities, which can change with time. The data file is called data_kf_000x.txt
in this example. That’s what I meant by “key data”, the “kf” stands for “key frame” here.
But in your case I think you don’t need this much complexity, you can just write something like
BC_MASSFLOW_S(BC,Phase) = C1 + C2*SIN(W * time)
in your UDF, for some constants C1, C2, and W. This is what I meant by “hard code”.
If you want to change the parameters, you will have to recompile the solver.
If you want to be able to change the frequency or amplitude of your sinusoid without recompiling, or have these parameters be time-varying through the similation, you could put these values into a data file and read them, as in the conveyor example.
Hope this helps,
– Charles
Thank you for that, I understand now.
Is there any documentation to help me learn to write a UDF? I have only used the GUI in MFIX and dont know where to start.
Start with this section from the reference manual: 8.2. User-Defined Functions — MFiX 21.3 documentation
and post here if you have any questions or problems.
– Charles
Sorry, I have worded what I want to do slightly wrong, so I think I need the conveyor tutorial method.
I want to run my model at constant mass inflow rate for 10,000s, and then after 10,000s I want it to run for another 10,000s under a sine wave particle input. So I think I need do use the key data method.
To do this, would I have to write out the input rate for all time values for the first 10,000s, or could I use much bigger intervals in here?
Also, because after 10,000s I want the sine wave to repeat, do I then have to write out all the values or can I tell it to repeat a group of inputs? I saw from the conveyor tutorial that it assumed the last input number for the rest of the run, but didn’t know if I could do this for a group of numbers?
Hi Chloe.
I would not advise creating the sine wave out of values in the datafile. This is possible but you won’t get a very smooth wave unless you use a lot of points, and this becomes unweildy.
I think you still have two options:
the simpler one is to simply hard-code the pattern in Fortran, in your UDF:
IF (time .LE. 10000) THEN
BC_MASSFLOW_S(BC,PHASE) = C0
ELSE
BC_MASSFLOW_S(BC,PHASE) = C1 + C2*SIN(W * time)
or even just
IF (time .GE. 10000) BC_MASSFLOW_S(BC,PHASE) = C1 + C2*SIN(W * time)
this second version will just use the initial value read from your .mfx file until time reaches 10000 and the calculated value will switch on.
For more complex patterns, I would use the key data approach, but I’d modify the code so that the values in the data are not used directly as the flow rate value, but instead are the parameters (amplitude, frequency, phase) that describe the sinusoid. I’d put the computation of sin
in the place where the linear interpolation happens. But this is a bit more complex and maybe more than you need.
One more comment - are you really simulating this out to tstop=10000s
? That’s a rather lengthy run! It’s probably going to take a lot of CPU time.
Good luck, and Happy Thanksgiving!
– Charles
Thank you, this makes sense.
In terms of writing the UDF, would this be a similar process to that of the conveyor belt tutorial, or is there a specific file that I should focus on?
Here’s the reference section on UDFs. https://mfix.netl.doe.gov/doc/mfix/21.3/html/reference/user_defined_functions.html
The file you are interested in is (probably)
usr1_des.f
Subroutine called every DEM timestep after calculating DES source terms
but before source terms are applied to the particles.
at least if you are using a DEM model.
You can follow any of the UDF tutorials for an example. Rotating drum might be good, it’s a bit simpler than the conveyor belt.
– Charles
You can set the flow rate in usr1_des.f but you will also need to update the dem mass inlet seeding. Please see attached for an example with the conveyor case (make sure you also use the other files in that tutorial as well).
The caveat is if the mass flow rate becomes zero (or near zero) it will throw off the next time for seeding, and the mass inlet will basically shut off.
You also want to test the min and max flow rates in a preliminary run because the datacheck will terminate the run if it is not possible to seed the inlet.
I used a monitor to verify the transient flowrate. You should not expect a smooth signal due to the discrete nature of the flow (here we have 10cm particles or rocks). There is also a slight delay between the seeding and when the particles are detected by the monitor because particles are seeded slightly above the inlet plane and they need to travel before reaching the monitor plane.
I used MFiX 21.3.2 and only tested in serial.
conveyor.mfx (18.0 KB)
set_bc_dem_mi.f (19.8 KB)
usr_mod.f (11.7 KB)
usr1_des.f (3.4 KB)
I have gone through your example and I can see what you have done to impose the sinusoid onto the input rate within the model within the usr1_des.f file.
I have tried to adapt what you have done in this example to my own model, but I don’t know how to write code in fortran so I’m struggling to know what other code to write in order to make this work. I have tried to look through your usr.mod.f file, but all of this seems to relate to key-frames which i’m not using, so do I need to include this UDF?
Would you be able to provide any more help on this?
calc_collision_wall_mod.f (43.2 KB)
calc_force_dem.f (12.8 KB)
geometry.stl (16.6 KB)
geometry_0002.stl (16.6 KB)
rp.mfx (13.1 KB)
set_bc_dem_mi.f (19.6 KB)
usr_mod.f (446 Bytes)
usr1_des.f (1.7 KB)
Please confirm the following:
- The geometry is fixed.
- You want to hard code the sine wave, not use keyframe data.
- You want to use a
particle_input.dat
file as initial condition. If so please attach it.
Yes the geometry is fixed.
I only say hardcode, because I want the model to run under a sine wave for potentially >5000s, which seems a lot of data to code into a keyframe.
I want the model to run under a constant mass flow rate of 0.000018 kg/s for 100 seconds, and then change the input to a sine wave after this time stamp, and run as this for the remaining time of the model.
Charles suggested something like this was possible in the above comment:
IF (time .LE. 100) THEN
BC_MASSFLOW_S(BC,PHASE) = C0
ELSE
BC_MASSFLOW_S(BC,PHASE) = C1 + C2*SIN(W * time)
Yes I would like an input file, I have now attached this.
particle_input.zip (4.9 KB)
Is the input file I have provided ok?
It looks fine. We’ve been a bit busy here, working on the 21.4 release. We’ll get back to you ASAP.
Please try the attached (adjust the wave parameters in usr1_des.f, lines 41-44).
rp.mfx (17.3 KB)
set_bc_dem_mi.f (19.8 KB)
usr1_des.f (2.5 KB)
usr_mod.f (605 Bytes)
particle_input.dat (15.0 KB)
Thank you. I’ve tried the files you attach. They work and I can see the lines to adjust the wave patterns.
However, ive tried to add a monitor to see the input wave but It doesn’t seem to be working in the same way the one you attached previously for the conveyor does. I’ve attached an image below, with the input values on the left and the monitor pane on the right. I’ve rebuilt the solver.
Is this an issue with the monitor or the numbers i’ve put in the system?
The UDF file name is wrong. You have usr1_des(1).f
which means it is probably a copy. This file will not be used when building the solver. Please rename to usr1_des.f
(remove (1)
), and rebuild.
The plot you are showing is probably using a constant value of around 0.0014 kg/s. My guess is each spike corresponds to one particle trickling down. The example I showed earlier was more continuous because the flow rate was higher and many particles where injected at each time step.
Thank you, i’ve changed the name now and rebuilt the solver, but its still coming out in the same format.
My mean input is 0.00017 kg/s which is about 10 particles a second in my model.
Eventually, I want to impose a sine wave which has a mean rate of 0.00017 (10 particles) and an amplitude of 0.00007 (5 particles), and a period of 10 seconds.