CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Udm value on the walls (https://www.cfd-online.com/Forums/fluent-udf/193538-udm-value-walls.html)

rarnaunot September 27, 2017 08:03

Udm value on the walls
 
When we save the value of a UDS on a defined UDM (code C_UDMI(c,tc,i)= C_UDSI(c,tc,i)), we obtain a UDM value equal to zero at the walls where the boundary conditions were defined. How can we fix it? :eek:
Should we use a User Defined Node Memory Location? Has anyone know how to use them in the next code?


DEFINE_ADJUST(a1_adjust_udm, domain)
{
cell_t c; /* Cell index has its own type too */
Thread *tc; /* Threads are pointers to a structure */

/* Loop through all the cell threads in the domain */
thread_loop_c(tc,domain)
{/* Loop through the cells in each cell thread */
begin_c_loop(c,tc)
{

C_UDMI(c,tc,0)=C_UDSI(c,tc,0)*5;

}
end_c_loop(c,tc)
}
}

sbaffini September 27, 2017 08:33

You're looping over cells. Boundaries have F_UDMI and F_UDSI

rarnaunot September 27, 2017 09:15

Quote:

Originally Posted by sbaffini (Post 665843)
You're looping over cells. Boundaries have F_UDMI and F_UDSI

Should I do this?

DEFINE_ADJUST(a1_adjust_udm, domain)
{
cell_t c; /* Cell index has its own type too */
Thread *tc; /* Threads are pointers to a structure */

/* Loop through all the cell threads in the domain */
thread_loop_c(tc,domain)
{/* Loop through the cells in each cell thread */
begin_c_loop(c,tc)
{

C_UDMI(c,tc,0)=C_UDSI(c,tc,0)*5;

}
end_c_loop(c,tc)
}

begin_f_loop(f,t)
{

F_UDMI(f,t,0) = F_UDSI(c,tc,0)*5;
}
end_f_loop(f,t)

}

sbaffini September 27, 2017 11:00

That's the concept. You should obviously define f and t (as well as providing a loop on the face threads) and check that what is stored in F_UDSI actually corresponds to what you are looking for.

rarnaunot September 28, 2017 07:10

Quote:

Originally Posted by sbaffini (Post 665869)
That's the concept. You should obviously define f and t (as well as providing a loop on the face threads) and check that what is stored in F_UDSI actually corresponds to what you are looking for.

Hello!

I've done what you said:


DEFINE_ADJUST(adjust_udm, domain)
{
cell_t c; /* Cell index has its own type too */
Thread *tc; /* Threads are pointers to a structure */
face_t f;/* Face index has its own type*/

/* Loop through all the cell threads in the domain */
thread_loop_c(tc,domain)
{/* Loop through the cells in each cell thread */
begin_c_loop(c,tc)
{
C_UDMI(c,tc,0)=C_UDSI(c,tc,0)*C_R(c,tc);
}
end_c_loop(c,tc)
}
/* loops over all face threads in a domain*/
thread_loop_f(tc,domain)
{/* Loop over faces in a face thread to get the information stored on faces. */
begin_f_loop(f,tc)
{
F_UDMI(f,tc,0)=F_UDSI(f,tc,0)*C_R(c,tc);

}
end_f_loop(f,tc)
}
}

The compilation of the code work but I got "Segmentation violation" at the begining of the calculation. Is there something wrong on my code?

Hope the same thread could be used for cells and faces at the same time...

sbaffini September 28, 2017 10:24

That's kind of lazy of you but, that's not actually at the same time, so there should not be any problem with that.

A first problem is that F_UDSI and F_UDMI are only available for wall and flow boundary faces. Attempts to access any other face zone will result in error. But you are looping over all face threads, including the interior one, which will give you error.

Another problem is with C_R(c,tc) in the face loop. Face variables start with F_, but there is no density stored on faces. There are few options here, according to what you want to achieve.

Try this (you need to get from the GUI the proper integer ID of the default-interior group of faces to put in place of YOUR_INPUT):

DEFINE_ADJUST(adjust_udm, domain)
{
cell_t c; /* Cell index has its own type too */
Thread *tc; /* Threads are pointers to a structure */
Thread *tf; /*Note lack of laziness here*/
face_t f; /* Face index has its own type*/

Thread *t_interior = Lookup_Thread(domain,YOUR_INPUT); /*ID of the "default-interior" set of faces, from GUI -- INPUT REQUIRED HERE*/

/* Loop through all the cell threads in the domain */
thread_loop_c(tc,domain)

{
/* Loop through the cells in each cell thread */
begin_c_loop(c,tc)
{
C_UDMI(c,tc,0)=C_UDSI(c,tc,0)*C_R(c,tc);
}
end_c_loop(c,tc)
}

/* loops over all face threads in a domain*/
thread_loop_f(tf,domain)
{

if (tf == t_interior) continue; /*skip default-interior faces*/

tc = THREAD_T0(tf); /*unique cell thread next to boundary face thread*/
/* Loop over faces in a face thread to get the information stored on faces. */
begin_f_loop(f,tf)
{

c = F_C0(f,tf); /*index of cell next to given face on boundary*/


F_UDMI(f,tf,0)=F_UDSI(f,tf,0)*C_R(c,tc); /*getting the density from cell next to boundary*/

}
end_f_loop(f,tc)
}
}

I have not checked it, so you need to see if errors come out

rarnaunot October 3, 2017 04:51

Thanks a lot because my college and I didn't know this important part!!
Quote:

Originally Posted by sbaffini (Post 665985)
A first problem is that F_UDSI and F_UDMI are only available for wall and flow boundary faces. Attempts to access any other face zone will result in error. But you are looping over all face threads, including the interior one, which will give you error.

Yes! I noticed this after writing here and I change it but the same error ocurred because of the above problem.
Quote:

Originally Posted by sbaffini (Post 665985)
Another problem is with C_R(c,tc) in the face loop. Face variables start with F_, but there is no density stored on faces. There are few options here, according to what you want to achieve.

The code of sbaffini works perfectly to my case

:confused: I'm a little confussed with your first sentence :
Quote:

Originally Posted by sbaffini (Post 665985)
That's kind of lazy of you but, that's not actually at the same time, so there should not be any problem with that.

I tried to write the more kindly I can and English is not my mother tongue so I try always my best in here. Sometimes I decide to write the shortest as possible in order to not make any english mistakes. So I really apologised if I express myself as an unfriendly or unpleasant person because I REALLY APRECIATE YOUR HELP THROUGH HERE!!

THANKS for your kindly help, sbaffini!!!

sbaffini October 3, 2017 15:55

Dear rarnaunot, don't worry. What I meant is that, instead of guessing if using the same variable for two loops on two kind of threads, it would have been faster to just test it. Note my remainder of this as comment. That was ironic.

Glad it worked.

sina_sls August 3, 2022 07:12

Quote:

Originally Posted by sbaffini (Post 666467)
Dear rarnaunot, don't worry. What I meant is that, instead of guessing if using the same variable for two loops on two kind of threads, it would have been faster to just test it. Note my remainder of this as comment. That was ironic.

Glad it worked.

Hello,

How can i change UDS boundary value in a Define Adjust UDF? i mean how can i call UDS boundary value to changing in a UDF of Define Adjust?

Regards,

sbaffini August 3, 2022 07:33

Quote:

Originally Posted by sina_sls (Post 833000)
Hello,

How can i change UDS boundary value in a Define Adjust UDF? i mean how can i call UDS boundary value to changing in a UDF of Define Adjust?

Regards,

Not sure I understand, nor I will be able to check or help with any code now. But, you need to know the following, define_adjust is called at the beginning of each iteration and it is general, doesn't have any thread as input, so it is up to what you want to do in it. Yet, it is not meant to directly operate on the F_PROFILE variable (nor it actually makes sense).

What you can do in define_adjust is to update some global variable that is later accessed in the define_profile udf of the UDS and use it there for your updated bc.

Is this what you were looking for?

sina_sls August 3, 2022 07:45

Quote:

Originally Posted by sbaffini (Post 833004)
Not sure I understand, nor I will be able to check or help with any code now. But, you need to know the following, define_adjust is called at the beginning of each iteration and it is general, doesn't have any thread as input, so it is up to what you want to do in it. Yet, it is not meant to directly operate on the F_PROFILE variable (nor it actually makes sense).

What you can do in define_adjust is to update some global variable that is later accessed in the define_profile udf of the UDS and use it there for your updated bc.

Is this what you were looking for?

Thank you for your response


I want to set sinusoidal value of electric potential (MHD module) for a wall, first i try expression but i faced to error :

Error: wta(2nd) to string_eq

Error Object: __expr__

then i try Profile and UDF profile , but agian i faced to problem , when i use them it consider the wall to insulated.

Could someone help me how can i set sinusoidal value for current density ( Electric Potential MHD) ?

this is my UDF profile code:

#include "udf.h"
#define PI 3.141592654

DEFINE_PROFILE(current_density,thread,position)
{

face_t f;
real t = CURRENT_TIME;

begin_f_loop(f,thread)
{

F_PROFILE(f,thread,position)=13*sin((2*PI/0.04)*t);

end_f_loop(f,thread)
}
}

This is expression :

13*sin((2*PI/0.04[s])*Time)

I try Define Adjust , but it dosent work like which i want :
# include "udf.h"

DEFINE_ADJUST(adjust_gradient, domain)
{
int i = 13.;
Thread *t = Lookup_Thread(domain, i);
face_t f;
real tt = CURRENT_TIME;

begin_f_loop (f,t)
{
F_UDSI(f,t,0) = 0.02*tt;
}
end_f_loop (f,t)
}

but when i use Define Adjust boundary value changes wrong and weird i think boundary value didn't change and other things changes

sbaffini August 3, 2022 08:10

Ok, you certainly don't need a define_adjust to simply assign a sinusoidal time variation to a BC. As I said, it is meant for other things.

Now, your scenario is very simple, and there certainly is an UDF example with a time varying inlet bc in the manual (probably with pressure). I am no expert with expressions (which were not yet in Fluent last time I used it), but I suspect that they are exactly meant to be used for simple cases like yours, and you should be able to find a simple example in the manual as well.

So, I won't check your UDF (or expression).

I think you should also double check the variables you are using, as you mention MHD but use the UDS. I have no idea if this is how the MHD module works with UDF.

sina_sls August 3, 2022 08:22

1 Attachment(s)
Quote:

Originally Posted by sbaffini (Post 833010)
Ok, you certainly don't need a define_adjust to simply assign a sinusoidal time variation to a BC. As I said, it is meant for other things.

Now, your scenario is very simple, and there certainly is an UDF example with a time varying inlet bc in the manual (probably with pressure). I am no expert with expressions (which were not yet in Fluent last time I used it), but I suspect that they are exactly meant to be used for simple cases like yours, and you should be able to find a simple example in the manual as well.

So, I won't check your UDF (or expression).

I think you should also double check the variables you are using, as you mention MHD but use the UDS. I have no idea if this is how the MHD module works with UDF.

Thanks

i attached the picture that show the box where i can set value for boundary value , it shows that it is UDS part so i use UDS in Define Adjust

Thank You

sbaffini August 3, 2022 09:23

I took some time and checked better. Two things:

1) Apparently, MHD module in Fluent is still based on UDF and UDS, so your findings seems coherent with the fact that MHD is based on UDS.

2) Have you read the manual? Because, in less than a minute, I just found this, well evidenced, in a section named "Setting Up Boundary Conditions" in the MHD part of the user guide:

Note: Note that all boundary conditions used by the MHD model must be set in the Boundary Condition tab of the MHD Model dialog box. Customized boundary conditions of any form, such as parameters and expressions, are not supported.

As the MHD module is based on UDFs, I'm pretty sure there is a way/hack to use UDF also to assign your bc but, given the above warning, it is a possibility only for an experienced user with a full knowledge of CFD and Fluent. Nothing we can distill here in few posts, unless someone else shows up here with a ready solution.

sina_sls August 3, 2022 09:52

Quote:

Originally Posted by sbaffini (Post 833024)
I took some time and checked better. Two things:

1) Apparently, MHD module in Fluent is still based on UDF and UDS, so your findings seems coherent with the fact that MHD is based on UDS.

2) Have you read the manual? Because, in less than a minute, I just found this, well evidenced, in a section named "Setting Up Boundary Conditions" in the MHD part of the user guide:

Note: Note that all boundary conditions used by the MHD model must be set in the Boundary Condition tab of the MHD Model dialog box. Customized boundary conditions of any form, such as parameters and expressions, are not supported.

As the MHD module is based on UDFs, I'm pretty sure there is a way/hack to use UDF also to assign your bc but, given the above warning, it is a possibility only for an experienced user with a full knowledge of CFD and Fluent. Nothing we can distill here in few posts, unless someone else shows up here with a ready solution.

Thank you and i appreciate you for your time,

i read some part of manual , you mean this part of limitation of setting BC :

"You must specify the applied magnetic field directly. The alternative specification of an imposed electrical current is not supported."

according to this i cant use UDF simply ?

sbaffini August 3, 2022 09:58

No, I mean the part that I reported in my previous post:

"Note: Note that all boundary conditions used by the MHD model must be set in the Boundary Condition tab of the MHD Model dialog box. Customized boundary conditions of any form, such as parameters and expressions, are not supported."

which is at section 29.3.3.4 of the User Guide, named "Setting Up Boundary Conditions".

The key here is "Customized boundary conditions of any form are not supported". UDF are not explicitly mentioned, but not even excluded. So, you can't use UDF or expressions or parameters to assign boundary conditions for the MHD variables.

sina_sls August 3, 2022 10:30

Quote:

Originally Posted by sbaffini (Post 833029)
No, I mean the part that I reported in my previous post:

"Note: Note that all boundary conditions used by the MHD model must be set in the Boundary Condition tab of the MHD Model dialog box. Customized boundary conditions of any form, such as parameters and expressions, are not supported."

which is at section 29.3.3.4 of the User Guide, named "Setting Up Boundary Conditions".

The key here is "Customized boundary conditions of any form are not supported". UDF are not explicitly mentioned, but not even excluded. So, you can't use UDF or expressions or parameters to assign boundary conditions for the MHD variables.

Thank you

in User Guide 2021 at section "Setting Up Boundary Conditions" , there isn't that Note

Thank you for your help and guidance

Regards,


All times are GMT -4. The time now is 20:03.