|
[Sponsors] |
Problems with using the Laplacian operator in Openfoam |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 4, 2020, 06:20 |
Problems with using the Laplacian operator in Openfoam
|
#1 |
New Member
Edmund Teller
Join Date: Feb 2020
Posts: 12
Rep Power: 6 |
Hi,
sorry, I feel like I'm just doing this incorrectly, but I'm trying to add a description of the magnetic field to one of the compressible solvers, and I have modified the energy equation like so: Code:
fvScalarMatrix EEqn ( fvm::ddt(rho, he) + fvm::div(phi, he) + fvc::ddt(rho, K) + fvc::div(phi, K) - 2*DMU*fvc::div(B*(B & U)) + (DDB*fvc::div(fvc::div(B*B))) + ( he.name() == "e" ? fvc::div ( fvc::absolute(phi/fvc::interpolate(rho), U), p, "div(phiv,p)" ) : -dpdt ) - fvm::laplacian(turbulence->alphaEff(), he) - DDB*fvm::laplacian(sqr(B)) == fvOptions(rho, he) ); Code:
- DDB*fvm::laplacian(sqr(B)) Code:
In file included from mhdFoam.C:149:0: EEqn.H: In function 'int main(int, char**)': EEqn.H:21:34: error: no matching function for call to 'laplacian(Foam::tmp<Foam::GeometricField<Foam::SymmTensor<double>, Foam::fvPatchField, Foam::volMesh> >)' - DDB*fvm::laplacian(sqr(B)) ^ In file included from /home/edders/OpenFOAM-dev/src/finiteVolume/lnInclude/fvmLaplacian.H:188:0, from /home/edders/OpenFOAM-dev/src/finiteVolume/lnInclude/fvm.H:46, from /home/edders/OpenFOAM-dev/src/finiteVolume/lnInclude/fvCFD.H:10, from mhdFoam.C:36: /home/edders/OpenFOAM-dev/src/finiteVolume/lnInclude/fvmLaplacian.C:45:1: note: candidate: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&) laplacian ^ Thanks |
|
March 4, 2020, 06:48 |
|
#2 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hi,
is your B field really a volVectorField? Code:
EEqn.H:21:34: error: no matching function for call to 'laplacian(Foam::tmp<Foam::GeometricField<Foam::SymmTensor<double>, Foam::fvPatchField, Foam::volMesh> >)'
__________________
Keep foaming, Tobias Holzmann |
|
March 5, 2020, 05:31 |
|
#3 |
New Member
Edmund Teller
Join Date: Feb 2020
Posts: 12
Rep Power: 6 |
Hi, yeah the B field is defined in createFields.H as
Code:
Info<< "Reading field B\n" << endl; volVectorField B ( IOobject ( "B", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ); But I fixed my problem anyway, I guess because that equation is defined as fvScalarMatrix, it required the terms in the Laplacian to be volScalarField, and the dot product of the B field didn't produce that type for some reason. So i defined a new scalar field above it: Code:
volScalarField BB ( IOobject ( "BB", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), B&B ); and then used it in the equation: Code:
fvScalarMatrix EEqn ( fvm::ddt(rho, he) + fvm::div(phi, he) + fvc::ddt(rho, K) + fvc::div(phi, K) - 2*DMU*fvc::div(B*(B & U)) + (DDB*fvc::div(fvc::div(B*B))) + ( he.name() == "e" ? fvc::div ( fvc::absolute(phi/fvc::interpolate(rho), U), (p+DMU*(BB)), "div(phiv,p)" ) : -dpdt ) - fvm::laplacian(turbulence->alphaEff(), he) - DDB*fvc::laplacian((BB)) == fvOptions(rho, he) ); and now it seems to work. |
|
March 5, 2020, 05:33 |
|
#4 |
New Member
Edmund Teller
Join Date: Feb 2020
Posts: 12
Rep Power: 6 |
also yes, I think the output from the Laplacian, when the input was a volVectorField, is a symmTensor field
|
|
March 5, 2020, 07:56 |
|
#5 |
Senior Member
Gerry Kan
Join Date: May 2016
Posts: 373
Rep Power: 11 |
Howdy Folks:
At the risk of hijacking the thread ...... I am trying to perform a Laplacian of a volVectorField U that contains only the Uz component (i.e., Ux and Uy will be set to zero). It should be implemented in UEqn.H like this: Code:
tmp<fvVectorMatrix> tUEqn ( fvm::ddt(rho, U) + fvm::div(phi, U) + turbulence->divDevRhoReff(U) == fvOptions(rho, U) + fvm::laplacian(rho*50.0,Uz) ); To produce the Uz volVectorField, I tried the following method: Code:
volVectorField& Uz = U.component(vector::Z) Then I tried the following: Code:
volVectorField Uz(U.component(vector::Z), mesh) I am not quite sure how I should proceed. Any pointer would be greatly appreciated. Sincerely, Gerry. |
|
March 5, 2020, 08:11 |
|
#6 |
New Member
Edmund Teller
Join Date: Feb 2020
Posts: 12
Rep Power: 6 |
Hi, yeah it's looking for that file because it want you to set boundary conditions for the new vector field you've defined, so you can either add a Uz file to the ./0/ folder, with the boundary conditions taken from U, or you can define this vector field in a similar way to how I defined the BB field above, i.e. with NO_READ defined so that it doesn't look for BCs
|
|
March 5, 2020, 12:31 |
|
#7 | |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Quote:
The first way of his implementation is not working because a volvectorField is not a scalar Field. The return of U.x() does return the x component as a scalarField (out of the box, check doxygen). The second one calls the constructor of Geometric Field and uses the provided information. However, if he uses the second approach and a new file in the 0 folder needs to be created as you already pointed out (never mind the name of the file). However, he does have again the same problem, if I get his question correct and also the code snippet. I guess he wants the velocity of z only to be diffused while the other components should only feel the convection and time term't. No idea for which purpose one would use this but this would make at least a bit sense to me, otherwise the equation is somehow wired (and I am sure it does not work with fvm) This assumption comes from the fact that he tries to reference the U.x() component rather than copying it or just use the second way you provided. The first question we should know is, is my assumption correct? If not, use the approach given by Edmund and the explicit Laplace operator.
__________________
Keep foaming, Tobias Holzmann |
||
March 5, 2020, 12:34 |
|
#8 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
This is wrong. Setting No_Read probably needs the boundaries. In your case it is taken from the fields you set here. If you don't use the B field here you are forced to give information about the boundaries. You just had luck.
__________________
Keep foaming, Tobias Holzmann |
|
March 5, 2020, 15:45 |
|
#9 | |
Senior Member
Gerry Kan
Join Date: May 2016
Posts: 373
Rep Power: 11 |
Quote:
You guessed correct. I would like to introduce a numerical diffusion term to the z-Momentum equation only. I use a compressible solver and I am seeing spurious oscillation in Uz near the corresponding boundaries. I ruled out pressure-momentum coupling, as well as advection scheme. My next guess is the sysyem's sensitivity to boundary conditions. This is ehy I want to see if adding the diffusion term in z alone, at least at the start of the simulation, would dampen the oscillation sufficiently. I have posted my original question here for reference. Gerry. |
||
March 5, 2020, 15:53 |
|
#10 |
Senior Member
Gerry Kan
Join Date: May 2016
Posts: 373
Rep Power: 11 |
Now that you mentioned .... you're both right. fvm::lsplacian won't work on U in UEwn because it must be operated on a volScalarField, not a volVectorField. The closest. thing I can think of is something similar to the turbulent stress tensor.
Having said that, there is a part of me that tells me the offending velocity oscillation could be remedied without artificial diffusion; I just don't know how exactly. Gerry. |
|
March 5, 2020, 16:42 |
|
#11 | |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Quote:
However, I guess the easiest is to use a vector as diffusivity rather than modifying the field here: Code:
// Correct the dimensions, should be m²/s I guess const dimensionedVector diffusivity("diffusivity", dimensionSet(0,0,0,0,0,0,0), vector(50,0,0)); // In your equation fvm::laplacian(diffusivity, U);
__________________
Keep foaming, Tobias Holzmann |
||
March 5, 2020, 16:59 |
|
#12 |
Senior Member
Gerry Kan
Join Date: May 2016
Posts: 373
Rep Power: 11 |
Hallo Tobias:
I suppose I can try first with the entire U first. If I get the desired damping effects in Uz, I can think about isolating the Laplacian for the z-momentum only. Thanks, Gerry. |
|
March 6, 2020, 04:49 |
|
#13 |
Senior Member
Gerry Kan
Join Date: May 2016
Posts: 373
Rep Power: 11 |
Dear Tobias:
Now I have a bigger screen, I managed to read your response more carefully. Actually, declaring a diffusivity vector and setting the other two components to zero will serve the purpose of introducing one-dimension diffusion without having to reconstruct a new volVectorField. Thank you very much for this. Further, based on this thread, I realize that it is still possible to call a Laplacian of U inside UEqn, which is still good. I implemented it quickly to test, and the code compiled. However, there was a linker error Code:
undefined reference to `Foam::fv::laplacianScheme< Foam::Vector<double>, Foam::Vector<double>>::IstreamConstructorTablePtr_' Thanks, Gerry. P.S. - Here is my implementation, in case there is a typo that I did not catch ... Code:
// in the main foam solver C file before the time loop const dimensionedVector GAMMA ( "GAMMA", dimensionSet ( 1, -1, -1, 0, 0, 0, 0 ), vector ( 0.0, 0.0, 1.0 ) ); // in UEqn.H tmp<fvVectorMatrix> tUEqn ( fvm::ddt(rho,U) + fvm::div(phi,U) + turbulence->divDevRhoReff(U) == fvOptions(rho,U) + fvm::laplacian(GAMMA,U) ); |
|
March 6, 2020, 10:16 |
|
#14 |
Senior Member
Gerry Kan
Join Date: May 2016
Posts: 373
Rep Power: 11 |
It looks like the first argument of the laplacian operator is to be a volScalarField, at least based on what I saw from scouring the OpenFOAM source files. Changing the definition of the diffusivity term accordingly solved linker issue for now.
At the moment I am looking at how the artificial damping will affect the velocity field ... so far the solver runs stably. I also noticed that this also affects the p and T transport processes, possibly because this artificial diffusion coefficient being set a bit too high. The job is still running as we speak ... let's see how it looks like. Gerry. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Map of the OpenFOAM Forum - Understanding where to post your questions! | wyldckat | OpenFOAM | 10 | September 2, 2021 06:29 |
OpenFOAM v3.0+ ?? | SBusch | OpenFOAM | 22 | December 26, 2016 15:24 |
OpenFOAM Training Jan-Apr 2017, Virtual, London, Houston, Berlin | cfd.direct | OpenFOAM Announcements from Other Sources | 0 | September 21, 2016 12:50 |
OpenFOAM Training, London, Chicago, Munich, Houston 2016-2017 | cfd.direct | OpenFOAM Announcements from Other Sources | 0 | September 14, 2016 04:19 |
[OpenFOAM.org] Problems with instalation of OpenFOAM 2.2.0 by source | Prosiaczek | OpenFOAM Installation | 3 | March 13, 2015 17:10 |