Skip to content

Commit 4080892

Browse files
author
Francesco Rizzi
committed
wip
1 parent 5354e10 commit 4080892

File tree

2,202 files changed

+1108588
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,202 files changed

+1108588
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
import os, subprocess
3+
4+
def _inviscid_flux_string_to_stencil_size(stringIn):
5+
if stringIn == "FirstOrder":
6+
return 3
7+
elif stringIn == "Weno3":
8+
return 5
9+
elif stringIn == "Weno5":
10+
return 7
11+
else:
12+
sys.exit("Invalid scheme detected {}".format(scheme))
13+
return None
14+
15+
# -----------------------------------------------------------
16+
# fncs and constants below are mandatory
17+
# -----------------------------------------------------------
18+
19+
dimensionality = 2
20+
numDofsPerCell = 3
21+
validParameterNames = ['coriolis', 'pulsemag', 'gravity']
22+
23+
def generate_full_mesh(pdaSrcPath, meshPath, dicIn):
24+
pdaMeshDir = pdaSrcPath + "/meshing_scripts"
25+
26+
nx, ny = dicIn['meshSize'][0], dicIn['meshSize'][1]
27+
28+
# figure out the stencil size needed for the mesh
29+
invFluxRec = dicIn['inviscidFluxReconstruction']
30+
stencilSize = _inviscid_flux_string_to_stencil_size(invFluxRec)
31+
32+
print('Generating mesh {}'.format(meshPath))
33+
# call script
34+
owd = os.getcwd()
35+
args = ("python3", pdaMeshDir + '/create_full_mesh.py',\
36+
"-n", str(nx), str(ny),\
37+
"--outDir", meshPath,\
38+
"--bounds", "-5.0", "5.0", "-5.0", "5.0",
39+
"-s", str(stencilSize))
40+
41+
popen = subprocess.Popen(args, stdout=subprocess.PIPE); popen.wait()
42+
output = popen.stdout.read();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wf.yaml wf.yaml COPYONLY)
3+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/plot.py plot.py COPYONLY)
4+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/clean.py clean.py COPYONLY)
5+
6+
execute_process(
7+
COMMAND
8+
ln -sf
9+
${CMAKE_CURRENT_BINARY_DIR}/../${exename}
10+
${CMAKE_CURRENT_BINARY_DIR}
11+
OUTPUT_VARIABLE OUTP)
317 KB
Loading
321 KB
Loading
329 KB
Loading
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
5+
if __name__== "__main__":
6+
os.system("rm -rf default_galerkin*")
7+
os.system("rm -rf offline_rom")
8+
os.system("rm -rf fom_*")
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python3
2+
3+
import matplotlib.pyplot as plt
4+
from matplotlib import cm
5+
import numpy as np
6+
import re, os
7+
8+
def extractMeshSize(ns):
9+
reg = re.compile(r''+ns+'.+')
10+
file1 = open('./fom_mesh/info.dat', 'r')
11+
strings = re.search(reg, file1.read())
12+
file1.close()
13+
assert(strings)
14+
return int(strings.group().split()[1])
15+
16+
def plotStateErrorOverTime(romDirs):
17+
# plot state error over time
18+
fig = plt.figure(1)
19+
for dirIt in romDirs:
20+
# extract how many modes
21+
modeCount = np.loadtxt(dirIt + "/rom_dofs_count.txt")
22+
print(modeCount)
23+
# load time errors
24+
errors = np.loadtxt(dirIt + "/errors_in_time.txt")
25+
plt.plot(errors[:,0], '-', label="modeCount = " + str(modeCount))
26+
27+
plt.ylim((0,0.1))
28+
plt.legend()
29+
30+
def plotHeight(romDirs):
31+
nx = extractMeshSize('nx')
32+
ny = extractMeshSize('ny')
33+
fomTotDofs = nx*ny*3
34+
35+
meshCoords = np.loadtxt('./fom_mesh/coordinates.dat', dtype=float)
36+
x, y = meshCoords[:,1], meshCoords[:,2]
37+
x = np.reshape(x, (ny,nx))
38+
y = np.reshape(y, (ny,nx))
39+
40+
fig = plt.figure(1)
41+
ax = fig.add_subplot(1, 1, 1, projection='3d')
42+
fomD = np.fromfile("fom_test_runid_0/state_snapshots.bin")
43+
nt = int(np.size(fomD)/fomTotDofs)
44+
print("fomTest: nt = ", nt)
45+
fomD = np.reshape(fomD, (nt, fomTotDofs))
46+
h = fomD[-1,0::3]
47+
bounds = [np.min(h), np.max(h)]
48+
fomD = np.reshape(h, (ny,nx))
49+
surf = ax.plot_surface(x, y, fomD, cmap=cm.jet, \
50+
vmin=bounds[0], vmax=bounds[1])
51+
ax.set_title("FOM", fontsize=20)
52+
ax.set_zlim((0.98, 1.06))
53+
fig.savefig("FOM.png", format="png", bbox_inches='tight', dpi=300)
54+
55+
for i in [0,1]:
56+
fig = plt.figure(i+2)
57+
ax = fig.add_subplot(1, 1, 1, projection='3d')
58+
K = np.loadtxt(romDirs[i] + "/rom_dofs_count.txt", dtype=int)
59+
romD = np.loadtxt(romDirs[i]+"/reconstructed.txt")
60+
romD = np.reshape(romD[0::3,-1], (ny,nx))
61+
surf = ax.plot_surface(x, y, romD, cmap=cm.jet, \
62+
vmin=bounds[0], vmax=bounds[1])
63+
ax.set_title("ROM: # modes = " + str(K), fontsize=20)
64+
ax.set_zlim((0.98, 1.06))
65+
fig.savefig("ROM_"+str(K)+".png", format="png", bbox_inches='tight', dpi=300)
66+
67+
plt.show()
68+
69+
if __name__== "__main__":
70+
# find all rom RUNs
71+
romDirs = [d for d in os.listdir(".") if "default_galerkin" in d]
72+
assert len(romDirs)==2, "for this demo, should only have two runs"
73+
74+
plotHeight(romDirs)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
problem: 2d_swe
2+
3+
parameterSpace:
4+
names: ['coriolis', 'pulsemag', 'gravity']
5+
trainPoints:
6+
0: [-1.0, 0.125, 9.8]
7+
1: [ 0.0, 0.125, 9.8]
8+
testPoints:
9+
0: [-0.5, 0.125, 9.8]
10+
11+
fom:
12+
meshSize: [65, 65]
13+
inviscidFluxReconstruction: "Weno3"
14+
odeScheme: "RK4"
15+
timeStepSize: 0.005
16+
train:
17+
finalTime: 5.0
18+
stateSamplingFreq: 10
19+
rhsSamplingFreq: 5
20+
test:
21+
finalTime: 5.0
22+
stateSamplingFreq: 10
23+
rhsSamplingFreq: 100
24+
25+
offlineRom:
26+
pod:
27+
stateData:
28+
useTrainingRuns: all
29+
rhsData:
30+
useTrainingRuns: all
31+
32+
onlineRom:
33+
algorithm: defaultGalerkin
34+
podTruncation:
35+
energyBased: [99.999, 99.99999]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wf.yaml wf.yaml COPYONLY)
3+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/plot.py plot.py COPYONLY)
4+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/clean.py clean.py COPYONLY)
5+
6+
execute_process(
7+
COMMAND
8+
ln -sf
9+
${CMAKE_CURRENT_BINARY_DIR}/../${exename}
10+
${CMAKE_CURRENT_BINARY_DIR}
11+
OUTPUT_VARIABLE OUTP)
317 KB
Loading

0 commit comments

Comments
 (0)