Apply fluid pressurization at specific cells

Hello,

I am attempting to apply fluid pressurization at specific cells using the usr1.f subroutine.
But, I am not getting an increase in pressure. (The pressure is not being applied)

Is it the correct way? Or could you please recommend other alternatives?

The contents of usr1.f subroutine are as follows:

  SUBROUTINE USR1

  USE USR
  USE fldvar, only: P_g
  USE run, only: time

  IMPLICIT NONE

  DOUBLE PRECISION :: p_target, step_time, mod_time
  INTEGER :: i, step_index
  INTEGER, DIMENSION(6) :: indices

  ! Total cycle time: 0.4 s (0.2 s inject + 0.2 s hold)
  step_time = 0.4

  ! Injection cell indices (localized region)
  indices = (/ 512, 513, 514, 681, 682, 683 /)

  ! Apply pressure only during first 0.2s of each 0.4s cycle 
  IF (time >= 0.5) THEN
        p_target = 10000.8 * (time - 0.5)**2 
        mod_time = MOD(time - 0.5, step_time)
        step_index = INT(mod_time / 0.2)

        IF (step_index == 0) THEN
              DO i = 1, SIZE(indices, 1)
                    P_g(indices(i)) = P_g(indices(i)) + p_target
              END DO
        END IF
  END IF

  RETURN
  END SUBROUTINE USR1

How are you sure that the pressure is not being applied?

Have you enabled the call_usr keyword?

1 Like

Hi @cgw,

Thank you very much.

I’ve processed the VTK outputs for the six target cells (indices 512, 513, 514, 681, 682 and 683) and computed the summed pressure in each timestep. Below is a snippet of the results (full data runs through 102 timesteps.)

timesteps Sum_of_Pressure
0001 624847.2109375
0002 620580.7734375
0003 620169.9375
0004 620077.78125
0005 620046.1015625
0006 619982.8125
0007 619981.15625
0008 620014.0
0009 619983.546875
0010 620004.7265625
0011 619979.7890625
0012 619998.6015625
0013 619989.9921875
0014 619955.0234375
0015 619998.234375
0016 619956.5
0017 619947.265625
0018 619963.046875
0019 619999.1484375
0020 619958.296875
0021 619999.4921875
0022 620017.375
0023 620004.9453125
0024 619951.6484375
0025 620005.7265625
0026 619987.1015625
0027 620002.40625
0028 619920.4609375
0029 620040.140625
0030 619992.1015625
0031 619992.46875
0032 620012.734375
0033 619960.6328125
0034 619976.1796875
0035 619980.7734375
0036 620050.921875
0037 619984.8515625
0038 620089.421875
0039 620010.9375
0040 619951.1953125
0041 619998.953125
0042 620105.7890625
0043 620002.71875
0044 620023.328125
0045 620016.6328125
0046 620029.375
0047 620106.640625
0048 620088.671875
0049 620065.0
0050 620047.6953125
0051 620001.71875
0052 619997.4453125
0053 620028.6875
0054 620016.484375
0055 620070.3203125
0056 620078.1484375
0057 620035.9140625
0058 620128.2890625
0059 620117.34375
0060 620030.53125
0061 620002.203125
0062 619983.8671875
0063 620019.265625
0064 619988.34375
0065 620070.9140625
0066 620137.09375
0067 620040.8359375
0068 620116.1484375
0069 620088.546875
0070 620031.5703125
0071 620026.6953125
0072 620121.6953125
0073 619983.421875
0074 620109.6953125
0075 620026.4296875
0076 620104.5625
0077 620064.3671875
0078 620093.9375
0079 620063.5703125
0080 619942.03125
0081 620097.5859375
0082 619963.40625
0083 619968.21875
0084 620100.6484375
0085 620007.03125
0086 619989.0546875
0087 619997.2265625
0088 620019.9453125
0089 620105.6796875
0090 619954.59375
0091 620035.1953125
0092 620116.6484375
0093 619995.828125
0094 620036.6484375
0095 619980.640625
0096 620035.75
0097 620121.4453125
0098 620047.9375
0099 620055.671875
0100 620007.34375
0101 620079.484375
0102 619921.5703125

Can you attach your entire case? Main menu/Submit bug report then upload the zip file here.

1 Like

Hi @cgw,

Thank you.

I have attached my zip file to this message. Please find the attachment.
step23_.zip (1.3 MB)

I have an additional question about the same model. Could you please guide me to apply the pressure (varying with time) using the pressure inflow boundary from the bottom of the model?

Code in usr1.f is not called unless call_usr (Enable user-defined subroutines) is enabled. When in doubt, add write statements to your code to see if it’s actually being called.

1 Like

Hi @cgw,
Thanks for your response.
"Enable user-defined subroutines: is enabled in my simulation (zip file), as shown in the attached screenshot.

Sorry @BimalChhushyabaga, I opened the wrong file!
Let me have a closer look at this and I will get back to you.

1 Like

No worries, @cgw. Please let me know if there are additional requirements.

Your usr1.f has:
IF (time >= 0.5) THEN

I ran your case for about an hour and it’s only at 0.035 s

How long did you run the simulation for?

Hi @cgw,
I ran it over a day using a cluster (1 node and 32 processors) to get a time of 1.02 s.

In usr1.f, I am applying pressure after 0.5 s.

DMP or SMP? The file you uploaded was configured for serial.

1 Like

I used DMP and ran it in version 23.1.1.

Hi @BimalChhushyabaga

A few comments and suggestions:

  1. When looking for help on the forum, it makes our job easier if you provide all the details - attaching case files, specifying DMP/SMP/serial, partitioning scheme, etc. The .mfx file you uploaded was set up for serial, and when I switched to DMP I did not know what partitioning you used and had to guess. I am running with 2x4x2=16 cores, I was not able to run on 32 cores (partitions too small).

  2. It also helps to provide a case which does not take all day to run! This makes debugging and testing much easier, with a faster turnaround cycle. This will make life easier for both of us. If possible, try to simplify the case to the simplest/smallest version which shows the same problem.

  3. When a case does not work in DMP, always try running in serial mode.

  4. WRITE statements are a primitive, but very helpful, debugging tool. Sprinkle them in your code liberally when you’re trying to figure out what’s going on.

With this in mind, I changed your code to the following, dividing the times by 100 and adding WRITE statements:

step_time = 0.004
! Injection cell indices (localized region)
indices = (/ 512, 513, 514, 681, 682, 683 /)
write(*,*) "USR1 TIME", time
IF (time >= 0.005) THEN
      p_target = 10000.8 * (time - 0.005)**2
      mod_time = MOD(time - 0.005, step_time)
      step_index = INT(mod_time / 0.002)
      IF (step_index == 0) THEN
          DO i = 1, SIZE(indices, 1)
             write(*,*) "TIME", time, "PE", myPE,"IDX", indices(i), "P_G", P_g(indices(i)),"P_TARGET", p_target
             P_g(indices(i)) = P_g(indices(i)) + p_target
          END DO
      END IF
 END IF

Running in serial mode, after a short time I see (slightly edited for readability):

USR1 TIME 5.00E-003TIME 5.00E-003  PE 0  IDX 512  P_G 102299.97  P_TARGET 1.24E-016
TIME 5.00E-003  PE 0  IDX 513  P_G 102136.65  P_TARGET 1.249-016
TIME 5.00E-003  PE 0  IDX 514  P_G 101973.32  P_TARGET 1.249-016
TIME 5.00E-003  PE 0  IDX 681  P_G 102136.65  P_TARGET 1.249-016
TIME 5.00E-003  PE 0  IDX 682  P_G 101973.32  P_TARGET 1.249-016
TIME 5.00E-003  PE 0  IDX 683  P_G 101809.99  P_TARGET 1.249-016

But running in DMP mode I see:

TIME 5.00E-003  PE 0  IDX 512  P_G 9.87654321E+031    P_TARGET 1.249-016
TIME 5.00E-003  PE 0  IDX 513  P_G 9.87654321E+031    P_TARGET 1.249-016
TIME 5.00E-003  PE 0  IDX 514  P_G 100817.605         P_TARGET 1.249-016
TIME 5.00E-003  PE 0  IDX 681  P_G 102628.199         P_TARGET 1.249-016
TIME 5.00E-003  PE 0  IDX 682  P_G 9.87654321E+031    P_TARGET 1.249-016
TIME 5.00E-003  PE 0  IDX 683  P_G 9.87654321E+031    P_TARGET 1.249-016
USR1 TIME 5.00E-003
TIME 5.00E-003  PE 3  IDX 512  P_G 100940.715         P_TARGET 1.249-016
TIME 5.00E-003  PE 3  IDX 513  P_G 102366.521         P_TARGET 1.249-016
TIME 5.00E-003  PE 3  IDX 514  P_G 102780.600         P_TARGET 1.249-016
TIME 5.00E-003  PE 3  IDX 681  P_G 102136.606         P_TARGET 1.249-016
TIME 5.00E-003  PE 3  IDX 682  P_G 99975.062          P_TARGET 1.249-016
TIME 5.00E-003  PE 3  IDX 683  P_G 102275.402         P_TARGET 1.249-016
USR1 TIME 5.00E-003
TIME 5.00E-003  PE 2  IDX 512  P_G 100998.270         P_TARGET 1.249-016
TIME 5.00E-003  PE 2  IDX 513  P_G 102399.224         P_TARGET 1.249-016
TIME 5.00E-003  PE 2  IDX 514  P_G 102787.067         P_TARGET 1.249-016
TIME 5.00E-003  PE 2  IDX 681  P_G 102136.613         P_TARGET 1.249-016
TIME 5.00E-003  PE 2  IDX 682  P_G 99885.7389         P_TARGET 1.249-016
TIME 5.00E-003  PE 2  IDX 683  P_G 102213.607         P_TARGET 1.249-016
USR1 TIME 5.00E-003
TIME 5.00E-003  PE 6  IDX 512  P_G 102136.615         P_TARGET 1.249-016
TIME 5.00E-003  PE 6  IDX 513  P_G 101973.290         P_TARGET 1.249-016
TIME 5.00E-003  PE 6  IDX 514  P_G 101809.966         P_TARGET 1.249-016
TIME 5.00E-003  PE 6  IDX 681  P_G 9.87654321E+031    P_TARGET 1.249-016
TIME 5.00E-003  PE 6  IDX 682  P_G 102136.610         P_TARGET 1.249-016

Note that if you run DMP jobs with the “interactive” mode solver in the GUI, you only get output from PE (processing element) 0, the main node, but if you run the batch solver you can see the output from all PEs.

But even looking just at the output from PE 0, there is an giant red flag, which is the number 9.87654321E+031.

This value is used in MFiX to represent invalid/uninitialized data. Whenever you see it, you know something has gone wrong.

What you have to understand here is that the cell indices

indices = (/ 512, 513, 514, 681, 682, 683 /)

are not valid in DEM mode. Each PE covers a different range of (I,J,K) indices and has its own list of IJK cells. Each IJK list of cells start at 1 so it is possible that each PE has a cell 512, but they will all be different cells. So, you are not incrementing the pressure at the cells you intended to. (How did you determine these indices?) It would be better to use I,J,K values and convert to a cell index using the function funijk in the functions module. This will work regardless of which PE we are in, and what DMP decomposition we use. And since your UDF code executes on all PEs you need to check if the cell belongs to the current PE. You can use

IS_ON_myPE_plus2layers(I,J,K)

If this returns .True. it means (I,J,K) is handled by the PE. (It could be an interior cell or a ghost cell.)

So you should do something like:

    if (IS_ON_myPE_plus2layers(I,J,K)) then
       ijk = funijk(I,J,K)
       P_g(ijk) = P_g(ijk) + p_target
    endif

See the comments at the top of functions.inc regarding inlining the funijk function. But in your case, since this only executes for a few cells once per time step, it probably does not matter.

Finally,

    p_target = 10000.8 * (time - 0.5)**2

looks a bit odd to me - the pressure will continue to rise quadratically, with no limit. Is this really what you want?

1 Like

Thank you very much, @cgw, for reviewing my case and providing such a detailed explanation and helpful suggestions. I appreciate the debugging tips, especially the use of IS_ON_myPE_plus2layers and funijk to ensure proper indexing across PEs. Your guidance on simplifying the case and using WRITE statements for troubleshooting has also been very helpful.

I’m planning to increase the pressure quadratically to study its effect on grain behavior. In the current code, I haven’t set pressure limits yet, as I was first testing the simulation. I’ll revise the code accordingly and proceed with the tests.

In future posts, I’ll make sure to provide all necessary details to avoid the confusion I caused this time. Apologies for that, and I’ll also ensure I test with simpler models that run in shorter durations.

Thanks again for your support!

1 Like