CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Counterpart representation of fvc::grad ??? (https://www.cfd-online.com/Forums/openfoam-programming-development/239447-counterpart-representation-fvc-grad.html)

SHUBHAM9595 November 5, 2021 18:16

Counterpart representation of fvc::grad ???
 
Dear Foamers,

I'm trying to solve a Equation for a volVectorField (H) such that

\nabla \cdot H = - \nabla \cdot Z

where, Z is another volVectorField and is of less concern.

Here, apparently the H field is irrotational and thus should also satisfy \nabla \times H = 0.

To justify the above condition, the H is represented in terms of gradient of scalar potential H = \nabla \phi (as the curl of gradient of scalar function is always zero )

Now, after substitution, the initial equation can be rewritten as \nabla \cdot H = - \nabla \cdot Z  \Rightarrow \nabla^{2}\phi = \nabla \cdot Z which then can be solved by constructing a scalar matrix as shown below

Code:

tmp<fvScalarMatrix> tphiHEqn
(
 fvm::laplacian(phiH)  == -fvc::div(Z)
);

where phiH (scalar potential) is a volScalarField.
Now, it is very easy to represent/reconstruct the H in terms of this scalar potential using
Code:

volVectorField H = fvc::grad(phiH);
But I need to initialize phiH in terms of H, hence the question is how can we write phiH (volScalarField) in terms of H (volVectorField)??

Field dimensions for both field are as mentioned below
H = [0 -1 0 0 0 1 0];//A/m
phiH = [0 0 0 0 0 1 0];//A

I've already tried some workarounds which are mentioned below, but unfortunately they are unable to resolve the issue .

1.
Code:

phiH = fvc::surfaceIntegrate(fvc::flux(H));
here
flux will convert the volVectorField to surfScalar &
surfaceIntegrate will convert surfScalarField to volScalarField
However, the dimensions of RHS appear to be A.m2 whereas LHS have dim of A.


2.
Code:

phiH = fvc::domainIntegrate(Foam::mag(H));
domainIntegrate will multiply H by its grid volume....also leads to the incompatible dimension

3.
Code:

phiH = (fvc::average((fvc::flux(H))))
average will convert surfScalarField to volScalarField....also leads to the incompatible dimension



All suggestions/comments are welcome. Thanks in advance:) !!!

Tobermory November 7, 2021 13:11

My advice is take a step back and think again about what you are trying to do. You effectively want to solve \nabla \phi  = H for \phi. Now, this equation is saying that the gradient of \phi at any point is determined by the local value of H ... but this means that you cannot calculate the value of \phi at that point just from the local gradient ... you need to find a point where you know the value of \phi (from a boundary condition), and then do a line integral from there to the point you are interested in. So, do you see now why you are struggling to find an analytical solution to this, based on the local values of H?

Or, a TLDR answer is - you can't do it that way; instead, why not just get OpenFOAM to solve the equation \nabla \phi  = H with appropriate BCs, as a precursor step? Good luck!

SHUBHAM9595 November 8, 2021 14:01

Hi Tobermory, thanks for your comment. Perhaps I was not able to mention the stuff in better way. As there is some misunderstanding which leads to the following part of your comment

Quote:

You effectively want to solve \nabla \phi = H.
As mentioned earlier, we want to solve the \nabla^{2} \phi = \nabla\cdot M to obtain \phi.

Later on using this scalar potential, we compute the H as H = \nabla \phi

Can you please elaborate the following statement :confused:?
Quote:

why not just get OpenFOAM to solve the equation \nabla \phi  = H with appropriate BCs, as a precursor step?

Tobermory November 9, 2021 04:32

No, no - I do understand what you mean ... Apologies if my comment:
Quote:

You effectively want to solve \nabla \phi  = H for \phi
was unclear. Recall that you asked earlier:
Quote:

But I need to initialize phiH in terms of H, hence the question is how can we write phiH (volScalarField) in terms of H (volVectorField)??
But \phi and H are linked by \nabla \phi  = H, and so if you want to express \phi in terms of H, then you have to solve the expression \nabla \phi  = H. That was the point of my initial paragraph - to get you to think about the fundamental of what you are trying to do, and why there is not a simple analytical answer to it.

For the second part, how to solve \nabla \phi  = H, it occurred to me that you could just set this up as an equation for OpenFOAM to solve, eg something like
Code:

tmp<fvScalarMatrix> tphiBoundaryEqn
(
 fvm::grad(phiH)  == H
);

supply the appropriate boundary conditions for H and let the code do the line integration to solve for phi. Just a suggestion - I haven't thought it all the way through. Let us know how you get on & good luck!


All times are GMT -4. The time now is 07:28.