示例#1
0
    def of7dynamicMeshdict(self, fipath):
        '''
		Creates the dynamic mesh dictionary for the moving wall

		Arguments
		-----------
			fipath: Path to the dakota.json file location
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get the file ID
        filepath = os.path.join(fipath, "constant", "dynamicMeshDict")
        fileID = open(filepath, "w")
        # Header
        header = hydroutil.of7header("dictionary", "constant",
                                     "dynamicMeshDict")
        fileID.write(header)
        # Other data
        fileID.write('\ndynamicFvMesh\tdynamicMotionSolverFvMesh;\n\n')
        fileID.write('motionSolverLibs\t("libfvMotionSolvers.so");\n\n')
        fileID.write('solver\tdisplacementLaplacian;\n\n')
        fileID.write(
            'displacementLaplacianCoeffs\n{\n\tdiffusivity uniform;\n}\n')
        # Close the file
        fileID.close()
示例#2
0
    def decomptext(self, data):
        '''
		Creates the necessary files for domain decomposition for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get the header text for the U-file
        decomptext = self.decompheader()

        # Get number of subdomains
        subdomains = ', '.join(
            hydroutil.extract_element_from_json(
                data, ["Events", "DomainDecomposition"]))

        decomptext = decomptext + "numberOfSubdomains\t" + subdomains + ";\n\n"

        decomptext = decomptext + "method\tscotch;\n\n"

        return decomptext
示例#3
0
	def creategeom(self,data,path):
		'''
		Creates the geometry for bathymetry 

		Arguments
		-----------
			data: all the JSON data
		'''

		# Create a utilities object
		hydroutil = hydroUtils()

		# Get information about the interface
		swcfdfile = ', '.join(hydroutil.extract_element_from_json(data, ["Events","SWCFDInteFile"]))
		swcfdfilepath = os.path.join(path,swcfdfile)
		swcfdpoints = np.genfromtxt(swcfdfilepath, delimiter=',',dtype=(float, float))

		# Add extremum to the constants file
		maxvalues = np.max(swcfdpoints,axis=0)
		minvalues = np.min(swcfdpoints,axis=0)

		# Points of interest
		bottompts = self.getbathy(maxvalues,minvalues,data)

		# 


		return 0
示例#4
0
    def scripts(self, data):
        '''
		Add to caserun.sh

		Arguments
		-----------
			NONE
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get the mesher
        mesher = ', '.join(
            hydroutil.extract_element_from_json(data, ["Events", "MeshType"]))

        # Combine STL files for Hydro mesh or using mesh dict
        if int(mesher[0]) == 0 or int(mesher[0]) == 2:
            # Get building flag from temp-geometry file
            geofile = 'temp_geometry.txt'
            data_geoext = np.genfromtxt(geofile, dtype=(float))
            flag = int(data_geoext[6])

            # If translate file exists, use it
            if os.path.exists('translate.sh'):
                caseruntext = 'echo Translating building STL files...\n'
                caseruntext = caseruntext + 'chmod +x translate.sh\n'
                caseruntext = caseruntext + './translate.sh\n\n'
                caseruntext = caseruntext + 'echo Combining STL files for usage...\n'
            else:
                caseruntext = 'echo Combining STL files for usage...\n'

            # Join all paths
            entryf = os.path.join('constant', 'triSurface', 'Entry.stl')
            exitf = os.path.join('constant', 'triSurface', 'Exit.stl')
            topf = os.path.join('constant', 'triSurface', 'Top.stl')
            bottomf = os.path.join('constant', 'triSurface', 'Bottom.stl')
            leftf = os.path.join('constant', 'triSurface', 'Left.stl')
            rightf = os.path.join('constant', 'triSurface', 'Right.stl')
            buildingf = os.path.join('constant', 'triSurface', 'Building.stl')
            otherbuildingf = os.path.join('constant', 'triSurface',
                                          'OtherBuilding.stl')
            all01 = 'cat ' + entryf + ' ' + exitf + ' ' + topf + ' ' + bottomf + ' ' + leftf + ' ' + rightf
            full = os.path.join('constant', 'triSurface', 'Full.stl')

            # For different building cases
            if flag == 0:
                caseruntext = caseruntext + all01 + ' > ' + full + '\n\n'
            elif flag == 1:
                caseruntext = caseruntext + all01 + ' ' + buildingf + ' > ' + full + '\n\n'
            elif flag == 2:
                caseruntext = caseruntext + all01 + ' ' + buildingf + ' ' + otherbuildingf + ' > ' + full + '\n\n'
            elif flag == 3:
                caseruntext = caseruntext + all01 + ' ' + otherbuildingf + ' > ' + full + '\n\n'
            # Write to caserun file
            scriptfile = open('caserun.sh', "a")
            scriptfile.write(caseruntext)
            scriptfile.close()
示例#5
0
    def createmesh(self, data, path):
        '''
		Creates the mesh dictionaries for openfoam7

		Arguments
		-----------
			data: all the JSON data
			path: Path where the geometry files (STL) needs to be created
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get mesher type
        mesher = ', '.join(
            hydroutil.extract_element_from_json(data, ["Events", "MeshType"]))

        # Create the meshing related file
        Meshing = of7Meshing()
        meshcode = Meshing.meshcheck(data, path)
        if meshcode == -1:
            return -1
        else:
            # Hydro mesher
            if int(mesher[0]) == 0:
                # blockMesh
                bmeshtext = Meshing.bmeshtext(data)
                fname = 'blockMeshDict'
                filepath = os.path.join(path, 'system', fname)
                bmeshfile = open(filepath, "w")
                bmeshfile.write(bmeshtext)
                bmeshfile.close()
                # surfaceFeatureExtract
                sfetext = Meshing.sfetext()
                fname = 'surfaceFeatureExtractDict'
                filepath = os.path.join(path, 'system', fname)
                sfefile = open(filepath, "w")
                sfefile.write(sfetext)
                sfefile.close()
                # snappyHexMesh
                shmtext = Meshing.shmtext(data)
                fname = 'snappyHexMeshDict'
                filepath = os.path.join(path, 'system', fname)
                shmfile = open(filepath, "w")
                shmfile.write(shmtext)
                shmfile.close()

            # Mesh files from other softwares (1)
            # Do nothing here. Add to caserun.sh

            # User mesh dictionaries (2)
            # Do nothing here. Copy files to relevant place
            # in caserun.sh

        # Scripts
        Meshing.scripts(data, path)

        return 0
示例#6
0
	def buildmanual(self,data,path):
		'''
		Creates the STL files for the buildings using manual data from table

		Arguments
		-----------
			data: all the JSON data
			path: Path to where the dakota.json exists
		'''

		# Create a utilities object
		hydroutil = hydroUtils()

		# Number of types of buildings
		numresbuild = 0
		numotherbuild = 0

		# Get the coordinate and dimension data


		# Find number of buildings
		numbuild = ', '.join(hydroutil.extract_element_from_json(data, ["Events","NumBuild"]))
		if int(numbuild) > 0:
			# Get data for each building
			for ii in range(int(numbuild)):
				builddata = ', '.join(hydroutil.extract_element_from_json(data, ["Events","BuildingTable"+str(ii)]))
				builddata = builddata.replace(',',' ')
				nums = [float(n) for n in builddata.split()]
				buildtype = nums[0]

				if int(buildtype) == -2:
					# Create a temporary file using GI information (Response)
					self.buildcubeGI(data,path)
					# Increment response buildign number
					numresbuild += 1
				elif int(buildtype) == -1:
					# Move the STL file to OF folder and change name to Building (Response)
					self.readResSTL(data,path,nums[3])
					# Increment response buildign number
					numresbuild += 1
				elif int(buildtype) == 1:
					print('no response + cuboid')
					# Create a temporary file 
					# Call flume to build an STL
					# Combine all STL to building + number
					# Increment response buildign number
					numotherbuild += 1
				elif int(buildtype) == 2:
					print('no response + STL')
					# Check if STL file exists
					# Increment response buildign number
					numotherbuild += 1

		# Create other buildings STL if more than one exists (Join buildings)

		# Create the building flag
		self.buildflagadd(numresbuild,numotherbuild)
示例#7
0
	def buildpara(self,data,path):
		'''
		Creates the STL files for the buildings using parametrized data

		Arguments
		-----------
			data: all the JSON data
			path: Path to where the dakota.json exists
		'''

		# Create a utilities object
		hydroutil = hydroUtils()
示例#8
0
    def Utext(self, data, fipath, patches):
        '''
		Creates the necessary folders for openfoam7

		Arguments
		-----------
			data: all the JSON data
			patches: List of boundary patches
			fipath: Path where the dakota.json file exists
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Number of moving walls
        numMovWall = 0

        # Get the header text for the U-file
        utext = self.Uheader()

        # Start the outside
        utext = utext + "boundaryField\n{\n"

        # Loop over all patches
        for patchname in patches:
            utext = utext + "\t" + patchname + "\n"
            patch = hydroutil.extract_element_from_json(
                data, ["Events", "VelocityType_" + patchname])
            if patch == [None]:
                Utype = -1
            else:
                Utype = ', '.join(
                    hydroutil.extract_element_from_json(
                        data, ["Events", "VelocityType_" + patchname]))
                if int(Utype) == 103 or int(Utype) == 104:
                    numMovWall += 1
            utext = utext + self.Upatchtext(data, Utype, patchname, fipath,
                                            numMovWall)

        # Check for building and other building
        utext = utext + '\tBuilding\n'
        utext = utext + self.Upatchtext(data, '301', 'Building', fipath,
                                        numMovWall)
        utext = utext + '\tOtherBuilding\n'
        utext = utext + self.Upatchtext(data, '301', 'OtherBuilding', fipath,
                                        numMovWall)

        # Close the outside
        utext = utext + "}\n\n"

        # Return the text for velocity BC
        return utext
示例#9
0
	def mattext(self,data):
		'''
		Creates the necessary files for materials for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

		# Create a utilities object
		hydroutil = hydroUtils()

		# Get the header text for the U-file
		mattext = self.matheader()

		# Start by stating phases
		mattext = mattext + "phases (water air);\n\n"

		# Water phase
		# Viscosity
		nuwater = ', '.join(hydroutil.extract_element_from_json(data, ["Events","WaterViscosity"]))
		# Exponent
		nuwaterexp = ', '.join(hydroutil.extract_element_from_json(data, ["Events","WaterViscosityExp"]))
		# Density
		rhowater = ', '.join(hydroutil.extract_element_from_json(data, ["Events","WaterDensity"]))

		mattext = mattext + "water\n{\n"
		mattext = mattext + "\ttransportModel\tNewtonian;\n"
		mattext = mattext + "\tnu\t[0 2 -1 0 0 0 0]\t" + nuwater + "e" + nuwaterexp + ";\n"
		mattext = mattext + "\trho\t[1 -3 0 0 0 0 0]\t" + rhowater + ";\n"
		mattext = mattext + "}\n\n"

		# Air properties
		# Viscosity
		nuair = ', '.join(hydroutil.extract_element_from_json(data, ["Events","AirViscosity"]))
		# Exponent
		nuairexp = ', '.join(hydroutil.extract_element_from_json(data, ["Events","AirViscosityExp"]))
		# Density
		rhoair = ', '.join(hydroutil.extract_element_from_json(data, ["Events","AirDensity"]))

		mattext = mattext + "air\n{\n"
		mattext = mattext + "\ttransportModel\tNewtonian;\n"
		mattext = mattext + "\tnu\t[0 2 -1 0 0 0 0]\t" + nuair + "e" + nuairexp + ";\n"
		mattext = mattext + "\trho\t[1 -3 0 0 0 0 0]\t" + rhoair + ";\n"
		mattext = mattext + "}\n\n"

		# Surface tension between water and air
		sigma = ', '.join(hydroutil.extract_element_from_json(data, ["Events","SurfaceTension"]))

		mattext = mattext + "sigma\t[1 0 -2 0 0 0 0]\t"+sigma +";\n"

		return mattext
示例#10
0
    def gfiletext(self, data):
        '''
		Creates the necessary text for gravity file for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Initialize gravity
        gx = 0.0
        gy = 0.0
        gz = 0.0

        simtype = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "SimulationType"]))

        if int(simtype) == 4:
            gz = -9.81
        else:
            # Get the gravity from dakota.json file
            gravity = ', '.join(
                hydroutil.extract_element_from_json(data,
                                                    ["Events", "Gravity"]))
            # Depending on the inputs, initialize gravity in the right direction
            if int(gravity) == 11:
                gx = 9.81
            elif int(gravity) == 12:
                gy = 9.81
            elif int(gravity) == 13:
                gz = 9.81
            elif int(gravity) == 21:
                gx = -9.81
            elif int(gravity) == 22:
                gy = -9.81
            elif int(gravity) == 23:
                gz = -9.81

        # Get the header text for the gravity-file
        gfiletext = self.othersheader("uniformDimensionedVectorField",
                                      "constant", "g")

        # All other data
        gfiletext = gfiletext + 'dimensions\t[0 1 -2 0 0 0 0];\n'
        gfiletext = gfiletext + 'value\t(' + str(gx) + '\t' + str(
            gy) + '\t' + str(gz) + ');\n'

        return gfiletext
示例#11
0
    def creategeom(self, data, path):
        '''
		Creates the geometry for user flume

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Read the flume segments
        flumesegs = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "FlumeSegments"]))
        # Get the number of flume segments
        numflumesegs = ', '.join(
            hydroutil.extract_element_from_json(
                data, ["Events", "NumFlumeSegments"]))

        # Replace the comma by spaces in segments list
        flumesegs = flumesegs.replace(',', ' ')
        # Convert the flume segment to list of floats
        nums = [float(n) for n in flumesegs.split()]
        # Remove the first item
        nums.pop(0)

        # Create temporary file
        filename = 'FlumeData.txt'
        if os.path.exists(filename):
            os.remove(filename)
        f = open(filename, "a")
        for ii in range(int(numflumesegs)):
            f.write(str(nums[2 * ii]) + ',' + str(nums[2 * ii + 1]) + '\n')
        f.close()

        # Get the breadth
        breadthval = ''.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "FlumeBreadth"]))
        breadth = float(breadthval)

        # Create the STL file and get extreme file (needed for blockmesh and building)
        flumeobj = flume()
        extreme = flumeobj.generateflume(breadth, path)

        # Write extreme values and building data to temporary file for later usage
        flumeobj.extremedata(extreme, breadth)

        return 0
示例#12
0
	def creategeom(self,data,path):
		'''
		Creates the geometry for bathymetry 

		Arguments
		-----------
			data: all the JSON data
		'''

		# Create a utilities object
		hydroutil = hydroUtils()


		return 0
示例#13
0
    def creategeometry(self, data, path):
        '''
		Creates the necessary folders for openfoam7

		Arguments
		-----------
			data: all the JSON data
			path: Path where the geometry files (STL) needs to be created
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get mesher type
        mesher = ', '.join(
            hydroutil.extract_element_from_json(data, ["Events", "MeshType"]))

        # Create the geometry related files
        Geometry = of7Geometry()
        if int(mesher[0]) == 1:
            return 0
        elif int(mesher[0]) == 0 or int(mesher[0]) == 2:
            geomcode = Geometry.geomcheck(data, path)
            if geomcode == -1:
                return -1
            else:
                stlcode = Geometry.createOFSTL(data, path)
                if stlcode < 0:
                    return -1

        # Building related files
        Building = of7Building()
        if int(mesher[0]) == 1:
            return 0
        elif int(mesher[0]) == 0 or int(mesher[0]) == 2:
            buildcode = Building.buildcheck(data, path)
            if buildcode == -1:
                return -1
            else:
                buildcode2 = Building.createbuilds(data, path)
                if buildcode2 < 0:
                    return -1

        # Solution related files (SW solutions)
        # Always needed irrespective of geometry / mesh

        # Scripts
        Geometry.scripts(data)

        return 0
示例#14
0
    def scripts(self, data, path):
        '''
		Creates the necessary postprocessing in scripts

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        pprocess = hydroutil.extract_element_from_json(
            data, ["Events", "Postprocessing"])
        if pprocess == [None]:
            return 0
        else:
            pprocess = ', '.join(
                hydroutil.extract_element_from_json(
                    data, ["Events", "Postprocessing"]))
            if pprocess == 'No':
                caseruntext = 'echo no postprocessing for EVT\n'
            elif pprocess == 'Yes':
                caseruntext = 'echo postprocessing for EVT\n'
                # Reconstruct case
                caseruntext = caseruntext + 'reconstructPar > reconstruct.log \n'
                # Move new controlDict
                cdictpppath = os.path.join('system', 'controlDict')
                caseruntext = caseruntext + 'cp cdictpp ' + cdictpppath + '\n'
                # Move the wavemakerfile (if exists)
                if os.path.exists(
                        os.path.join('constant', 'wavemakerMovement.txt')):
                    caseruntext = caseruntext + 'mkdir extras\n'
                    wavepath = os.path.join('constant',
                                            'wavemakerMovement.txt')
                    wavepathnew = os.path.join('extras',
                                               'wavemakerMovement.txt')
                    caseruntext = caseruntext + 'mv ' + wavepath + ' ' + wavepathnew + '\n'
                # Copy sample file
                caseruntext = caseruntext + 'cp sample ' + os.path.join(
                    'system', 'sample') + '\n'
                # Start the postprocessing
                caseruntext = caseruntext + 'postProcess -func sample \n\n'

        # Write to caserun file
        scriptfile = open('caserun.sh', "a")
        scriptfile.write(caseruntext)
        scriptfile.close()
示例#15
0
    def scripts(self, data, path):
        '''
		Create the scripts for caserun.sh

		Arguments
		-----------
			data: all the JSON data
			path: Path where dakota.json file is located
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get number of subdomains
        totalprocs = ', '.join(
            hydroutil.extract_element_from_json(
                data, ["Events", "DomainDecomposition"]))

        # Get simulation type
        simtype = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "SimulationType"]))

        # Decompose for parallel, else serial
        if int(totalprocs) > 1:
            # Decompose the domain
            caseruntext = 'echo Decomposing domain...\n'
            caseruntext = caseruntext + 'decomposePar > decomposePar.log\n\n'

            # Start the CFD simulation
            caseruntext = caseruntext + 'echo Starting CFD simulation in parallel...\n'
            if int(simtype) == 4:
                caseruntext = caseruntext + 'ibrun -n ' + totalprocs + ' -o 0 olaDyMFlow -parallel > olaDyMFlow.log\n\n'
            else:
                caseruntext = caseruntext + 'ibrun -n ' + totalprocs + ' -o 0 olaFlow -parallel > olaFlow.log\n\n'

        else:
            caseruntext = 'echo Starting CFD simulation in serial...\n'
            if int(simtype) == 4:
                caseruntext = caseruntext + 'olaDyMFlow > olaDyMFlow.log\n\n'
            else:
                caseruntext = caseruntext + 'olaFlow > olaFlow.log\n\n'

        # Write to caserun file
        scriptfile = open('caserun.sh', "a")
        scriptfile.write(caseruntext)
        scriptfile.close()
示例#16
0
    def PtDtext(self, data, fipath, patches):
        '''
		Create text for point displacement for openfoam7

		Arguments
		-----------
			data: all the JSON data
			patches: List of boundary patches
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get the header text for the U-file
        ptdtext = self.PtDheader()

        # Start the outside
        ptdtext = ptdtext + "boundaryField\n{\n"

        # Loop over all patch
        for patchname in patches:
            ptdtext = ptdtext + "\t" + patchname + "\n"
            # Get the type of velocity bc
            patch = hydroutil.extract_element_from_json(
                data, ["Events", "VelocityType_" + patchname])
            if patch == [None]:
                Utype = -1
            else:
                Utype = ', '.join(
                    hydroutil.extract_element_from_json(
                        data, ["Events", "VelocityType_" + patchname]))

            ptdtext = ptdtext + self.PtDpatchtext(data, Utype, patchname,
                                                  fipath)

        # Check for building and other building
        ptdtext = ptdtext + '\tBuilding\n'
        ptdtext = ptdtext + self.PtDpatchtext(data, '301', 'Building', fipath)
        ptdtext = ptdtext + '\tOtherBuilding\n'
        ptdtext = ptdtext + self.PtDpatchtext(data, '301', 'OtherBuilding',
                                              fipath)

        # Close the outside
        ptdtext = ptdtext + "}\n\n"

        # Return the text for pointDisplacement
        return ptdtext
示例#17
0
	def matcheck(self,data):
		'''
		Checks for material properties for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

		# Create a utilities object
		hydroutil = hydroUtils()

		# Check water properties
		# Viscosity
		nuwater = hydroutil.extract_element_from_json(data, ["Events","WaterViscosity"])
		if nuwater == [None]:
			return -1
		# Exponent
		nuwaterexp = hydroutil.extract_element_from_json(data, ["Events","WaterViscosityExp"])
		if nuwaterexp == [None]:
			return -1
		# Density
		rhowater = hydroutil.extract_element_from_json(data, ["Events","WaterDensity"])
		if rhowater == [None]:
			return -1

		# Check air properties
		# Viscosity
		nuair = hydroutil.extract_element_from_json(data, ["Events","AirViscosity"])
		if nuair == [None]:
			return -1
		# Exponent
		nuairexp = hydroutil.extract_element_from_json(data, ["Events","AirViscosityExp"])
		if nuairexp == [None]:
			return -1
		# Density
		rhoair = hydroutil.extract_element_from_json(data, ["Events","AirDensity"])
		if rhoair == [None]:
			return -1

		# Surface tension between water and air
		sigma = hydroutil.extract_element_from_json(data, ["Events","SurfaceTension"])
		if sigma == [None]:
			return -1

		# Return 0 if all is right
		return 0
示例#18
0
    def meshcheck(self, data, fipath):
        '''
		Checks for material properties for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get mesher type
        mesher = ', '.join(
            hydroutil.extract_element_from_json(data, ["Events", "MeshType"]))

        # If hydro mesher - nothing to check
        if int(mesher[0]) == 0:
            return 0

        # Other mesh softwares
        elif int(mesher[0]) == 1:
            meshfile = hydroutil.extract_element_from_json(
                data, ["Events", "MeshFile"])
            if meshfile == [None]:
                return -1
            else:
                meshfile = ', '.join(
                    hydroutil.extract_element_from_json(
                        data, ["Events", "MeshFile"]))
                meshfilepath = os.path.join(fipath, meshfile)
                if not os.path.isfile(meshfilepath):
                    return -1

        # Mesh dictionaries
        elif int(mesher[0]) == 2:
            # Get path of bm and shm
            bmfile = os.path.join(fipath, 'blockMeshDict')
            shmfile = os.path.join(fipath, 'snappyHexMeshDict')

            # Check if both blockmeshdict or SHM do not exist
            if (not os.path.isfile(bmfile)) and (not os.path.isfile(shmfile)):
                return -1

        # Return 0 if all is right
        return 0
示例#19
0
    def pprocesscheck(self, data, path):
        '''
		Checks for material properties for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Find if pprocess is required
        pprocess = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "Postprocessing"]))

        if pprocess == 'No':
            return 0
        else:
            pprocessV = ', '.join(
                hydroutil.extract_element_from_json(data,
                                                    ["Events", "PPVelocity"]))
            pprocessP = ', '.join(
                hydroutil.extract_element_from_json(data,
                                                    ["Events", "PPPressure"]))
            if pprocessV == 'Yes' or pprocessP == 'Yes':
                pprocessfile = hydroutil.extract_element_from_json(
                    data, ["Events", "PProcessFile"])
                if pprocessfile == [None]:
                    return -1
                else:
                    pprocessfile = ', '.join(
                        hydroutil.extract_element_from_json(
                            data, ["Events", "PProcessFile"]))
                    if not os.path.exists(os.path.join(path, pprocessfile)):
                        return -1
            else:
                return 0

        # Return 0 if all is right
        return 1
示例#20
0
    def Alptext(self, data, patches):
        '''
		Creates the necessary text for pressure bc for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get the header text for the U-file
        Alptext = self.Alpheader()

        # Start the outside
        Alptext = Alptext + "boundaryField\n{\n"

        # Loop over all patches
        for patchname in patches:
            Alptext = Alptext + "\t" + patchname + "\n"
            patch = hydroutil.extract_element_from_json(
                data, ["Events", "PressureType_" + patchname])
            if patch == [None]:
                Alptype = -1
            else:
                Alptype = 0
            Alptext = Alptext + self.Alppatchtext(Alptype, patchname)

        # Check for building and other building
        Alptext = Alptext + '\tBuilding\n'
        Alptext = Alptext + self.Alppatchtext(0, 'Building')
        Alptext = Alptext + '\tOtherBuilding\n'
        Alptext = Alptext + self.Alppatchtext(0, 'OtherBuilding')

        # Close the outside
        Alptext = Alptext + "}\n\n"

        # Return the text for velocity BC
        return Alptext
示例#21
0
    def __init__(self, iniFilename):
        
        #print "toto : " + iniFilename
        #super(hydroRun,self).__init__(iniFilename)
        
        self.param = hydroParam.hydroParams(iniFilename)

        self.utils = hydroUtils.hydroUtils(self.param)

        NBVAR = hydroParam.NBVAR

        # define workspace
        self.U  = np.zeros((self.param.isize,self.param.jsize,NBVAR))
        self.U2 = np.zeros((self.param.isize,self.param.jsize,NBVAR))
        self.Q  = np.zeros((self.param.isize,self.param.jsize,NBVAR))

        # if we use implementation version 1, we need other arrays
        if self.param.implementationVersion == 1:
            self.Qm_x = np.zeros((self.param.isize,self.param.jsize,NBVAR))
            self.Qm_y = np.zeros((self.param.isize,self.param.jsize,NBVAR))
            self.Qp_x = np.zeros((self.param.isize,self.param.jsize,NBVAR))
            self.Qp_y = np.zeros((self.param.isize,self.param.jsize,NBVAR))
示例#22
0
	def createbuilds(self,data,path):
		'''
		Creates the STL files for the buildings and move to correct location

		Arguments
		-----------
			data: all the JSON data
			path: Path to where the dakota.json exists
		'''

		# Create a utilities object
		hydroutil = hydroUtils()

		# Get the type of building definition
		buildeftype = ', '.join(hydroutil.extract_element_from_json(data, ["Events","BuildData"]))
		if buildeftype == 'Manual':
			self.buildmanual(data,path)
					
		elif buildeftype == 'Parameters':
			self.buildpara(data,path)
	
		return 0
示例#23
0
    def PtDcheck(self, data, patches):
        '''
		Checks if a point displacement for openfoam7 is required

		Arguments
		-----------
			data: all the JSON data
			patches: List of boundary patches
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Number of moving walls
        numMovWall = 0

        # Loop over all patches
        for patchname in patches:
            # Get the type of velocity bc
            patch = hydroutil.extract_element_from_json(
                data, ["Events", "VelocityType_" + patchname])
            if patch == [None]:
                Utype = -1
            else:
                Utype = ', '.join(
                    hydroutil.extract_element_from_json(
                        data, ["Events", "VelocityType_" + patchname]))

            # If any moving walls (103 - 104)
            if (int(Utype) == 103) or (int(Utype) == 104):
                numMovWall += 1
                if numMovWall > 0:
                    return 1

        if numMovWall == 0:
            return 0
        else:
            return 1
示例#24
0
    def cdictcheck(self, data):
        '''
		Creates the check for controlDict for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Start time
        startT = hydroutil.extract_element_from_json(data,
                                                     ["Events", "StartTime"])
        if startT == [None]:
            return -1

        # End time
        endT = hydroutil.extract_element_from_json(data, ["Events", "EndTime"])
        if endT == [None]:
            return -1

        # deltaT
        deltaT = hydroutil.extract_element_from_json(
            data, ["Events", "TimeInterval"])
        if deltaT == [None]:
            return -1

        # WriteT
        writeT = hydroutil.extract_element_from_json(
            data, ["Events", "WriteInterval"])
        if writeT == [None]:
            return -1

        # Return 0 if all available
        return 0
示例#25
0
    def of7wavemakerdict(self, fipath):
        '''
		Creates the wavemaker dictionary for the moving wall

		Arguments
		-----------
			fipath: Path to the dakota.json file location
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get the file ID
        filepath = os.path.join(fipath, "constant", "wavemakerMovementDict")
        fileID = open(filepath, "w")
        # Header
        header = hydroutil.of7header("dictionary", "constant",
                                     "wavemakerMovementDict")
        fileID.write(header)
        # Other data
        fileID.write('\nreread\tfalse;\n\n')
        fileID.write('#include\t"wavemakerMovement.txt"\n')
        # Close the file
        fileID.close()
示例#26
0
    def turbtext(self, data):
        '''
		Creates the necessary files for turbulenceDict for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get the header text for the U-file
        turbtext = self.turbheader()

        # Get the type of turbulence model
        turbmodel = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "TurbulenceModel"]))

        if int(turbmodel) == 0:
            turbtext = turbtext + '\nsimulationType\tlaminar;\n'
        elif int(turbmodel) == 1:
            turbtext = turbtext + 'simulationType\tRAS;\n\n'
            turbtext = turbtext + 'RAS\n{\n'
            turbtext = turbtext + '\tRASModel\tkEpsilon;\n'
            turbtext = turbtext + '\tturbulence\ton;\n'
            turbtext = turbtext + '\tprintCoeffs\ton;\n}\n'
        elif int(turbmodel) == 2:
            turbtext = turbtext + 'simulationType\tRAS;\n\n'
            turbtext = turbtext + 'RAS\n{\n'
            turbtext = turbtext + '\tRASModel\tkOmegaSST;\n'
            turbtext = turbtext + '\tturbulence\ton;\n'
            turbtext = turbtext + '\tprintCoeffs\ton;\n}\n'

        return turbtext
示例#27
0
    def pprocesstext(self, data, path):
        '''
		Creates the necessary files for post-processing for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()
        solver = of7Solve()

        # Point data from file
        pprocessfile = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "PProcessFile"]))
        pprocesspath = os.path.join(path, pprocessfile)
        pp_data = np.genfromtxt(pprocesspath, delimiter=',')
        num_points = np.shape(pp_data)[0]
        ptext = '\t\t(\n'
        for ii in range(num_points):
            ptext = ptext + '\t\t\t(' + str(pp_data[ii, 0]) + '\t' + str(
                pp_data[ii, 1]) + '\t' + str(pp_data[ii, 2]) + ')\n'
        ptext = ptext + '\t\t);\n'

        # Fields required
        value = 0
        pprocessV = hydroutil.extract_element_from_json(
            data, ["Events", "PPVelocity"])
        if pprocessV != [None]:
            pprocessV = ', '.join(
                hydroutil.extract_element_from_json(data,
                                                    ["Events", "PPVelocity"]))
            if pprocessV == 'Yes':
                value += 1
        pprocessP = hydroutil.extract_element_from_json(
            data, ["Events", "PPPressure"])
        if pprocessP != [None]:
            pprocessP = ', '.join(
                hydroutil.extract_element_from_json(data,
                                                    ["Events", "PPPressure"]))
            if pprocessP == 'Yes':
                value += 2
        if value == 1:
            fieldtext = '(U)'
        elif value == 2:
            fieldtext = '(p_rgh)'
        else:
            fieldtext = '(U p_rgh)'

        # Get the header text for the U-file
        sampletext = solver.solverheader("sample")

        # Other information
        sampletext = sampletext + '\ntype sets;\n'
        sampletext = sampletext + 'libs\t("libsampling.so");\n\n'
        sampletext = sampletext + 'interpolationScheme\tcellPoint;\n\n'
        sampletext = sampletext + 'setFormat\traw;\n\n'
        sampletext = sampletext + 'sets\n(\n\tdata\n\t{\n'
        sampletext = sampletext + '\t\ttype\tpoints;\n'
        sampletext = sampletext + '\t\tpoints\n'
        sampletext = sampletext + ptext
        sampletext = sampletext + '\t\tordered\tyes;\n'
        sampletext = sampletext + '\t\taxis\tx;\n'
        sampletext = sampletext + '\t}\n'
        sampletext = sampletext + ');\n\n'
        sampletext = sampletext + 'fields\t' + fieldtext + ';\n'

        return sampletext
示例#28
0
    def alphatext(self, data, fipath):
        '''
		Creates the necessary files for alpha - setFields for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get the simulation type
        simtype = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "SimulationType"]))

        # Get the header text for the U-file
        alphatext = self.alphaheader()

        # Read the values
        if int(simtype) == 1:
            fname = "SWAlpha.txt"
            swalphafile = os.path.join(fipath, fname)
            with open(swalphafile) as f:
                gloalpha, localalpha, x1, y1, z1, x2, y2, z2 = [
                    float(x) for x in next(f).split(',')
                ]

            alphatext = alphatext + 'defaultFieldValues\n(\n\tvolScalarFieldValue\talpha.water\t' + str(
                gloalpha) + '\n);\n\n'

            alphatext = alphatext + 'regions\n(\n'
            alphatext = alphatext + '\tboxToCell\n\t{\n\t\t'
            alphatext = alphatext + 'box\t(' + str(x1) + '\t' + str(
                y1) + '\t' + str(z1) + ')\t(' + str(x2) + '\t' + str(
                    y2) + '\t' + str(z2) + ');\n\n\t\t'
            alphatext = alphatext + 'fieldValues\n\t\t(\n\t\t\tvolScalarFieldValue\talpha.water\t' + str(
                localalpha) + '\n\t\t);\n\t}\n\n'

        else:
            gloalpha = ', '.join(
                hydroutil.extract_element_from_json(
                    data, ["Events", "InitialAlphaGlobal"]))

            numregs = ', '.join(
                hydroutil.extract_element_from_json(
                    data, ["Events", "NumAlphaRegion"]))

            alphatext = alphatext + 'defaultFieldValues\n(\n\tvolScalarFieldValue\talpha.water\t' + str(
                gloalpha) + '\n);\n\n'

            alphatext = alphatext + 'regions\n(\n'

            # Check for each alpha region
            for ii in range(int(numregs)):

                # Get the region
                # We dont check if region is inside the geometry
                # Should be added later on
                region = ', '.join(
                    hydroutil.extract_element_from_json(
                        data, ["Events", "InitialAlphaRegion" + str(ii)]))
                regsegs = region.replace(',', ' ')
                # Convert the regions to list of floats
                nums = [float(n) for n in regsegs.split()]

                alphatext = alphatext + '\tboxToCell\n\t{\n\t\t'
                alphatext = alphatext + 'box\t(' + str(nums[0]) + '\t' + str(
                    nums[1]) + '\t' + str(nums[2]) + ')\t(' + str(
                        nums[3]) + '\t' + str(nums[4]) + '\t' + str(
                            nums[5]) + ');\n\n\t\t'
                alphatext = alphatext + 'fieldValues\n\t\t(\n\t\t\tvolScalarFieldValue\talpha.water\t' + str(
                    nums[6]) + '\n\t\t);\n\t}\n\n'

        alphatext = alphatext + '\n);'

        return alphatext
示例#29
0
    def alphacheck(self, data, fipath):
        '''
		Checks for initial conditions for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()

        # Get the simulation type
        simtype = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "SimulationType"]))

        # For SW-CFD coupling
        if simtype == 1:

            # Check for the file exists
            fname = "SWAlpha.txt"
            swalphafile = os.path.join(fipath, fname)
            if not os.path.exists(swalphafile):
                return -1

        # For all types other than the shallow water
        else:

            # Check global alpha value
            alphaglobal = hydroutil.extract_element_from_json(
                data, ["Events", "InitialAlphaGlobal"])
            if alphaglobal == [None]:
                return -1

            # Check number of alpha region
            numreg = hydroutil.extract_element_from_json(
                data, ["Events", "NumAlphaRegion"])
            if numreg == [None]:
                return -1
            else:
                numreg = ', '.join(
                    hydroutil.extract_element_from_json(
                        data, ["Events", "NumAlphaRegion"]))
                if int(numreg) < 1:
                    return -1

            # Check for each alpha region
            for ii in range(int(numreg)):

                # Get the region
                # We dont check if region is inside the geometry
                # Should be added later on
                region = hydroutil.extract_element_from_json(
                    data, ["Events", "InitialAlphaRegion" + str(ii)])
                if region == [None]:
                    return -1
                else:
                    region = ', '.join(
                        hydroutil.extract_element_from_json(
                            data, ["Events", "InitialAlphaRegion" + str(ii)]))
                    regsegs = region.replace(',', ' ')
                    # Convert the regions to list of floats
                    nums = [float(n) for n in regsegs.split()]
                    # Check if 6 coordinates + 1 alpha number
                    if len(nums) != 7:
                        return -1

        # Return 0 if all is right
        return 0
示例#30
0
    def pprocesscdict(self, data, path):
        '''
		Creates the necessary files for new controldict for post-processing for openfoam7

		Arguments
		-----------
			data: all the JSON data
		'''

        # Create a utilities object
        hydroutil = hydroUtils()
        solver = of7Solve()

        # Get the header text for the U-file
        cdicttext = solver.solverheader("controlDict")

        # Get the simulation type: Solver
        simtype = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "SimulationType"]))
        if int(simtype) == 4:
            cdicttext = cdicttext + '\napplication \t olaDyMFlow;\n\n'
        else:
            cdicttext = cdicttext + '\napplication \t olaFlow;\n\n'

        # Check restart situation and give start time
        restart = ', '.join(
            hydroutil.extract_element_from_json(data, ["Events", "Restart"]))
        if restart == "Yes":
            cdicttext = cdicttext + 'startFrom \t latestTime;\n\n'
        elif restart == "No":
            # Start time
            startT = ', '.join(
                hydroutil.extract_element_from_json(data,
                                                    ["Events", "StartTime"]))
            cdicttext = cdicttext + 'startFrom \t startTime;\n\n'
            cdicttext = cdicttext + 'startTime \t' + startT + ';\n\n'

        # End time
        endT = ', '.join(
            hydroutil.extract_element_from_json(data, ["Events", "EndTime"]))
        cdicttext = cdicttext + 'stopAt \t endTime;\n\n'
        cdicttext = cdicttext + 'endTime \t' + endT + ';\n\n'

        # Time interval
        deltaT = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "TimeInterval"]))
        cdicttext = cdicttext + 'deltaT \t' + deltaT + ';\n\n'

        # Write control
        cdicttext = cdicttext + 'writeControl \t adjustableRunTime;\n\n'

        # Write interval
        writeT = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "WriteInterval"]))
        cdicttext = cdicttext + 'writeInterval \t' + writeT + ';\n\n'

        # All others
        cdicttext = cdicttext + 'purgeWrite \t 0;\n\n'
        cdicttext = cdicttext + 'writeFormat \t ascii;\n\n'
        cdicttext = cdicttext + 'writePrecision \t 6;\n\n'
        cdicttext = cdicttext + 'writeCompression \t uncompressed;\n\n'
        cdicttext = cdicttext + 'timeFormat \t general;\n\n'
        cdicttext = cdicttext + 'timePrecision \t 6;\n\n'
        cdicttext = cdicttext + 'runTimeModifiable \t yes;\n\n'
        cdicttext = cdicttext + 'adjustTimeStep \t yes;\n\n'
        cdicttext = cdicttext + 'maxCo \t 1.0;\n\n'
        cdicttext = cdicttext + 'maxAlphaCo \t 1.0;\n\n'
        cdicttext = cdicttext + 'maxDeltaT \t 1;\n\n'

        # Point data from file
        pprocessfile = ', '.join(
            hydroutil.extract_element_from_json(data,
                                                ["Events", "PProcessFile"]))
        pprocesspath = os.path.join(path, pprocessfile)
        pp_data = np.genfromtxt(pprocesspath, delimiter=',')
        num_points = np.shape(pp_data)[0]
        ptext = '\t\t\t\t(\n'
        for ii in range(num_points):
            ptext = ptext + '\t\t\t\t\t(' + str(pp_data[ii, 0]) + '\t' + str(
                pp_data[ii, 1]) + '\t' + str(pp_data[ii, 2]) + ')\n'
        ptext = ptext + '\t\t\t\t);\n'

        # Fields required
        value = 0
        pprocessV = hydroutil.extract_element_from_json(
            data, ["Events", "PPVelocity"])
        if pprocessV != [None]:
            pprocessV = ', '.join(
                hydroutil.extract_element_from_json(data,
                                                    ["Events", "PPVelocity"]))
            if pprocessV == 'Yes':
                value += 1
        pprocessP = hydroutil.extract_element_from_json(
            data, ["Events", "PPPressure"])
        if pprocessP != [None]:
            pprocessP = ', '.join(
                hydroutil.extract_element_from_json(data,
                                                    ["Events", "PPPressure"]))
            if pprocessP == 'Yes':
                value += 2
        if value == 1:
            fieldtext = '(U)'
        elif value == 2:
            fieldtext = '(p_rgh)'
        else:
            fieldtext = '(U p_rgh)'

        # Get the library data
        cdicttext = cdicttext + 'function\n{\n\tlinesample\n\t{\n'
        cdicttext = cdicttext + '\t\ttype\tsets;\n'
        cdicttext = cdicttext + '\t\tfunctionObjectLibs\t("libsampling.so");\n'
        cdicttext = cdicttext + '\t\twriteControl\ttimeStep;\n'
        cdicttext = cdicttext + '\t\toutputInterval\t1;\n'
        cdicttext = cdicttext + '\t\tinterpolationScheme\tcellPoint;\n'
        cdicttext = cdicttext + '\t\tsetFormat\traw;\n\n'
        cdicttext = cdicttext + '\t\tsets\n\t\t(\n'
        cdicttext = cdicttext + '\t\t\tdata\n\t\t\t{\n'
        cdicttext = cdicttext + '\t\t\t\ttype\tpoints;\n'
        cdicttext = cdicttext + '\t\t\t\tpoints\n'
        cdicttext = cdicttext + ptext
        cdicttext = cdicttext + '\t\t\t\tordered\tyes;\n'
        cdicttext = cdicttext + '\t\t\t\taxis\tx;\n'
        cdicttext = cdicttext + '\t\t\t}\n\t\t);\n'
        cdicttext = cdicttext + '\t\tfields\t' + fieldtext + ';\n'
        cdicttext = cdicttext + '\t}\n}'

        return cdicttext