コード例 #1
0
    def initial_mesh(self):

        mesh = self.coarse_mesh()

        for cycle in range(self.initial_hot_wall_refinement_cycles):

            edge_markers = fenics.MeshFunction("bool", mesh, 1, False)

            self.hot_wall.mark(edge_markers, True)

            fenics.adapt(mesh, edge_markers)

            mesh = mesh.child()

        return mesh
コード例 #2
0
    def refine_initial_mesh(self):
        """ Refine near the hot wall. """
        class HotWall(fenics.SubDomain):
            def inside(self, x, on_boundary):

                return on_boundary and fenics.near(x[0], 0.)

        hot_wall = HotWall()

        for i in range(self.initial_hot_wall_refinement_cycles):

            edge_markers = fenics.MeshFunction("bool", self.mesh, 1, False)

            hot_wall.mark(edge_markers, True)

            fenics.adapt(self.mesh, edge_markers)

            self.mesh = self.mesh.child()
コード例 #3
0
    def refine_initial_mesh(self):
        """ Refine near the phase-change interface. """
        y_pci = self.y_pci

        class PhaseInterface(fenics.SubDomain):
            def inside(self, x, on_boundary):

                return fenics.near(x[1], y_pci)

        phase_interface = PhaseInterface()

        for i in range(self.pci_refinement_cycles):

            edge_markers = fenics.MeshFunction("bool", self.mesh, 1, False)

            phase_interface.mark(edge_markers, True)

            fenics.adapt(self.mesh, edge_markers)

            self.mesh = self.mesh.child(
            )  # Does this break references? Can we do this a different way?
コード例 #4
0
def test_variable_viscosity__nightly():

    lid = "near(x[1],  1.)"

    ymin = -0.25
    
    fixed_walls = "near(x[0],  0.) | near(x[0],  1.) | near(x[1],  '+str(ymin)+')"

    left_middle = "near(x[0], 0.) && near(x[1], 0.5)"
    
    output_dir = "output/test_variable_viscosity"
    
    mesh = fenics.RectangleMesh(fenics.Point(0., ymin), fenics.Point(1., 1.), 20, 25, 'crossed')
    
    
    # Refine the initial PCI.
    initial_pci_refinement_cycles = 4
    
    class PCI(fenics.SubDomain):
        
        def inside(self, x, on_boundary):
        
            return fenics.near(x[1], 0.)

            
    pci = PCI()
    
    for i in range(initial_pci_refinement_cycles):
        
        edge_markers = fenics.EdgeFunction("bool", mesh)
        
        pci.mark(edge_markers, True)

        fenics.adapt(mesh, edge_markers)
        
        mesh = mesh.child()
    
    
    # Run the simulation.
    w, mesh = phaseflow.run(
        mesh = mesh,
        end_time = 20.,
        time_step_size = 1.,
        stop_when_steady = True,
        steady_relative_tolerance = 1.e-4,
        thermal_conductivity = 0.,
        liquid_viscosity = 0.01,
        solid_viscosity = 1.e6,
        temperature_of_fusion = -0.01,
        regularization_smoothing_factor = 0.01,
        gravity = (0., 0.),
        stefan_number = 1.e16,
        adaptive = True,
        output_dir = output_dir,
        initial_values_expression = (lid, "0.", "0.", "1. - 2.*(x[1] <= 0.)"),
        boundary_conditions = [
            {'subspace': 0, 'value_expression': ("1.", "0."), 'degree': 3, 'location_expression': lid, 'method': 'topological'},
            {'subspace': 0, 'value_expression': ("0.", "0."), 'degree': 3, 'location_expression': fixed_walls, 'method': 'topological'},
            {'subspace': 1, 'value_expression': "0.", 'degree': 2, 'location_expression': left_middle, 'method': 'pointwise'}])
    
    
    # Verify against the known solution.
    verify_against_ghia1982(w, mesh)
コード例 #5
0
    def inside(self, x, on_boundary):

        return on_boundary and fenics.near(x[0], 0.)


hot_wall = HotWall()

initial_hot_wall_refinement_cycles = 6

for cycle in range(initial_hot_wall_refinement_cycles):

    edge_markers = fenics.MeshFunction("bool", mesh, 1, False)

    hot_wall.mark(edge_markers, True)

    fenics.adapt(mesh, edge_markers)

    mesh = mesh.child()

P1 = fenics.FiniteElement('P', mesh.ufl_cell(), 1)

P2 = fenics.VectorElement('P', mesh.ufl_cell(), 2)

mixed_element = fenics.MixedElement([P1, P2, P1])

W = fenics.FunctionSpace(mesh, mixed_element)

psi_p, psi_u, psi_T = fenics.TestFunctions(W)

w = fenics.Function(W)
コード例 #6
0
def melt_toy_pcm(output_dir="output/test_melt_toy_pcm/",
                 restart=False,
                 restart_filepath='',
                 start_time=0.):

    # Make the mesh.
    initial_mesh_size = 1

    mesh = fenics.UnitSquareMesh(initial_mesh_size, initial_mesh_size,
                                 'crossed')

    initial_hot_wall_refinement_cycles = 6

    class HotWall(fenics.SubDomain):
        def inside(self, x, on_boundary):

            return on_boundary and fenics.near(x[0], 0.)

    hot_wall = HotWall()

    for i in range(initial_hot_wall_refinement_cycles):

        edge_markers = fenics.EdgeFunction("bool", mesh)

        hot_wall.mark(edge_markers, True)

        fenics.adapt(mesh, edge_markers)

        mesh = mesh.child()

    # Run phaseflow.
    T_hot = 1.

    T_cold = -0.1

    w, mesh = phaseflow.run(
        stefan_number=1.,
        rayleigh_number=1.e6,
        prandtl_number=0.71,
        solid_viscosity=1.e4,
        liquid_viscosity=1.,
        mesh=mesh,
        time_step_size=1.e-3,
        start_time=start_time,
        end_time=0.02,
        stop_when_steady=True,
        temperature_of_fusion=T_f,
        regularization_smoothing_factor=0.025,
        adaptive=True,
        adaptive_metric='phase_only',
        adaptive_solver_tolerance=1.e-4,
        nlp_relative_tolerance=1.e-8,
        initial_values_expression=("0.", "0.", "0.",
                                   "(" + str(T_hot) + " - " + str(T_cold) +
                                   ")*(x[0] < 0.001) + " + str(T_cold)),
        boundary_conditions=[{
            'subspace': 0,
            'value_expression': ("0.", "0."),
            'degree': 3,
            'location_expression':
            "near(x[0],  0.) | near(x[0],  1.) | near(x[1], 0.) | near(x[1],  1.)",
            'method': "topological"
        }, {
            'subspace': 2,
            'value_expression': str(T_hot),
            'degree': 2,
            'location_expression': "near(x[0],  0.)",
            'method': "topological"
        }, {
            'subspace': 2,
            'value_expression': str(T_cold),
            'degree': 2,
            'location_expression': "near(x[0],  1.)",
            'method': "topological"
        }],
        output_dir=output_dir,
        restart=restart,
        restart_filepath=restart_filepath)

    return w