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

Operations during iterations

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

Reply
 
LinkBack Thread Tools Display Modes
Old   December 30, 2012, 21:27
Default Operations during iterations
  #1
Member
 
Martin
Join Date: Dec 2011
Location: Latvia
Posts: 54
Rep Power: 5
latvietis is on a distinguished road
Greetings, FOAMers!

I have magnetic problem solver

Code:
1.    B=fvc::curl(A);

2.    B2=B&B;

3.    //--> calculate reluctivity (viR) using some algorithm

4.    solve (viconst*viR*fvm::laplacian(A)==-fvc::curl(Hc));

5.    // move to point 1. using new A values
but I can't get this code to be iterative. All it solves iterative in different time steps is A (that is what it should do written as this I guess). What I want is that from initial A is calculated B, then B2, then viR, then NEW set of A values. Initial fields are A, viR, and Hc. First two are changing with every iteration. And process should repeat until there is achieved some kind of tolerance. How can I do this in OpenFOAM?

Basically I want that these 5 steps are done during each iteration, so I could get an output similar to this

Code:
DICPCG:  Solving for Ax, Initial residual = 1, Final residual = 8.67698e-06, No Iterations 96
DICPCG:  Solving for Ay, Initial residual = 1, Final residual = 9.81058e-06, No Iterations 101
DICPCG:  Solving for Az, Initial residual = 0, Final residual = 0, No Iterations 0
which now informs that I have successfully calculated A, but that would tell me that I have successfully calculated A by being trough all 5 steps.


Any hint would be much appreciated!

Yours,
Martin
latvietis is offline   Reply With Quote

Old   January 1, 2013, 07:15
Default
  #2
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 12
Bernhard is on a distinguished road
I do not fully understand what sets of equations you are trying to solve. Is it a time-dependent problem?

Short answer: A while loop does the job.

Long answer:
In case of a steady-state problem, you can just use the time-iteration as iteration over your set of equations. This is what is done in the simpleFoam solver. You can look at some of these cases and check how iterative convergence is controlled in these examples. (using residualControl). (Now rechecking the code, and simpleFoam in 2.1.1 does not explicitly call it a time-loop anymore, although the output does)

If your problem is transient, you cannot misuse the time loop for that, and you should build an additional loop around your five lines of code. This what is done in the pimpleFoam solver.
Bernhard is offline   Reply With Quote

Old   January 4, 2013, 13:24
Default
  #3
Member
 
Martin
Join Date: Dec 2011
Location: Latvia
Posts: 54
Rep Power: 5
latvietis is on a distinguished road
Sweet, thanks Bernhard! I tried this before but calculation was blowing up so I was looking for different ways. Just had to rearrange order of equations and then follow your advice.

I don't want to start a new thread for a new simple question as I hope someone will reply in here.

How can I write a field? But not simply like

Code:
volScalarField T (     IOobject     (         "T",         runTime.timeName(),         mesh,         IOobject::MUST_READ,         IOobject::AUTO_WRITE     ),     mesh );
but something like

Code:
volScalarField T (     IOobject     (         "T",         runTime.timeName(),         mesh     ) );
?

Sadly it doesn't work this simple as I understand there is need for some argument (equation).
Like
Code:
volScalarField T (     IOobject     (         "T",         runTime.timeName(),         mesh     )
b+a (or what ever)
);
The problem is that I can't write a simple equation and solution is calculated by a rather long C code, so what I want is to simply define a field in createFields.H and that I will use later.
latvietis is offline   Reply With Quote

Old   January 4, 2013, 14:28
Default
  #4
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 12
Bernhard is on a distinguished road
I don't understand your follow-up question. Also, writing all on one line doesn't make it clearer to read. I thought it was possible to do just something like T.write() or something like that (see e.g. the source code of potentialFoam)
Bernhard is offline   Reply With Quote

Old   January 5, 2013, 16:23
Default
  #5
Member
 
Martin
Join Date: Dec 2011
Location: Latvia
Posts: 54
Rep Power: 5
latvietis is on a distinguished road
Sorry, was a bit tired when I wrote this question.

Lets say I define a field B in createFields.H.

Code:
volVectorField B
(
  IOobject
  (
     "B",
     runTime.timeName(),
     mesh
  ),
fvc::curl(A)
);
This rather straightforward definition. I simply write in my C file a line

B = fvc::curl(A)

and solver knows that here I want to calculate my field and afterwards it creates a nice file with all values. But I can't do this:

Code:
volVectorField A
(
  IOobject
  (
     "A",
     runTime.timeName(),
     mesh
  )
          //and put nothing here
);
It doesn't compile and puts error message "No matching function to call to...... (and some details after)." What should I do if I need to define a field that will be calculated at some point, but I don't have a simple formula to put in there.

Sorry if question seems too trivial, and I hope I explained it better.

Yours,
Martin
latvietis is offline   Reply With Quote

Old   January 7, 2013, 04:46
Default
  #6
Senior Member
 
Olivier
Join Date: Jun 2009
Location: France, grenoble
Posts: 238
Rep Power: 9
olivierG is on a distinguished road
hello,

The value in createFields, like your "fvc::curl(A)" are only for initialisation, so you can put what you want (should be dimensioned correctly through). So try to provide a "good" initial guess.

regards,
olivier
olivierG is offline   Reply With Quote

Reply

Thread Tools
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
pimpleFoam: turbulence->correct(); is not executed when using residualControl hfs OpenFOAM Running, Solving & CFD 3 October 29, 2013 09:35
High Courant Number @ icoFoam Artex85 OpenFOAM Running, Solving & CFD 9 January 3, 2012 09:06
Orifice Plate with a fully developed flow - Problems with convergence jonmec OpenFOAM Running, Solving & CFD 3 July 28, 2011 05:24
Extrusion with OpenFoam problem No. Iterations 0 Lord Kelvin OpenFOAM 6 April 12, 2011 11:24
Differences between serial and parallel runs carsten OpenFOAM Bugs 11 September 12, 2008 11:16


All times are GMT -4. The time now is 18:59.