Exemplo n.º 1
0
    def writeDictionaryContents(self,directory,name,contents):
        """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"""

        theDir=self.name
        if directory:
            theDir=path.join(theDir,directory)

        result=WriteParameterFile(path.join(theDir,name))
        result.content=contents
        result.writeFile()
    def writeDictionaryContents(self,directory,name,contents):
        """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"""

        theDir=self.name
        if directory:
            theDir=path.join(theDir,directory)

        result=WriteParameterFile(path.join(theDir,name))
        result.content=contents
        result.writeFile()
Exemplo n.º 3
0
    def run(self):
        method = self.config.attrib["method"]
        n = self.config.attrib["n"]
        self.logger.info("Decomposing case for %s domains using method %s.", n, method)
        decomposeParDict = WriteParameterFile(os.path.join(self.case, "system/decomposeParDict"), createZipped=False)
        decomposeParDict["method"] = method
        decomposeParDict["numberOfSubdomains"] = n
        coeffs = {}
        for i in self.config:
            coeffs[i.tag] = i.text
            
        decomposeParDict[method + "Coeffs"] = coeffs
        decomposeParDict.writeFile()

        self.start_process("decomposePar -case %s" % self.case)
Exemplo n.º 4
0
def _mutable_data_file_manager(path, create_class=FileClass.DICTIONARY, 
                               create=True):
    """Context manager for mutating an OpenFOAM dict.

    If the dictionary is created, create_class is used to specify the class of
    the created dictionary.

    >>> dict_path = getfixture('tmpdir').join('tmpDict').strpath
    >>> with _mutable_data_file_manager(dict_path, create=True) as d:
    ...     d['test'] = 'foo'
    >>> read_data_file(dict_path)['test']
    'foo'

    Args:
        path (str): path to OpenFOAM dict
        create_class (str or FileClass): specify the class of created files
        create (bool): create file if it does not exist

    Returns:
        A context manager which reads (or optionally creates) an OpenFOAM dict
        file, returns a Python representation. When the context is left, the
        content is written back to disk.

    """
    if create and not os.path.isfile(path):
        dir_path = os.path.dirname(path)
        if not os.path.isdir(dir_path):
            os.makedirs(dir_path)

        try:
            create_class = create_class.value
        except AttributeError:
            create_class = create_class

        foam_file = WriteParameterFile(path, className=create_class)
    else:
        foam_file = ParsedParameterFile(path)
    yield foam_file.content
    foam_file.writeFile()
Exemplo n.º 5
0
def _mutable_data_file_manager(path, create_class=FileClass.DICTIONARY,
                               create=True):
    """Context manager for mutating an OpenFOAM dict.

    If the dictionary is created, create_class is used to specify the class of
    the created dictionary.

    >>> dict_path = getfixture('tmpdir').join('tmpDict').strpath
    >>> with _mutable_data_file_manager(dict_path, create=True) as d:
    ...     d['test'] = 'foo'
    >>> read_data_file(dict_path)['test']
    'foo'

    Args:
        path (str): path to OpenFOAM dict
        create_class (str or FileClass): specify the class of created files
        create (bool): create file if it does not exist

    Returns:
        A context manager which reads (or optionally creates) an OpenFOAM dict
        file, returns a Python representation. When the context is left, the
        content is written back to disk.

    """
    if create and not os.path.isfile(path):
        dir_path = os.path.dirname(path)
        if not os.path.isdir(dir_path):
            os.makedirs(dir_path)

        try:
            create_class = create_class.value
        except AttributeError:
            create_class = create_class

        foam_file = WriteParameterFile(path, className=create_class)
    else:
        foam_file = ParsedParameterFile(path)
    yield foam_file.content
    foam_file.writeFile()
Exemplo n.º 6
0
        "p_{0:05} {{start ({1:} {2:} {3:}); end ({1:} {2:} {4:});  type face; axis z; nPoints {5:}; }}"
        .format(i, *p) for i, p in enumerate(waveProbesList)
    ]

    return d


def createLinearWaveProbesList(xMin, xMax, nX, y, zMin, zMax, nZ):
    waveProbesList = []
    deltaX = (xMax - xMin) / (nX - 1)
    for i in range(0, nX):
        waveProbesList.append([xMin + i * deltaX, y, zMin, zMax, nZ])
    return waveProbesList


if __name__ == "__main__":

    # works with tuples or with lists
    #waveProbesList = ( (10.,0.,-1.,+1 , 100) , (15.,0.,-1.,+1 , 100) )
    waveProbesList = [[10., 0., -1., +1, 100], [15., 0., -1., +1, 100]]
    print(waveProbesList)

    waveProbesList = createLinearWaveProbesList(-100.0, 100.0, 201, 0.05, -3.0,
                                                3.0, 100)
    print(waveProbesList)
    d = setWaveProbes(waveProbesList, "foamStar", writeProbesInterval=0.01)

    waveProbFile = WriteParameterFile("waveProb.inc")
    waveProbFile["functions"] = d
    waveProbFile.writeFile()