Skip to content
Snippets Groups Projects
Commit 09deddf4 authored by Malte Nyhuis's avatar Malte Nyhuis
Browse files

copy template and more implementations. on our way...but not even close to be there yet

parent 8c01d4fa
Branches
Tags
No related merge requests found
Showing
with 334 additions and 8 deletions
......@@ -33,7 +33,7 @@ import ntrfc
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
# Add any paths that contain templates here, relative to this directory.
# Add any paths that contain TEMPLATES here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
......
from snakemake.utils import validate
#todo move this snakepipe to according dir in sourcecode
configfile : "casesettings.yaml"
validate(config,"config.schema.yaml")
rule all:
input:
"done.txt"
rule copy_template:
output:
#todo: is there a readable dataformat alternative (csv) instead of pickle?
dynamic("01_case/{case_type}/{case_files}")
params:
case_type = config["case_params"]["case_type"],
run:
from case_creation import create_case_fromtemplate
create_case_fromtemplate(params["case_type"])
rule check_template:
input:
dynamic("01_case/{case_type}/{case_files}"),
output:
"done.txt"
run:
print("tbd")
import os
from functools import reduce
import shutil
from pathlib import Path
import copy
import re
from ntrfc.utils.dictionaries.dictutils import nested_dict_pairs_iterator, setInDict
TEMPLATEDIR = r"D:\CodingProjects\NTRfC\ntrfc\database\case_templates"
path_to_sim=r"D:\CodingProjects\NTRfC\examples\gwk_compressor_casegeneration\01_case"
TEMPLATES = [i for i in os.listdir(TEMPLATEDIR) if os.path.isdir(os.path.join(TEMPLATEDIR, i))]
def get_directory_structure(rootdir):
"""
Creates a nested dictionary that represents the folder structure of rootdir
"""
dir = {}
rootdir = rootdir.rstrip(os.sep)
start = rootdir.rfind(os.sep) + 1
for path, dirs, files in os.walk(rootdir):
folders = path[start:].split(os.sep)
subdir = dict.fromkeys(files)
parent = reduce(dict.get, folders[:-1], dir)
parent[folders[-1]] = subdir
return dir
def find_vars_opts(case_structure, sign, all_pairs, path_to_sim):
# allowing names like JOB_NUMBERS, only capital letters and underlines - no digits, no whitespaces
datadict = copy.deepcopy(case_structure)
varsignature = r"<PLACEHOLDER [A-Z]{3,}(_{1,1}[A-Z]{3,}){,} PLACEHOLDER>".replace(r'PLACEHOLDER', sign)
siglim = (len(sign)+2, -(len(sign)+2))
for pair in all_pairs:
#if os.path.isfile(os.path.join(path_to_sim,*pair)):
setInDict(datadict, pair[:-1], {})
filepath = os.path.join(*pair[:-1])
with open(os.path.join(path_to_sim, filepath), "r") as fhandle:
for line in fhandle.readlines():
datadict = search_paras(datadict, line, pair, siglim, varsignature, sign)
return datadict
def create_simdirstructure(case_structure, path):
directories = list(nested_dict_pairs_iterator(case_structure))
for d in directories:
dirstructure = d[:-2]
Path(os.path.join(path,*dirstructure)).mkdir(parents=True, exist_ok=True)
return 0
def search_paras(case_structure, line, pair, siglim, varsignature, varsign):
lookforvar = True
while (lookforvar):
lookup_var = re.search(varsignature, line)
if not lookup_var:
lookforvar = False
else:
span = lookup_var.span()
parameter = line[span[0] + siglim[0]:span[1] + siglim[1]]
setInDict(case_structure, list(pair[:-1]) + [parameter], varsign)
match = line[span[0]:span[1]]
line = line.replace(match, "")
return case_structure
def create_case_fromtemplate(template, path_to_sim):
found = template in TEMPLATES
assert found, "template unknown. check ntrfc.database.casetemplates directory"
case_structure = get_directory_structure(os.path.join(TEMPLATEDIR, template))
case_files = [i[:-1] for i in list(nested_dict_pairs_iterator(case_structure)) if os.path.isfile(os.path.join(TEMPLATEDIR,*list(i[:-1])))]
for fpath in case_files:
filename = fpath[-1]
dirstructure = fpath[:-1]
if dirstructure == ():
dirstructure = ""
template_fpath = os.path.join(TEMPLATEDIR,
*dirstructure,
filename)
create_simdirstructure(case_structure,path_to_sim)
sim_fpath = os.path.join(path_to_sim, *dirstructure)
shutil.copyfile(template_fpath, os.path.join(sim_fpath,filename))
variables = find_vars_opts(case_structure, "var", list(nested_dict_pairs_iterator(case_structure)),"01_case")
nov = len(list(nested_dict_pairs_iterator(variables)))
print("found ", str(nov), "parameters of type var in copied template")
return case_files
case_structure = create_case_fromtemplate('trace-compressor-cascade-ras', path_to_sim)
case_params:
case_type: trace-compressor-cascade-ras
$schema : "http://json-schema.org/draft-06/schema#"
description : Config file for the parPE snakemake optimization workflow
properties :
case_params :
type : object
description : definition of the case and its parameterspace
case_type :
type : string
description : name of the case-template
pattern : trace-compressor-cascade-ras
<var TRACE_CONTROLINPUT var>
\ No newline at end of file
# journal recorded by gmc_v9.1.8 at 2021/06/11 14:58:57
gmc -> open '<var MESHNAME var>'
gmc -> repair
gmc -> create_zone : name 'row01' type STATOR
gmc -> move_block 'Block_7' to zone named 'row01'
gmc -> move_block 'Block_8' to zone named 'row01'
gmc -> move_block 'Block_9' to zone named 'row01'
gmc -> move_block 'Block_1' to zone named 'row01'
gmc -> move_block 'Block_10' to zone named 'row01'
gmc -> move_block 'Block_11' to zone named 'row01'
gmc -> move_block 'Block_12' to zone named 'row01'
gmc -> move_block 'Block_2' to zone named 'row01'
gmc -> move_block 'Block_3' to zone named 'row01'
gmc -> move_block 'Block_4' to zone named 'row01'
gmc -> move_block 'Block_5' to zone named 'row01'
gmc -> move_block 'Block_6' to zone named 'row01'
gmc -> delete_empty_zones
gmc -> set_global_tolerance <var GLOBAL_TOLERANCE var>
gmc -> set_pmode linear_periodic
gmc -> set_y_translation_count of zone named 'row01' to <var LENGTH_YPER var>
gmc -> set_z_translation_count of zone named 'row01' to 0.0
gmc -> find_connectivity_light
gmc -> find_connectivity
gmc -> create_panel_group : name 'INLET' type INLET_BC
gmc -> create_panel_group : name 'OUTLET' type OUTLET_BC
gmc -> create_panel_group : name 'BLADE' type VISCOUS_BC
gmc -> create_panel_group : name 'FREESLIP' type INVISCID_BC
gmc -> move_panel 'Block_2/1' to group named 'INLET'
gmc -> move_panel 'Block_3/1' to group named 'INLET'
gmc -> move_panel 'Block_1/1' to group named 'INLET'
gmc -> move_panel 'Block_7/2' to group named 'OUTLET'
gmc -> move_panel 'Block_6/2' to group named 'OUTLET'
gmc -> move_panel 'Block_5/2' to group named 'OUTLET'
gmc -> move_panel 'Block_11/4' to group named 'BLADE'
gmc -> move_panel 'Block_12/3' to group named 'BLADE'
gmc -> move_panel 'Block_10/4' to group named 'BLADE'
gmc -> move_panel 'Block_9/2' to group named 'BLADE'
gmc -> move_panel 'Block_1/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_1/6' to group named 'FREESLIP'
gmc -> move_panel 'Block_2/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_2/6' to group named 'FREESLIP'
gmc -> move_panel 'Block_3/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_3/6' to group named 'FREESLIP'
gmc -> move_panel 'Block_4/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_4/6' to group named 'FREESLIP'
gmc -> move_panel 'Block_5/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_5/6' to group named 'FREESLIP'
gmc -> move_panel 'Block_6/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_6/6' to group named 'FREESLIP'
gmc -> move_panel 'Block_7/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_7/6' to group named 'FREESLIP'
gmc -> move_panel 'Block_8/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_8/6' to group named 'FREESLIP'
gmc -> move_panel 'Block_9/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_9/6' to group named 'FREESLIP'
gmc -> move_panel 'Block_10/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_10/6' to group named 'FREESLIP'
gmc -> move_panel 'Block_11/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_11/6' to group named 'FREESLIP'
gmc -> move_panel 'Block_12/5' to group named 'FREESLIP'
gmc -> move_panel 'Block_12/6' to group named 'FREESLIP'
gmc -> compute_wall_distances
gmc -> generate_machine_from_scratch
gmc -> modify_component named 'default_component' : name 'CascadeCase_rans_trace' type LPC
gmc -> set_trans_velocity of component type 'LPC' to 0.000000 0.000000 0.000000
gmc -> set_default_stages of component type 'LPC'
gmc -> apply_default_settings for component type 'LPC'
gmc -> apply_default_settings for machine
gmc -> delete_attributes of panel_group named 'BLADE' : delete transition_properties
gmc -> set_attributes of zone named 'row01' : set UpstreamRPM to 0.000000
gmc -> set_attributes of zone named 'row01' : set UpstreamNoOfBlades to 0.000000
gmc -> set_reference Length to 0.13
gmc -> set_reference Temperature to 298
gmc -> set_reference Pressure to 1e6
gmc -> set_equation_properties for machine : StagnationPointAnomallyFix to <var STAGPOINT_ANNOMALLYFIX var>
gmc -> set_equation_properties for machine : QuasiUnsteadyModel to <var QUASIUNSTEADYMODEL var>
gmc -> set_equation_properties for machine : WavinessModel to <var WAVINESSMODEL var>
gmc -> set_equation_properties for machine : Version2009 to <var VERSION_TWONULLNULLNINE var>
gmc -> set_equation_properties for machine : HeatFluxModel to <var HEATFLUXMODEL var>
gmc -> set_equation_properties for machine : PrandtlTurbulent to <var PRANDTLTURBULENT var>
gmc -> set_equation_properties for machine : RotationalEffects to <var ROTATIONAL_EFF var>
gmc -> set_equation_properties for machine : TransitionModel to <var TRANSITIONMODEL var>
gmc -> set_equation_properties for machine : VGJModel to <var VGJMODEL var>
gmc -> set_equation_properties for row01 : StagnationPointAnomallyFix to <var STAGPOINT_ANNOMALLYFIX var>
gmc -> set_equation_properties for row01 : QuasiUnsteadyModel to <var QUASIUNSTEADYMODEL var>
gmc -> set_equation_properties for row01 : WavinessModel to <var WAVINESSMODEL var>
gmc -> set_equation_properties for row01 : Version2009 to <var VERSION_TWONULLNULLNINE var>
gmc -> set_equation_properties for row01 : HeatFluxModel to <var HEATFLUXMODEL var>
gmc -> set_equation_properties for row01 : PrandtlTurbulent to <var PRANDTLTURBULENT var>
gmc -> set_equation_properties for row01 : RotationalEffects to <var ROTATIONAL_EFF var>
gmc -> set_equation_properties for row01 : TransitionModel to <var TRANSITIONMODEL var>
gmc -> set_equation_properties for row01 : VGJModel to <var VGJMODEL var>
gmc -> set_solver_properties for 'machine' : SpatialAccuracy to <var ACCURACY_ORDER var>
gmc -> set_solver_properties for 'row01' : SpatialAccuracy to <var ACCURACY_ORDER var>
gmc -> set_attributes of panel_group named 'BLADE' : set wall_treatment to low_Reynolds
gmc -> set_attributes of panel_group named 'BLADE' : set translational_velocity to 0.0 0.0 0.0
gmc -> set_attributes of panel_group named 'OUTLET' : set massflow to <var OUTLET_MFLOW var>
gmc -> set_attributes of panel_group named 'OUTLET' : set radial_equilibrium to Midspan to <var OUTLET_RADIAL_EQUI var>
gmc -> set_attributes of panel_group named 'OUTLET' : set create_radial_bands to On
gmc -> set_attributes of panel_group named 'INLET' : set PressureStagnationAbs to <var INLET_TOTAL_PRESSURE var>
gmc -> set_attributes of panel_group named 'INLET' : set VelocityAngleYAbs to <var VEL_YANGLE var>
gmc -> set_attributes of panel_group named 'INLET' : set VelocityAngleZ to 0.000000
gmc -> set_attributes of panel_group named 'INLET' : set TemperatureStagnationAbs to <var ABS_STAGN_TEMP var>
gmc -> set_attributes of panel_group named 'INLET' : set TurbulenceIntensityAbs to <var TURBULENTINTENSITY var>
gmc -> set_attributes of panel_group named 'INLET' : set TurbulentLengthScale to <var TURBULENTLENGTHSCALE var>
gmc -> set_attributes of panel_group named 'INLET' : set Species all to null
gmc -> set_attributes of panel_group named 'INLET' : set create_radial_bands to On
gmc -> set_init_properties for machine : DataFile to ''
gmc -> set_init_properties for row01 : InflowTemperature to <var INLET_TEMP var>
gmc -> set_init_properties for row01 : InflowPressure to <var INLET_TOTAL_PRESSURE var>
gmc -> set_init_properties for row01 : InflowVelocityX to <var INLET_VELX var>
gmc -> set_init_properties for row01 : InflowVelocityYAbs to <var INLET_VELY var>
gmc -> set_init_properties for row01 : InflowVelocityZ to <var INLET_VELZ var>
gmc -> set_init_properties for row01 : OutflowTemperature to <var OUTFLOW_TEMP var>
gmc -> set_init_properties for row01 : OutflowPressure to <var OUTFLOW_PRESSURE var>
gmc -> set_init_properties for row01 : OutflowVelocityX to <var OUTFLOW_VELX var>
gmc -> set_init_properties for row01 : OutflowVelocityYAbs to <var OUTFLOW_VELY var>
gmc -> set_init_properties for row01 : OutflowVelocityZ to <var OUTFLOW_VELZ var>
gmc -> set_init_properties for row01 : XStart to -0.100000
gmc -> set_init_properties for row01 : XEnd to 0.270000
gmc -> set_trace6_conventions on
gmc -> save 'TRACE.cgns'
from functools import reduce
import operator
def nested_dict_pairs_iterator(dict_obj):
''' This function accepts a nested dictionary as argument
and iterate over all values of nested dictionaries
'''
# Iterate over all key-value pairs of dict argument
for key, value in dict_obj.items():
# Check if value is of dict type
if isinstance(value, dict):
# If value is dict then iterate over all its values
for pair in nested_dict_pairs_iterator(value):
yield (key, *pair)
else:
# If value is not dict type then yield the value
yield (key, value)
def setInDict(dataDict, mapList, value):
"""
sets value to nested dict
"""
#todo: test-method
getFromDict(dataDict, mapList[:-1])[mapList[-1]] = value
def getFromDict(dataDict, mapList):
#todo: test-method
return reduce(operator.getitem, mapList, dataDict)
......@@ -6,6 +6,8 @@ import pytest
import pyvista as pv
import numpy as np
from utils.dictionaries.dictutils import nested_dict_pairs_iterator
@pytest.fixture
def response():
......@@ -129,4 +131,7 @@ def test_refine_spline():
assert fline.number_of_points == fineres
def test_nested_dict_pairs_iterator():
testdict = {"0":{"0":0,"1":1},"1":1}
check = [('0', '0', 0), ('0', '1', 1), ('1', 1)]
assert check == list(nested_dict_pairs_iterator(testdict)), "error"
......@@ -40,7 +40,7 @@ def test_calcConcaveHull():
def test_parsec():
from ntrfc.database.parsec_airfoil_creator import parsec_airfoil_gen
from database.airfoil_generators.parsec_airfoil_creator import parsec_airfoil_gen
R_LE = 0.01
x_PRE = 0.450
......@@ -58,7 +58,7 @@ def test_parsec():
def test_naca():
from ntrfc.database.naca_airfoil_creator import naca
from database.airfoil_generators.naca_airfoil_creator import naca
def rand_naca_code():
digits = np.random.choice([4,5])
if digits ==4:
......@@ -79,7 +79,7 @@ def test_extract_vk_hk(verbose=False):
:return:
"""
from ntrfc.utils.geometry.pointcloud_methods import extract_vk_hk
from ntrfc.database.naca_airfoil_creator import naca
from database.airfoil_generators.naca_airfoil_creator import naca
res = 400
# d1,d2,d3,d4 = np.random.randint(0,9),np.random.randint(0,9),np.random.randint(0,9),np.random.randint(0,9)
......@@ -115,7 +115,7 @@ def test_extract_vk_hk(verbose=False):
def test_midline_from_sides():
from ntrfc.utils.geometry.pointcloud_methods import midline_from_sides
from ntrfc.utils.math.vectorcalc import vecAbs
from ntrfc.database.naca_airfoil_creator import naca
from database.airfoil_generators.naca_airfoil_creator import naca
from ntrfc.utils.geometry.pointcloud_methods import extractSidePolys
res = 240
......@@ -160,7 +160,7 @@ def test_midLength():
def test_extractSidePolys():
from ntrfc.utils.geometry.pointcloud_methods import extractSidePolys
from ntrfc.database.naca_airfoil_creator import naca
from database.airfoil_generators.naca_airfoil_creator import naca
d1, d2, d3, d4 = np.random.randint(0, 9), np.random.randint(0, 9), np.random.randint(0, 9), np.random.randint(0, 9)
digitstring = str(d1) + str(d2) + str(d3) + str(d4)
......@@ -179,7 +179,7 @@ def test_extractSidePolys():
def test_extract_geo_paras():
from ntrfc.utils.geometry.pointcloud_methods import extract_geo_paras
from ntrfc.database.naca_airfoil_creator import naca
from database.airfoil_generators.naca_airfoil_creator import naca
naca_code = "0009"
angle = 20 # deg
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment