Skip to content

Customer Outreach Examples #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions examples/Solver_Features/Adaptive_CFL/ONERAM6/Flow360.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"geometry": {
"meshName": "wing_mixed_ph.2.lb8.ugrid",
"endianness": "little",
"refArea": 1.15315084119231,
"momentCenter": [
0,
0,
0
],
"momentLength": [
0.801672958512342,
0.801672958512342,
0.801672958512342
]
},
"volumeOutput": {
"outputFormat": "paraview",
"outputFields": ["primitiveVars", "Mach", "qcriterion"]
},
"surfaceOutput": {
"outputFormat": "paraview",
"outputFields": ["primitiveVars", "Cp", "Cf", "CfVec", "yPlus"]
},
"navierStokesSolver": {
"absoluteTolerance": 1e-10,
"linearIterations": 25,
"kappaMUSCL": -1,
"limitVelocity": false,
"limitPressureDensity": false
},
"turbulenceModelSolver": {
"modelType": "SpalartAllmaras",
"absoluteTolerance": 1e-10,
"linearIterations": 20,
"kappaMUSCL": -1,
"rotationCorrection": false
},
"freestream": {
"Reynolds": 14600000,
"Mach": 0.84,
"Temperature": 288.15,
"alphaAngle": 3.06,
"betaAngle": 0
},
"timeStepping": {
"timeStepSize": "inf",
"physicalSteps": 1,
"maxPseudoSteps": 4000,
"CFL": {
"initial": 10,
"final": 100,
"rampSteps": 200,
"type": "ramp"
}
},
"boundaries": {
"1": {
"type": "NoSlipWall"
},
"2": {
"type": "SlipWall"
},
"3": {
"type": "Freestream"
}
}
}
9 changes: 9 additions & 0 deletions examples/Solver_Features/Adaptive_CFL/ONERAM6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The following example demonstrates the use of adaptive CFL for the ONERAM6 wing

To run the demo case follow these steps:

1. Run `python submit_cases_from_downloads.py` -> this script will download the ONERAM6 mesh, and upload it to the Flexcompute servers. The cases will also be submitted for both adaptive and ramp CFL at two angles of attack. Alternatively the script `submit_cases_from_id.py` can also be used to run the cases from meshes already uploaded to Flexcompute servers.

2. Run `python download_data.py` -> this script will download the csv files containing the loads and residual histories at two angles of attack

3. Run `python convergence_plots_3p06.py` and `python convergence_plots_10.py` -> these scripts will cross-plot the load and residual convergence histories for the ramp and adaptive CFL cases at two angles of attack.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""Plot the loads and residuals convergence plots for the ramp and adaptive CFL cases at 10 degrees"""

import os

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

with open("case_name_list.dat", "r", encoding="utf-8") as file:
case_name_list = file.read().splitlines()

loads = ["CL", "CD"]
residuals = ["0_cont", "1_momx", "2_momy", "3_momz", "4_energ", "5_nuHat"]
figures = []
axes = []


def plot_loads(data, plot_name):
"""Plot the loads"""
x = data["pseudo_step"]
for ax, load in zip(axes, loads):
ax.plot(x, data[load], label=plot_name)
ax.set_ylabel(load)
ax.legend()
ax.set_xlabel("Pseudo step")
ax.grid(which="major", color="gray")
if load == "CL":
ax.set_ylim(0.45, 0.8)
elif load == "CD":
ax.set_ylim(0.1, 0.15)


def plot_residuals(data, plot_name):
"""Plot the residuals"""
x = data["pseudo_step"]
for ax, res in zip(axes, residuals):
for res in residuals:
if "RAMP" in plot_name:
ax.semilogy(x, data[res], label=plot_name + " " + res)
else:
ax.semilogy(x, data[res], "--", label=plot_name + " " + res)
ax.set_ylabel("Residuals")
ax.legend(fontsize="8")
ax.set_title("ONERAM6 -10 deg")
ax.grid(which="major", color="gray")
ax.set_xlabel("Pseudo step")
ax.set_yticks(10.0 ** np.arange(-14, -3))
ax.set_ylim([1e-10, 1e-3])
ax.set_xlim([0, 8000])


# set output directory
dir_path = os.path.join(os.getcwd(), "figures")
os.makedirs(dir_path, exist_ok=True)

# initialize figures & axes
for load in loads:
fig, ax = plt.subplots(figsize=(8, 6))
figures.append(fig)
axes.append(ax)

# calculate and plot loads convergence histories
for case_name in case_name_list:
if "10" in case_name:
csv_path = os.path.join(os.getcwd(), f"{case_name}", "total_forces_v2.csv")
data = pd.read_csv(csv_path, skipinitialspace=True)
plot_loads(data, case_name)

for i, load in enumerate(loads):
figures[i].savefig(os.path.join(dir_path, load + "_AoA10.png"), dpi=500)

for ax in axes:
ax.cla()


# plot residual convergence histories
fig, ax = plt.subplots(figsize=(8, 6))
figures.append(fig)
axes.append(ax)

for case_name in case_name_list:
if "10" in case_name:
if "ADAPTIVE" in case_name:
figures[0].gca().set_prop_cycle(None)
csv_path = os.path.join(os.getcwd(), case_name, "nonlinear_residual_v2.csv")
data = pd.read_csv(csv_path, skipinitialspace=True)
plot_residuals(data, case_name)

figures[0].savefig(os.path.join(dir_path, "Residuals_AoA10.png"), dpi=500)
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""Plot the loads and residuals convergence plots for the ramp and adaptive CFL cases at 3.06 degrees"""

import os

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

with open("case_name_list.dat", "r", encoding="utf-8") as file:
case_name_list = file.read().splitlines()

loads = ["CL", "CD"]
residuals = ["0_cont", "1_momx", "2_momy", "3_momz", "4_energ", "5_nuHat"]
figures = []
axes = []


def plot_loads(data, plot_name):
"""Plot the loads"""
x = data["pseudo_step"]
for ax, load in zip(axes, loads):
ax.plot(x, data[load], label=plot_name)
ax.set_ylabel(load)
ax.legend()
ax.set_xlabel("Pseudo step")
ax.grid(which="major", color="gray")
if load == "CL":
ax.set_ylim(0.25, 0.3)
elif load == "CD":
ax.set_ylim(0.0, 0.05)


def plot_residuals(data, plot_name):
"""Plot the residuals"""
x = data["pseudo_step"]
for ax, res in zip(axes, residuals):
for res in residuals:
if "RAMP" in plot_name:
ax.semilogy(x, data[res], label=plot_name + " " + res)
else:
ax.semilogy(x, data[res], "--", label=plot_name + " " + res)
ax.set_ylabel("Residuals")
ax.legend(fontsize="8")
ax.set_title("ONERAM6 -3.06 deg")
ax.grid(which="major", color="gray")
ax.set_xlabel("Pseudo step")
ax.set_yticks(10.0 ** np.arange(-14, -3))
ax.set_ylim([1e-10, 1e-3])
ax.set_xlim([0, 4000])


# set output directory
dir_path = os.path.join(os.getcwd(), "figures")
os.makedirs(dir_path, exist_ok=True)

# initialize figures & axes
for load in loads:
fig, ax = plt.subplots(figsize=(8, 6))
figures.append(fig)
axes.append(ax)

# calculate and plot loads convergence histories
for case_name in case_name_list:
if "3p06" in case_name:
csv_path = os.path.join(os.getcwd(), f"{case_name}", "total_forces_v2.csv")
data = pd.read_csv(csv_path, skipinitialspace=True)
plot_loads(data, case_name)

for i, load in enumerate(loads):
figures[i].savefig(os.path.join(dir_path, load + "_AoA3p06.png"), dpi=500)

for ax in axes:
ax.cla()


# plot residual convergence histories
fig, ax = plt.subplots(figsize=(8, 6))
figures.append(fig)
axes.append(ax)

for case_name in case_name_list:
if "3p06" in case_name:
if "ADAPTIVE" in case_name:
figures[0].gca().set_prop_cycle(None)
csv_path = os.path.join(os.getcwd(), case_name, "nonlinear_residual_v2.csv")
data = pd.read_csv(csv_path, skipinitialspace=True)
plot_residuals(data, case_name)

figures[0].savefig(os.path.join(dir_path, "Residuals_AoA3p06.png"), dpi=500)
29 changes: 29 additions & 0 deletions examples/Solver_Features/Adaptive_CFL/ONERAM6/download_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Download the results for the ramp and adaptive CFL cases at both angles of attack"""

import os

from flow360 import MyCases

# read in case_name_list
with open("case_name_list.dat", "r", encoding="utf-8") as file:
case_name_list = file.read().splitlines()

my_cases = MyCases(limit=None)

case = None

for case_name in case_name_list:
case_folder = os.path.join(os.getcwd(), case_name)
os.makedirs(case_folder, exist_ok=True)
# find the latest case with the name corresponding to the name in case_name_list
for case in my_cases:
if case.name == case_name:
break
print(case.name)
# download the files
case.results.download(
nonlinear_residuals=True,
surface_forces=True,
total_forces=True,
destination=case_folder,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""Case submission through mesh download and upload onto Flexcompute servers"""

import os.path
from urllib.request import urlretrieve

import flow360 as fl

case_name_list = []

# download meshes to the current directory

URL = "PLACEHOLDER"
MESH_FILENAME = "mesh.lb8.ugrid"

if not os.path.isfile(MESH_FILENAME):
urlretrieve(URL, MESH_FILENAME)


# submit mesh
volume_mesh = fl.VolumeMesh.from_file(MESH_FILENAME, name="ONERAM6_Mesh")
volume_mesh = volume_mesh.submit()

params = fl.Flow360Params("Flow360.json")

# submit ramp CFL case at alpha = 3.06
case = fl.Case.create("ONERAM6_3p06_RAMP", params, volume_mesh.id)
case_name_list.append(case.name)
case = case.submit()

# change CFL type to adaptive
params.time_stepping.CFL.type = "adaptive"

# submit adaptive CFL case at alpha = 3.06
case2 = fl.Case.create("ONERAM6_3p06_ADAPTIVE", params, volume_mesh.id)
case_name_list.append(case2.name)
case2 = case2.submit()

# change CFL type to ramp, modify time stepping settings and increase alpha to 10
params.time_stepping.CFL.type = "ramp"
params.time_stepping.max_pseudo_steps = 8000
params.time_stepping.CFL.initial = 1
params.time_stepping.CFL.final = 20
params.time_stepping.CFL.ramp_steps = 200
params.freestream.alpha = 10

# submit ramp CFL case at alpha = 10
case3 = fl.Case.create("ONERAM6_10_RAMP", params, volume_mesh.id)
case_name_list.append(case3.name)
case3 = case3.submit()


# change CFL type to adaptive
params.time_stepping.CFL.type = "adaptive"

# submit adaptive CFL case at alpha = 10
case4 = fl.Case.create("ONERAM6_10_ADAPTIVE", params, volume_mesh.id)
case_name_list.append(case4.name)
case4 = case4.submit()

# dump case names for use in download and post-processing scripts

with open("case_name_list.dat", "w", encoding="utf-8") as f:
for line in case_name_list:
f.write(f"{line}\n")
Loading