# Operations during iterations

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

 December 30, 2012, 21:27 Operations during iterations #1 Member   Martin Join Date: Dec 2011 Location: Latvia Posts: 54 Rep Power: 7 Sponsored Links 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

 January 1, 2013, 07:15 #2 Senior Member   Bernhard Join Date: Sep 2009 Location: Delft Posts: 790 Rep Power: 14 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.

 January 4, 2013, 13:24 #3 Member   Martin Join Date: Dec 2011 Location: Latvia Posts: 54 Rep Power: 7 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.

 January 4, 2013, 14:28 #4 Senior Member   Bernhard Join Date: Sep 2009 Location: Delft Posts: 790 Rep Power: 14 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)

 January 5, 2013, 16:23 #5 Member   Martin Join Date: Dec 2011 Location: Latvia Posts: 54 Rep Power: 7 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

 January 7, 2013, 04:46 #6 Senior Member   Olivier Join Date: Jun 2009 Location: France, grenoble Posts: 266 Rep Power: 11 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

 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 Artex85 OpenFOAM Running, Solving & CFD 11 February 16, 2017 14:40 Lord Kelvin OpenFOAM Running, Solving & CFD 8 March 28, 2016 11:08 hfs OpenFOAM Running, Solving & CFD 3 October 29, 2013 09:35 jonmec OpenFOAM Running, Solving & CFD 3 July 28, 2011 05:24 carsten OpenFOAM Bugs 11 September 12, 2008 11:16