Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
- [ ] I am submitting my contribution to the develop branch.
- [ ] I have updated the list of python modules in [required_packages.txt](../required_packages.txt) and [environment.yml](../environment.yml), if necessary.
- [ ] I have properly commented my changes.
- [ ] I used the pre-commit hook to prevent dirty commits and used `pre-commit run --all` to format old commits.
- [ ] I have updated the [documentation](../Documentation/), if necessary.
- [ ] I have added a test case that demonstrates my contribution, if necessary.
28 changes: 28 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Linting

on:
pull_request:
branches:
- 'develop'

jobs:
Ruff:
name: Code linting with Ruff
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Install Ruff
run: pip install ruff
- name: Trailing whitespaces
run: ruff check --select=W291
- name: Unused modules
run: ruff check --select=F401
- name: Unused variables
run: ruff check --select=F841
- name: Duplicate class members
run: ruff check --select=PIE794
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.15.13
hooks:
# Run the linter.
- id: ruff-check
name: Trailing whitespaces
args: [ --fix, --select=W291]
- id: ruff-check
name: Unused modules
args: [ --fix, --select=F401]
- id: ruff-check
name: Unused variables
args: [--select=F841]
- id: ruff-check
name: Duplicate class members
args: [--select=PIE794]
7 changes: 2 additions & 5 deletions Common/DataDrivenConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def SetFluid(self, fluid_name=DefaultSettings_NICFD.fluid_name):
# raise Exception("Only two fluids can be used for mixtures")

self.__fluid_names = []
fluid_mixing = []
for f in fluid_name:
if type(f) is not str:
raise Exception("Fluid name should be provided in string format.")
Expand Down Expand Up @@ -1263,7 +1262,7 @@ def SetNpMix(self, input:int=DefaultSettings_FGM.Np_eq):
"""
Set number of divisions between lean and rich mixture status for flamelet generation.

:param input: Number of divisions between leanest and richest pre-mixed solution.
:param input: Number of divisions between leanest and richest pre-mixed solution.
:type input: int
:raise: Exception: If the number of divisions is lower than one.

Expand Down Expand Up @@ -1509,7 +1508,7 @@ def GetProgressVariableWeights(self):
return self.__pv_weights

def SetDefaultProgressVariable(self):
"""Set progress variable to be weighted sum of fuel and oxidizer species (minus N2) and major product at stochiometry.
"""Set progress variable to be weighted sum of fuel and oxidizer species (minus N2) and major product at stochiometry.
Weights are set as the inverse of specie molecular weight: negative for reactants, positive for product.
"""

Expand Down Expand Up @@ -1684,8 +1683,6 @@ def GetSparkSources(self, val_phi:float, val_T:float, iGroup:int=0):
flame = ct.FreeFlame(self.gas)
flame.transport_model = self.__transport_model
flame.solve(auto=True,refine_grid=True,loglevel=0)
dx = flame.grid[1:] - flame.grid[:-1]
t_res = np.sum(dx / flame.velocity[:-1])
qdot = flame.heat_release_rate
ix_max = np.argmax(qdot)
ydot = flame.net_production_rates
Expand Down
6 changes: 3 additions & 3 deletions Data_Generation/DataGenerator_Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def SetTrainFraction(self, input:float=DefaultProperties.train_fraction):
Define the fraction of fluid data used for training multi-layer perceptrons.

:param input: fluid data train fraction.
:type input: float
:type input: float
:raise: Exception: if provided fraction is equal or higher than one.
"""
if input >= 1 or input <=0:
Expand All @@ -146,7 +146,7 @@ def GetTrainFraction(self):
Get fluid data fraction used for multi-layer perceptron training.

:return: fluid data train fraction.
:rtype: float
:rtype: float
"""
return self.__train_fraction

Expand All @@ -155,7 +155,7 @@ def GetTestFraction(self):
Get fluid data fraction used for determining accuracy after training.

:return: fluid data test fraction.
:rtype: float
:rtype: float
"""
return self.__test_fraction

Expand Down
2 changes: 1 addition & 1 deletion Data_Generation/DataGenerator_FGM.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def ComputeBurnerFlames(self, mix_status:float, m_dot:np.ndarray[float], T_burne
pass

def ComputeCounterFlowFlames(self, v_fuel:float, v_ox:float, T_ub:float):
"""Generate counter-flow diffusion flamelet data for a given temperature, and reactant velocities.
"""Generate counter-flow diffusion flamelet data for a given temperature, and reactant velocities.
Strain rate is gradually increased until extinction in order to distribute data over the progress variable spectrum.

:param v_fuel: Fuel reactant velocity in meters per second.
Expand Down
12 changes: 2 additions & 10 deletions Data_Generation/DataGenerator_NICFD.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def UpdateConfig(self):
def VisualizeDataGrid(self):
"""Visualize query points at which fluid data are evaluated.
"""
fig = plt.figure(figsize=[10,10])
plt.figure(figsize=[10,10])
ax = plt.axes()
ax.plot(self.__X_grid.flatten(), self.__Y_grid.flatten(), 'k.')
if self. __use_PT:
Expand Down Expand Up @@ -830,7 +830,7 @@ def __get_saturated_transport_properties(self, p:float):
'k_l': k_l, 'k_g': k_g,
'rho_l': rho_l, 'rho_g': rho_g
}
except Exception as ex:
except Exception:
return None

def __compute_void_fraction(self, quality:float, rho_l:float, rho_g:float):
Expand Down Expand Up @@ -949,18 +949,10 @@ def DiscretizationError(self, rho, e):
self.UpdateFluid(rho, e)
state_vector,_ = self.GetStateVector()
self.UpdateFluid(rho, e)
dPde_rho_ref = self.fluid.first_partial_deriv(CP.iP, CP.iUmass, CP.iDmass)
dPdrho_e_ref = self.fluid.first_partial_deriv(CP.iP, CP.iDmass, CP.iUmass)
dTde_rho_ref = self.fluid.first_partial_deriv(CP.iT, CP.iUmass, CP.iDmass)
dTdrho_e_ref = self.fluid.first_partial_deriv(CP.iT, CP.iDmass, CP.iUmass)
P_ref = self.fluid.p()
T_ref = self.fluid.T()
ref_data = np.array([P_ref, T_ref])

dPde_rho_test = state_vector[EntropicVars.dpde_rho.value]
dPdrho_e_test = state_vector[EntropicVars.dpdrho_e.value]
dTde_rho_test = state_vector[EntropicVars.dTde_rho.value]
dTdrho_e_test = state_vector[EntropicVars.dTdrho_e.value]
P_test = state_vector[EntropicVars.p.value]
T_test = state_vector[EntropicVars.T.value]
test_data = np.array([P_test, T_test])
Expand Down
2 changes: 1 addition & 1 deletion Data_Processing/DataPlotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, Config_in:Config_FGM=None):
def ManualSelection(self, input:bool=False):
"""Select flamelets to plot manually.

:param input: select flamelets manually(True) or all flamelets within
:param input: select flamelets manually(True) or all flamelets within
:type input: bool
"""
self.__manual_select = input
Expand Down
9 changes: 4 additions & 5 deletions Data_Processing/OptimizeProgressVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import matplotlib.pyplot as plt
from scipy.optimize import differential_evolution, Bounds, LinearConstraint, minimize
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler, RobustScaler, MinMaxScaler
from sklearn.preprocessing import MinMaxScaler

from Common.Properties import FGMVars, DefaultSettings_FGM
from Common.DataDrivenConfig import Config_FGM
Expand Down Expand Up @@ -290,7 +290,7 @@ def PlotConvergence(self):


def penalty_function(self, x:np.array):
"""Optimization penalty function computing the derivative of the
"""Optimization penalty function computing the derivative of the
progress vector w.r.t. that of the progress variable increment.

:param x: progress variable weights vector.
Expand Down Expand Up @@ -397,10 +397,10 @@ def SetCurveStepThreshold(self, val_tol:float=1e-4):
self.__CurveStepTolerance = val_tol

def SetSpeciesRangeTolerance(self, val_tol:float=1e-5):
"""Specify the minimum change in species mass fraction for species to be
"""Specify the minimum change in species mass fraction for species to be
considered in progress variable optimization.

:param val_tol: species mass fraction range threshold.
:param val_tol: species mass fraction range threshold.
:type val_tol: float
:raises Exception: if threshold value is negative.
"""
Expand Down Expand Up @@ -897,7 +897,6 @@ def RunOptimizer(self):
else:
update_strategy = "immediate"

A_constr = np.hstack((-self._progress_vector, self._delta_Y_flamelets))
#self._monotonicity_full = LinearConstraint(A_constr, lb=-1e-4,keep_feasible=True)
# Initiate evolutionary algorithm.
print("Generation,Penalty," + ",".join(s for s in self._pv_definition_optim))
Expand Down
2 changes: 1 addition & 1 deletion Data_Processing/collectFlameletData.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ def __ComputeNumberofEvaluations(self, group_variables:list[list[str]]):
return n_networks_eval

def PostProcessGroups(self):
"""Extract the combinations of variables with the highest affinity and fewest number of network evaluations.
"""Extract the combinations of variables with the highest affinity and fewest number of network evaluations.
Groups with most potential are visualized in a figure.
"""
min_group = min(self.__n_groups)
Expand Down
11 changes: 11 additions & 0 deletions Documentation/source/Development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ Publish branch, push changes

Open a pull request on the GitHub page, review PR checklist

Formatting
----------

Before commiting changes, run the command

.. code-block::

>>> pre-commit run --all

in order to check the code for unused variables and modules and for trailing whitespaces.


Regression Tests
----------------
Expand Down
2 changes: 1 addition & 1 deletion GUI/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def get_descendants(self, _id, descendants_list=[]):
if self._nodes[k]['parent']==_id:
#child_name = self._nodes[k]['name']
descendants_list.append(k)
child = self.get_descendants(k,descendants_list)
self.get_descendants(k,descendants_list)

#print("descendants=",descendants_list)
#return descendants_list
13 changes: 3 additions & 10 deletions GUI/trame_test.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
from trame.app import get_server
from trame.widgets import vuetify, paraview
from trame.widgets import vuetify
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import vuetify, vtk as vtk_widgets
import vtk
from vtkmodules.vtkCommonDataModel import vtkDataObject
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkDataSetMapper,
vtkRenderer,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkColorTransferFunction,
)
from vtkmodules.vtkRenderingAnnotation import vtkCubeAxesActor, vtkScalarBarActor
from vtkmodules.vtkInteractionWidgets import vtkOrientationMarkerWidget, vtkScalarBarWidget
from vtkmodules.vtkRenderingAnnotation import vtkScalarBarActor
from vtkmodules.vtkInteractionWidgets import vtkScalarBarWidget
from Common.Properties import DefaultSettings_FGM
from Common.DataDrivenConfig import Config_FGM

#from .pipeline import PipelineManager
from trame.assets.local import LocalFileManager

import numpy as np
import time

server = get_server(client_type='vue2')
renderer = vtkRenderer()
Expand Down Expand Up @@ -138,7 +132,6 @@

DEFAULT_Z=0.5

from vtk import vtkPlaneSource
planeSource = vtk.vtkPlaneSource()
planeSource.SetCenter(0.5,0.5,0.5)
planeSource.SetNormal(0,0,1.0)
Expand Down
10 changes: 3 additions & 7 deletions Manifold_Generation/LUT/FlameletTableGeneration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
from Common.DataDrivenConfig import Config_FGM, Config
from Common.CommonMethods import GetReferenceData
from Common.Properties import DefaultSettings_FGM
import cantera as ct
import gmsh
import pickle
from multiprocessing import Pool
from Common.Interpolators import Invdisttree
from random import sample

class SU2TableGenerator_Base:
_Config = None
Expand Down Expand Up @@ -176,7 +174,6 @@ def EvaluateManifoldInterpolator(self, CV_unscaled:np.ndarray):
return data_interp

def Compute2DTable(self, CV_1:str, CV_2:str):
Np_grid = 300

return

Expand Down Expand Up @@ -460,7 +457,7 @@ def VisualizeTableLevel(self, val_mix_frac:float, var_to_plot:str=None):

def GenerateTableNodes(self):
"""
Generate the table nodes and connectivity.
Generate the table nodes and connectivity.
"""

self.__PrepareTableLevels()
Expand Down Expand Up @@ -646,7 +643,7 @@ def ComputeTableLevelMesh(self, val_mix_frac:float):
:type val_mix_frac: float
:return Connectivity: Delaunay triangulation connectivity
:rtype Connecivity: NDarray
:return MeshNodes:
:return MeshNodes:
"""
Coord_refinement, Coord_hull, hull_area,z_norm, CV_mesh, table_level_data = self.__ComputeCurvature(val_mix_frac)
MeshNodes_Norm, table_level_data = self.__Compute2DMesh(XY_hull=Coord_hull, XY_refinement=Coord_refinement,val_mixfrac_norm=z_norm, level_area=hull_area)
Expand All @@ -661,7 +658,7 @@ def __ComputeCurvature(self, val_mix_frac:float):
Compute the curvature of the reaction rate surface at a constant mixture fraction level. Identify the locations of high curvature where table refinement is required.

:param val_mix_frac: mixture fraction of current table level.
:type val_mix_frac: float
:type val_mix_frac: float
:return XY_refinement: normalized pv and enth coordinates where refinement should be applied.
:rtype XY_refinement: array
:return XY_hull: normalized pv and enth coordinates of the convex hull of the current table level.
Expand Down Expand Up @@ -820,7 +817,6 @@ def __Compute2DMesh(self, XY_hull:np.ndarray, XY_refinement:np.ndarray, val_mixf
gmsh.model.mesh.field.setNumbers(7, "FieldsList", [2])
gmsh.model.mesh.field.setAsBackgroundMesh(7)

lc = base_cell_size
def meshSizeCallback(dim,tag,x,y,z,lc):
return lc

Expand Down
1 change: 0 additions & 1 deletion Manifold_Generation/LUT/LUTGenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import gmsh
from concave_hull import concave_hull, concave_hull_indexes
import meshio
import matplotlib.pyplot as plt

def shoelace(XY:np.ndarray[float]):
"""Shoelace algorithm for area computations
Expand Down
4 changes: 2 additions & 2 deletions Manifold_Generation/MLP/Trainer_Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def SaveWeights(self):
return

def SetDecaySteps(self):
"""Set the number of steps in the exponential decay algorithm. The number of steps scale are proportioned based on the number of epochs,
"""Set the number of steps in the exponential decay algorithm. The number of steps scale are proportioned based on the number of epochs,
and training data size and mini batch size.
"""
self._decay_steps = int(1e-3 * self._n_epochs * self._Np_train / self._Np_batch)
Expand Down Expand Up @@ -429,7 +429,7 @@ def GetActivationFunction(self):
return self._activation_function_name

def PlotR2Data(self):
"""Plot the MLP prediction in the form of R2-plots w.r.t. the reference data, and along each of the
"""Plot the MLP prediction in the form of R2-plots w.r.t. the reference data, and along each of the
normalized controlling variables.
"""

Expand Down
Loading
Loading