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

Adjoint method. Backwards in time

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 22, 2018, 12:32
Default Adjoint method. Backwards in time
  #1
New Member
 
Jose
Join Date: Dec 2017
Location: Madrid
Posts: 6
Rep Power: 8
jlorenzo is on a distinguished road
Hello,

I'm trying to code the adjoint method for the unsteady heat equation in OpenFOAM. I am able to solve the forward problem, but I'm having some trouble with the backwards problem. Actually, I don't know how to tell OpenFoam to solve a problem backwards in time, I've tried something like runTime--, but apparently this doesn't make sense to OF. Any idea on this?

Another option I'm thinking about is to solve the adjoint problem forward in time by means of a change of variable like tau = T - t. However, in this case I have to reverse the contents in the time folders, so that data files in folder 0 go to folder T, data files in folder 1 go to folder T - 1, and so on... How could I achieve this?

Thank you.
jlorenzo is offline   Reply With Quote

Old   January 23, 2018, 12:28
Default
  #2
New Member
 
Jose
Join Date: Dec 2017
Location: Madrid
Posts: 6
Rep Power: 8
jlorenzo is on a distinguished road
I have tried the second option, reading the volScalarFields in reverse direction and saving the result. This way I can solve the adjoint problem in forward direction. However, probably there are more elegant ways of doing so, I would appreciate if someone could give some hints.

By the way, maybe this thread should go in the "Programming & Development" sub-forum, but I don't know how to move it.

writeAdjointSourceTerm.H
Code:
// Reverse source term in the adjoint equation
instantList Times = runTime.times();
scalar nTimes = Times.size() - 1;

for (label i = 1; i <= nTimes; i++)
{
    runTime.setTime(Times[nTimes - i + 1], nTimes - i + 1);

    volScalarField T
    (
        IOobject
        (
        "T",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
        ),
        mesh
    );

    volScalarField Td
    (
        IOobject
        (
        "Td",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
        ),
        mesh
    );

    runTime.setTime(Times[i], i);

    volScalarField g
    (
        IOobject
        (
        "g",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
        ),
        T - Td
    );

    g.write();
}
__________________
Jose
jlorenzo is offline   Reply With Quote

Old   May 10, 2018, 18:59
Default
  #3
New Member
 
Chuangxin HE
Join Date: Apr 2016
Posts: 3
Rep Power: 9
Chuangxin is on a distinguished road
Did you try using a negative time step? I find it works.


Quote:
Originally Posted by jlorenzo View Post
I have tried the second option, reading the volScalarFields in reverse direction and saving the result. This way I can solve the adjoint problem in forward direction. However, probably there are more elegant ways of doing so, I would appreciate if someone could give some hints.

By the way, maybe this thread should go in the "Programming & Development" sub-forum, but I don't know how to move it.

writeAdjointSourceTerm.H
Code:
// Reverse source term in the adjoint equation
instantList Times = runTime.times();
scalar nTimes = Times.size() - 1;

for (label i = 1; i <= nTimes; i++)
{
    runTime.setTime(Times[nTimes - i + 1], nTimes - i + 1);

    volScalarField T
    (
        IOobject
        (
        "T",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
        ),
        mesh
    );

    volScalarField Td
    (
        IOobject
        (
        "Td",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
        ),
        mesh
    );

    runTime.setTime(Times[i], i);

    volScalarField g
    (
        IOobject
        (
        "g",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
        ),
        T - Td
    );

    g.write();
}
Chuangxin 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
AMI speed performance danny123 OpenFOAM 21 October 24, 2020 05:13
pressure in incompressible solvers e.g. simpleFoam chrizzl OpenFOAM Running, Solving & CFD 13 March 28, 2017 06:49
Micro Scale Pore, icoFoam gooya_kabir OpenFOAM Running, Solving & CFD 2 November 2, 2013 14:58
How to write k and epsilon before the abnormal end xiuying OpenFOAM Running, Solving & CFD 8 August 27, 2013 16:33
plot over time fferroni OpenFOAM Post-Processing 7 June 8, 2012 08:56


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