# How to read freestream velocity vector in a new boundary condition?

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

April 5, 2013, 10:49
How to read freestream velocity vector in a new boundary condition?
#1
Member

Roberto Pieri
Join Date: Feb 2012
Location: Milan
Posts: 57
Rep Power: 7
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:
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
Attached Files

 April 5, 2013, 22:30 #2 Senior Member   Fumiya Nozaki Join Date: Jun 2010 Location: Yokohama, Japan Posts: 217 Blog Entries: 1 Rep Power: 11 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

April 6, 2013, 18:29
#3
Member

Roberto Pieri
Join Date: Feb 2012
Location: Milan
Posts: 57
Rep Power: 7

Quote:
 Originally Posted by fumiya 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()':
/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
/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: *** Waiting for unfinished jobs....```
Thank you all,
Roberto
Attached Files

 April 6, 2013, 20:00 #4 Senior Member   Fumiya Nozaki Join Date: Jun 2010 Location: Yokohama, Japan Posts: 217 Blog Entries: 1 Rep Power: 11 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 samiam1000 likes this.

 April 7, 2013, 16:37 #5 Member   Roberto Pieri Join Date: Feb 2012 Location: Milan Posts: 57 Rep Power: 7 Thank you very much Fumiya, your help was precise and useful; now it compiles without errors. I have two other questions: 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; 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

 April 24, 2013, 09:43 #6 Member   Roberto Pieri Join Date: Feb 2012 Location: Milan Posts: 57 Rep Power: 7 Any idea about question number 2 of previous post? Roberto