-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute_stability.py
executable file
·86 lines (69 loc) · 2.38 KB
/
compute_stability.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 13 10:58:52 2020
@author: user
"""
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 9 15:58:29 2019
@author: boulle
"""
import sys
import os
import gc
from firedrake import *
import numpy as np
from defcon import *
from defcon import backend, StabilityTask
from defcon.cli.common import fetch_bifurcation_problem
from petsc4py import PETSc
RB = __import__("linear_eigenvalue")
# Branch
comm = COMM_WORLD
COMPUTE_CRITICAL = None
# Construct mono-3d problem
problem = RB.EVRayleighBenardProblem()
mesh = problem.mesh(comm=comm)
Z = problem.function_space(mesh)
# Set-up io function
io = problem.io("output")
params = problem.parameters()
io.setup(params, problem.functionals(), Z)
# set the petsc options from the solver_parameters
solver_parameters = problem.solver_parameters(problem.parameters(), StabilityTask)
# PETSC options
opts = PETSc.Options()
for k in solver_parameters:
opts[k] = solver_parameters[k]
#consts = [Ra, Pr]
consts = [max(y[0], y[-1]) for x, y in problem.parameter_values().items()]
#consts = problem.parameters()
print(consts)
#solution = io.fetch_solutions(consts, [0])[0]
solution = Function(Z)
d = problem.compute_stability(consts, 0, solution, critical=COMPUTE_CRITICAL)
io.save_stability(d["stable"], d.get("eigenvalues", []), d.get("eigenfunctions", []), consts, 0)
# pvd = File("eigenfunctions/eigenfunctions.pvd")
# for e in d.get("eigenfunctions", []):
# problem.save_pvd(e, pvd)
eigs = d.get("eigenvalues", [])
evals = list(map(complex, eigs))
evalsR = np.array([l.real for l in evals])
eigsPos = evalsR[evalsR>=0]
print(eigsPos)
print(len(eigsPos))
pvd_path = "initial_guess/solution/"
pvd = File(pvd_path + "eigenfuction_critical.pvd")
if COMPUTE_CRITICAL:
for i, ra in enumerate(eigsPos[:10]):
consts[0] = ra
print(consts)
d = problem.compute_stability(consts, 0, solution)
# import ipdb; ipdb.set_trace()
eigenfunction = d.get("eigenfunctions", [])
problem.save_pvd(eigenfunction[i], pvd, consts)
download_path = "laakmann@wolverine:" + os.getcwd()
download_pvd_path = os.path.join(download_path, pvd_path)
download_msg = f"scp -r {download_pvd_path}* . ; scp {download_path}/paraview_simple_eigenfunction.py .; /Applications/ParaView-5.10.1.app/Contents/bin/pvpython paraview_simple_eigenfunction.py"
print(download_msg)