|
[Sponsors] |
November 3, 2016, 07:13 |
Adjoint Shape Optimization
|
#1 |
Senior Member
Join Date: Mar 2016
Location: Bergamo
Posts: 157
Rep Power: 10 |
Hello to all,
i have two questions about the adjoint shape optimization. I try to add this equation as boundary condition for the outlet in the file adjointOutletPressureFvPatchScalarField.C but when i compile it gives me an error the equation is Code:
operator == ((Up & Uap) + nuw*snGradUan +(phiap/patch().magSf())*(phip/patch().magSf())); Code:
adjointOutletPressure/adjointOutletPressureFvPatchScalarField.C: In member function ‘virtual void Foam::adjointOutletPressureFvPatchScalarField::updateCoeffs()’: adjointOutletPressure/adjointOutletPressureFvPatchScalarField.C:107:31: error: ‘nuw’ was not declared in this scope operator == ((Up & Uap) + nuw*snGradUan +(phiap/patch().magSf())*(phip/patc ^ adjointOutletPressure/adjointOutletPressureFvPatchScalarField.C:107:35: error: ‘snGradUan’ was not declared in this scope operator == ((Up & Uap) + nuw*snGradUan +(phiap/patch().magSf())*(phip/patc ^ Second i want to ask the meaning of the terms Up, Uap, phiap and phip because they are not declared in the file. Thanks for your help and time. |
|
November 3, 2016, 09:35 |
|
#2 | |
Member
Ben Jankauskas
Join Date: Jun 2013
Location: Exeter
Posts: 34
Rep Power: 13 |
Hi,
First of all a disclaimer that I am not fully familiar with adjoint optimisation formulation, nonetheless I believe I can give some input as to what is wrong with your implementation. As I understand you have introduced an additional term to your operator. Unfortunately, as it says in the error message the variables nuw and snGradUan have not been declared in your code. To fix that you simply need to introduce them either in that *.C file or somewhere else in your code. Quote:
Anyways, to my understanding from what is written in the code Up and phip are patch values for U and phi fields. Similarly Uap and phiap are patch values for adjoint velocity and adjoint pressure variables. If my memory doesn't lie adjoint variables fall out in derivation when Lagrange multiplier method is applied. All of these parameters are declared in the same updateCoeffs() function just above the operator declaration. Hope this helps. Cheers, Ben |
||
November 3, 2016, 11:06 |
|
#3 |
Senior Member
Join Date: Mar 2016
Location: Bergamo
Posts: 157
Rep Power: 10 |
Hi Ben,
First of all thank you for your reply. I think i started the thread very bad, because i have noticed only now that in the .C file phi is renamed as phip, phia as phiap and so on. That's the reason of my second question and i ask sorry. about the nuw parameter you have right i haven't defined it yet, but i'm more worried about the snGrad. Now i want to be more precise. The equation i want to implement is Code:
q=u*v+un*vn+nu(n*grad)ut I made this Code:
operator == ((Up & Uap) + nu*snGradUt + (phiap/patch().magSf())*(phip/patch().magSf())) Code:
scalarField Un(mag(patch().nf() & Up)); scalarField Uan(mag(patch().nf() & Uap)); vectorField Ut(Up - patch().nf()*Un); vectorField Uat(Uap - patch().nf()*Uan); Code:
adjointOutletPressure/adjointOutletPressureFvPatchScalarField.C: In member function ‘virtual void Foam::adjointOutletPressureFvPatchScalarField::updateCoeffs()’: adjointOutletPressure/adjointOutletPressureFvPatchScalarField.C:116:31: error: ‘nu’ was not declared in this scope operator == ((Up & Uap) + nu*snGradUt + (phiap/patch().magSf())*(phip/patch ^ adjointOutletPressure/adjointOutletPressureFvPatchScalarField.C:116:34: error: ‘snGradUt’ was not declared in this scope operator == ((Up & Uap) + nu*snGradUt + (phiap/patch().magSf())*(phip/patch ^ tanks for help |
|
November 3, 2016, 18:03 |
|
#4 |
Member
Ben Jankauskas
Join Date: Jun 2013
Location: Exeter
Posts: 34
Rep Power: 13 |
Hi,
Again, the error message that you are getting is the same as previously. You are asking the code to use variables that haven't been defined. If you are providing viscosity values in your transportProperties dictionary, then you can use the following code written inside updateCoeffs() function to tell the class where to look for it: Code:
scalar nu = readScalar(db().lookupObject<IOdictionary>("transportProperties").lookup("nu")); Couple of comments though: 1) First of all your use of C++ syntax is incorrect, because at the moment it is written as snGradUt which is interpreted as a variable and not a function snGrad() applied on a Ut field. Ideally you would like it to be written in the form Code:
fvc::snGrad(Ut) Code:
Ut.boundaryField()[patchi].snGrad() 2) Your calculation of tangential velocity component is mathematically correct. Unfortunately, snGrad() function requires input of a GeometricField type that has both boundaryField and an internalField, as it needs to know the field values away from the boundary in order to be able to calculate surface normal gradient. One solution might be to use Code:
volVectorField& U = db().lookupObject<volVectorField>("U") Anyways here's an example of how someone else extracted surface normal gradients of the velocity field (Taken from http://www.cfd-online.com/Forums/ope...chfield-u.html): Code:
// in the custom boundary condition of U const volVectorField& Vs = this->db().lookupObject<volVectorField>("Vs"); const surfaceVectorField snGradVs = fvc::snGrad(Vs); const label& patchIndex(this->patch().index()); const vectorField& patchSnGradVs = snGradVs.boundaryField()[patchIndex]; Cheers, Ben |
|
November 6, 2016, 16:34 |
|
#5 |
Senior Member
Join Date: Mar 2016
Location: Bergamo
Posts: 157
Rep Power: 10 |
Hi Ben,
thanks for your reply; your suggestions were really helpfull. I solved the question about the normal gradient. As you said the command snGrad can't be used and it's necessary to apply a first order discretization Code:
(n*nabla)u_n= (u_nw-u_nw-1)/h Code:
// DISTANCE^(-1) const scalarField& deltainv = patch().deltaCoeffs(); // nu / h const scalarField& nd = - nuw * deltainv; // NORMAL VECTOR vectorField n = patch().nf(); // TANGENT VECTOR // vectorField r = // SCALAR NORMAL VELOCITY COMPONENT scalarField Un = Up & patch().nf(); // 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 + 2 * (n ^ r) / (pow(mag(r^U_t),3) + SMALL)) ); http://www.tfd.chalmers.se/~hani/kur...ortAdjoint.pdf Now i have to implement the equation of the velocity Code:
u_tw = 1/(v_n - nu/h)*(-nu/h*u_(tw-1) + 2*(n x r)/|| r x v_t ||^(3) ) Code:
vectorField n = patch().nf(); Last edited by FlyBob91; November 14, 2016 at 11:19. |
|
May 24, 2019, 17:28 |
|
#6 |
New Member
liliu
Join Date: Nov 2018
Posts: 12
Rep Power: 7 |
Hi,
in this " operator == ((Up & Uap) + nuw*snGradUan +(phiap/patch().magSf())*(phip/patch().magSf()));" equation, what's the meaning of "operator ==" ? thanks |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
adjoint Shape Optimization | mechy | OpenFOAM Running, Solving & CFD | 11 | June 19, 2017 10:05 |
SU2 Shape optimization questions | AdriC | SU2 Shape Design | 6 | January 27, 2016 05:25 |
hard to convergent with SU2 4.0 for Euler adjoint | Xianguu | SU2 | 1 | July 14, 2015 18:09 |
Adjoint method for shape optimization | Edris | Main CFD Forum | 6 | November 1, 2012 09:10 |
SQP method for adjoint based aerodynamic shape optimization | cfdbooks | Main CFD Forum | 2 | May 26, 2009 11:40 |