def __init__(self, analysis_obj): """ analysis_obj should contains all the information needed, boundaryConditionList is a list of all boundary Conditions objects(FemConstraint) """ self.analysis_obj = analysis_obj self.solver_obj = CfdTools.getSolver(analysis_obj) self.mesh_obj = CfdTools.getMesh(analysis_obj) self.material_obj = CfdTools.getMaterial(analysis_obj) self.bc_group = CfdTools.getConstraintGroup(analysis_obj) self.mesh_generated = False self.case_folder = self.solver_obj.WorkingDir + os.path.sep + self.solver_obj.InputCaseName self.mesh_file_name = self.case_folder + os.path.sep + self.solver_obj.InputCaseName + u".unv" if self.solver_obj.HeatTransfering: self.builder = fcb.BasicBuilder(self.case_folder, CfdTools.getSolverSettings(self.solver_obj)) else: self.builder = fcb.BasicBuilder(self.case_folder, CfdTools.getSolverSettings(self.solver_obj)) self.builder.createCase()
def __init__(self, analysis_obj): """ analysis_obj should contains all the information needed, boundaryConditionList is a list of all boundary Conditions objects(FemConstraint) """ self.analysis_obj = analysis_obj self.solver_obj = CfdTools.getSolver(analysis_obj) self.mesh_obj = CfdTools.getMesh(analysis_obj) self.material_obj = CfdTools.getMaterial(analysis_obj) self.bc_group = CfdTools.getConstraintGroup(analysis_obj) self.mesh_generated = False # unit schema detection is usful for mesh scaling, boundary type area, pressure calculation self.unit_shema = FreeCAD.ParamGet( "User parameter:BaseApp/Preferences/Units/").GetInt("UserSchema") self.case_folder = self.solver_obj.WorkingDir + os.path.sep + self.solver_obj.InputCaseName self.mesh_file_name = self.case_folder + os.path.sep + self.solver_obj.InputCaseName + u".unv" if self.solver_obj.HeatTransfering: self.builder = fcb.BasicBuilder( self.case_folder, CfdTools.getSolverSettings(self.solver_obj)) else: self.builder = fcb.BasicBuilder( self.case_folder, CfdTools.getSolverSettings(self.solver_obj))
def __init__(self, obj): self.obj = obj analysis_obj = CfdTools.getParentAnalysisObject(obj) solver_obj = CfdTools.getSolver(analysis_obj) material_objs = CfdTools.getMaterials(analysis_obj) self.boundaryWidget = CfdBoundaryWidget(obj, None, solver_obj, material_objs) # fill the table in each variable tab, saved from the previous setup, existing case if BC name, done in each widget # geometry selection widget, only face is needed as boundary for CFD # GeometryElementsSelection(ref, eltypes=[], multigeom=True) # allow_multiple_geom_types = multigeom self.selectionWidget = FemSelectionWidgets.GeometryElementsSelection( obj.References, ['Face'], False) # check references, has to be after initialization of selectionWidget try: self.selectionWidget.has_equal_references_shape_types( ) # boundarySelector has no such method except: print( '`selectionWidget.has_equal_references_shape_types()` is only available in FreeCAD 0.18+' ) #the magic to have two widgets in one taskpanel self.form = [self.selectionWidget, self.boundaryWidget] if True: # todo: check if solver is 'OpenFOAM' from CfdFoamTools import getVariableList solverSettings = CfdTools.getSolverSettings( solver_obj) # physical_model variable_list = getVariableList(solverSettings) # TODO: if boundary_settings is empty dict, default setting for each variable could be provided if "FoamBoundarySettings" in self.obj.PropertiesList and self.obj.FoamBoundarySettings: self.foam_boundary_conditions = self.obj.FoamBoundarySettings else: print("debug print: variable_list", variable_list) self.foam_boundary_conditions = { var: {} for var in variable_list } # {varible: bc_dict, ...} from FoamCaseBuilder.FoamBoundaryWidget import FoamBoundaryWidget s = {"variables": self.foam_boundary_conditions} self.foamWidget = FoamBoundaryWidget(s) self.form.append(self.foamWidget)
def __init__(self, obj): self.obj = obj analysis_obj = CfdTools.getParentAnalysisObject(obj) solver_obj = CfdTools.getSolver(analysis_obj) material_objs = CfdTools.getMaterials(analysis_obj) from CfdBoundaryWidget import CfdBoundaryWidget self.boundaryWidget = CfdBoundaryWidget(obj, None, solver_obj, material_objs) # fill the table in each variable tab, saved from the previous setup, existing case if BC name, done in each widget # geometry selection widget, only face is needed as boundary self.selectionWidget = FemSelectionWidgets.BoundarySelector() self.selectionWidget.setReferences(obj.References) # check references, has to be after initialisation of selectionWidget try: self.selectionWidget.has_equal_references_shape_types() except: RuntimeError('this function only works for FreeCAD 0.18') #the magic to have two widgets in one taskpanel self.form = [self.selectionWidget, self.boundaryWidget] if True: # todo: check if solver is 'OpenFOAM' from CfdFoamTools import getVariableList solverSettings = CfdTools.getSolverSettings(solver_obj) # physical_model variable_list = getVariableList(solverSettings) # build a parameterTabWidget, with each tab has a tableView # TODO: if boundary_settings is empty dict, default setting for each variable could be provided if not self.obj.FoamBoundarySettings: self.foam_boundary_conditions = {'U': {"key": "value"}, 'p':{"key": "value"}} # {varible: bc_dict, ...} else: self.foam_boundary_conditions = self.obj.FoamBoundarySettings from FoamCaseBuilder.FoamBoundaryWidget import FoamBoundaryWidget self.foamWidget = FoamBoundaryWidget(self.foam_boundary_conditions) self.form.append(self.foamWidget)
def writeCase(self): """ writeCase() will collect case settings, and finally build a runnable case. """ cfdMessage("Start to write case to folder {}\n".format( self.working_dir)) if not os.path.exists(self.working_dir): raise IOError("Path " + self.solver_obj.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.get_module_path(), "data", "defaults") solverSettingsDict = CfdTools.getSolverSettings(self.solver_obj) # Collect settings into single dictionary if not self.mesh_obj: raise RuntimeError("No mesh object found in analysis") phys_settings = dict( zip(self.physics_model.PropertiesList, (getattr(self.physics_model, prop) for prop in self.physics_model.PropertiesList))) if 'gx' in phys_settings: phys_settings['gx'] = Units.Quantity( phys_settings['gx']).getValueAs('m/s^2') phys_settings['gy'] = Units.Quantity( phys_settings['gy']).getValueAs('m/s^2') phys_settings['gz'] = Units.Quantity( phys_settings['gz']).getValueAs('m/s^2') self.settings = { 'physics': phys_settings, 'fluidProperties': [], # Order is important, so use a list 'initialValues': self.initial_conditions, 'boundaries': dict((b.Label, b.BoundarySettings) for b in self.bc_group), 'bafflesPresent': self.bafflesPresent(), 'porousZones': {}, 'porousZonesPresent': False, 'initialisationZones': { o.Label: o.initialisationZoneProperties for o in self.initialisationZone_objs }, 'initialisationZonesPresent': len(self.initialisationZone_objs) > 0, 'zones': { o.Label: { 'PartNameList': tuple(o.partNameList) } for o in self.zone_objs }, 'zonesPresent': len(self.zone_objs) > 0, 'meshType': self.mesh_obj.Proxy.Type, 'meshDimension': self.mesh_obj.ElementDimension, 'solver': solverSettingsDict, 'system': {}, 'runChangeDictionary': False } self.processSystemSettings() self.processSolverSettings() self.processFluidProperties() self.processBoundaryConditions() self.processInitialConditions() self.clearCase() self.exportZoneStlSurfaces() if self.porousZone_objs: self.processPorousZoneProperties() self.processInitialisationZoneProperties() self.settings['createPatchesFromSnappyBaffles'] = False cfdMessage("Matching boundary conditions ...\n") self.setupPatchNames() TemplateBuilder.TemplateBuilder(self.case_folder, self.template_path, self.settings) self.writeMesh() # Update Allrun permission - will fail silently on Windows fname = os.path.join(self.case_folder, "Allrun") import stat s = os.stat(fname) os.chmod(fname, s.st_mode | stat.S_IEXEC) # Move mesh files, after being edited, to polyMesh.org CfdTools.movePolyMesh(self.case_folder) cfdMessage("Successfully wrote {} case to folder {}\n".format( self.solver_obj.SolverName, self.working_dir)) return True
def write_case(self, updating=False): """ Write_case() will collect case setings, and finally build a runnable case. """ print("Start to write case to folder {}\n".format( self.solver_obj.WorkingDir)) _cwd = os.curdir if not os.path.exists(self.solver_obj.WorkingDir): raise IOError("Path " + self.solver_obj.WorkingDir + " does not exist.") os.chdir( self.solver_obj.WorkingDir ) # pyFoam can not write to cwd if FreeCAD is started NOT from terminal try: # Make sure we restore cwd after exception here # Perform initialisation here rather than __init__ in case of path changes self.case_folder = os.path.join(self.solver_obj.WorkingDir, 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.get_module_path(), "data", "defaults") solverSettingsDict = CfdTools.getSolverSettings(self.solver_obj) # Collect settings into single dictionary if not self.mesh_obj: raise RuntimeError("No mesh object found in analysis") self.settings = { 'physics': self.physics_model, 'fluidProperties': [], # Order is important, so use a list 'initialValues': self.initial_conditions, 'boundaries': dict((b.Label, b.BoundarySettings) for b in self.bc_group), 'bafflesPresent': self.bafflesPresent(), 'porousZones': {}, 'porousZonesPresent': False, 'initialisationZones': { o.Label: o.initialisationZoneProperties for o in self.initialisationZone_objs }, 'initialisationZonesPresent': len(self.initialisationZone_objs) > 0, 'zones': { o.Label: { 'PartNameList': tuple(o.partNameList) } for o in self.zone_objs }, 'zonesPresent': len(self.zone_objs) > 0, 'meshType': self.mesh_obj.Proxy.Type, 'solver': solverSettingsDict, 'system': {} } self.processSystemSettings() self.processSolverSettings() self.processFluidProperties() self.processBoundaryConditions() self.processInitialConditions() self.clearCase() self.exportZoneStlSurfaces() if self.porousZone_objs: self.processPorousZoneProperties() self.processInitialisationZoneProperties() self.settings['createPatchesFromSnappyBaffles'] = False if self.mesh_obj.Proxy.Type == "CfdMeshCart": # Cut-cell Cartesian self.setupPatchNames() TemplateBuilder.TemplateBuilder(self.case_folder, self.template_path, self.settings) self.writeMesh() # Update Allrun permission - will fail silently on Windows fname = os.path.join(self.case_folder, "Allrun") import stat s = os.stat(fname) os.chmod(fname, s.st_mode | stat.S_IEXEC) # Move mesh files, after being edited, to polyMesh.org CfdTools.movePolyMesh(self.case_folder) except: raise finally: os.chdir(_cwd) # Restore working dir print("Successfully wrote {} case to folder {}\n".format( self.solver_obj.SolverName, self.solver_obj.WorkingDir)) return True