def Build_static(cls, case): """Build dynamicMeshDict for static cases """ res = cls(name=join(case, getFilePath("dynamicMeshDict")), read=False) res.header["class"] = "dictionary" res["dynamicFvMesh"] = "staticFvMesh" return res
return d class WaveProperties(ReadWriteFile): """ waveProperty foamStar file """ @classmethod def Build(cls, case, initWaveCondition, relaxZones=[], seaLevel=0., application="foamStar"): res = cls(name=os.path.join(case, getFilePath("waveProperties")), read=False) res.case = case res.relaxZones = relaxZones res["#inputMode"] = "overwrite" if application == "foamStar": res["initWave"] = initWaveCondition.pyFoamDict( application=application) res["seaLevel"] = 0.0 res["initCoeffs"] = {"$initWave": ''} if len(relaxZones) > 0: res["relaxationNames"] = [ relax.name for relax in relaxZones if relax.relax ]
class FvSchemes(ReadWriteFile): """ FvSchemes dictionnary """ @classmethod def Build(cls, case, application="foamStar", prsJump=False, orthogonalCorrection=False, blendCN=0.9, simType="steady", limitedGrad=False): res = cls(name=join(case, getFilePath("fvSchemes")), read=False) #-------- ddtSchemes ddt = DictProxy() if simType.lower() == "steady": ddt["default"] = "steadyState" ddt["ddt(U)"] = "Euler" ddt["ddt(alpha.water)"] = "Euler" elif simType.lower() == "euler": ddt["default"] = "Euler" ddt["ddt(U)"] = "Euler" else: ddt["default"] = "CrankNicolson {}".format(blendCN) ddt["ddt(rho,U)"] = "backward" ddt["ddt(U)"] = "Euler" res["ddtSchemes"] = ddt
List of patches names to compute pressure pressureFields : list of str, default ['p','p_rgh'] Pressure type to use for pressure and force output. Values can include 'p' or 'p_rgh'. outputLocalMotions : bool, default False Logical defining if local motions shoudl be output rhoWater : float, default 1000. Fuild density OFversion : int, default 5 OpenFOAM version used application : str, default 'foamStar' OpenFOAM application used """ res = cls( name = join(case, getFilePath("controlDict") ), read = False ) res["application"] = app[application] res["startFrom"] = startFrom res["startTime"] = startTime res["stopAt"] = "endTime" res["endTime"] = endTime res["deltaT"] = deltaT res["writeControl"] = writeControl res["writeInterval"] = writeInterval res["purgeWrite"] = purgeWrite res["writeFormat"] = writeFormat res["writeCompression"] = "off" # Compressed binary is reported as inefficient by openFoam if writeFormat == "ascii" : res["writePrecision"] = writePrecision res["writeCompression"] = writeCompression
from ideFoam.inputFiles import ReadWriteFile, getFilePath from PyFoam.Basics.DataStructures import Dimension, Vector from os.path import join """ Convenience class to simply write DecomposeParDict """ class DecomposeParDict(ReadWriteFile): """ DecomposeParDict dictionnary """ @classmethod def Build(cls, case, nProcs=1, method="scotch", application="foamStar"): res = cls(name=join(case, getFilePath("decomposeParDict")), read=False) res["numberOfSubdomains"] = nProcs res["method"] = method if method == "simple": res["simpleCoeffs"] = {"n": "( 1 3 1 )", "delta": 0.001} res["hierarchicalCoeffs"] = { "n": "( 3 2 1 )", "delta": 0.001, "order": "xzy" } res["manualCoeffs"] = {"dataFile": '"cellDecomposition"'} elif method == "scotch": res["distributed"] = "no"
self.createParaviewFile() def clean(self,clean = False) : cleanCase(self.case, clean) @classmethod def Read( cls, case, source, application = "foamStar" ): """Read file from existing folder """ source = abspath(source) case = abspath(case) fileDict = {} for f in cls.handledFiles: fname = join(source, getFilePath(f) ) if exists(fname) : tmpobj = getFileClass()( join(source, getFilePath(f) ) , read = True) tmpobj.case = case tmpobj.name = tmpobj.name.replace(source, case) fileDict[ f ] = tmpobj else: print (fname, "does not exists") return cls( case, **fileDict , application = application, meshFolder = join(source, "constant") ) def createParaviewFile(self): #create file for Paraview open(join(self.case,'view.foam'), 'a').close() @classmethod
from ideFoam.inputFiles import ReadWriteFile, getFilePath from PyFoam.Basics.DataStructures import Dimension, Vector, DictProxy from os.path import join """ Convenience class to simply write SurfaceFeatureExtractDict """ class SurfaceFeatureExtractDict(ReadWriteFile): """ SurfaceFeatureExtractDict dictionary """ @classmethod def Build(cls, case, stlname="body"): res = cls(name=join(case, getFilePath("surfaceFeatureExtractDict")), read=False) stlname = stlname.split('.stl')[0] #remove .stl extension body = DictProxy() body["extractionMethod"] = "extractFromSurface" body["extractFromSurfaceCoeffs"] = {"includedAngle": 150.} body["subsetFeatures"] = { "nonManifoldEdges": "yes", "openEdges": "yes" } body["writeObj"] = "yes" res[stlname + ".stl"] = body return res
cellRatio : int, default 1 If not waveMesh, Y/Z cell ratio createPatch : bool, default True Logical defining is patches should be created by blockMesh patches : list If createPatch is True, user can define a custom patch definition (refer to blockMesh help gridlvl : int, default 1 TODO OFversion: int or str, default 5 OpenFOAM version used """ res = cls(name=join(case, getFilePath("blockMeshDict", OFversion)), read=False) res["fastMerge"] = "yes" res["convertToMeters"] = 1 res["xmin"] = xmin res["xmax"] = xmax if isinstance(ymin, float): res["ymin"] = ymin if isinstance(ymax, float): res["ymax"] = ymax if isinstance(zmin, float): res["zmin"] = zmin if isinstance(zmax, float): res["zmax"] = zmax if isinstance(fsmin, float): res["fsmin"] = fsmin if isinstance(fsmax, float): res["fsmax"] = fsmax if waveMesh:
from ideFoam.inputFiles.compatOF import namePatch """Convenient class to simply write ExtrudeMeshDict """ class ExtrudeMeshDict(ReadWriteFile) : """ExtrudeMeshDict dictionnary """ @classmethod def Build(cls , case, sourceCase='"./"', sourcePatch = "outlet", exposedPatchName="inlet", nLayers=1, expansionRatio=1, thickness=0.1, mergeFaces=False, mergeTol=0, version='foamStar', flipNormals = True): res = cls( name = join(case, getFilePath("extrudeMeshDict") ), read = False ) patch = namePatch[version] res["constructFrom"] = "patch" res["sourceCase"] = sourceCase res["sourcePatches"] = [patch[sourcePatch]] res["exposedPatchName"] = patch[exposedPatchName] if flipNormals : res["flipNormals"] = True res["extrudeModel"] = "linearNormal" res["nLayers"] = nLayers res["expansionRatio"] = expansionRatio
from ideFoam.inputFiles import ReadWriteFile, getFilePath from PyFoam.Basics.DataStructures import Vector, SymmTensor """ Convenience class to simply write "SixDofDomainBody" """ class SixDofDomainBody(ReadWriteFile): """SixDofDomainBody dictionnary """ @classmethod def Build(cls , case, mass, inertia, COG, nModes=0, donName=None) : res = cls( name = join(case, getFilePath("sixDofDomainBody") ), read = False ) res.header["class"] = "dictionary" res.header["object"] = "singleBody" res["mass"] = mass res["momentOfInertia"] = SymmTensor( *inertia ) res["cogInitial"] = Vector( *COG ) res["Xrel"] = "(0 0 0)" res["dotXrel"] = "(0 0 0)" res["omega"] = "(0 0 0)" res["EulerZYX"] = { "rollPitchYaw" : "(0 0 0)" } if nModes>0: res["modalData"] = { "readFromFile" : "constant/{}.flex".format(donName) } return res
} class FvSolution(ReadWriteFile) : """ FvSchemes dictionnary """ @classmethod def Build(cls , case, fsiTol = 1e-8, useEulerCells=False, nOuterCorrectors=10, nInnerCorrectors = 4, application = "foamStar", pressureSolver = "PCG_1", velocitySolver = "SMOOTHSOLVER_1", airDamping = 0.0 ) : res = cls( name = join(case, getFilePath("fvSolution") ), read = False ) solvers = DictProxy() #Alpha alpha = DictProxy() alpha["nAlphaCorr"] = 3 alpha["nAlphaSubCycles"] = 1 alpha["cAlpha"] = 0.3 alpha["MULESCorr"] = "yes" alpha["nLimiterIter"] = 5 alpha["alphaApplyPrevCorr"] = "no" alpha["solver"] = "smoothSolver" alpha["smoother"] = "symGaussSeidel" alpha["tolerance"] = 1e-8 alpha["relTol"] = 0
def Build_free(cls, case, mass, cog, inertia, rampTime, releaseTime, meshMotion, hullPatch="(ship)", innerDistance=None, outerDistance=None, OFversion=5, application="foamStar"): """Build dynamicMeshDict for standard rigid seakeeping """ res = cls(name=join(case, getFilePath("dynamicMeshDict")), read=False) res.header["class"] = "dictionary" import tempfile with tempfile.NamedTemporaryFile("w", delete=False) as f: f.write(template_free) res.content = ReadWriteFile(f.name).content os.unlink(f.name) res["multiBodyFvMeshCoeffs"]["meshMotion"] = meshMotion res.setMechanics(mass, cog, inertia, hullPatch) if meshMotion == "cpMorphing": res["multiBodyFvMeshCoeffs"]["ship"][ "innerDistance"] = innerDistance res["multiBodyFvMeshCoeffs"]["ship"][
from os.path import join from ideFoam.inputFiles.compatOF import alpha, p_rgh, waveAlpha, waveVelocity, pointDisp, namePatch from ideFoam.inputFiles import ReadWriteFile, getFilePath """ Convenience class to simply write boudary condition for sea-keeping case """ class BoundaryOmega(ReadWriteFile): @classmethod def Build(cls, case, symmetry=1, wallFunction=False, application="foamStar", namePatch=namePatch, omega=2., case2D=False): patch = namePatch[application] res = cls(name=join(case, getFilePath("boundaryOmega")), read=False) res.header["class"] = "volScalarField" res["dimensions"] = Dimension(*[0, 0, -1, 0, 0, 0, 0]) res["internalField"] = "uniform {}".format(omega) bf = DictProxy() bf[patch["outlet"]] = {"type": "fixedValue", "value": omega} bf[patch["inlet"]] = {"type": "fixedValue", "value": omega} if application == "foamStar": bf[patch["side1"]] = {"type": "fixedValue", "value": omega} bf[patch["side2"]] = {"type": "fixedValue", "value": omega} else: bf[patch["side"]] = {"type": "fixedValue", "value": omega} bf[patch["bottom"]] = {"type": "fixedValue", "value": omega} bf[patch["top"]] = {"type": "fixedValue", "value": omega} bf[patch["structure"]] = {"type": "zeroGradient"} bf["defaultFaces"] = {"type": "empty"}
"""InitFlexDict file """ @classmethod def Build(cls, case, mdFile=None, modes2use=None, datFile=None, dmigFile=None, draft=0., scale=1., vtkOut=True, hullPatch=None, localPts=None): res = cls(name=join(case, getFilePath("initFlexDict")), read=False) res.header["class"] = "dictionary" fem = DictProxy() fem["mdFile"] = '"../{}"; selected ( '.format( mdFile) + len(modes2use) * '{} '.format(*modes2use) + ')' fem["datFile"] = '"../{}"'.format(datFile) fem["dmigMfile"] = '"../{}"'.format(dmigFile) fem["dmigKfile"] = '"../{}"'.format(dmigFile) fem["pchCoordinate"] = SymmTensor(*[0, 0, -draft, 0, 0, 0]) fem["pchScaleMode"] = scale fem["pchLengthUnit"] = 1 fem["pchMassUnit"] = 1 if not vtkOut: fem["outputToVTK"] = "no" fem["patches"] = "({})".format(hullPatch)
Disable layers creation on selected patches (e.g. deck) maxNonOrtho : int, default 55 TODO (option maxNonOrtho) minTwist : float, default 0.05 TODO (option minTwist) nSmoothScale : int, default 5 TODO (option nSmoothScale) errorReduction : float, default 0.85 TODO (option errorReduction) OFversion: int or str, default 5 OpenFOAM version used """ res = cls(name=join(case, getFilePath("snappyHexMeshDict")), read=False) stlname = stlname.split('.stl')[0] #remove .stl extension res["#inputMode"] = "overwrite" res["castellatedMesh"] = castellatedMesh res["snap"] = snap res["addLayers"] = addLayers geometry = DictProxy() body = DictProxy() body["type"] = "triSurfaceMesh" body["name"] = patchName body["patchInfo"] = {"type": "wall"}
from os.path import join """ Convenience class to simply write "TurbulenceProperties" and RASModel """ RASturbulenceModel = ["kOmegaSST", "fsKOmegaSST"] #navalFoam rhoKomegaSST class TurbulenceProperties(ReadWriteFile): """ FvSchemes dictionnary """ @classmethod def Build(cls, case, turbulenceModel=None): res = cls(name=join(case, getFilePath("turbulenceProperties")), read=False) if turbulenceModel == "laminar": res["simulationType"] = "laminar" elif turbulenceModel in RASturbulenceModel: res["simulationType"] = "RASModel" else: print("Unknown turbulence model") return res class RASProperties(ReadWriteFile): """ RASProperties dictionnary
class TransportProperties(ReadWriteFile): """ TransportProperties dictionnary """ @classmethod def Build(cls, case, rhoWater=1000, nuWater=1e-6, rhoAir=1., nuAir=1.48e-05, sigma=0.0, application="foamStar"): res = cls(name=join(case, getFilePath("transportProperties")), read=False) res.header["class"] = "dictionary" if application == "foamStar": res["phases"] = ["water", "air"] dw = DictProxy() dw["transportModel"] = "Newtonian" dw["nu"] = "nu [0 2 -1 0 0 0 0] {}".format(nuWater) dw["rho"] = "rho [1 -3 0 0 0 0 0] {}".format(rhoWater) res['"' + water[application] + '"'] = dw da = DictProxy() da["transportModel"] = "Newtonian", da["nu"] = "nu [0 2 -1 0 0 0 0] {}".format(nuAir)