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/)
-   -   How to read freestream velocity vector in a new boundary condition? (https://www.cfd-online.com/Forums/openfoam-programming-development/115733-how-read-freestream-velocity-vector-new-boundary-condition.html)

robyTKD April 5, 2013 10:49

How to read freestream velocity vector in a new boundary condition?
 
1 Attachment(s)
Hi to everyone,

I would like to build a new boundary condition for adjointShapeOptimizationFoam.
I need to read the freestream velocity vector (which I named U_inf); my ideas to do this are:
  1. adding U_inf in the transportProperties dictionary and reading from it;
  2. defining a new dictionary and reading the vector from this new dictionary;
  3. reading the velocity from the inlet patch.

Which of these ones is the best? How can I implement it?

Attached below you find the file.

Thank you
Roberto

fumiya April 5, 2013 22:30

Hi Roberto,

Are you addressing the drag coefficient minimization problems by the adjoint method?

Personally, I think it is the most desirable approach to read a freestreamValue from U file,
because we don't have to define another dictionary.
Unfortunately, I don't know how to do that, but you can try the approach 1,2 by following
the instructions:

http://albertopassalacqua.com/?p=947

Hope this helps,
Fumiya

robyTKD April 6, 2013 18:29

1 Attachment(s)
Thank you for the reply.

Quote:

Originally Posted by fumiya (Post 418683)
Are you addressing the drag coefficient minimization problems by the adjoint method?

Yes. The first step is to solve the adjoint problem for drag and lift in laminar regime.

I followed the instructions from the link you suggested to me, but, unfortunately, it doesn't work.
The modified BC is attached below while this is the error:

Code:

adjointCdWallVelocity/adjointCdWallVelocityFvPatchVectorField.C: In member function 'virtual void Foam::adjointCdWallVelocityFvPatchVectorField::updateCoeffs()':
adjointCdWallVelocity/adjointCdWallVelocityFvPatchVectorField.C:113:44: error: no matching function for call to 'Foam::Field<double>::Field(Foam::dimensioned<double>)'
adjointCdWallVelocity/adjointCdWallVelocityFvPatchVectorField.C:113:44: note: candidates are:
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:193:9: note: Foam::Field<Type>::Field(const Foam::word&, const Foam::dictionary&, Foam::label) [with Type = double, Foam::label = int]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:193:9: note:  candidate expects 3 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:190:9: note: Foam::Field<Type>::Field(Foam::Istream&) [with Type = double]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:190:9: note:  no known conversion for argument 1 from 'Foam::dimensioned<double>' to 'Foam::Istream&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:186:9: note: Foam::Field<Type>::Field(const Foam::tmp<Foam::Field<Type> >&) [with Type = double]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:186:9: note:  no known conversion for argument 1 from 'Foam::dimensioned<double>' to 'const Foam::tmp<Foam::Field<double> >&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:177:9: note: Foam::Field<Type>::Field(const Foam::Xfer<Foam::Field<Type> >&) [with Type = double]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:177:9: note:  no known conversion for argument 1 from 'Foam::dimensioned<double>' to 'const Foam::Xfer<Foam::Field<double> >&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:174:9: note: Foam::Field<Type>::Field(Foam::Field<Type>&, bool) [with Type = double]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:174:9: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:171:9: note: Foam::Field<Type>::Field(const Foam::Field<Type>&) [with Type = double]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:171:9: note:  no known conversion for argument 1 from 'Foam::dimensioned<double>' to 'const Foam::Field<double>&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:164:9: note: Foam::Field<Type>::Field(const Foam::tmp<Foam::Field<Type> >&, const Foam::FieldMapper&) [with Type = double]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:164:9: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:157:9: note: Foam::Field<Type>::Field(const Foam::UList<T>&, const Foam::FieldMapper&) [with Type = double]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:157:9: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:149:9: note: Foam::Field<Type>::Field(const Foam::tmp<Foam::Field<Type> >&, const labelListList&, const scalarListList&) [with Type = double, Foam::labelListList = Foam::List<Foam::List<int> >, Foam::scalarListList = Foam::List<Foam::List<double> >]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:149:9: note:  candidate expects 3 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:141:9: note: Foam::Field<Type>::Field(const Foam::UList<T>&, const labelListList&, const scalarListList&) [with Type = double, Foam::labelListList = Foam::List<Foam::List<int> >, Foam::scalarListList = Foam::List<Foam::List<double> >]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:141:9: note:  candidate expects 3 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:134:9: note: Foam::Field<Type>::Field(const Foam::tmp<Foam::Field<Type> >&, const labelUList&) [with Type = double, Foam::labelUList = Foam::UList<int>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:134:9: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:127:9: note: Foam::Field<Type>::Field(const Foam::UList<T>&, const labelUList&) [with Type = double, Foam::labelUList = Foam::UList<int>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:127:9: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:124:18: note: Foam::Field<Type>::Field(const Foam::Xfer<Foam::List<T> >&) [with Type = double]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:124:18: note:  no known conversion for argument 1 from 'Foam::dimensioned<double>' to 'const Foam::Xfer<Foam::List<double> >&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:121:18: note: Foam::Field<Type>::Field(const Foam::UList<T>&) [with Type = double]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:121:18: note:  no known conversion for argument 1 from 'Foam::dimensioned<double>' to 'const Foam::UList<double>&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:118:9: note: Foam::Field<Type>::Field(Foam::label, const Type&) [with Type = double, Foam::label = int]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:118:9: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:115:18: note: Foam::Field<Type>::Field(Foam::label) [with Type = double, Foam::label = int]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:115:18: note:  no known conversion for argument 1 from 'Foam::dimensioned<double>' to 'int'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:111:9: note: Foam::Field<Type>::Field() [with Type = double]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.H:111:9: note:  candidate expects 0 arguments, 1 provided
adjointCdWallVelocity/adjointCdWallVelocityFvPatchVectorField.C:115:35: error: no matching function for call to 'Foam::Field<Foam::Vector<double> >::Field(Foam::dimensioned<Foam::Vector<double> >)'
adjointCdWallVelocity/adjointCdWallVelocityFvPatchVectorField.C:115:35: note: candidates are:
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:205:1: note: Foam::Field<Type>::Field(const Foam::word&, const Foam::dictionary&, Foam::label) [with Type = Foam::Vector<double>, Foam::label = int]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:205:1: note:  candidate expects 3 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:198:1: note: Foam::Field<Type>::Field(Foam::Istream&) [with Type = Foam::Vector<double>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:198:1: note:  no known conversion for argument 1 from 'Foam::dimensioned<Foam::Vector<double> >' to 'Foam::Istream&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:188:1: note: Foam::Field<Type>::Field(const Foam::tmp<Foam::Field<Type> >&) [with Type = Foam::Vector<double>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:188:1: note:  no known conversion for argument 1 from 'Foam::dimensioned<Foam::Vector<double> >' to 'const Foam::tmp<Foam::Field<Foam::Vector<double> > >&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:163:1: note: Foam::Field<Type>::Field(const Foam::Xfer<Foam::Field<Type> >&) [with Type = Foam::Vector<double>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:163:1: note:  no known conversion for argument 1 from 'Foam::dimensioned<Foam::Vector<double> >' to 'const Foam::Xfer<Foam::Field<Foam::Vector<double> > >&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:149:1: note: Foam::Field<Type>::Field(Foam::Field<Type>&, bool) [with Type = Foam::Vector<double>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:149:1: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:141:1: note: Foam::Field<Type>::Field(const Foam::Field<Type>&) [with Type = Foam::Vector<double>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:141:1: note:  no known conversion for argument 1 from 'Foam::dimensioned<Foam::Vector<double> >' to 'const Foam::Field<Foam::Vector<double> >&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:128:1: note: Foam::Field<Type>::Field(const Foam::tmp<Foam::Field<Type> >&, const Foam::FieldMapper&) [with Type = Foam::Vector<double>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:128:1: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:115:1: note: Foam::Field<Type>::Field(const Foam::UList<T>&, const Foam::FieldMapper&) [with Type = Foam::Vector<double>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:115:1: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:101:1: note: Foam::Field<Type>::Field(const Foam::tmp<Foam::Field<Type> >&, const labelListList&, const scalarListList&) [with Type = Foam::Vector<double>, Foam::labelListList = Foam::List<Foam::List<int> >, Foam::scalarListList = Foam::List<Foam::List<double> >]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:101:1: note:  candidate expects 3 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:87:1: note: Foam::Field<Type>::Field(const Foam::UList<T>&, const labelListList&, const scalarListList&) [with Type = Foam::Vector<double>, Foam::labelListList = Foam::List<Foam::List<int> >, Foam::scalarListList = Foam::List<Foam::List<double> >]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:87:1: note:  candidate expects 3 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:74:1: note: Foam::Field<Type>::Field(const Foam::tmp<Foam::Field<Type> >&, const labelUList&) [with Type = Foam::Vector<double>, Foam::labelUList = Foam::UList<int>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:74:1: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:61:1: note: Foam::Field<Type>::Field(const Foam::UList<T>&, const labelUList&) [with Type = Foam::Vector<double>, Foam::labelUList = Foam::UList<int>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:61:1: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:156:1: note: Foam::Field<Type>::Field(const Foam::Xfer<Foam::List<T> >&) [with Type = Foam::Vector<double>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:156:1: note:  no known conversion for argument 1 from 'Foam::dimensioned<Foam::Vector<double> >' to 'const Foam::Xfer<Foam::List<Foam::Vector<double> > >&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:179:1: note: Foam::Field<Type>::Field(const Foam::UList<T>&) [with Type = Foam::Vector<double>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:179:1: note:  no known conversion for argument 1 from 'Foam::dimensioned<Foam::Vector<double> >' to 'const Foam::UList<Foam::Vector<double> >&'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:54:1: note: Foam::Field<Type>::Field(Foam::label, const Type&) [with Type = Foam::Vector<double>, Foam::label = int]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:54:1: note:  candidate expects 2 arguments, 1 provided
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:47:1: note: Foam::Field<Type>::Field(Foam::label) [with Type = Foam::Vector<double>, Foam::label = int]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:47:1: note:  no known conversion for argument 1 from 'Foam::dimensioned<Foam::Vector<double> >' to 'int'
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:40:1: note: Foam::Field<Type>::Field() [with Type = Foam::Vector<double>]
/Users/roberto/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude/Field.C:40:1: note:  candidate expects 0 arguments, 1 provided
make: *** [Make/darwinIntel64Gcc46DPOpt/adjointCdWallVelocityFvPatchVectorField.o] Error 1
make: *** Waiting for unfinished jobs....

Thank you all,
Roberto

fumiya April 6, 2013 20:00

There is no problem with the descriptions in the link.
The errors you encountered are related to how to use your variable U_inf.

You might want to try
Code:

scalar C_inf(.5*pow(mag(U_inf.value()), 2));
vector d(U_inf.value()/mag(U_inf.value()));

instead of
Code:

scalarField C_inf(.5*pow(mag(U_inf), 2));
vectorField d(U_inf/mag(U_inf));

Hope this helps,
Fumiya

robyTKD April 7, 2013 16:37

Thank you very much Fumiya, your help was precise and useful; now it compiles without errors. :cool:

I have two other questions:
  1. How can I import differential operators? Probably I'll need to add this term in my BC: nut*snGrad(phiap/patch().magSf()) and I would like to know what I have to include in the file;
  2. a useful improvement is to build a "freestream-like" boundary condition, which will select Inlet or Outlet condition for the unknowns of the adjoint problem. Do you know how to modify freestream and freestreamPressure boundary conditions in order to do this?

Unfortunately I built my mesh with only FARFIELD patch and it isn't so easy to divide in Inlet and Outlet.

Best regards,
Roberto

robyTKD April 24, 2013 09:43

Any idea about question number 2 of previous post?

Roberto


All times are GMT -4. The time now is 06:00.