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/)
-   -   differentiate between dimensionles and non-dimensionles fields (https://www.cfd-online.com/Forums/openfoam-programming-development/100503-differentiate-between-dimensionles-non-dimensionles-fields.html)

linch April 26, 2012 07:46

differentiate between dimensionles and non-dimensionles fields
 
Hi guys,

I want to use the same template for dimensionless and non-dimensionless fields (an a MULES modification).

For the beginning I have
Code:

template<class RhoType>
void ....
(
const RhoType& rho
)

At some point I want to multiply something by the dimensionless value of rho. The Problem is, rho may have a dimensions or may already be dimensionless.

So I want to do something like:
Code:

const dimensionedScalar dimRho("dimRho", rho.dimensions(), 1.0);
a*rho/dimRho

if rho has rho.dimensions(), and simply
Code:

a*rho
if it rho.dimensions() doesn't exist.

How can I check if rho has a member 'dimensions'?

Best regards,
Illya

marupio April 26, 2012 10:43

Not sure I understand the problem.

Do you actually have two types defined? Or, are they both RhoTypes, one of which has dimensions defined, and the other does not?

Instead of a*rho/dimRho, you could use a*rho.value().

linch April 26, 2012 12:06

Hi David,
Quote:

Originally Posted by marupio (Post 357220)
Not sure I understand the problem.

Do you actually have two types defined? Or, are they both RhoTypes, one of which has dimensions defined, and the other does not?

The second case.
Quote:

Instead of a*rho/dimRho, you could use a*rho.value().
In my particular case it can be either geometricOneField(), which has neither .dimensions() nor .value(), or a volScalarField, which have both .dimensions() and .field(). What I need is a universal formulation that is valid for both of them.

This is a minimum requirement. But since it is a template, the formulation should be as universal as possible. It would be nice, if it would be valid also for other types of rho.

Because it sounds too abstract, here is some code. Here is the equation to be solved (originates from MULESTemplates.C):
Code:

fvScalarMatrix psiConvectionDiffusion
    (
        fvm::ddt(rho, psi)
      + fv::gaussConvectionScheme<scalar>(mesh, phi, UDs).fvmDiv(phi, psi)
      - fvm::Sp(Sp, psi)
      - Su
    );

As I already said, rho can be anything, that makes sense. In my case either geometricOneField or volScalarField. The dimensions of the fluxes phi logically depend on the dimensions of rho.

But before solving the equation, this coefficient is to be computed:
Code:

tmp<surfaceScalarField> Cof =
            mesh.time().deltaT()*mesh.surfaceInterpolation::deltaCoeffs()
          *mag(phi)/mesh.magSf()

This coefficient have to be dimensionless. Unfortunately it isn't. It has the dimensions of rho instead. So it works for geometricOneField as rho but doesn't work for a dimensioned volScalarField, e.g. for a density field.

So I have to somehow modify it, to have dimensions (0,0,0,0,0,0,0), no mater which type of rho do I have.

Best regards,
Illya

marupio April 26, 2012 12:20

I see, it's a template, and it changes behaviour depending on which type is used. You can accomplish this with template specialization. You can define different implementations of the same function given a specific template parameter. OpenFOAM does this routinely. For example, Field. Field defines the generic functions, scalarField redefines many of these functions for use specifically with scalars.

linch April 27, 2012 05:15

I know that templates can be specified, but I don't know how to do it in an elegant way. Copying the whole MULES::implicitSolve and than changing only one line in it doesn't seem to be a good approach. In this case I would have the same function twice with an only little difference in implementation.

linch April 27, 2012 08:02

are you sure the is no possibility to check if rho has a member named "dimensions"? It would make everything much easier.

Best regards,
Illya


All times are GMT -4. The time now is 20:27.