# Second equation uses wrong state variables boundary condition

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

 January 22, 2013, 08:08 Second equation uses wrong state variables boundary condition #1 New Member   Fabian Wein Join Date: Jan 2013 Posts: 13 Rep Power: 6 Hello, this is my first post, so I introduce myself quickly. I am Fabian, a Postdoc in Germany. I do topology optimization and now work on an OF based project. Someone else wrote most of the solver and other stuff, my task is to change the code in such a way, that a second problem is solved afterwards. I do it in the same code. I have good C++ knowledge but am totally new to OpenFOAM. The forward problem is solved for h with dynamic boundary conditions defined based on the time in 0/h as inlet code. The forward problem is nonlinear with implicit time stepping. I need to solve a so called adjoint problem which is linear, needs to be solved with explicit time stepping and goes backwards in time. I do the backwards in time by going forward in time (resetting my time object) but have for the solution variable the boundary conditions with other times in the dynamic 0/lambda code. I have fvScalarMatrix lambda_eqn( phi * C * fvm::ddt(lambda) == -fvc::laplacian(k, lambda) ); lambda_eqn.solve(); and hope, this solves my problem with an explicit time stepping. in fvSolution I have solvers { h { solver PCG; preconditioner DIC; // tolerance 1e-06; tolerance 1e-14; relTol 0.1; } lambda { solver PCG; preconditioner DIC; // tolerance 1e-06; tolerance 1e-14; relTol 0.1; } hFinal { \$h; relTol 0.0; } } In fvSchemes I have laplacianSchemes { default none; laplacian(k,lambda) Gauss linear uncorrected; laplacian(k,h) Gauss linear uncorrected; } For the forward problem the inlet code of 0/h is executed (I do a command line output) and then it is written "DICPCG: Solving for h, Initial residual ..." For the adjoint problem again the code from 0/h is executed and then it is written " diagonal: Solving for lambda, Initial residual = 0, Final residual = 0, No Iterations 0" My problem is, that the inlet code from h is executed but not from lambda ?! Any help or hint is very much appreciated! Thank you very much, Fabian

 January 22, 2013, 19:18 #2 Senior Member     Daniel P. Combest Join Date: Mar 2009 Location: St. Louis, USA Posts: 612 Rep Power: 22 Fabian, there are a number of things that could be the issue. You could... * Have a zero values for your constants that zero out your field * Ill-posed boundary conditions (e.g. all are set to zeroGradient) that essentially do nothing * Mean to use fvm::laplacian(k,lambda) instead of fvc::laplacian( * Have an issue somewhere else in your algorithm that is causing your problem. is there more code that you have changed that we can see and track down the problem?

January 23, 2013, 05:00
#3
New Member

Fabian Wein
Join Date: Jan 2013
Posts: 13
Rep Power: 6
Chegdan,

thank you very much for reply. Please note, that I am really new to OF and have much
more guessing about how it works than knowledge.

From you points I can see that they are issues, but I do not see, how they could cause my problem, that the boundary conditions from the state variable of the first problem are used for the second problem with another state variable.

Quote:
 Originally Posted by chegdan * Mean to use fvm::laplacian(k,lambda) instead of fvc::laplacian(
As far as I understood this is the notation for an explicit in time scheme. As there is no explicit ddt scheme I could find, I hope that OF uses explicit from my notation.

Here is some of the code

Foam::Time time(Foam::Time::controlDictName, args);

// h is state variable for first problem
// state variable for second problem (adjoint problem) adjoint solution - counterpart of h. Reversed time scheme in 0/lambda

while(time.run())
{
....

fvScalarMatrix hEqn
(
phi*C*(fvm::ddt(h) - fvc::ddt(h)) == fvm::laplacian(k,h) - phi*fvc::ddt(s)
);
hEqn.solve();
}

time.setTime(0.0, 0); // reset to start again from 0

// history saves h for every timestep in the forward problem
for (int i = history.size() - 1; i >= 0; i--)
{
const TimeStep& step = history[i];
time.setDeltaT(step.dt);
time++;

// set C and K
fvScalarMatrix lambda_eqn(
-1.0 * phi * C * fvm::ddt(lambda) == -fvc::laplacian(k, lamba)
);
lambda_eqn.solve();
}

Now the problem is, that during solving the first and second problem, the dynamic boundary conditions from the inlet code 0/h are used but not from 0/lambda. But 0/lambda is compiled (easy to check with a syntax error)!

Why is OF touching h in the second problem?

Thanks for any help!

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post hinca CFX 15 January 26, 2014 18:11 AlbertoVe Main CFD Forum 1 January 17, 2013 04:11 Pankaj CFX 9 November 23, 2009 05:05 Paolo Lampitella FLUENT 0 February 21, 2008 07:30 Jan Ramboer Main CFD Forum 11 August 16, 1999 08:59

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