# differentiate between dimensionles and non-dimensionles fields

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

 April 26, 2012, 07:46 differentiate between dimensionles and non-dimensionles fields #1 Senior Member   Illya Shevchuk Join Date: Aug 2009 Location: Darmstadt, Germany Posts: 174 Rep Power: 7 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 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

 April 26, 2012, 10:43 #2 Senior Member   David Gaden Join Date: Apr 2009 Location: Winnipeg, Canada Posts: 397 Rep Power: 12 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

April 26, 2012, 12:06
#3
Senior Member

Illya Shevchuk
Join Date: Aug 2009
Posts: 174
Rep Power: 7
Hi David,
Quote:
 Originally Posted by marupio 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

 April 26, 2012, 12:20 #4 Senior Member   David Gaden Join Date: Apr 2009 Location: Winnipeg, Canada Posts: 397 Rep Power: 12 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

 April 27, 2012, 05:15 #5 Senior Member   Illya Shevchuk Join Date: Aug 2009 Location: Darmstadt, Germany Posts: 174 Rep Power: 7 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.

 April 27, 2012, 08:02 #6 Senior Member   Illya Shevchuk Join Date: Aug 2009 Location: Darmstadt, Germany Posts: 174 Rep Power: 7 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

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

All times are GMT -4. The time now is 18:34.