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

Adding Sensitivity Adjoint Problem

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By verboomj
  • 1 Post By FlyBob91

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 10, 2016, 07:21
Lightbulb Adding Sensitivity Adjoint Problem
  #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 going to add the sensitivity equation to my createFields.H

the equation is

Code:
-A*nu*(n*nabla)u*(n*nabla)u
I know how define all the terms because i included them in the outlet boundary files, however i think i missed some header line to be included.

At the end of the file i added

Code:
 
    scalar nu = readScalar(db().lookupObject<IOdictionary>("transportProperties").lookup  
    ("nu"));

volScalarField sens
(
    IOobject 
    (
        "sensitivity"
        "alpha",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::AUTO_WRITE
    ),
    -magSf()*nu*snGrad(Ua)*snGrad(U)
);
and this is the error

Code:
In file included from /home/roby/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/postProcess.H:129:0,
                 from myAdjointShapeOptimizationFoam.C:72:
./createFields.H: In function ‘int main(int, char**)’:
./createFields.H:112:34: error: ‘patch’ was not declared in this scope
     vectorField U_n = (U & patch().nf())*patch().nf();  // Normale
                                  ^
./createFields.H:118:31: error: ‘db’ was not declared in this scope
     scalar nu = readScalar(db().lookupObject<IOdictionary>("transportProperties
                               ^
./createFields.H:118:58: error: expected primary-expression before ‘>’ token
     scalar nu = readScalar(db().lookupObject<IOdictionary>("transportProperties
                                                          ^
./createFields.H:118:83: error: request for member ‘lookup’ in ‘("transportProperties")’, which is of non-class type ‘const char [20]’
 nu = readScalar(db().lookupObject<IOdictionary>("transportProperties").lookup  
                                                                        ^
./createFields.H:132:12: error: ‘magSf’ was not declared in this scope
     -magSf()*nu*snGrad(Ua_t)*snGrad(U_t)
            ^
./createFields.H:132:28: error: ‘snGrad’ was not declared in this scope
     -magSf()*nu*snGrad(Ua_t)*snGrad(U_t)
                            ^
./createFields.H:132:28: note: suggested alternative:
In file included from /home/roby/OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/fvcSnGrad.H:88:0,
                 from /home/roby/OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/fvc.H:51,
                 from /home/roby/OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/fvCFD.H:8,
                 from myAdjointShapeOptimizationFoam.C:48:
/home/roby/OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/fvcSnGrad.C:88:1: note:   ‘Foam::fvc::snGrad’
 snGrad
 ^
In file included from myAdjointShapeOptimizationFoam.C:78:0:
createFields.H:112:34: error: ‘patch’ was not declared in this scope
     vectorField U_n = (U & patch().nf())*patch().nf();  // Normale
                                  ^
createFields.H:118:31: error: ‘db’ was not declared in this scope
     scalar nu = readScalar(db().lookupObject<IOdictionary>("transportProperties
                               ^
createFields.H:118:58: error: expected primary-expression before ‘>’ token
     scalar nu = readScalar(db().lookupObject<IOdictionary>("transportProperties
                                                          ^
createFields.H:118:83: error: request for member ‘lookup’ in ‘("transportProperties")’, which is of non-class type ‘const char [20]’
 nu = readScalar(db().lookupObject<IOdictionary>("transportProperties").lookup  
                                                                        ^
createFields.H:132:12: error: ‘magSf’ was not declared in this scope
     -magSf()*nu*snGrad(Ua_t)*snGrad(U_t)
            ^
createFields.H:132:28: error: ‘snGrad’ was not declared in this scope
     -magSf()*nu*snGrad(Ua_t)*snGrad(U_t)
                            ^
createFields.H:132:28: note: suggested alternative:
In file included from /home/roby/OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/fvcSnGrad.H:88:0,
                 from /home/roby/OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/fvc.H:51,
                 from /home/roby/OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/fvCFD.H:8,
                 from myAdjointShapeOptimizationFoam.C:48:
/home/roby/OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/fvcSnGrad.C:88:1: note:   ‘Foam::fvc::snGrad’
 snGrad
 ^
/home/roby/OpenFOAM/OpenFOAM-4.1/wmake/rules/General/transform:8: set di istruzioni per l'obiettivo "Make/linux64GccDPInt32Opt/myAdjointShapeOptimizationFoam.o" non riuscito
make: *** [Make/linux64GccDPInt32Opt/myAdjointShapeOptimizationFoam.o] Errore 1

Last edited by FlyBob91; November 16, 2016 at 04:54.
FlyBob91 is offline   Reply With Quote

Old   November 12, 2016, 21:12
Default
  #2
Senior Member
 
FlyBob91's Avatar
 
Join Date: Mar 2016
Location: Bergamo
Posts: 157
Rep Power: 10
FlyBob91 is on a distinguished road
Ok i added these line above runTime.write(); in the shapeOptimization.C file

Code:
// Sensitivity calculation
word patchName = "wing";
label patchID = mesh.boundary().findPatchID(patchName);
scalarField temp = (U.boundaryField()[patchID].snGrad() & 
Ua.boundaryField()[patchID].snGrad());
sensitivity.boundaryField()[patchID] =
mesh.boundary()[patchID].magSf() * (temp);
but now the problem is how correctly to initialize it in the createFields.H
I added this lines at the end of the file

Code:
volScalarField sensitivity
(
    IOobject
    (
        "sensitivity",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::AUTO_WRITE
    ),
    ******************
)
but i don't know what to write where i used the stars.
Any idea?

Best Regards,
Roberto
FlyBob91 is offline   Reply With Quote

Old   November 16, 2016, 05:46
Default
  #3
Senior Member
 
FlyBob91's Avatar
 
Join Date: Mar 2016
Location: Bergamo
Posts: 157
Rep Power: 10
FlyBob91 is on a distinguished road
Sorry for the bump, i'm a bit disperate
FlyBob91 is offline   Reply With Quote

Old   November 28, 2016, 03:53
Default
  #4
New Member
 
Jeroen
Join Date: Oct 2016
Posts: 21
Rep Power: 9
verboomj is on a distinguished road
Check chapter 3.4: http://www.tfd.chalmers.se/~hani/kur...ortAdjoint.pdf
FlyBob91 likes this.
verboomj is offline   Reply With Quote

Old   November 28, 2016, 04:23
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 verboomj View Post
Hi verboomj,
I have already read that article but it was a very simple case compared to mine.
Here the solution of what i did few days ago, maybe it can help someone.

I created a file where i wrote the sensitivity equation and then i initializied it in this manner in the createFields.H

Code:
// PRIMAL NORMAL GRADIENT
volVectorField wallGradU
(
	IOobject
	(
	"wallGradU",
	runTime.timeName(),
	mesh,
	IOobject::NO_READ,
	IOobject::NO_WRITE
	),
	mesh,
	dimensionedVector
 	(
  	"wallGradU",
  	U.dimensions()/dimLength,
  	vector::zero
  	)
);


// ADJOINT NORMAL GRADIENT
volVectorField wallGradUa
(
 	IOobject
 	(
  	"wallGradUa",
  	runTime.timeName(),
  	mesh,
  	IOobject::NO_READ,
  	IOobject::NO_WRITE
  	),
 	mesh,
	dimensionedVector
 	(
  	"wallGradUa",
  	Ua.dimensions()/dimLength,
  	vector::zero
  	)
);


// FACE AREA
volScalarField areaMag
(
	IOobject
	(
	"areaMag",
	runTime.timeName(),
	mesh,
	IOobject::NO_READ,
	IOobject::AUTO_WRITE
	),
	mesh,
	dimensionedScalar("areaMag", dimLength*dimLength, 0.0)
);



// SENSITIVITY
volScalarField Sens
(
	IOobject
	(
	"Sens",
	runTime.timeName(),
	mesh,
	IOobject::NO_READ,
	IOobject::AUTO_WRITE
	),	
	mesh,
	dimensionedScalar("Sens", dimLength*dimLength*dimLength*dimLength/(dimTime*dimTime*dimTime), 0.0)
);
Best Regards,
Roberto
Attached Files
File Type: h Sensitivity.H (537 Bytes, 40 views)
hokhay likes this.
FlyBob91 is offline   Reply With Quote

Reply


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
conjugateHeatFoam + interFoam farhagim OpenFOAM Programming & Development 15 July 19, 2016 07:55
chtMultiRegionSimpleFoam samiam1000 OpenFOAM Running, Solving & CFD 39 March 31, 2016 08:43
chtMultiRegionSimpleFoam: strange error samiam1000 OpenFOAM Running, Solving & CFD 26 December 29, 2015 22:14
Adjoint sensitivity on specified surface robyTKD OpenFOAM Programming & Development 0 April 29, 2013 05:05
Help with chtMultiRegionFoam jbvw96 OpenFOAM Running, Solving & CFD 2 December 26, 2010 17:16


All times are GMT -4. The time now is 14:05.