PyFoam.Infrastructure.FoamServer module

A XMLRPC-Server that answeres about the current state of a Foam-Run

class PyFoam.Infrastructure.FoamServer.FoamAnswerer(run=None, master=None, lines=100, foamserver=None)[source]

Bases: object

The class that handles the actual requests (only needed to hide the Thread-methods from the world

__dict__ = mappingproxy({'tail': <function FoamAnswerer.tail>, 'createTime': <function FoamAnswerer.createTime>, '__init__': <function FoamAnswerer.__init__>, 'elapsedTime': <function FoamAnswerer.elapsedTime>, 'getDictionaryContents': <function FoamAnswerer.getDictionaryContents>, 'lastLine': <function FoamAnswerer.lastLine>, '__module__': 'PyFoam.Infrastructure.FoamServer', 'foamVersion': <function FoamAnswerer.foamVersion>, 'nrWarnings': <function FoamAnswerer.nrWarnings>, 'ip': <function FoamAnswerer.ip>, 'startTime': <function FoamAnswerer.startTime>, 'lastLogLineSeen': <function FoamAnswerer.lastLogLineSeen>, 'time': <function FoamAnswerer.time>, 'uname': <function FoamAnswerer.uname>, 'startTimestamp': <function FoamAnswerer.startTimestamp>, 'getPlotData': <function FoamAnswerer.getPlotData>, 'hostname': <function FoamAnswerer.hostname>, 'solutionFiles': <function FoamAnswerer.solutionFiles>, 'pid': <function FoamAnswerer.pid>, 'commandLine': <function FoamAnswerer.commandLine>, 'id': <function FoamAnswerer.id>, 'mpi': <function FoamAnswerer.mpi>, '_insertLine': <function FoamAnswerer._insertLine>, 'getEnviron': <function FoamAnswerer.getEnviron>, 'isLiving': <function FoamAnswerer.isLiving>, '__dict__': <attribute '__dict__' of 'FoamAnswerer' objects>, 'getPlots': <function FoamAnswerer.getPlots>, 'argv': <function FoamAnswerer.argv>, 'writtenTimesteps': <function FoamAnswerer.writtenTimesteps>, 'getRemark': <function FoamAnswerer.getRemark>, '__weakref__': <attribute '__weakref__' of 'FoamAnswerer' objects>, 'controlDictUnmodified': <function FoamAnswerer.controlDictUnmodified>, 'setRemark': <function FoamAnswerer.setRemark>, 'writeDictionaryContents': <function FoamAnswerer.writeDictionaryContents>, 'write': <function FoamAnswerer.write>, 'procNr': <function FoamAnswerer.procNr>, 'configuration': <function FoamAnswerer.configuration>, 'jobId': <function FoamAnswerer.jobId>, 'writeDictionaryText': <function FoamAnswerer.writeDictionaryText>, 'cwd': <function FoamAnswerer.cwd>, '_kill': <function FoamAnswerer._kill>, 'runnerData': <function FoamAnswerer.runnerData>, 'lastTimeStepSeen': <function FoamAnswerer.lastTimeStepSeen>, 'deltaT': <function FoamAnswerer.deltaT>, 'user': <function FoamAnswerer.user>, 'getDictionaryText': <function FoamAnswerer.getDictionaryText>, '__doc__': 'The class that handles the actual requests (only needed to hide the\n Thread-methods from the world\n ', 'isParallel': <function FoamAnswerer.isParallel>, 'scriptName': <function FoamAnswerer.scriptName>, 'usedArgv': <function FoamAnswerer.usedArgv>, 'stop': <function FoamAnswerer.stop>, '_readParameter': <function FoamAnswerer._readParameter>, 'listFiles': <function FoamAnswerer.listFiles>, 'isFoamServer': <function FoamAnswerer.isFoamServer>, 'pathToSolution': <function FoamAnswerer.pathToSolution>, 'endTime': <function FoamAnswerer.endTime>, 'loadAvg': <function FoamAnswerer.loadAvg>, 'pyFoamVersion': <function FoamAnswerer.pyFoamVersion>, 'actualCommandLine': <function FoamAnswerer.actualCommandLine>})
__init__(run=None, master=None, lines=100, foamserver=None)[source]
Parameters:
  • run – The thread that controls the run
  • master – The Runner-Object that controls everything
  • lines – the number of lines the server should remember
__module__ = 'PyFoam.Infrastructure.FoamServer'
__weakref__

list of weak references to the object (if defined)

_insertLine(line)[source]

Inserts a new line, not to be called via XMLRPC

_kill()[source]

Interrupts the FOAM-process

_readParameter(name)[source]

Reads a parametr from the controlDict :param name: the parameter :return: The value

actualCommandLine()[source]

The actual command line used

argv()[source]

Argument vector with which the runner was called

commandLine()[source]

The command line

configuration()[source]
Returns:all the configured parameters
controlDictUnmodified()[source]

Checks whether there is a pending change to the controlDict

createTime()[source]
Returns:the time in the simulation for which the mesh was created
cwd()[source]
Returns:the current working directory
deltaT()[source]
Returns:parameter startTime from the controlDict
elapsedTime()[source]
Returns:time in seconds since the last line was output
endTime()[source]
Returns:parameter endTime from the controlDict
foamVersion()[source]

Version number of the Foam-Version

getDictionaryContents(directory, name)[source]
Parameters:
  • directory – Sub-directory of the case
  • name – name of the dictionary file
Returns:

the contents of the file as a python data-structure

getDictionaryText(directory, name)[source]
Parameters:
  • directory – Sub-directory of the case
  • name – name of the dictionary file
Returns:

the contents of the file as a big string

getEnviron(name)[source]
Parameters:name – name of an environment variable
Returns:value of the variable, empty string if non-existing
getPlotData()[source]

Get all the data for the plots

getPlots()[source]

Get all the information about the plots

getRemark()[source]

Get the user-defined remark for this job

hostname()[source]
Returns:The name of the computer
id()[source]
Returns:an ID for this run: IP:port:startTimestamp
ip()[source]
Returns:the ip of this machine
isFoamServer()[source]

This is a Foam-Server (True by default)

isLiving()[source]

The calculation still generates output and therefor seems to be living

isParallel()[source]

Is it a parallel run?

jobId()[source]

Return the job-ID of the queuing-system. Empty if unset

lastLine()[source]
Returns:the last line that was output by the running FOAM-process
lastLogLineSeen()[source]
Returns:the time at which the last log-line was seen
lastTimeStepSeen()[source]
Returns:the time at which the last log-line was seen
listFiles(directory)[source]
Parameters:directory – Sub-directory of the case
Returns:List of the filenames (not directories) in that case
loadAvg()[source]
Returns:a tuple with the average loads of the last 1, 5 and 15 minutes
mpi()[source]
Returns:name of the MPI-implementation
nrWarnings()[source]

Number of warnings the executable emitted

pathToSolution()[source]
Returns:the path to the solution directory
pid()[source]
Returns:the PID of the script
procNr()[source]

How many processors are used?

pyFoamVersion()[source]
Returns:Version number of the PyFoam
runnerData()[source]
Returns:the data the runner collected so far
scriptName()[source]

Name of the Python-Script that runs the show

setRemark(remark)[source]

Overwrite the user-defined remark :return: True if the remark was set previously

solutionFiles(time)[source]
Parameters:time – name of the timestep
Returns:list of the solution files at that timestep
startTime()[source]
Returns:parameter startTime from the controlDict
startTimestamp()[source]
Returns:the unix-timestamp of the process start
stop()[source]

Stops the run gracefully (after writing the last time-step to disk)

tail()[source]
Returns:the current last lines as a string
time()[source]
Returns:the current time in the simulation
uname()[source]
Returns:the complete uname-information
usedArgv()[source]

Argument vector with which the runner started the run

user()[source]
Returns:the user that runs this script
write()[source]

Makes the program write the next time-step to disk and the continue

writeDictionaryContents(directory, name, contents)[source]

Writes the contents of a dictionary :param directory: Sub-directory of the case :param name: name of the dictionary file :param contents: Python-dictionary with the dictionary contents

writeDictionaryText(directory, name, text)[source]

Writes the contents of a dictionary :param directory: Sub-directory of the case :param name: name of the dictionary file :param text: String with the dictionary contents

writtenTimesteps()[source]
Returns:list of the timesteps on disc
class PyFoam.Infrastructure.FoamServer.FoamServer(run=None, master=None, lines=100)[source]

Bases: threading.Thread

This is the class that serves the requests about the FOAM-Run

__init__(run=None, master=None, lines=100)[source]
Parameters:
  • run – The thread that controls the run
  • master – The Runner-Object that controls everything
  • lines – the number of lines the server should remember
__module__ = 'PyFoam.Infrastructure.FoamServer'
_insertLine(line)[source]

Inserts a new line, not to be called via XMLRPC

deregister()[source]

Tries to deregister with the Meta-Server

info()[source]

Returns the IP, the PID and the port of the server (as one tuple)

kill()[source]

Interrupts the FOAM-process (and kills the server)

killServer()[source]

Kills the server process

register()[source]

Tries to register with the Meta-Server

run()[source]
PyFoam.Infrastructure.FoamServer.findFreePort()[source]

Finds a free server port on this machine and returns it

Valid server ports are in the range 18000 upward (the function tries to find the lowest possible port number

ATTENTION: this part may introduce race conditions

PyFoam.Infrastructure.FoamServer.random() → x in the interval [0, 1).