Extract 2D profiles and compute averages

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
jankolino
Posts: 12
Joined: Fri Jun 22, 2018 2:03 pm

Extract 2D profiles and compute averages

Post by jankolino »

Hello,

I am simulating flow through an annulus. I want to extract a profile at different r=R and calculate an average. I would basically average my field over phi and z. I saw that there is a 1D profile extraction possible (cs_extra_operations-extract_1d_profiles), but what would be the best way to do it at higher dimensions, especially for polar coordinate system?

Thanks for all the suggestions and help.
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Extract 2D profiles and compute averages

Post by Yvan Fournier »

Hello,

We do not yet have the equivalent of the 1D profile for 2D profiles using the GUI (though you are not the first to ask, an it would not be too complicated to add, so we will try to add that in the future).

You my find an example of a velocity profile in cylindrical coordinates here https://github.com/code-saturne/code_sa ... achinery.c (this example does not appear in the Doxygen documentation yet).

Another approach would be to use co-processing with ParaView/Catalyst, but this assumes it is installed in your build, and direct extraction from the code is usually a better option (avoids extra interpolations).

Best regards,

Yvan
jankolino
Posts: 12
Joined: Fri Jun 22, 2018 2:03 pm

Re: Extract 2D profiles and compute averages

Post by jankolino »

Hello,

thanks for the example. I have occurred another problem. I am calling function findpt (predefined) and am getting following error;
extra_operations.o: In function `cs_user_extra_operations':
extra_operations.c:(.text+0x240): undefined reference to `findpt'
collect2: error: ld returned 1 exit status

eventhough I have all the dependencies listed. Does the order of the #INCLUDE-s matter?

I am using Code_Saturne 5.0.5.
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Extract 2D profiles and compute averages

Post by Yvan Fournier »

Hello,

No, the order of includes should not be important. Could you post your file ?

Best regards,

Yvan
jankolino
Posts: 12
Joined: Fri Jun 22, 2018 2:03 pm

Re: Extract 2D profiles and compute averages

Post by jankolino »

Hi there,

I am sending the file through attachment.

I have also tried with my own function to find the global minimum, but was not successful. I think the problem is not in the function itself, but with the parallelization. I must have done something wrong there. But as I see it, I find the local minimum in findpt_r and with the function cs_parall_min_id_rank_r(node, rank, dis2mn) compare it with other instances and return the cell_id and rank_id of the cell and rank with the lowest dis2mn. Then I compare the ranks in main function and if the ranks do match, I add to the sums, but as my results are not good, I must have done something wrong. If you could help me out with some suggestions, I would be really grateful. I know my code is a bit messy, but I am fairly new to this.

Kind regards.
Attachments
dodatek_z.c
(8.2 KiB) Downloaded 153 times
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Extract 2D profiles and compute averages

Post by Yvan Fournier »

Hello,

For the parallelization, you should also sum across all ranks before computing the mean (and not divide by j, which is rank-dependent), using cs_parall_sum or MPI_Allreduce.

I also recommend opening/closing/writing to files only on a single rank (for example if cs_glob_rank_id < 1), to avoid overwriting files between processors.

Best regards,

Yvan
jankolino
Posts: 12
Joined: Fri Jun 22, 2018 2:03 pm

Re: Extract 2D profiles and compute averages

Post by jankolino »

Hello Yvan,

thanks for all the help, with your recommendations my code is running well now.

Kind regards,
Jan
jankolino
Posts: 12
Joined: Fri Jun 22, 2018 2:03 pm

Re: Extract 2D profiles and compute averages

Post by jankolino »

Hello again,

Now, I am trying to run my code faster and therefore am trying to avoid writing in files as much as possible. With that said, I want to create an array, that is not going to be reinitialized in every time step but only updated. Is there any nice solution to this or should I use cs_field for that? Because, if I understand correctly, cs_field defines some field in every mesh point and this is not what I need.

Thanks again.
Kind regards,
Jan
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Extract 2D profiles and compute averages

Post by Yvan Fournier »

Hello,

In C, if uou declare an array pointer as static in a function, its value will be saved from one call ro rhe next, so you can use this to keep values after the first initialization.

Also check the cs_tlmer_stats.csv to see which steps cost most time (in a regular case and time steps without IO, gradiens plus linear solvers should be mist of the total).

Best regards,

Yvan
Post Reply