|
[Sponsors] |
April 17, 2018, 13:14 |
Issue adding force
|
#1 |
Member
Join Date: Jun 2017
Posts: 58
Rep Power: 9 |
I'm trying to add a force to a modified simpleFoam. I managed to get the code to execute without any floating point errors but the solution is odd and non-physical so I think I may have made a mistake - in particular, I notice odd effects across regions where the cell size changes, making me think I've mistakenly multiplied by volume/area somewhere, or missed this out.
My implementation is in the UEqn is: Code:
volScalarField u("u", (vector(1,0,0) & U)); volScalarField v("v", (vector(0,1,0) & U)); volScalarField w("w", (vector(0,0,1) & U)); volScalarField Fx("Fx",(f*v-l*w*J)); volScalarField Fy("Fy",-f*u); volScalarField Fz("Fz",(pow(J,2)-1)*(l*u/J+beta*(T-TRef)*mag(g))+l*u/J+J*zeta*(p-pow(w,2))); volVectorField F("F",Fx*vector(1,0,0)+Fy*vector(0,1,0)+Fz*vector(0,0,1)); surfaceScalarField Ff = fvc::interpolate(F)&mesh.Sf(); solve(UEqn == fvc::reconstruct ( ( fvc::interpolate(rhok-1)*(g & mesh.Sf()) + Ff - fvc::snGrad(p)*mesh.magSf() ) ) ); fvOptions.correct(U); } My understanding of "fvc::interpolate(rhok-1)*(g & mesh.Sf())" is that rhok is extrapolated to the cell surfaces, then multiplied by g crossed with the mesh surface, to give the rho*g buoyancy term (ignore the -1 in my code) g is a uniformDimensionedVectorField, whereas fvc::interpolate(F) returns a volumeVectorField, so I don't think "fvc::interpolate(F)&mesh.Sf();" is doing the same thing as "(g & mesh.Sf())". But I can't get any other variation to compile. I thought rewriting F as a vectorField rather than a volumeVectorField would fix it (so the code is just surfaceScalarField Ff = F&mesh.Sf()) but I can't get it to compile like that, which I find quite confusing since I thought g in this context was a vectorField, unless there's a subtle difference between vectorField and uniformDimensionedVectorField that I am missing? Anyway, I feel like I am missing something obvious, can anyone help me out? Thank you EDIT: Looking up uniformDimensionedVectorField, the only reference I can see is related to the g term, and if I add "Info << g << nl" in my code, the console shows it's just a dimensioned vector, despite the field name? This would make sense because I can do something like "Ff = F[1]&mesh.Sf()" and it compiles fine, so I need a single vector, not a vector field. I am thinking perhaps g&mesh.Sf() is the cross product of the vector g to every vector within mesh.Sf(), and I need to do the same thing but element by element, since F is a field rather than a singular vector? But this makes me think my original method of "surfaceScalarField Ff = fvc::interpolate(F)&mesh.Sf();" was correct. (Personally I am hoping not since I can't find any other areas where I could have made a mistake) Does anyone have any insight? Cheers |
|
April 26, 2018, 09:23 |
|
#2 |
Member
Join Date: Jun 2017
Posts: 58
Rep Power: 9 |
Sorry for the bump but can anyone confirm if my method is correct or not? Thank you
|
|
April 27, 2018, 05:28 |
Cleaner code
|
#3 |
Member
Tomas Denk
Join Date: May 2017
Posts: 30
Rep Power: 9 |
Hi Sturgeon,
I'm not able to pin point where in your code is the mistake, because there are several symbols that are not defined in the code snippet. What I would do first if I were in your situation is dimension analysis. The equation for U is momentum equation and its dimension is N*m. So it seems that all components of your vector F should be in N/m. Make sure that all terms in Fz (which is sort of complex) are od the same dimension too. I would also warn you not to use practice like Code:
beta*(T-Tref)*mag(g) Code:
g = (0, -9.81, 0) m/s^2 Code:
fvc::interpolate(rhok-1)*(g & mesh.Sf()) Code:
beta*(T-Tref)*mag(g) A while ago I wanted to added time averaged effect of a stirrer into momentum equation. My vector had correct dimension and worked perfectly: Code:
tmp<fvVectorMatrix> tUEqn ( fvm::div(phi, U) + MRF.DDt(rho, U) + turb.divDevRhoReff(U) == fvOptions(rho, U) + stirrerMomentum ); fvVectorMatrix& UEqn = tUEqn.ref(); Tom |
|
April 27, 2018, 07:15 |
|
#4 | ||
Member
Join Date: Jun 2017
Posts: 58
Rep Power: 9 |
Quote:
Quote:
Thanks for your input |
|||
April 27, 2018, 10:17 |
|
#5 | |
Member
Tomas Denk
Join Date: May 2017
Posts: 30
Rep Power: 9 |
Quote:
Code:
Fx beta*(T-TRef)*(vector(1,0,0)&g)) Fy beta*(T-TRef)*(vector(0,1,0)&g)) Fz beta*(T-TRef)*(vector(0,0,1)&g)) |
||
May 3, 2018, 17:00 |
|
#6 | |
Member
Join Date: Jun 2017
Posts: 58
Rep Power: 9 |
Quote:
You say my vector F should be N/m. If I output the dimensions of F to the console, I'm getting ms^-2. But if I look at the other terms in the momentum predictor (so I use reconstruct individually on fvc::interpolate(rhok-1)*(g & mesh.Sf()) and fvc::snGrad(p)*mesh.magSf() and output their dimensions) they are also ms^-2. Surely my F must therefore be consistent with this? Last edited by sturgeon; May 3, 2018 at 18:19. |
||
May 4, 2018, 04:19 |
|
#7 | |
Member
Tomas Denk
Join Date: May 2017
Posts: 30
Rep Power: 9 |
Quote:
Code:
fvc::interpolate(rhok-1)*(g & mesh.Sf()) + Ff - fvc::snGrad(p)*mesh.magSf() Code:
Ff = fvc::interpolate(F)&mesh.Sf() |
||
May 4, 2018, 06:10 |
|
#8 | |
Member
Join Date: Jun 2017
Posts: 58
Rep Power: 9 |
Quote:
Code:
fvc::interpolate(rhok-1)*(g & mesh.Sf() Code:
fvc::snGrad(p)*mesh.magSf() |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Hydrodynamic force? | arun7328 | STAR-CCM+ | 24 | July 25, 2020 05:04 |
Adding volumetric body force term to compressibleInterFoam | alicharchi | OpenFOAM Programming & Development | 3 | April 18, 2016 12:40 |
adding dispersion force term in UEqn leads to oscillations of velocity field | sr_tenedor | OpenFOAM Programming & Development | 2 | June 6, 2014 07:59 |
A Little Drag Force to Drag Coeffiecient Issue | MMP | Main CFD Forum | 0 | March 28, 2011 18:21 |
Help with chtMultiRegionFoam | jbvw96 | OpenFOAM Running, Solving & CFD | 2 | December 26, 2010 18:16 |