Non-constant Diffusion Coefficient
Hello,
I'm currently solving the transport equation as follows: Code:
solve Code:
Diff = max( upper_value*(1-C) , lower_value ) |
You can hardcode it. All you have to do it to create a volScalarField with a diffusivity-value for each cell.
Code:
volScalarField Diff Stefan P.S. For speed reasons, the declaration of Diff can be done outside the time loop. |
Perfect.. it works.. thank you!
|
I think the loop can be avoided, Did you try
Code:
Diff = max(upperValue*(1.0-C),lowerValue); Regards. |
Santiago, do you know if there's any difference in using the openfoam operations on fields instead of a forAll loop other than readability?
|
Anton, good question! Fields operations are quite hard to hack, but I think I got it, max in this case:
Code:
GeometricFieldFunctions.C Hope it might be useful. Regards. |
Santiago, thanks a lot for your effort, I appreciate it. I'll try to do a profiling run to see if I can confirm your findings.
|
Santiago, your assumption was correct! I tested this on my own solver and the result was astounding. By replacing two forAll loops in my code by the top level notation, the computation got 3x faster.
My initial motivation to use forAll was higher optimization - following code should result in a loop to calculate A, and a second one to calculate D: A = B * C; D = (E + A) * (F + A); With a forAll loop you can do the computation by looping through the fields only once, yet it turns out now it's slower anyway. The OpFunc function you posted makes me think of expression templates, but to be honest I don't fully understand it yet. As you mentioned hacking through all the macros is not straight-forward. |
Anton, thanks for sharing your experience. These procedures with macros, etc. are well optimized for up two ops at the same time. In your case you have four ops and they are nested, preprocessing requires to separate the loops and I think it cannot be inlined at all, nevertheless, as you showed, field ops are still faster in this case. I think it isn't the rule ever and it is necessary to do some profiling to assure it.
Regards. |
Hi there!!
I am trying to solve the laplace's equation for a scalar phi over an arbitrary domain!! do you know how I should modify the laplacianFoam application?? I have noticed in the .C file the laplacian application has 2 inputs and I just need one of them: laplacian(phi). By the moment, the steps I have followed have been: 1) create my phi volScalarField in the same manner as T in the original laplacianFoam, and comment the rest 2) leave the original libraries in the top of the laplacianFoam.C file and modify the diffusion equation by solve ( fvm::laplacian(phi); ); It should be very easy, but I don't see the mistake! Thanks a lot! |
Hi there!!
I am trying to solve the laplace's equation for a scalar phi over an arbitrary domain!! do you know how I should modify the laplacianFoam application?? I have noticed in the .C file the laplacian application has 2 inputs and I just need one of them: laplacian(phi). By the moment, the steps I have followed have been: 1) create my phi volScalarField in the same manner as T in the original laplacianFoam, and comment the rest 2) leave the original libraries in the top of the laplacianFoam.C file and modify the diffusion equation by solve ( fvm::laplacian(phi); ); It should be very easy, but I don't see the mistake! Thanks a lot! |
All times are GMT -4. The time now is 17:33. |