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

systemCall for defined time steps

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

Reply
 
LinkBack Thread Tools Display Modes
Old   May 6, 2011, 05:17
Default systemCall for defined time steps
  #1
New Member
 
Peter Canfield
Join Date: Mar 2009
Posts: 16
Rep Power: 8
canfield is on a distinguished road
I have been looking for a way to modify the alpha field during a simulation and stumbled across systemCall. It allows you to execute functions at the end of an iteration step, at a write interval and/or at the end of the simulation. I would like to be able to specify explicitly at which time steps the desired functions should be executed. Maybe someone has had some experience with systemCall and help me out?

Thanks in advance

n.b. I am using OF 1.7.x

Last edited by canfield; May 6, 2011 at 07:23.
canfield is offline   Reply With Quote

Old   May 6, 2011, 14:13
Default
  #2
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,312
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Greetings Peter,

Does this page help: Tip Function Object systemCall @ openfoamwiki.net ?

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   May 6, 2011, 16:26
Default
  #3
New Member
 
Peter Canfield
Join Date: Mar 2009
Posts: 16
Rep Power: 8
canfield is on a distinguished road
Thanks for the link, Bruno. Unfortunately, I had already scoured that page for additional information and haven't got any further. It basically says what i posted initially; a function can be called either before an iteration, before a write interval, or just before the end of the simulation. I would like to be able to use systemCall between write intervals, but not as often as every iteration.

Other hints would be very welcome!

Peter
canfield is offline   Reply With Quote

Old   May 7, 2011, 03:39
Default
  #4
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,312
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Hi Peter,

OK, now read again the chapter: Usage Description
Back when I first wrote that page, I didn't fully test all of it's options...

Either way, the new information sums up to using these options together:
Code:
outputControl timeStep;
outputInterval 2;
Quote:
Originally Posted by http://openfoamwiki.net/index.php/Tip_Function_Object_systemCall#Usage_Description
outputInterval is an integer/scalar value of the same type as controlDict's writeInterval.
edit: "outputInterval 2" means that it executes at every 2 iterations. So you'll have to do a bit of math if you want to output between two write times. Things will get a bit strange if the solver uses adaptive time steps...

I've also fixed the other sibling page "Tip Function Object writeRegisteredObject", in which I had wrongly categorized outputInterval but now it's fixed.

Best regards,
Bruno

Last edited by wyldckat; May 7, 2011 at 03:43. Reason: see "edit:"
wyldckat is offline   Reply With Quote

Old   May 7, 2011, 03:54
Default
  #5
New Member
 
Peter Canfield
Join Date: Mar 2009
Posts: 16
Rep Power: 8
canfield is on a distinguished road
Bruno, you are amazing! This is indeed very good news. Thank you for opening my eyes to that option.

All the best
canfield is offline   Reply With Quote

Old   June 9, 2011, 09:47
Default Function "executeCalls"
  #6
New Member
 
Matthias Hettel
Join Date: Apr 2011
Location: Karlsruhe, Germany
Posts: 28
Rep Power: 6
matthi is on a distinguished road
Hello Bruno,

thanks for the helpful informations about the system calls. This tool is very helpful for me, because I want to call a fortran Program externally.
I tried the approach given in the wiki page to test the availability:

functions
{
sysCall
{
type systemCall;
functionObjectLibs ( "libsystemCall.so" );
executeCalls 1("echo Execute system call before time iteration is done");
endCalls 1("echo Finishing up with a system call, which is seems to be before the write call...");
writeCalls 2("echo Writing to file call" "ls -l");
outputControl outputTime;
}
}

It works ... but the command "executeCalls 1" shows NO echo line on the terminal ! The other comand lines work properly.
Maybe this has something to do with my version ? I use version 1.7.1.

Thanks in advance

Matthi
matthi is offline   Reply With Quote

Old   June 9, 2011, 16:15
Default
  #7
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,312
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Hi Matthias and welcome to the forum!

Well, you could have said which solver you were using
But I suspect the issue you're seeing is quite simple and I'm going to quote with bold letters on the two critical words:
Quote:
echo Execute system call before time iteration is done
The solver you are using most probably doesn't use time iterations! I have a vague memory of seeing a solver that does explicit iterations instead of time iterations, but I can't remember which solver it was

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   June 10, 2011, 03:15
Default
  #8
New Member
 
Matthias Hettel
Join Date: Apr 2011
Location: Karlsruhe, Germany
Posts: 28
Rep Power: 6
matthi is on a distinguished road
Hello Bruno,

thanks a lot for the fast answer. You`re completely right. I should read all items more carefully. I tried it with the solver rhoSimpleFoam (steady state) and therefore it didn`t work.

I thought about my approach again and I will try to call the external Fortran program and several system calls (copy of files and so on) directly inside the solver. This gives me more freedom to position and handle the calls. But nevertheless the option of using your functions in controldict is a very valuable tool.

Thank you again

Greetings Matthias
matthi is offline   Reply With Quote

Old   June 10, 2011, 12:58
Default
  #9
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,312
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Hi Matthias,
Quote:
Originally Posted by matthi View Post
But nevertheless the option of using your functions in controldict is a very valuable tool.
To be clear, I didn't make those functions, I simply documented them since about these there was pretty much no information, except having to look into the code, tinkering with the options and figuring out how things work!

But indeed, an option for any iterations, not just time iterations, would be a nice feature. I wonder if I that option already exists and I didn't see it...

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   June 10, 2011, 13:53
Default
  #10
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,312
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Hello again Matthias,

Hold on, something is amiss... I just ran the tutorial tutorials/compressible/rhoPorousSimpleFoam/angledDuctImplicit with the example from the wiki page and it showed me this:
Code:
Starting time loop

Time = 1

DILUPBiCG:  Solving for h, Initial residual = 0.567508, Final residual = 0.021675, No Iterations 2
GAMG:  Solving for p, Initial residual = 1, Final residual = 0.04149, No Iterations 6
time step continuity errors : sum local = 5.65325, global = -0.302944, cumulative = -0.302944
rho max/min : 1.22254 1.1863
smoothSolver:  Solving for epsilon, Initial residual = 0.178745, Final residual = 0.00240625, No Iterations 2
smoothSolver:  Solving for k, Initial residual = 1, Final residual = 0.0389567, No Iterations 2
ExecutionTime = 0.27 s  ClockTime = 1 s

Execute system call before time iteration is done
Time = 2

DILUPBiCG:  Solving for h, Initial residual = 1, Final residual = 0.0359937, No Iterations 2
GAMG:  Solving for p, Initial residual = 0.409515, Final residual = 0.019402, No Iterations 4
time step continuity errors : sum local = 11.5033, global = -1.95711, cumulative = -2.26005
rho max/min : 1.58949 1.1863
smoothSolver:  Solving for epsilon, Initial residual = 0.0863096, Final residual = 0.00417895, No Iterations 4
smoothSolver:  Solving for k, Initial residual = 0.291302, Final residual = 0.0239134, No Iterations 4
ExecutionTime = 0.44 s  ClockTime = 1 s

Execute system call before time iteration is done
Time = 3

DILUPBiCG:  Solving for h, Initial residual = 0.927538, Final residual = 0.041592, No Iterations 2
(...)
The sentence "Execute system call before time iteration is done" does show up!

That solver should be very similar to rhoSimpleFoam, so it should work as intended!


And I also just tested tutorials/stressAnalysis/solidDisplacementFoam/plateHole, which seems to be a strict iteration only solver and it showed this:
Code:
Calculating displacement field

Iteration: 1

GAMG:  Solving for Dx, Initial residual = 1, Final residual = 0.47337, No Iterations 2
GAMG:  Solving for Dy, Initial residual = 0, Final residual = 0, No Iterations 0
ExecutionTime = 0.02 s  ClockTime = 0 s

Execute system call before time iteration is done
Iteration: 2

GAMG:  Solving for Dx, Initial residual = 0.0217996, Final residual = 0.00712496, No Iterations 1
GAMG:  Solving for Dy, Initial residual = 1, Final residual = 0.443501, No Iterations 1
ExecutionTime = 0.03 s  ClockTime = 0 s

Execute system call before time iteration is done
Iteration: 3
The sentence shows up just the same!

Sooo... something is not right! I think it should have worked as intended for you as well!

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   June 15, 2011, 09:37
Default
  #11
New Member
 
Matthias Hettel
Join Date: Apr 2011
Location: Karlsruhe, Germany
Posts: 28
Rep Power: 6
matthi is on a distinguished road
Hi Bruno,

sorry for my late answer. I was out of office. Thanks or your effort. I tried it again with rhoSimpleFoam and maybe I solved the secret. Here my entry in controldict:

functions
{
sysCall
{
type systemCall;
functionObjectLibs ( "libsystemCall.so" );
executeCalls 1("echo Execute system call before time iteration is done");
endCalls 1("echo Finishing up with a system call, which is seems to be before the write call...");
outputControl outputTime;
}
}

Here the output for only ONE iteration (this is what I did last week):

Starting time loop
Time = 3611
smoothSolver: Solving for Ux, Initial residual = 0.0171106, Final residual = 0.000317189, No Iterations 2
smoothSolver: Solving for Uy, Initial residual = 0.074749, Final residual = 0.00156304, No Iterations 2
smoothSolver: Solving for Uz, Initial residual = 0.02481, Final residual = 0.00060317, No Iterations 2
DILUPBiCG: Solving for h, Initial residual = 0.0148062, Final residual = 0.00114063, No Iterations 4
GAMG: Solving for p, Initial residual = 0.81745, Final residual = 0.0212307, No Iterations 2
time step continuity errors : sum local = 1.91384, global = -0.00727263, cumulative = -0.00727263
rho max/min : 1.15865 1.15098
ExecutionTime = 9.37 s ClockTime = 12 s

Finishing up with a system call, which is seems to be before the write call...
End

THE SENTENCE IS NOT HERE !

Here the output for TWO iterations:

Starting time loop
Time = 3612
smoothSolver: Solving for Ux, Initial residual = 0.0143379, Final residual = 0.000299003, No Iterations 2
smoothSolver: Solving for Uy, Initial residual = 0.0575645, Final residual = 0.00140563, No Iterations 2
smoothSolver: Solving for Uz, Initial residual = 0.0187994, Final residual = 0.000524105, No Iterations 2
DILUPBiCG: Solving for h, Initial residual = 0.0147228, Final residual = 0.000794698, No Iterations 4
GAMG: Solving for p, Initial residual = 0.85305, Final residual = 0.0210801, No Iterations 2
time step continuity errors : sum local = 2.05708, global = -0.00686541, cumulative = -0.00686541
rho max/min : 1.15865 1.15098
ExecutionTime = 10.07 s ClockTime = 12 s


Execute system call before time iteration is done

Time = 3613
smoothSolver: Solving for Ux, Initial residual = 0.0115322, Final residual = 0.000258155, No Iterations 2
smoothSolver: Solving for Uy, Initial residual = 0.0431911, Final residual = 0.0011706, No Iterations 2
smoothSolver: Solving for Uz, Initial residual = 0.0140338, Final residual = 0.000416262, No Iterations 2
DILUPBiCG: Solving for h, Initial residual = 0.0110091, Final residual = 0.000334477, No Iterations 4
GAMG: Solving for p, Initial residual = 0.840982, Final residual = 0.0209793, No Iterations 2
time step continuity errors : sum local = 2.13375, global = -0.00501545, cumulative = -0.0118809
rho max/min : 1.15865 1.15098
ExecutionTime = 15.11 s ClockTime = 19 s

Finishing up with a system call, which is seems to be before the write call...
End


Here you can find the message just right befor the second time information is written. A little bit strange, but it seems, that it works not right for only on iteration.
I will not investigate it furthermore, because I search for another way. If it works, I will post it here.

Many Greetings

Matthias
matthi is offline   Reply With Quote

Old   June 15, 2011, 15:57
Default
  #12
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,312
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Hi Matthias,

Ah, now I understand the logic behind this function object:
  • Before the first iteration is when the solver starts, so it's not very useful to call the shell right after the solver starts.
  • executeCalls is executed before the next (time) iteration.
  • endCalls is executed instead of executeCalls, after the last iteration. This is because after the final iteration, it's very likely that one might not want to do exactly the same task as in executeCalls; and if one does want it so, simply repeat the same list from executeCalls!
I'm going to update the wiki page to reflect this reasoning

Edit: OK, I'm a bit slow today... You needed it to run after writing the fields. Mmm, then you need writeCalls, not either one of the other two!

Best regards,
Bruno

Last edited by wyldckat; June 15, 2011 at 16:01. Reason: see "Edit:"
wyldckat is offline   Reply With Quote

Old   November 23, 2012, 13:53
Default
  #13
Member
 
Join Date: Aug 2012
Posts: 74
Rep Power: 4
HakikiCanakkaleli is on a distinguished road
Hi,

I also try to use systemCall to couple an external executable file with OpenFOAM ( a small C++ code which also reads and writes some text files inside the case file).

However, I receive this error:

Code:
sh: 1: ./cwind: Permission denied
Nevertheless, in the same run, I also obtain:

Code:
allowSystemOperations : Allowing user-supplied system call operations
which shows me that OpenFOAM allows me to use sort of C++ code.

My systemCall function in the controlDict is as follows:

Code:
functions
{
    sysCall
    {
        type systemCall;
        functionObjectLibs ( "libsystemCall.so" );
        executeCalls 1( "./cwind" );
        endCalls 0();
        writeCalls 0();
        outputControl timeStep;
	outputInterval 1;
    }
}
I kindly ask any help which may show where I possibly do a mistake.

During that time, if I could find an answer I will post its explanation.

Many thanks in advance and millions espresso.
HakikiCanakkaleli is offline   Reply With Quote

Old   November 23, 2012, 14:07
Default
  #14
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by HakikiCanakkaleli View Post
Hi,

I also try to use systemCall to couple an external executable file with OpenFOAM ( a small C++ code which also reads and writes some text files inside the case file).

However, I receive this error:

Code:
sh: 1: ./cwind: Permission denied
Nevertheless, in the same run, I also obtain:

Code:
allowSystemOperations : Allowing user-supplied system call operations
which shows me that OpenFOAM allows me to use sort of C++ code.

My systemCall function in the controlDict is as follows:

Code:
functions
{
    sysCall
    {
        type systemCall;
        functionObjectLibs ( "libsystemCall.so" );
        executeCalls 1( "./cwind" );
        endCalls 0();
        writeCalls 0();
        outputControl timeStep;
	outputInterval 1;
    }
}
I kindly ask any help which may show where I possibly do a mistake.

During that time, if I could find an answer I will post its explanation.

Many thanks in advance and millions espresso.
The problem is on the OS level not OF: seems like the shell tried to execute your script but couldn't. My two guesses:
- cwind is not executable
- the current working directory is different than what you're expecting and the shell doesn't even find the util
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   November 23, 2012, 14:39
Default
  #15
Member
 
Join Date: Aug 2012
Posts: 74
Rep Power: 4
HakikiCanakkaleli is on a distinguished road
Hi,

Thanks for your answer.

I think you are right. I also consider what you said beforehand and tried to solve it.

Even though I am not an expert on Linux, it is obvious that the problem stems from the OS itself.

I have made the changes in the following:

1. I edited "sudoers" file in order to eliminate the OS functionality which asks password for any execution of any C++ executable script.

a. First, select editor by inputting the following command in the terminal:

Code:
sudo select-editor
b. Second, select "nano" editor because its usage is the simpliest.

c. Third, launch editor by inputting the following command in the terminal
Code:
sudo visudo
d. If you want to have access to all programs without password add this line in the relevant line: (as far as I concern, the sequence of the commands in the "sudoers" file is important; therefore, please be careful and do double check.
Code:
%admin    ALL = NOPASSWD: ALL
e. To save the file: use CONTROL+X. (It took this for me at least half an hour.)

2. In the case folder, please also pay attention to the "folder access". Some does not let the user to create or delete files inside a folder. So, make sure that everything is appropriate in the folder "Permissions" properties.

I expected everything would be fine; but, I observed that I have had issues and systemCall didn't work properly.

3. Then I realized that there is no gap between the execution of the external program and OpenFOAM solver - the relevant time iteration. Hence, I have modified the systemCall accordingly by adding 1 second between the start of execution of the external program and OpenFOAM time step:

Code:
functions
{
    sysCall
    {
        type systemCall;
        functionObjectLibs ( "libsystemCall.so" );
        executeCalls 1( "./cwind" );
        endCalls 0();
        writeCalls 1("sleep 1");
        outputControl timeStep;
	outputInterval 1;
    }
}
This does not give the exact picture, though. There would be some hidden things that I couldn't appreciate yet worked for me. Hopefully it gives some idea for whom deal with similar issues.

And thanks a lot to Bruno, without the Wiki page which is his product and Bernhard for the "sleep 1" tip in the forum somewhere, I would not end up with the coupling.

Millions Turkish coffee.
HakikiCanakkaleli is offline   Reply With Quote

Old   November 23, 2012, 16:43
Default
  #16
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by HakikiCanakkaleli View Post
Hi,

Thanks for your answer.

I think you are right. I also consider what you said beforehand and tried to solve it.

Even though I am not an expert on Linux, it is obvious that the problem stems from the OS itself.

I have made the changes in the following:

1. I edited "sudoers" file in order to eliminate the OS functionality which asks password for any execution of any C++ executable script.

a. First, select editor by inputting the following command in the terminal:

Code:
sudo select-editor
b. Second, select "nano" editor because its usage is the simpliest.

c. Third, launch editor by inputting the following command in the terminal
Code:
sudo visudo
d. If you want to have access to all programs without password add this line in the relevant line: (as far as I concern, the sequence of the commands in the "sudoers" file is important; therefore, please be careful and do double check.
Code:
%admin    ALL = NOPASSWD: ALL
e. To save the file: use CONTROL+X. (It took this for me at least half an hour.)

2. In the case folder, please also pay attention to the "folder access". Some does not let the user to create or delete files inside a folder. So, make sure that everything is appropriate in the folder "Permissions" properties.

I expected everything would be fine; but, I observed that I have had issues and systemCall didn't work properly.

3. Then I realized that there is no gap between the execution of the external program and OpenFOAM solver - the relevant time iteration. Hence, I have modified the systemCall accordingly by adding 1 second between the start of execution of the external program and OpenFOAM time step:

Code:
functions
{
    sysCall
    {
        type systemCall;
        functionObjectLibs ( "libsystemCall.so" );
        executeCalls 1( "./cwind" );
        endCalls 0();
        writeCalls 1("sleep 1");
        outputControl timeStep;
	outputInterval 1;
    }
}
This does not give the exact picture, though. There would be some hidden things that I couldn't appreciate yet worked for me. Hopefully it gives some idea for whom deal with similar issues.

And thanks a lot to Bruno, without the Wiki page which is his product and Bernhard for the "sleep 1" tip in the forum somewhere, I would not end up with the coupling.

Millions Turkish coffee.
What I don't fully understand: is the problem solved now? Anyway. I'm qutie sure that step 1 (editing the sudoers file) has nothing to do with it. What I meant with "permission problem" is that the execution bit of the script file is not set (that would generate the error message you reported). Best way to check that is to try to execute it "by hand" (==from the shell). If that doesn't work check the man-page for chmod
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   November 23, 2012, 18:40
Default
  #17
Member
 
Join Date: Aug 2012
Posts: 74
Rep Power: 4
HakikiCanakkaleli is on a distinguished road
The problem seems to be solved now. I also checked from the shell whether the external program works or not and it worked well. Now, considering your message, I will reconsider the reason behind why it did not work properly.
HakikiCanakkaleli is offline   Reply With Quote

Old   November 27, 2012, 10:43
Default
  #18
New Member
 
Matthias Hettel
Join Date: Apr 2011
Location: Karlsruhe, Germany
Posts: 28
Rep Power: 6
matthi is on a distinguished road
Hi,

I also don`t understand the problem fully. But anyway, there is another possibility to launch an external program or to use system calls.
This might be easier than defining an own function.

If you want to call a programm named "test" in a routine you can use: system(./test);

If the program is NOT in the case folder, then you have to change the directory. E.G. the program is in the subfolder "system". The you could use the command: system("cd system; ./test; cd ..");

Hope this helps.

Greetings Matthi
matthi is offline   Reply With Quote

Reply

Tags
systemcall

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
calculation diverge after continue to run zhajingjing OpenFOAM 0 April 28, 2010 04:35
Time Steps gets smaller and smaller titio OpenFOAM Running, Solving & CFD 1 July 22, 2009 08:19
Time steps - Large Eddy - LES Gernot FLUENT 0 September 14, 2005 11:54
Number of time steps in fluent 4-NT Newbie FLUENT 0 March 24, 2001 14:44
unsteady calcs in FLUENT Sanjay Padhiar Main CFD Forum 1 March 31, 1999 12:32


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