diff --git a/run.py b/run.py index 3c05c30..989a718 100644 --- a/run.py +++ b/run.py @@ -93,7 +93,6 @@ def createMesh(tasks): def calculate(tasks): foamCase = [ "0", "constant", "system" ] rmDirs = ["0", "constant", "system", "postProcessing", "logs"] + [ "processor{}".format(n) for n in range(4)] - #fancyline = "--------------------------------------------------------------------------------" for task in tasks: @@ -158,9 +157,22 @@ def calculate(tasks): def postprocessing(tasks): - - surfaceFieldValue = [] - dat = [ line.strip().split() for line in open("surfaceFieldValue.dat", "r").readlines() ] + + surfaceFieldValue = {} + porosity = {} + + for task in tasks: + direction = "direction-{}{}{}".format(task.direction[0], task.direction[1], task.direction[2]) + path = os.path.join(BUILD, task.structure, "postProcessing", direction) + surfaceFieldValuePath = os.path.join(task.saveto, "postProcessing", "") + + if not os.path.exists(path): + os.makedirs(path) + + surfaceFieldValues = [ line.strip().split() for line in open(surfaceFieldValuePath, "r").readlines() ] + + with open(os.path.join(path, "porosity.dat")) as io: + io.write("{}\t{}".format(task.coeff, surfaceFieldValues[-1][1])) if __name__ == "__main__": @@ -180,22 +192,25 @@ if __name__ == "__main__": ]) # TODO: add force arg - Args = namedtuple("Args", ["mesh", "calc"]) + Args = namedtuple("Args", ["mesh", "calc", "pp"]) if len(sys.argv) > 1: action = sys.argv[1] if action == "mesh": - args = Args(True, False) + args = Args(True, False, False) elif action == "calc": - args = Args(False, True) + args = Args(False, True, False) + + elif action == "pp": + args = Args(False, False, True) elif action == "all": - args = Args(True, True) + args = Args(True, True, True) else: - args = Args(True, True) + args = Args(True, True, True) tasks = createTasks() logging.info("Tasks: {}".format(len(tasks))) @@ -221,5 +236,6 @@ if __name__ == "__main__": logging.info("-" * 80) logging.info("Elapsed time: {}".format(timedelta(seconds=end_time - start_time))) - + if args.pp: + postprocessing(tasks) diff --git a/samples/__init__.py b/samples/__init__.py index eb5264c..163639a 100644 --- a/samples/__init__.py +++ b/samples/__init__.py @@ -63,13 +63,14 @@ def genMesh(stype, theta, fillet, direction, saveto): [length, surfaceArea, volume] = geompy.BasicProperties(shape, theTolerance = 1e-06) logging.info("""shape: + edges length:\t{} surface area:\t{} - volume:\t{}""".format(surfaceArea, volume)) + volume:\t{}""".format(length, surfaceArea, volume)) ### # Mesh ## - fineness = 1 + fineness = 0 parameters = mesh_utils.Parameters( minSize = 0.001, maxSize = 0.1, diff --git a/src/paraview_utils.py b/src/paraview_utils.py new file mode 100644 index 0000000..8edb71b --- /dev/null +++ b/src/paraview_utils.py @@ -0,0 +1,28 @@ +from paraview.simple import * + +def plotMagnitude(): + + rv = CreateRenderView() + rv.ViewSize = [1920, 1080] + rv.CameraPosition = [1e-05, 2e-05, 1e-05] + rv.CameraFocalPoint = [1e-05, 2e-05, 1e-05] + + + layout1 = CreateLayout(name='Layout #1') + layout1.AssignView(0, rv) + + SetActiveView(rv) + + foam = OpenFOAMReader(FileName = "simple.foam") + foam.CaseType = "Decomposed Case" + foam.MeshRegions = ["internalMesh"] + foam.CellArrays = ["U", "p"] + + SetActiveSource(foam) + display = Show(foam, rv, "UnstructuredGridRepresentation") + r = Render() + + SaveScreenshot("test.png", r) + +if __name__ == "__main__": + plotMagnitude() diff --git a/temp/paraview.1.py b/temp/paraview.1.py index 386dea5..a37aaa4 100644 --- a/temp/paraview.1.py +++ b/temp/paraview.1.py @@ -185,5 +185,6 @@ clip1Display.SetScalarBarVisibility(renderView1, True) # ---------------------------------------------------------------- # finally, restore active source -SetActiveSource(clip1) -# ---------------------------------------------------------------- \ No newline at end of file +SetActiveSource(clip1Display) +# ---------------------------------------------------------------- +SaveScreenshot("test.png", renderView1)