-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
converted all example config.py files.
- Loading branch information
1 parent
de31324
commit 1703291
Showing
37 changed files
with
3,838 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env python | ||
import numpy as np | ||
import plot3dnasa as p3d | ||
|
||
def grid(size): | ||
x_min = -14. | ||
x_max = 14. | ||
y_min = -14. | ||
y_max = 14. | ||
g = p3d.Grid().set_size(size, True) | ||
x = np.linspace(x_min, x_max, g.size[0,0]) | ||
y = np.linspace(y_min, y_max, g.size[0,1]) | ||
g.xyz[0][:,:,0,:2] = np.transpose(np.meshgrid(x, y)) | ||
return g | ||
|
||
def target_mollifier(g): | ||
x_min = -1. | ||
x_max = 1. | ||
y_min = -10. | ||
y_max = 10. | ||
f = p3d.Function().copy_from(g) | ||
f.f[0].fill(1.) | ||
n = f.get_size(0) | ||
for i in range(n[0]): | ||
f.f[0][i,:,0,0] *= p3d.tanh_support( | ||
g.xyz[0][i,:,0,1], y_min, y_max, 40., 0.2) | ||
for j in range(n[1]): | ||
f.f[0][:,j,0,0] *= p3d.cubic_bspline_support( | ||
g.xyz[0][:,j,0,0], x_min, x_max) | ||
imin, imax = p3d.find_extents(g.xyz[0][:,0,0,0], x_min, x_max) | ||
jmin, jmax = p3d.find_extents(g.xyz[0][0,:,0,1], y_min, y_max) | ||
print (' {:<20} {:<21} {:>4d} {:>7d}' + 6 * ' {:>4d}').format( | ||
'targetRegion', 'COST_TARGET', 1, 0, imin, imax, jmin, jmax, 1, -1) | ||
return f | ||
|
||
def control_mollifier(g): | ||
x_min = 1. | ||
x_max = 5. | ||
y_min = -2. | ||
y_max = 2. | ||
f = p3d.Function().copy_from(g) | ||
f.f[0].fill(1.) | ||
n = f.get_size(0) | ||
for j in range(n[1]): | ||
f.f[0][:,j,0,0] *= p3d.cubic_bspline_support( | ||
g.xyz[0][:,j,0,0], x_min, x_max) | ||
for i in range(n[0]): | ||
f.f[0][i,:,0,0] *= p3d.cubic_bspline_support( | ||
g.xyz[0][i,:,0,1], y_min, y_max) | ||
imin, imax = p3d.find_extents(g.xyz[0][:,0,0,0], x_min, x_max) | ||
jmin, jmax = p3d.find_extents(g.xyz[0][0,:,0,1], y_min, y_max) | ||
print (' {:<20} {:<21} {:>4d} {:>7d}' + 6 * ' {:>4d}').format( | ||
'controlRegion', 'ACTUATOR', 1, 0, imin, imax, jmin, jmax, 1, -1) | ||
return f | ||
|
||
def mean_pressure(s): | ||
f = p3d.Function().copy_from(s) | ||
f.f[0][:,:,:,0] = s.toprimitive().q[0][:,:,:,4] | ||
return f | ||
|
||
def random_solution(g,time=0.0,timestep=0): | ||
|
||
gamma = 1.4 | ||
s = p3d.Solution().copy_from(g).quiescent(gamma) | ||
n = s.get_size(0) | ||
s.q[0][:,:,0,0] = ( 2.0 * np.random.rand(n[0],n[1]) - 1.0 ) * 1.0e-2 + 1.0 | ||
s.q[0][:,:,0,1] = ( 2.0 * np.random.rand(n[0],n[1]) - 1.0 ) * 1.0e-3 + 0.0 | ||
s.q[0][:,:,0,2] = ( 2.0 * np.random.rand(n[0],n[1]) - 1.0 ) * 1.0e-3 + 0.0 | ||
s.q[0][:,:,0,4] = ( 2.0 * np.random.rand(n[0],n[1]) - 1.0 ) * 1.0e-2 + 1./(gamma-1.) | ||
s.q[0][:,:,0,4] *= (gamma-1.)/gamma * s.q[0][:,:,0,0] | ||
|
||
s.time = time | ||
s._format.aux_header[0] = timestep | ||
|
||
return s.fromprimitive(gamma) | ||
|
||
if __name__ == '__main__': | ||
g = grid([201, 201]) | ||
g.save('AcousticMonopole.xyz') | ||
gamma = 1.4 | ||
s = p3d.Solution().copy_from(g).quiescent(gamma) | ||
s.save('AcousticMonopole.ic.q') | ||
mean_pressure(s).save('AcousticMonopole.mean_pressure.f') | ||
|
||
# dt = 5.0e-2 | ||
# Nt = 100 | ||
# for k in range(2): | ||
# random_solution(g,k*Nt*dt,k*Nt).save('AcousticMonopole-%d.ic.q'%k) | ||
target_mollifier(g).save('AcousticMonopole.target_mollifier.f') | ||
control_mollifier(g).save('AcousticMonopole.control_mollifier.f') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env python | ||
import numpy as np | ||
import plot3dnasa as p3d | ||
|
||
def mapping_function(x, sigma): | ||
return np.sinh(sigma * x) / np.sinh(sigma) | ||
|
||
def grid(size, mapping_type='sinh'): | ||
from scipy.optimize import fsolve | ||
x_min = -150. | ||
x_max = 150. | ||
y_min = 0. | ||
y_max = 50. | ||
z_min = -40. | ||
z_max = 40. | ||
dy_min = 0.016 | ||
num_uniform = 7 | ||
g = p3d.Grid().set_size(size, True) | ||
x = np.linspace(x_min, x_max, g.size[0,0] + 1)[:-1] | ||
if mapping_type == 'sinh': | ||
sigma = fsolve(lambda x: ( | ||
(y_max - y_min - num_uniform * dy_min) * mapping_function( | ||
1. / (g.size[0,1] - 1.), x) - dy_min) ** 2, 2.) | ||
y = np.append(np.linspace(y_min, y_min + dy_min * num_uniform, | ||
num_uniform + 1), y_min + dy_min * | ||
num_uniform + (y_max - y_min - num_uniform * dy_min) * | ||
mapping_function(np.linspace(0., 1., g.size[0,1] - | ||
num_uniform), sigma)[1:]) | ||
else: | ||
sigma = fsolve(lambda x: (y_max - y_min) / dy_min - num_uniform + 1 - | ||
(x ** (g.size[0,1] - num_uniform) - 1.) / | ||
(x - 1.), 1.02) | ||
print 100. * (sigma - 1.) | ||
y = np.append([0.], np.cumsum( | ||
[dy_min if r < num_uniform - 1 | ||
else dy_min * sigma ** (r - num_uniform + 1) | ||
for r in range(g.size[0,1] - 1)])) | ||
z = np.linspace(z_min, z_max, g.size[0,2] + 1)[:-1] | ||
for i in range(x.size): | ||
g.xyz[0][i,:,:,0] = x[i] | ||
for j in range(y.size): | ||
g.xyz[0][:,j,:,1] = y[j] | ||
for k in range(z.size): | ||
g.xyz[0][:,:,k,2] = z[k] | ||
return g | ||
|
||
def target_state(g, mach_number=0.5, gamma=1.4): | ||
s = p3d.Solution().copy_from(g).quiescent(gamma) | ||
s.q[0][:,:,:,1] = mach_number | ||
return s.fromprimitive() | ||
|
||
def initial_condition(g, external_grid='External/RocFlo-CM.00000000.xyz', | ||
external_solution='External/RocFlo-CM.00240000.q', | ||
chunk_size=20): | ||
from scipy.signal import resample | ||
from scipy.interpolate import interp1d | ||
x, y, z = g.xyz[0][:,0,0,0], g.xyz[0][0,:,0,1], g.xyz[0][0,0,:,2] | ||
ge = p3d.Grid(external_grid) | ||
xe = ge.set_subzone(0, [0, 0, 0], [-2, 0, 0]).load().xyz[0][:,0,0,0] | ||
ye = ge.set_subzone(0, [0, 0, 0], [0, -1, 0]).load().xyz[0][0,:,0,1] | ||
ze = ge.set_subzone(0, [0, 0, 0], [0, 0, -2]).load().xyz[0][0,0,:,2] | ||
if x.size == xe.size and z.size == ze.size: | ||
st = p3d.fromfile(external_solution, 0, [0, 0, 0], [-2, -1, -2]) | ||
else: | ||
st = p3d.Solution().set_size([x.size, ye.size, z.size], True) | ||
ends = [int(d) for d in np.linspace(chunk_size - 1, ye.size - 1, | ||
ye.size / chunk_size)] | ||
subzones = [([0, ends[i-1] + 1, 0], [-2, ends[i], -2]) | ||
if i > 0 else ([0, 0, 0], [-2, ends[0], -2]) | ||
for i in range(len(ends))] | ||
se = p3d.Solution(external_solution) | ||
for subzone in subzones: | ||
se.set_subzone(0, *subzone).load() | ||
q = np.empty_like(se.q[0], dtype='float64') | ||
q[:,:,:,:] = se.q[0] | ||
if x.size != xe.size: | ||
q = resample(q, x.size, axis=0, window='hann') | ||
if z.size != ze.size: | ||
q = resample(q, z.size, axis=2, window='hann') | ||
st.q[0][:,subzone[0][1]:subzone[1][1]+1,:,:] = q | ||
s = p3d.Solution().copy_from(g) | ||
for j in range(5): | ||
for k in range(z.size): | ||
for i in range(x.size): | ||
f = interp1d(ye, st.q[0][i,:,k,j], kind='linear', | ||
bounds_error=False, fill_value=st.q[0][i,-1,k,j]) | ||
s.q[0][i,0,k,j] = st.q[0][i,0,k,j] | ||
s.q[0][i,1:,k,j] = f(y[1:]) | ||
return s | ||
|
||
if __name__ == '__main__': | ||
g = grid([500, 216, 400], mapping_type='geom') | ||
g.save('BoundaryLayer.xyz') | ||
target_state(g).save('BoundaryLayer.target.q') | ||
initial_condition(g).save('BoundaryLayer.ic.q') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python | ||
import numpy as np | ||
import plot3dnasa as p3d | ||
|
||
def mapping_function(x, sigma): | ||
return np.sinh(sigma * x) / np.sinh(sigma) | ||
|
||
def grid(size, eta=0.97): | ||
from scipy.optimize import fsolve | ||
x_min = -2.0 * np.pi | ||
x_max = 2.0 * np.pi | ||
y_min = -1.0 | ||
y_max = 1.0 | ||
z_min = -2.0 / 3.0 * np.pi | ||
z_max = 2.0 / 3.0 * np.pi | ||
dy_min = 0.016 | ||
num_uniform = 7 | ||
g = p3d.Grid().set_size(size, True) | ||
x = np.linspace(x_min, x_max, g.size[0,0] + 1)[:-1] | ||
z = np.linspace(z_min, z_max, g.size[0,2] + 1)[:-1] | ||
|
||
xi = np.linspace(-1.0, 1.0, g.size[0,1]) | ||
y = np.sin(eta*xi*np.pi/2.0) / np.sin(eta*np.pi/2.0) | ||
y *= (y_max - y_min)/2.0 | ||
|
||
dx, dz = (x_max-x_min)/g.size[0,0], (z_max-z_min)/g.size[0,2] | ||
dy = y[1:] - y[:-1] | ||
print ('dx : %.5E, dz : %.5E, dy_min : %.5E, dy_max : %.5E' % (dx,dz,np.min(dy),np.max(dy)) ) | ||
|
||
for i in range(x.size): | ||
g.xyz[0][i,:,:,0] = x[i] | ||
for j in range(y.size): | ||
g.xyz[0][:,j,:,1] = y[j] | ||
for k in range(z.size): | ||
g.xyz[0][:,:,k,2] = z[k] | ||
return g | ||
|
||
def initial_condition(g, mach_number=1.5, gamma=1.4): | ||
x = g.xyz[0][:,:,:,0] | ||
y = g.xyz[0][:,:,:,1] | ||
z = g.xyz[0][:,:,:,2] | ||
u0 = mach_number * 1.5 * ( 1.0 - y**2 ) | ||
|
||
s = p3d.Solution().copy_from(g).quiescent(gamma) | ||
s.q[0][:,:,:,0] = 1.0 | ||
s.q[0][:,:,:,1:4] = 0.0 | ||
s.q[0][:,:,:,4] = 1.0 / gamma | ||
|
||
temp = np.zeros_like(s.q[0][:,:,:,1:4],dtype=np.complex128) | ||
for k in range(3,6): | ||
for l in range(18,21): | ||
for m in range(6,9): | ||
for dim in range(3): | ||
amp = np.random.rand(2) | ||
amp = amp[0] + amp[1] * 1.0j | ||
phase = 2.0 * np.pi * np.random.rand(2) | ||
yphase = 2 * np.random.randint(2) - 1 | ||
print ('amp: (%.15E + %.15E i), phase: (%.15E, %.15E), y-phase: %d' | ||
%(amp.real,amp.imag,phase[0],phase[1],yphase)) | ||
temp[:,1:-1,:,dim] += u0[:,1:-1,:] * amp \ | ||
* np.sin( k * np.pi * y[:,1:-1,:] * yphase ) \ | ||
* np.exp( l * 0.5j * x[:,1:-1,:] + phase[0] * 1.0j ) \ | ||
* np.exp( m * 1.5j * z[:,1:-1,:] + phase[1] * 1.0j ) | ||
|
||
temp = temp.real | ||
temp *= 0.05 * mach_number * 1.5 / np.amax(np.abs(temp)) | ||
|
||
s.q[0][:,:,:,1] = u0 | ||
s.q[0][:,:,:,1:4] += temp.real | ||
return s.fromprimitive() | ||
|
||
if __name__ == '__main__': | ||
g = grid([300, 200, 300],eta=0.99) | ||
g.save('ChannelFlow.xyz') | ||
initial_condition(g).save('ChannelFlow.ic.q') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.