Exemplo n.º 1
0
 def setupMeshCaseDir(self):
     """ Create temporary mesh case directory """
     CfdTools.clearCase(self.meshCaseDir)
     os.makedirs(self.triSurfaceDir)
     os.makedirs(self.gmshDir)
Exemplo n.º 2
0
    def writeCase(self):
        """ writeCase() will collect case settings, and finally build a runnable case. """
        cfdMessage("Writing case to folder {}\n".format(self.working_dir))
        if not os.path.exists(self.working_dir):
            raise IOError("Path " + self.working_dir + " does not exist.")

        # Perform initialisation here rather than __init__ in case of path changes
        self.case_folder = os.path.join(self.working_dir,
                                        self.solver_obj.InputCaseName)
        self.case_folder = os.path.expanduser(os.path.abspath(
            self.case_folder))
        self.mesh_file_name = os.path.join(self.case_folder,
                                           self.solver_obj.InputCaseName,
                                           u".unv")
        self.template_path = os.path.join(CfdTools.getModulePath(), "Data",
                                          "Templates", "case")

        # Collect settings into single dictionary
        if not self.mesh_obj:
            raise RuntimeError("No mesh object found in analysis")
        phys_settings = CfdTools.propsToDict(self.physics_model)

        # Validate BC labels
        bc_labels = [b.Label for b in self.bc_group]
        for i, l in enumerate(bc_labels):
            if bc_labels[i].find(' ') >= 0:
                raise ValueError("Boundary condition label '" + bc_labels[i] +
                                 "' is not valid: May not contain spaces")
        for i, l in enumerate(bc_labels):
            for j in range(i + 1, len(bc_labels)):
                if bc_labels[j] == l:
                    raise ValueError("Boundary condition label '" +
                                     bc_labels[i] + "' is duplicated")

        self.settings = {
            'physics':
            phys_settings,
            'fluidProperties': [],  # Order is important, so use a list
            'initialValues':
            CfdTools.propsToDict(self.initial_conditions),
            'boundaries':
            dict((b.Label, CfdTools.propsToDict(b)) for b in self.bc_group),
            'reportingFunctions':
            dict((fo.Label, CfdTools.propsToDict(fo))
                 for fo in self.reporting_functions),
            'reportingFunctionsEnabled':
            False,
            'scalarTransportFunctions':
            dict((st.Label, CfdTools.propsToDict(st))
                 for st in self.scalar_transport_objs),
            'scalarTransportFunctionsEnabled':
            False,
            'dynamicMesh': {},
            'dynamicMeshEnabled':
            False,
            'bafflesPresent':
            self.bafflesPresent(),
            'porousZones': {},
            'porousZonesPresent':
            False,
            'initialisationZones': {
                o.Label: CfdTools.propsToDict(o)
                for o in self.initialisation_zone_objs
            },
            'initialisationZonesPresent':
            len(self.initialisation_zone_objs) > 0,
            'zones': {
                o.Label: {
                    'PartNameList': tuple(r[0].Name for r in o.ShapeRefs)
                }
                for o in self.zone_objs
            },
            'zonesPresent':
            len(self.zone_objs) > 0,
            'meshType':
            self.mesh_obj.Proxy.Type,
            'meshDimension':
            self.mesh_obj.ElementDimension,
            'meshDir':
            "../" + self.mesh_obj.CaseName,
            'solver':
            CfdTools.propsToDict(self.solver_obj),
            'system': {},
            'runChangeDictionary':
            False
        }

        self.processSystemSettings()
        self.processSolverSettings()
        self.processFluidProperties()
        self.processBoundaryConditions()
        self.processInitialConditions()
        CfdTools.clearCase(self.case_folder)

        self.exportZoneStlSurfaces()
        if self.porous_zone_objs:
            self.processPorousZoneProperties()
        self.processInitialisationZoneProperties()

        if self.reporting_functions:
            cfdMessage(f'Reporting functions present')
            self.processReportingFunctions()

        if self.scalar_transport_objs:
            cfdMessage(f'Scalar transport functions present')
            self.processScalarTransportFunctions()

        if self.dynamic_mesh_refinement_obj:
            cfdMessage(f'Dynamic mesh adaptation rule present')
            self.processDynamicMeshRefinement()

        self.settings['createPatchesFromSnappyBaffles'] = False
        cfdMessage("Matching boundary conditions ...\n")
        if self.progressCallback:
            self.progressCallback("Matching boundary conditions ...")
        self.setupPatchNames()

        TemplateBuilder(self.case_folder, self.template_path, self.settings)

        # Update Allrun permission - will fail silently on Windows
        file_name = os.path.join(self.case_folder, "Allrun")
        import stat
        s = os.stat(file_name)
        os.chmod(file_name, s.st_mode | stat.S_IEXEC)

        cfdMessage("Successfully wrote case to folder {}\n".format(
            self.working_dir))
        if self.progressCallback:
            self.progressCallback("Case written successfully")

        return True