CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   UDF, Breathing Waveform - Repeating Sinewave (https://www.cfd-online.com/Forums/fluent/233465-udf-breathing-waveform-repeating-sinewave.html)

bazinga22 January 28, 2021 11:00

UDF, Breathing Waveform - Repeating Sinewave
 
1 Attachment(s)
Hello all,

I am working to create a UDF that represents a breathing pattern for a 3D transient simulation. The UDF is set for the massflow rate of the persons nostril.

The pattern lasts 6 seconds is pretty much just a sine-wave when t<5, but from t=5 to t=6 the person is resting and the breathing mass flow rate is 0 as seen in the screen shot attached. However I cannot figure out how to loop this to continue "infinitely" as right now the breathing waveform runs once through from 0-6 seconds and I would like it to continue/restart the same pattern 6-12 s, 12-18 s and so on....

Can anyone help me with fixing my code to do so? Thank you!

AlexanderZ January 29, 2021 06:29

Code:

/*************************
transient.c
UDF for specifying a transient boudnary condition
******************************/

#include "udf.h"

DEFINE_PROFILE(transient_massflowrate,thread,position)
{
        face_t f;
        real t = CURRENT_TIME;

        begin_f_loop(f, thread)
        {
                F_PROFILE(f, thread, position) = .000125*sin((2*M_PI*(t%5))/5);
        }
        end_f_loop(f, thread)
}


bazinga22 January 29, 2021 09:34

Hi thank you, this doesn't work I don't believe, because I need the 1s of rest from 5 to 6 seconds of 0 flow rate. Your reply will just loop the sine function every 5 seconds.

Any other thoughts?

AlexanderZ February 1, 2021 19:45

lol

Code:

/*************************
transient.c
UDF for specifying a transient boudnary condition
******************************/

#include "udf.h"

DEFINE_PROFILE(transient_massflowrate,thread,position)
{
        face_t f;
        real t = CURRENT_TIME;

        begin_f_loop(f, thread)
        {
                if (t%6 == 0)
                        F_PROFILE(f, thread, position) = 0.0;
                else
                        F_PROFILE(f, thread, position) = .000125*sin((2*M_PI*(t%6))/5);
        }
        end_f_loop(f, thread)
}


tiztaz November 17, 2021 05:44

Quote:

Originally Posted by AlexanderZ (Post 795078)
lol

Code:

/*************************
transient.c
UDF for specifying a transient boudnary condition
******************************/

#include "udf.h"

DEFINE_PROFILE(transient_massflowrate,thread,position)
{
        face_t f;
        real t = CURRENT_TIME;

        begin_f_loop(f, thread)
        {
                if (t%6 == 0)
                        F_PROFILE(f, thread, position) = 0.0;
                else
                        F_PROFILE(f, thread, position) = .000125*sin((2*M_PI*(t%6))/5);
        }
        end_f_loop(f, thread)
}


Hi everibody, what is the meaning of t%6? I don't understand, thank you

AlexanderZ November 17, 2021 21:16

its a check if number is divisible by 6 without remainder

google operator % for C language


All times are GMT -4. The time now is 16:12.