-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplot_wabbit_scaling_function.py
129 lines (105 loc) · 4.06 KB
/
plot_wabbit_scaling_function.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 31 10:55:09 2019
@author: krah
"""
import numpy as np
import wabbit_tools as wt
import matplotlib.pyplot as plt
import re
import os
import glob
from matplotlib import cm
from mpl_toolkits.mplot3d import axes3d
###############################################################################
# %% Change parameters here
###############################################################################
# directories needed
dirs= {
'wabbit' : "~/develop/WABBIT/" , # directory of wabbit
'work' : "./", # where to save big data files
'images' : "./" #pictures are saved here
}
# setup for wabbit call
wabbit_setup = {
'mpicommand' : "mpirun -np 4",
'memory' : "--memory=32GB"
}
# parameters to adjust
class params:
jmax_list = np.arange(1,10) # maximal tree level
predictor_order= 4
class domain:
N = [16, 16] # number of points for 3d use 3 elements
L = [1, 1] # length of domain
def init(N): # this function will be initialized on the domain
field = np.zeros(N)
field[N[0]//2,N[1]//2]=1
return field
###############################################################################
# %%
###############################################################################
def wabbit_adapt(dirs, params, wabbit_setup):
mpicommand = wabbit_setup["mpicommand"]
memory = wabbit_setup["memory"]
wdir = dirs["wabbit"]
work = dirs["work"]
jmax_list = params.jmax_list
# set initial gird
dim = len(params.domain.L)
x = [np.linspace(0,params.domain.L[d],params.domain.N[d]) \
for d in range(dim) ]
X = np.meshgrid(*x)
phi = params.init(params.domain.N)
Bs = wt.field_shape_to_bs(params.domain.N,jmax_list[0])
# create reference file
file_coarse = wt.dense_to_wabbit_hdf5(phi,work+"/phi", Bs, params.domain.L,0)
for j,jmax in enumerate(params.jmax_list):
print("\n\n###################################################################")
print("###################################################################")
print( "\t\tJmax: ", jmax, "\n\n")
fname = "phi-j"+str(jmax)+".h5"
file_dense = work +"/"+fname
# command for densing file again
dense_command = mpicommand + " " + wdir + \
"wabbit-post"+ " --sparse-to-dense " + \
" "+ file_coarse + " "+file_dense + " "+str(jmax)+" "+ \
str(params.predictor_order)+ " >adapt.log"
# -----------------------------
# Execute Command
# -----------------------------
print("\n",dense_command,"\n\n")
success = os.system(dense_command) # execute command
#wt.plot_wabbit_file(file_dense,savepng=True)
if success != 0:
print("command did not execute successfully")
return
# delete reference file
os.system("rm " + file_coarse)
return file_dense
file = wabbit_adapt(dirs, params, wabbit_setup)
# Grab some test data.
time, x0, dx, box, field, treecode = wt.read_wabbit_hdf5(file)
field, box = wt.dense_matrix(x0,dx,field,treecode)
# %%
plt.close("all")
fig1 = plt.figure()
ax1 = fig1.gca(projection='3d')
Nxy=field.shape
Z = field[Nxy[0]//3:-Nxy[0]//3:40, Nxy[1]//3:-Nxy[1]//3:40]
x = np.linspace(0,params.domain.L[0],Z.shape[0])
y = np.linspace(0,params.domain.L[1],Z.shape[1])
[X,Y] = np.meshgrid(x,y)
# Plot a basic wireframe.
ax1.plot_wireframe(X,Y, Z, rstride=1, cstride=1, antialiased = True,
color = "black")
ax1.set_axis_off()
# Equally stretch all axes
ax1.set_aspect("equal")
plt.show()
#
################################################
#%% save figure
###############################################
fig1.savefig( dirs["images"]+'waveletDD'+str(params.predictor_order)+'.png', dpi=300, transparent=True, bbox_inches='tight' )# -*- coding: utf-8 -