def create_circular_mesh(radius, cellSize): """ Function creates circular 2D mesh **Input** - radius = Radius of mesh - cellSize = Size of unit cell *Note* : No support for 3D meshes currently and **requires GMSH** """ mesh = Gmsh2D(''' cellSize = %g; radius = %g; Point(1) = {0, 0, 0, cellSize}; Point(2) = {-radius, 0, 0, cellSize}; Point(3) = {0, radius, 0, cellSize}; Point(4) = {radius, 0, 0, cellSize}; Point(5) = {0, -radius, 0, cellSize}; Circle(6) = {2, 1, 3}; Circle(7) = {3, 1, 4}; Circle(8) = {4, 1, 5}; Circle(9) = {5, 1, 2}; Line Loop(10) = {6, 7, 8, 9}; Plane Surface(11) = {10}; ''' % (cellSize, radius)) # doctest: +GMSH return (mesh)
Circle(13) = {15, 12, 14}; Circle(14) = {14, 12, 13}; Line Loop(1) = {1, 2, 3, 4, 5, 6}; Line Loop(2) = {7, 8, 9, 10}; Line Loop(3) = {11, 12, 13, 14}; Plane Surface(1) = {1, 2, 3}; Plane Surface(2) = {2}; Plane Surface(3) = {3}; Physical Line("Ground") = {4, 5, 6}; Physical Surface("Field") = {1}; Physical Surface("Anode") = {2}; Physical Surface("Cathode") = {3}; """ for refinement in range(10): mesh = Gmsh2D(geo, background=monitor) charge = CellVariable(mesh=mesh, name=r"$\rho$", value=0.) charge.setValue(+1, where=mesh.physicalCells["Anode"]) charge.setValue(-1, where=mesh.physicalCells["Cathode"]) potential = CellVariable(mesh=mesh, name=r"$\psi$") potential.constrain(0., where=mesh.physicalFaces["Ground"]) eq = DiffusionTerm(coeff=1.) == -charge res0 = eq.sweep(var=potential) res = eq.justResidualVector(var=potential) res1 = numerix.L2norm(res)
logLevel = 'INFO' logFilename = 'convectionTestProblem2D_01.log' logging.basicConfig(filename=logFilename, filemode="w", level=logLevel, format='%(asctime)s - %(levelname)s - %(message)s') del logLevel, logFilename R_outer = 2e-6 #SETTING must match what is in .geo file R_inner = 1e-6 #SETTING must match what is in .geo file cellSize = .05 * (R_outer - R_inner) #SETTING must match what is in .geo file #run gmsh gui to produce this mesh (.msh file) #gmsh infiniteCylinder01.geo filename = 'infiniteCylinder01.msh' mesh = Gmsh2D(filename, communicator=serialComm) del filename T_initial = 425.08 #deg K T_infinity = 293.15 #deg K #SETTING var = CellVariable(mesh=mesh, value=T_initial - T_infinity) #let var be T-T_infinity rho = 6980. #kg/m^3 cp = 227. #J/kg/K k = 59.6 #W/m/K D_thermal = k / rho / cp X_faces, Y_faces = mesh.faceCenters
#Solve a two-dimensional diffusion problem in a square domain. #This example solves a diffusion problem and demonstrates the use of #applying boundary condition patches. #.. index:: Grid2D from fipy import CellVariable, Grid2D, Viewer, TransientTerm, DiffusionTerm from fipy.tools import numerix import random doBlob = True doCirc = False if doBlob: from fipy import Gmsh2D mesh = Gmsh2D("meshed.msh") elif doCirc: from fipy import Gmsh2D cellSize = 0.05 radius = 1. mesh = Gmsh2D(''' cellSize = %(cellSize)g; radius = %(radius)g; Point(1) = {0, 0, 0, cellSize}; Point(2) = {-radius, 0, 0, cellSize}; Point(3) = {0, radius, 0, cellSize}; Point(4) = {radius, 0, 0, cellSize}; Point(5) = {0, -radius, 0, cellSize};
Line(12) = {{3,4}}; Line(13) = {{4,5}}; Line(14) = {{5,1}}; Line Loop(15) = {{10,11,12,13,14}}; Plane Surface(16) = {{15}}; Physical Line("outer") = {{14}}; Physical Line("inner") = {{11, 12}}; Physical Surface("surface") = {{16}}; '''.format(cellSize, l1, l2, math.tan(beta) * (l2 - l1), l3, math.tan(alpha) * l3) #mesh = Gmsh2D("C:\\Users\\muel_hd\\Desktop\\test.geo") mesh = Gmsh2D(geometryTemplate) phi = CellVariable(name="Temperature", mesh=mesh, value=T0) # Die Waermeleitungsgleichung equation = TransientTerm() == DiffusionTerm(coeff=D) # boundry conditions ---------------------------------------------------------- phi.constrain(Ti, where=mesh.physicalFaces["inner"]) phi.constrain(Te, where=mesh.physicalFaces["outer"]) # Viewer mit Limits entsprechend den Werten initialisieren viewer = Viewer(vars=phi, datamin=0., datamax=Te * 1.1) if steady_state:
def create_mesh(self): # TODO save and re-load mesh! print("Creating mesh") cellSize = self.parameter.cellSize radius = 0.1 # Not actually important without curved surfaces splines_flag = False # Splines caused issues with sharp boundaries # get region data coordinates = self.region_coordinates # setup the base string g_str = '''cellSize = %(cellSize)g; ''' # Loop through coordinates and create the gmsh input file count = itertools.count(1) # counter to label the points line_loop_list = [] # list to keep track of the line loops if splines_flag: for point_list in coordinates: # loop through each of the sublists of points current_point_list = [] # keep track of the points in the current list for points in point_list: # loop through the point coordinates current_point = next(count) # update point number current_point_list.append(current_point) # add point number to current list g_str = g_str + 'Point(' + str(current_point) + ') = {' + str(points[0]) + ', ' + \ str(points[1]) + ', 0, cellSize};\n' # add the point to the string spline_number = next(count) # label current spline g_str = g_str + 'Spline(' + str(spline_number) + ') = {' # add spline number # loop through the points and add them to the current spline for point in current_point_list: g_str = g_str + str(point) + ',' g_str = g_str + str(current_point_list[0]) + '};\n' # add the first point again to complete the loop # add the line loop line_loop_number = next(count) line_loop_list.append(line_loop_number) g_str = g_str + 'Line Loop (' + str(line_loop_number) + ') = {' + str(spline_number) + '};\n' surface_number = next(count) # define surface number g_str = g_str + 'Plane Surface(' + str(surface_number) + ') = {' # add surface number to string # loop through the line loops and add to the string (up to the final one, which doesn't need a comma). for line_loop in line_loop_list[:-1]: g_str = g_str + str(line_loop) + ',' g_str = g_str + str(line_loop_list[-1]) + '};\n' # add the final line loop and close brackets else: for point_list in coordinates: # loop through each of the sublists of points current_point_list = [] # keep track of the points in the current list for points in point_list: # loop through the point coordinates current_point = next(count) # update point number current_point_list.append(current_point) # add point number to current list g_str = g_str + 'Point(' + str(current_point) + ') = {' + str(points[0]) + ', ' + \ str(points[1]) + ', 0, cellSize};\n' # add the point to the string current_line_list = [] for point1, point2 in zip(current_point_list, current_point_list[1:] + [current_point_list[0]]): current_line = next(count) current_line_list.append(current_line) g_str = g_str + 'Line(' + str(current_line) + ') = {' + str(point1) + ',' + str(point2) + '};\n' # add the line loop line_loop_number = next(count) line_loop_list.append(line_loop_number) g_str = g_str + 'Line Loop (' + str(line_loop_number) + ') = {' for line_number in current_line_list[:-1]: g_str = g_str + str(line_number) + ',' g_str = g_str + str(current_line_list[-1]) + '};\n' surface_number = next(count) # define surface number g_str = g_str + 'Plane Surface(' + str(surface_number) + ') = {' # add surface number to string # loop through the line loops and add to the string (up to the final one, which doesn't need a comma). for line_loop in line_loop_list[:-1]: g_str = g_str + str(line_loop) + ',' g_str = g_str + str(line_loop_list[-1]) + '};\n' # add the final line loop and close brackets mesh = Gmsh2D(g_str % locals()) # define mesh x = mesh.cellCenters.value[0] print("Mesh created with {x} points".format(x=len(x))) return mesh