CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

differentiate between dimensionles and non-dimensionles fields

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 26, 2012, 08:46
Default differentiate between dimensionles and non-dimensionles fields
  #1
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 16
linch is on a distinguished road
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
linch is offline   Reply With Quote

Old   April 26, 2012, 11:43
Default
  #2
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 21
marupio is on a distinguished road
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().
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   April 26, 2012, 13:06
Default
  #3
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 16
linch is on a distinguished road
Hi David,
Quote:
Originally Posted by marupio View Post
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
linch is offline   Reply With Quote

Old   April 26, 2012, 13:20
Default
  #4
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 21
marupio is on a distinguished road
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.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   April 27, 2012, 06:15
Default
  #5
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 16
linch is on a distinguished road
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 is offline   Reply With Quote

Old   April 27, 2012, 09:02
Default
  #6
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 16
linch is on a distinguished road
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
linch is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 12:14.