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

Insert Dimensioned Salar

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

Like Tree7Likes
  • 2 Post By shereez234
  • 2 Post By rhythm
  • 1 Post By shereez234
  • 1 Post By rhythm
  • 1 Post By rhythm

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 26, 2016, 11:22
Lightbulb Insert Dimensioned Salar
  #1
Senior Member
 
FlyBob91's Avatar
 
Join Date: Mar 2016
Location: Bergamo
Posts: 157
Rep Power: 10
FlyBob91 is on a distinguished road
Hello to all,
i'm creating a new adjoint solver and i have to implement new boundary conditions.
i made all but i still have to add a dimensioned scalar constant to make the boundary condition correct, dimensionally talking.


i added these lines to the adjointOutletVelocityFvPatchVectorField.C

Code:
scalar Ke = readScalar(db().lookupObject<IOdictionary>("transportProperties").lookup("Ke"));
and i compiled correctly the solver.

Here my transportProperties file

Code:
transportModel  Newtonian;

nu              nu [0 2 -1 0 0 0 0] 1.02e-06;

Ke             Ke [0 7 -5 0 0 0 0] 1;

lambda          lambda   [0 -2 1 0 0 0 0] 1e5;
alphaMax        alphaMax [0 0 -1 0 0 0 0] 200.0;
Unfortutely i have the following error when i run my case

Code:
wrong token type - expected Scalar, found on line 22 the word 'Ke'

file: /home/roby/Scrivania/HAGAGA/constant/transportProperties.Ke at line 22.

    From function operator>>(Istream&, Scalar&)
    in file lnInclude/Scalar.C at line 93.

Any idea?

Thanks for help
FlyBob91 is offline   Reply With Quote

Old   November 26, 2016, 12:26
Default
  #2
Senior Member
 
shereez234's Avatar
 
M Sereez
Join Date: Jan 2014
Location: England
Posts: 352
Blog Entries: 1
Rep Power: 13
shereez234 is on a distinguished road
You are defining a scalar and giving it dimensions. If you want a dimensioned scalar then the correct way to declare it is:

const dimensioned<double> ke;
FlyBob91 and sadra2003 like this.
shereez234 is offline   Reply With Quote

Old   November 28, 2016, 04:15
Default
  #3
Senior Member
 
FlyBob91's Avatar
 
Join Date: Mar 2016
Location: Bergamo
Posts: 157
Rep Power: 10
FlyBob91 is on a distinguished road
Quote:
Originally Posted by shereez234 View Post
You are defining a scalar and giving it dimensions. If you want a dimensioned scalar then the correct way to declare it is:

const dimensioned<double> ke;
Hi shereez,
thank you for your reply. I corrected my code and that line doesn't give me error anymore.
However another very strange error has appeared.
Here part of my code

Code:
   // GETTING NU
      const incompressible::RASModel& ras
    = db().lookupObject<incompressible::RASModel>("RASProperties");
    
    scalarField nuw
    = ras.nuEff()().boundaryField()[patch().index()];

    // DISTANCE^(-1)
    const scalarField& deltainv = patch().deltaCoeffs();

    // nu / h
    const scalarField& nd =  - nuw * deltainv;

    // NORMAL VECTOR
    vectorField n = patch().nf();

    // TANGENT VECTOR
    vectorField r = patch().Cf() - vector(10,11,12);

    // SCALAR NORMAL VELOCITY COMPONENT
    scalarField Un = Up & patch().nf();

    // DIMENSIONED CORRECTION COEFFICIENT

    const dimensioned<double> Ke = readScalar(db().lookupObject<IOdictionary>("transportProperties").lookup("Ke"));  

    // PATCH-ADIACENT TANGENT ADJOINT VELOCITY (VECTOR)
    vectorField Uac   = Uap.patchInternalField();
    vectorField Uac_n = ( Uac & patch().nf() ) * patch().nf();
    vectorField Uac_t = Uac - Uac_n;

    // TANGENT VELOCITY COMPONENT (VECTOR)
    vectorField U_n = ( Up & patch().nf() ) * patch().nf();
    vectorField U_t = Up - U_n;


    vectorField :: operator = (
                              phiap*patch().Sf()/sqr(patch().magSf())
                              + (1/(Un + nd))
                              * (nd * Uac_t + Ke *

 (n ^ r) / (pow(mag(r^U_t),3) + SMALL))
                              );
and here part of my error

Code:
/home/roby/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/GeometricFieldFunctionsM.C:119:55: note: template<template<class> class PatchField, class GeoMesh> Foam::tmp<Foam::GeometricField<Foam::Tensor<double>, PatchField, GeoMesh> > Foam::operator*(const Foam::GeometricField<Foam::Vector<double>, PatchField, GeoMesh>&)
 tmp<GeometricField<ReturnType, PatchField, GeoMesh> > operator Op             \
                                                       ^
/home/roby/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/GeometricTensorField.C:60:1: note: in expansion of macro ‘UNARY_OPERATOR’
 UNARY_OPERATOR(tensor, vector, *, hdual, transform)
 ^
/home/roby/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/GeometricFieldFunctionsM.C:119:55: note:   template argument deduction/substitution failed:
 tmp<GeometricField<ReturnType, PatchField, GeoMesh> > operator Op             \
                                                       ^
/home/roby/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/GeometricTensorField.C:60:1: note: in expansion of macro ‘UNARY_OPERATOR’
 UNARY_OPERATOR(tensor, vector, *, hdual, transform)
 ^
adjointOutletVelocity/adjointOutletVelocityFvPatchVectorField.C:143:58: note:   ‘const Foam::dimensioned<double>’ is not derived from ‘const Foam::GeometricField<Foam::Vector<double>, PatchField, GeoMesh>’
                               * (nd * Uac_t + Ke * (n ^ r) / (pow(mag(r^U_t),3) + SMALL))
                                                          ^
In file included from /home/roby/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/GeometricTensorField.C:30:0,
                 from /home/roby/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/GeometricTensorField.H:88,
                 from /home/roby/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/GeometricFields.H:36,
                 from /home/roby/OpenFOAM/OpenFOAM-2.3.0/src/finiteVolume/lnInclude/volFields.H:37,
                 from adjointOutletVelocity/adjointOutletVelocityFvPatchVectorField.C:27:
/home/roby/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/GeometricFieldFunctionsM.C:147:55: note: template<template<class> class PatchField, class GeoMesh> Foam::tmp<Foam::GeometricField<Foam::Tensor<double>, PatchField, GeoMesh> > Foam::operator*(const Foam::tmp<Foam::GeometricField<Foam::Vector<double>, PatchField, GeoMesh> >&)
 tmp<GeometricField<ReturnType, PatchField, GeoMesh> > operator Op             \
                                                       ^
/home/roby/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/GeometricTensorField.C:60:1: note: in expansion of macro ‘UNARY_OPERATOR’
 UNARY_OPERATOR(tensor, vector, *, hdual, transform)
 ^
/home/roby/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/GeometricFieldFunctionsM.C:147:55: note:   template argument deduction/substitution failed:
 tmp<GeometricField<ReturnType, PatchField, GeoMesh> > operator Op             \
                                                       ^
/home/roby/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/GeometricTensorField.C:60:1: note: in expansion of macro ‘UNARY_OPERATOR’
 UNARY_OPERATOR(tensor, vector, *, hdual, transform)
 ^
adjointOutletVelocity/adjointOutletVelocityFvPatchVectorField.C:143:58: note:   ‘const Foam::dimensioned<double>’ is not derived from ‘const Foam::tmp<Foam::GeometricField<Foam::Vector<double>, PatchField, GeoMesh> >’
                               * (nd * Uac_t + Ke * (n ^ r) / (pow(mag(r^U_t),3) + SMALL))
Any idea?
Attached Files
File Type: c adjointOutletVelocityFvPatchVectorField.C (4.8 KB, 2 views)
FlyBob91 is offline   Reply With Quote

Old   November 28, 2016, 07:51
Default
  #4
Member
 
Ben Jankauskas
Join Date: Jun 2013
Location: Exeter
Posts: 34
Rep Power: 12
rhythm is on a distinguished road
Hi,

I'm not sure whether this is correct advice. But you are using operator ^ in multiple areas. As I understand you are trying to raise to the power, eg. n ^ r . But my guess is that this operator is not defined, and you should use function:
Code:
double pow(double x, double y)
x - base 
y - power
Feel free to correct me, if my interpretation of your code is incorrect.
Cheers,
Ben
rhythm is offline   Reply With Quote

Old   November 28, 2016, 09:11
Default
  #5
Senior Member
 
FlyBob91's Avatar
 
Join Date: Mar 2016
Location: Bergamo
Posts: 157
Rep Power: 10
FlyBob91 is on a distinguished road
Quote:
Originally Posted by rhythm View Post
Hi,

I'm not sure whether this is correct advice. But you are using operator ^ in multiple areas. As I understand you are trying to raise to the power, eg. n ^ r . But my guess is that this operator is not defined, and you should use function:
Code:
double pow(double x, double y)
x - base 
y - power
Feel free to correct me, if my interpretation of your code is incorrect.
Cheers,
Ben

Hi rhythm, thank you for your reply.
It's strange because when i don't include the Ke term, the solvers compile correctly but when i run my case the solvers stops.
I firstly thought it was up to the fact the formula wasn't dimensionally correct, so i try to insert the Ke term to make it balanced (but i'm not sure this is the problem).

In the image the boudary condition i have to implement. I took it from a report so it should be correct.

n represents the normal vector of the outlet, while r the distance vector between the outlet center and the point considered.


Best Regards,
Roberto
Attached Images
File Type: png Formula.png (7.6 KB, 12 views)
FlyBob91 is offline   Reply With Quote

Old   November 28, 2016, 10:05
Default
  #6
Senior Member
 
shereez234's Avatar
 
M Sereez
Join Date: Jan 2014
Location: England
Posts: 352
Blog Entries: 1
Rep Power: 13
shereez234 is on a distinguished road
Code:
   // GETTING NU
      const incompressible::RASModel& ras
    = db().lookupObject<incompressible::RASModel>("RASProperties");
    
    scalarField nuw
    = ras.nuEff()().boundaryField()[patch().index()];

    // DISTANCE^(-1)
    const scalarField& deltainv = patch().deltaCoeffs();

    // nu / h
    const scalarField& nd =  - nuw * deltainv;

    // NORMAL VECTOR
    vectorField n = patch().nf();

    // TANGENT VECTOR
    vectorField r = patch().Cf() - vector(10,11,12);

    // SCALAR NORMAL VELOCITY COMPONENT
    scalarField Un = Up & patch().nf();

    // DIMENSIONED CORRECTION COEFFICIENT

    const dimensioned<double> Ke = readScalar(db().lookupObject<IOdictionary>("transportProperties").lookup("Ke"));  

    // PATCH-ADIACENT TANGENT ADJOINT VELOCITY (VECTOR)
    vectorField Uac   = Uap.patchInternalField();
    vectorField Uac_n = ( Uac & patch().nf() ) * patch().nf();
    vectorField Uac_t = Uac - Uac_n;

    // TANGENT VELOCITY COMPONENT (VECTOR)
    vectorField U_n = ( Up & patch().nf() ) * patch().nf();
    vectorField U_t = Up - U_n;


    vectorField :: operator = (
                              phiap*patch().Sf()/sqr(patch().magSf())
                              + (1/(Un + nd))
                              * (nd * Uac_t + Ke * pow(n, r) / (pow(mag(pow(r,U_t),3) + SMALL))
                              );
shereez234 is offline   Reply With Quote

Old   November 28, 2016, 10:29
Default
  #7
Member
 
Ben Jankauskas
Join Date: Jun 2013
Location: Exeter
Posts: 34
Rep Power: 12
rhythm is on a distinguished road
Hi FlyBob91,

Ah.. My apologies I wasn't sure that the hat represented a cross product between vectorFields.
(P.S.: shereez234 sorry about me causing confusion in the thread. As FlyBob91 wants to perform cross product operation between n and r then his use of 'hat' operator is correct, and it is not a power operator)


Quote:
I firstly thought it was up to the fact the formula wasn't dimensionally correct, so i try to insert the Ke term to make it balanced (but i'm not sure this is the problem).
If it was a dimensionality issue, then the code should explicitly say that it is the case.

As I am not entirely sure what is the issue, would you mind sending the code, for me to play around with and see if I can fix the issue?

Cheers,
Ben
shereez234 and FlyBob91 like this.
rhythm is offline   Reply With Quote

Old   November 28, 2016, 10:30
Default
  #8
Senior Member
 
FlyBob91's Avatar
 
Join Date: Mar 2016
Location: Bergamo
Posts: 157
Rep Power: 10
FlyBob91 is on a distinguished road
Quote:
Originally Posted by shereez234 View Post
Code:
    vectorField :: operator = (
                              phiap*patch().Sf()/sqr(patch().magSf())
                              + (1/(Un + nd))
                              * (nd * Uac_t + Ke * pow(n, r) / (pow(mag(pow(r,U_t),3) + SMALL))
                              );
Hi shereez, thanks again for your reply.
I don't understand why you wrote
Code:
pow(n, r)
and
Code:
pow(r,U_t),3
.
I thought the cross product should be written with the operator ^

Best Regards,
Roberto
FlyBob91 is offline   Reply With Quote

Old   November 28, 2016, 10:42
Default
  #9
Senior Member
 
FlyBob91's Avatar
 
Join Date: Mar 2016
Location: Bergamo
Posts: 157
Rep Power: 10
FlyBob91 is on a distinguished road
Quote:
Originally Posted by rhythm View Post
As I am not entirely sure what is the issue, would you mind sending the code, for me to play around with and see if I can fix the issue?
Many thanks ben.


P.S. i'm working on OpenFoam 2.3.0
Attached Files
File Type: gz adjointChannelFoam.tar.gz (5.4 KB, 4 views)
FlyBob91 is offline   Reply With Quote

Old   November 28, 2016, 11:10
Default
  #10
Senior Member
 
shereez234's Avatar
 
M Sereez
Join Date: Jan 2014
Location: England
Posts: 352
Blog Entries: 1
Rep Power: 13
shereez234 is on a distinguished road
Quote:
Originally Posted by FlyBob91 View Post
Hi shereez, thanks again for your reply.
I don't understand why you wrote
Code:
pow(n, r)
and
Code:
pow(r,U_t),3
.
I thought the cross product should be written with the operator ^

Best Regards,
Roberto
That is correct. I am sorry I thought you were trying to use the power. Many Apologies
FlyBob91 likes this.
shereez234 is offline   Reply With Quote

Old   November 29, 2016, 09:28
Default
  #11
Member
 
Ben Jankauskas
Join Date: Jun 2013
Location: Exeter
Posts: 34
Rep Power: 12
rhythm is on a distinguished road
Hi,

With very minor change I got it to compile. Try running it and see if it works.

There is a comment in the code explaining the change and why I believe it should be the correct way of doing it.

Cheers,
Ben
Attached Files
File Type: gz adjointChannelFoam.tar.gz (6.3 KB, 2 views)
FlyBob91 likes this.
rhythm is offline   Reply With Quote

Old   December 1, 2016, 09:39
Default
  #12
Senior Member
 
FlyBob91's Avatar
 
Join Date: Mar 2016
Location: Bergamo
Posts: 157
Rep Power: 10
FlyBob91 is on a distinguished road
Quote:
Originally Posted by rhythm View Post
Hi,

With very minor change I got it to compile. Try running it and see if it works.

There is a comment in the code explaining the change and why I believe it should be the correct way of doing it.

Cheers,
Ben
Hi Ben,
I have no words for thanking you and sorry for my late answer but i have been really busy in these days.

Your comment in the boundary condition file makes me think

Code:
do not carry dimension values with them
In fact i wanted to introduce the Ke term because i thought the boudary condition should be dimensionally balanced. In fact i wanted to equalize Ke to one and give the dimension necessary. I should have verificated it firstly.
So, trying with the old but good method of trial and error, i found the problematic therm was this one

Code:
const scalarField& nd =  - nuw * deltainv;
but i don't really understand why. Anyway i found the solution by decoupling it and writing nuw and deltainv directly in the boundary condition

Code:
 phiap*patch().Sf()/sqr(patch().magSf())
                              + (1/(Un - nuw * deltainv))
                              * (-nuw * deltainv * Uac_t + 2 * (n ^ r) / (pow(mag(r^U_t),3) + SMALL))
                              );
In this manner the solver compiled and the case run correctly.

However i have a last question in the following therm

Code:
// TANGENT VECTOR
    vectorField r = patch().Cf() - vector(10,11,12);
the vector
HTML Code:
vector(10,11,12)
represents the outlet center. There is manner to extract it with some command without writing it directly?


Thank you another time for you help, you played a key role for the solution.


Best Regards,
Roberto
FlyBob91 is offline   Reply With Quote

Old   December 2, 2016, 06:56
Default
  #13
Member
 
Ben Jankauskas
Join Date: Jun 2013
Location: Exeter
Posts: 34
Rep Power: 12
rhythm is on a distinguished road
Hi,

Regarding the dimensions of the boundary conditions.
I have had a discussion with my colleagues last year and it seems that in OpenFOAM the implementation is currently such that the boundary condition files (such as your adjointOutletPressureFvPatchScalarField) do not carry dimensions. So far I haven't seen any of the boundary conditions that are written differently. We presumed that later when the solver is running the Field just picks numerical values from the boundary condition and uses it's own set dimension values.

My guess is that this is done to avoid the need to have different boundary conditions for each type of field with different dimensions, or it might just be a less involved way to write it, but that is just a guess.

Anyway, when you are writing a boundary condition file, you only need to work with primitives like scalarFields, vectorFields, doubles, floats, etc. which you've been doing for the most part (apart from that Ke parameter).


Regarding the question about vector value, I'm afraid I don't have an answer, though I'm pretty sure there should be a function in the code that does that.

Cheers,
Ben
FlyBob91 likes this.
rhythm 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Grabbing value of a dimensioned quantity / Problem creating a dimensioned tensor ThomasV OpenFOAM 5 February 18, 2019 11:05
Insert Points in CFD-Post Supersonic ANSYS 3 August 26, 2016 01:45
Division of dimensioned scalars Joachim OpenFOAM 5 August 8, 2013 01:53
dimensioned volScalarField lions85 OpenFOAM 1 November 12, 2009 02:41
3D Insert modelling in Mold Flow Dan Rößler Main CFD Forum 0 December 20, 2005 06:37


All times are GMT -4. The time now is 19:46.