コード例 #1
0
class ElasticitySolver:
    """docstring for ElasticitySolver"""
    def __init__(self, energy, state, bcs, parameters={}):
        super(ElasticitySolver, self).__init__()
        solver_name = 'elasticity'
        self.problem = ElasticityProblem(energy, state, bcs)
        # Set the solver
        self.solver = PETScSNESSolver()
        snes = self.solver.snes()

        prefix = "elasticity_"
        snes.setOptionsPrefix(prefix)
        print(parameters)
        for parameter, value in parameters.items():
            log(LogLevel.DEBUG,
                "DEBUG: Set: {} = {}".format(prefix + parameter, value))
            PETScOptions.set(prefix + parameter, value)

        snes.setFromOptions()

    def solve(self):
        log(LogLevel.INFO,
            '________________________ EQUILIBRIUM _________________________')
        log(LogLevel.INFO, 'Solving elasticity')
        problem = self.problem

        u = problem.state["u"].vector()
        self.solver.solve(problem, u)
        return (self.solver.snes().getIterationNumber(),
                self.solver.snes().getConvergedReason())
コード例 #2
0
 def solve(self):
     PETScSNESSolver.solve(self, self.problem,
                           self.problem.block_solution.block_vector())
     # Keep subfunctions up to date
     self.problem.block_solution.apply("to subfunctions")
コード例 #3
0
ファイル: stokes_heat.py プロジェクト: prklVIP/maelstrom
def solve(mesh, W_element, P_element, Q_element, u0, p0, theta0, kappa, rho,
          mu, cp, g, extra_force, heat_source, u_bcs, p_bcs,
          theta_dirichlet_bcs, theta_neumann_bcs, dx_submesh, ds_submesh):
    # First do a fixed_point iteration. This is usually quite robust and leads
    # to a point from where Newton can converge reliably.
    u0, p0, theta0 = solve_fixed_point(mesh,
                                       W_element,
                                       P_element,
                                       Q_element,
                                       theta0,
                                       kappa,
                                       rho,
                                       mu,
                                       cp,
                                       g,
                                       extra_force,
                                       heat_source,
                                       u_bcs,
                                       p_bcs,
                                       theta_dirichlet_bcs,
                                       theta_neumann_bcs,
                                       my_dx=dx_submesh,
                                       my_ds=ds_submesh,
                                       max_iter=100,
                                       tol=1.0e-8)

    WPQ = FunctionSpace(mesh, MixedElement([W_element, P_element, Q_element]))
    uptheta0 = Function(WPQ)

    # Initial guess
    assign(uptheta0.sub(0), u0)
    assign(uptheta0.sub(1), p0)
    assign(uptheta0.sub(2), theta0)

    rho_const = rho(_average(theta0))

    stokes_heat_problem = StokesHeat(WPQ,
                                     kappa,
                                     rho,
                                     rho_const,
                                     mu,
                                     cp,
                                     g,
                                     extra_force,
                                     heat_source,
                                     u_bcs,
                                     p_bcs,
                                     theta_dirichlet_bcs=theta_dirichlet_bcs,
                                     theta_neumann_bcs=theta_neumann_bcs,
                                     my_dx=dx_submesh,
                                     my_ds=ds_submesh)

    # solver = FixedPointSolver()
    from dolfin import PETScSNESSolver
    solver = PETScSNESSolver()
    # http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/SNESType.html
    solver.parameters['method'] = 'newtonls'
    # The Jacobian system for Stokes (+heat) are hard to solve.
    # Use LU for now.
    solver.parameters['linear_solver'] = 'lu'
    solver.parameters['maximum_iterations'] = 100
    # TODO tighten tolerance. might not always work though...
    solver.parameters['absolute_tolerance'] = 1.0e-3
    solver.parameters['relative_tolerance'] = 0.0
    solver.parameters['report'] = True

    solver.solve(stokes_heat_problem, uptheta0.vector())

    # u0, p0, theta0 = split(uptheta0)
    # Create a *deep* copy of u0, p0, theta0 to be able to deal with them
    # as actually separate entities vectors.
    u0, p0, theta0 = uptheta0.split(deepcopy=True)
    return u0, p0, theta0
コード例 #4
0
 def solve(self):
     no_iterations, convergence_flag = PETScSNESSolver.solve(
         self, self.problem, self.problem.block_solution.block_vector())
     # Keep subfunctions up to date
     self.problem.block_solution.apply("to subfunctions")
     return no_iterations, convergence_flag
コード例 #5
0
ファイル: stokes_heat.py プロジェクト: nschloe/maelstrom
def solve(
        mesh,
        W_element, P_element, Q_element,
        u0, p0, theta0,
        kappa, rho, mu, cp,
        g, extra_force,
        heat_source,
        u_bcs, p_bcs,
        theta_dirichlet_bcs,
        theta_neumann_bcs,
        dx_submesh, ds_submesh
        ):
    # First do a fixed_point iteration. This is usually quite robust and leads
    # to a point from where Newton can converge reliably.
    u0, p0, theta0 = solve_fixed_point(
        mesh,
        W_element, P_element, Q_element,
        theta0,
        kappa, rho, mu, cp,
        g, extra_force,
        heat_source,
        u_bcs, p_bcs,
        theta_dirichlet_bcs,
        theta_neumann_bcs,
        my_dx=dx_submesh,
        my_ds=ds_submesh,
        max_iter=100,
        tol=1.0e-8
        )

    WPQ = FunctionSpace(
        mesh, MixedElement([W_element, P_element, Q_element])
        )
    uptheta0 = Function(WPQ)

    # Initial guess
    assign(uptheta0.sub(0), u0)
    assign(uptheta0.sub(1), p0)
    assign(uptheta0.sub(2), theta0)

    rho_const = rho(_average(theta0))

    stokes_heat_problem = StokesHeat(
        WPQ,
        kappa, rho, rho_const, mu, cp,
        g, extra_force,
        heat_source,
        u_bcs, p_bcs,
        theta_dirichlet_bcs=theta_dirichlet_bcs,
        theta_neumann_bcs=theta_neumann_bcs,
        my_dx=dx_submesh,
        my_ds=ds_submesh
        )

    # solver = FixedPointSolver()
    from dolfin import PETScSNESSolver
    solver = PETScSNESSolver()
    # http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/SNESType.html
    solver.parameters['method'] = 'newtonls'
    # The Jacobian system for Stokes (+heat) are hard to solve.
    # Use LU for now.
    solver.parameters['linear_solver'] = 'lu'
    solver.parameters['maximum_iterations'] = 100
    # TODO tighten tolerance. might not always work though...
    solver.parameters['absolute_tolerance'] = 1.0e-3
    solver.parameters['relative_tolerance'] = 0.0
    solver.parameters['report'] = True

    solver.solve(stokes_heat_problem, uptheta0.vector())

    # u0, p0, theta0 = split(uptheta0)
    # Create a *deep* copy of u0, p0, theta0 to be able to deal with them
    # as actually separate entities vectors.
    u0, p0, theta0 = uptheta0.split(deepcopy=True)
    return u0, p0, theta0