Difference between revisions of "Synthetic Turbulence Inflow Generator"

From PHASTA Wiki
Jump to: navigation, search
(Creation of STGRand.dat)
(Creation of STGRand.dat)
Line 240: Line 240:
 
delete(gcp('nocreate'))
 
delete(gcp('nocreate'))
 
%% Parameter set
 
%% Parameter set
 
 
%These set the number of proccesses will search for optimal random number
 
%These set the number of proccesses will search for optimal random number
 
%sets (npool) and the number of random number sets each procces will
 
%sets (npool) and the number of random number sets each procces will
Line 249: Line 248:
 
npool=12;
 
npool=12;
 
nRand=100000;
 
nRand=100000;
 
 
%This choice will allow the user to specify a costom spectra, IF we want
 
%This choice will allow the user to specify a costom spectra, IF we want
 
%the spectra from PHASTA set this to 'none'
 
%the spectra from PHASTA set this to 'none'
Line 271: Line 269:
 
spectraPATH='/projects/tools/Models/BoeingBump/DNS/FlatPlate/Meshing/matchedReader_CRS_4delta6-15/Chef/8-8-Chef/RunPHASTA/';
 
spectraPATH='/projects/tools/Models/BoeingBump/DNS/FlatPlate/Meshing/matchedReader_CRS_4delta6-15/Chef/8-8-Chef/RunPHASTA/';
 
run_Dir=strsplit(spectraPATH,'RECREATE');run_Dir=cell2mat(run_Dir(1));
 
run_Dir=strsplit(spectraPATH,'RECREATE');run_Dir=cell2mat(run_Dir(1));
 
 
% These weights will specify which target covarience quantities are
 
% These weights will specify which target covarience quantities are
 
% most-highly valued
 
% most-highly valued
Line 284: Line 281:
 
weights=[1, 2, 2, 2, 2, 1];
 
weights=[1, 2, 2, 2, 2, 1];
 
weights=weights./sum(weights) ;  
 
weights=weights./sum(weights) ;  
 
 
%physical quantites for normalized units
 
%physical quantites for normalized units
 
rho=1;
 
rho=1;
 
mu=1.2502E-5;
 
mu=1.2502E-5;
 
nu=mu/rho;
 
nu=mu/rho;
 
 
% Specify the output STGRand files to be made
 
% Specify the output STGRand files to be made
 
STGRand_basename='STGRand_REDO_6_12_hex_JP_nRand100k';
 
STGRand_basename='STGRand_REDO_6_12_hex_JP_nRand100k';

Revision as of 15:25, 1 March 2021

Synthetic Turbulence Inflow Generator (STG)

Overview

The Synthetic Turbulence Inflow generator is a method to produce an inflow boundary condition that results in turbulent flow in a short downstream distance. This method is desired to be more computationally efficient than resolving a flow through from transition. This page will cover the workflow to produce the necessary auxiliary files as well as included specifications for the solver.inp file for running a simulation with the STG boundary condition. There are three auxiliary files that are needed for the method in the n-procs_case directory at runtime:

  • STGInflow.dat
  • STGSpectra.dat
  • STGRand.dat

In addition, there are scripts to determine the convergence of the 1st and 2nd order mean profiles that PHASTA will simulate BEFORE PHASTA simulates it. All of the mentioned tasks are performed with MATLAB scripts located in the STGInit subdirectory of the file structure contained in the PHASTA code-tree from github.

STGInflow.dat

This is a file that will contain the mean velocity profiles, mean cross correlation targets, and any additional turbulence modeled scalars.

STGSpectra.dat

This file will contain the N spectral modes for each node that has the STG the boundary condition.

STGRand.dat

This file will contain random numbers for the N spectral modes. This is not a spatially varying set of numbers as the spectra is.

README

Within STGInit subdirectory, there is a README file that contains a list of the most important routines, their inputs, their outputs files, and their outputs that occur in the command line. These scripts are listed in chronological order of the workflow. In addition it lists the helper functions that are also needed but do not require intimate knowledge for the ordinary user. This README is below:


 1 README for the matlab scripts for STGRand generation
 2 
 3 
 4     Below is a table that summarizes the inputs and outputs of the main matlab scripts developed. Further explaination is provided in the
 5 header of each file. The order of the script in the table below corresponds to their order in the workflow, I.E. choose your random numbers,
 6 find the long term effects of those choices, plot them, plot the time convergance wrt the bias, and re-calc bias measure if needed.
 7 
 8 
 9 
10 script name             inputs                       output files                                output commandLine
11 --------------------------------------------------------------------------------------------------------------------
12 STGspectra.m            coordinate file path        STGSpectra.dat (for PHASTA)
13                         connectivity file path      Matlab savefile for PHASTA spectral data
14                         Run Directory
15                         number of proccesses
16 
17 chooseSTGRand.m         PHASTA executable           npool optimized STGRand.dat                 -none-
18                         Run directory               containter for dmags for each npool
19                                                     Matlab savefile for PHASTA spectral data
20 AnalizeSTG_Rand.m       STGRand file                Matlab savefile for plotting 2nd moments    various additional measures
21                         PHASTA execuatble           Matlab savefile for plotting 1st moments
22                         Run directory
23                         Matlab savefile spectra
24 plotBias_TC.m           Matlab savefile plotting(2) --none--                                    plots
25                                                                                                 (Optional) Matlab savefile for TC to bias
26 analyzeTC.m             Matlab savefile TC->bias    --none--                                    plots
27 Analyze_Dmag.m          STGRand file                Dmag for that STGRand
28                         Matlab savefile spectra
29 PlotSTG_meanFeilds.m    Matlab savefile plotting(1) --none--
30 
31 
32 helper functions:
33 -----------------
34 
35 importCords.m
36 importD2Wall.m
37 interpSTG.m
38 investigateMesh.m
39 findPlaneInfo.m
40 getKmax.m
41 getKmin.m
42 importSPECTRApartfile.m
43 importSTGInflow.m
44 importSTGRand.m
45 getSpectra.m

Pre-Proccessing/Preparation of Auxiliary Files

Boundary Condition Attribute

Within the simmodeler or meshing tool, the face that is to have the STG boundary condition must have a specified SurfID attribute that will later match the specified in solver.inp. A typical value that has been given to this boundary condition within our group is 411.

Creation of STGInflow.dat

This auxiliary file will be required not only for the running of PHASTA, but also, will be required for the random number optimization. The user will need mean flow field data at the position of the inflow from some preliminary simulation such as RANS data or data repository. The code requires this file to have the following format:

N

d2wall_0 U_1(d2wall_0) U_2(d2wall_0) U_3(d2wall_0) uu(d2wall_0) vv(d2wall_0) ww(d2wall_0) uv(d2wall_0) uw(d2wall_0) vw(d2wall_0) sclr1(d2wall_0) sclr2(d2wall_0)

d2wall_1 U_1(d2wall_1) U_2(d2wall_1) U_3(d2wall_1) uu(d2wall_1) vv(d2wall_1) ww(d2wall_1) uv(d2wall_1) uw(d2wall_1) vw(d2wall_1) sclr1(d2wall_1) sclr2(d2wall_1)

d2wall_2 U_1(d2wall_2) U_2(d2wall_2) U_3(d2wall_2) uu(d2wall_2) vv(d2wall_2) ww(d2wall_2) uv(d2wall_2) uw(d2wall_2) vw(d2wall_2) sclr1(d2wall_2) sclr2(d2wall_2)

.

.

.

d2wall_N U_1(d2wall_N) U_2(d2wall_N) U_3(d2wall_N) uu(d2wall_N) vv(d2wall_N) ww(d2wall_N) uv(d2wall_N) uw(d2wall_N) vw(d2wall_N) sclr1(d2wall_N) sclr2(d2wall_N)



Where:

  • N is the number of rows that this file contains. It is the number of nodes in the specially varying direction.
  • d2wall is the distance to the wall
  • U_i are the three components of the average velocity feild
  • uu, vv, ww, uv, uw, vw are the averages of the Reynolds' stress tensor
  • sclr1 and sclr2 are the scalars that represent the turbulence model.

The input profiles are varied by the type of auxiliary simulation. So the post-processing of that preliminary simulation will be varied and so the generation of this data is left to the user. However for creating the STGInflow.dat file it is useful to know the format that the fortran file reader is setup for. The below chunk of MATLAB code is useful once the profiles are known:

 nPoints = length(d);
 [dSort,index]=sort(d);
 fid=fopen('STGINFLOWNAME.dat','w');
 fprintf(fid,'%d\n',nPoints);
 for j=1:nPoints
     i=index(j);
     tmp=[d(i) u(i,:) R(i,:) nut(i)];
     if (j~=nPoints)
         fprintf(fid,'%.12E %.12E %.12E %.12E %.12E %.12E %.12E %.12E %.12E %.12E %.12E\n',tmp);
     elseif (j==nPoints)
         fprintf(fid,'%.12E %.12E %.12E %.12E %.12E %.12E %.12E %.12E %.12E %.12E %.12E',tmp);
     end
 end
 fclose(fid);

Creation of STGSpectra.dat

This file will contain the spectral data at each nodal point within the mesh that is attributed with the STG attribute. To create this file 1) the case's run directory must be prepared and 2) we will use the first of several scripts within the STGInit subdirectory of the github remote repository for PHASTA. Within MATLAB open STGspectra.m. The following is what you should see from the header of the file:

 1 %% Create STGspectra.dat
 2 % This script will produce spectral data for the implementation in PHASTA
 3 % This script's intention is to move the spectral data calculation out of
 4 % PHASTA so as to not require a call to PHASTA to gather such data. (A
 5 % wasteful thing to do when large meshes are investigated)
 6 
 7 % Authors: Ken Jansen, John Patterson
 8 % Version: 1.0 
 9 % Last mod: 7/3/2020
10 
11 
12 %STGspectra('exampleInput/LES_DNS_ReL1M_2d_KEJ_SAVEFILE.mat','exampleInput/LES_DNS_ReL1M_2d_KEJ.cnnTet',1,'/projects/tools/Models/STG/STG_tests/Post/analizeRand/RunTetRand_newRAND_2/',8)
13 function []=STGspectra(x_Path,conn_PATH,d2wall_Path,Run_Dir,nprocs)
14 tic
15 %% Preliminary Settings
16     nu=1.5E-5;
17 
18     %Specify how the d2wall field may be constructed
19     d2wall_tech='load';%'calculate ana';
20     %Specify (if nessicary), the path of the nodal data of the d2wall field
21     d2wall_Path='d2wall_ana.mat';%'none';
22 
23     %Specify the method to determine the nodes of the STGInflow plane
24     STG_node_choose='min_x';
25 
26     %Spesify the method by which the mesh data is structured 
27     struct_Spe='structured';
28 
29     %Settings found in solver.inp that are nessisary for using the
30     %STGInflow
31     deltaBL=0.05;
32     alphaWave=0.01;
33     setEps=17251.0;
34 
35 
36 %% Unfolding
37     nprocs_Dir                 =strcat(num2str(nprocs),'-procs_case/');
38     [x,ien,surround_nodes]     =importCords(x_Path,conn_PATH);
39     d2wall                     =importD2Wall(d2wall_tech,x,d2wall_Path);
40 
41 
42 %% Load in STGInflow and interpolate onto the inflow mesh
43     STGInflow_Path=[Run_Dir,nprocs_Dir,'STGInflow.dat'];
44     STGInflow=importSTGInflow(STGInflow_Path);
45 
46     [U,V,W,uu,vv,ww,uv,uw,vw,sclr1,sclr2,lt,eps,ch_decomp]=...
47         interpSTG(STGInflow,x,d2wall);%x(:,2));
48     if(~isnan(setEps))
49         eps=ones(length(x),1).*setEps;
50     end


This will be the standard format for many of the scripts in this subdirectory. That is,

  • Description/ Authors (ln 1->9)
  • function call/ function call example (ln 12->13)
  • Settings for each run (ln 15->33)
  • Loadins from other files (ln 36->47)
  • Execution of the script (ln 48->end)

The user-controlled inputs is the content in the function call and the settings below:

function call

There are five inputs to this function call

  • x_Path (str)
  • conn_Path (str)
    • x_Path and conn_Path are strings that point to files that are able to be interpreted by importCords.m. When these files read-in a .crd .cnn type files, they will output not only what is required for the STGspectra function call, but also a MATLAB .mat file that will append the names of the original data with '_SAVEFILE'. Loading in this .mat file is MUCH quicker than the .crd and .cnn raw data.
  • d2wall_Path (str)
    • d2wall_Path is a path to a MATLAB datafile containing the distance to the wall for each node in the mesh Unlike x_Path and conn_Path these two files are not required for the script to run properly SEE Settings for each run BELOW
  • nprocs (int)
    • this will be the number of processors that the case will use in the execution of PHASTA. In this script it is used to import the STGInflow.dat file.

Settings

There are 8 inputs to this function call

  • nu: the kinematic viscosity of the fluid
  • d2wall_tech: This is the technique by which the code will make the distance to the wall field. There are currently 5 options to this:
    • x_dir: Takes the x coordinate as the distance to the wall
    • y_dir: Takes the y coordinate as the distance to the wall
    • z_dir: Takes the z coordinate as the distance to the wall
    • calculate_ana: This will calculate the distance to the wall via the function handle that is specified in importD2Wall ln 17 (Please modify this if you wish to create your own d2wall function) Like the importCoords file this will output a matlab file containing the d2wall at d2wall_ana
    • load: this will load in the path specified from d2wall_Path
  • d2wall_Path: If you choose to load in a specific d2wall field that has been already saved this will be the path to that file
  • struct_Spe: Currently only 'structured' is supported. This is the orientation of the mesh.
  • deltaBL: This is the boundary layer thickness at the STG boundary condition.
  • alphaWave: This is the logarithmic growth of the spacing between one wavenumber and the next. It may be set from 0.05 to 0.01. Normally we set this to 0.01.
  • setEps: This is set to the dissipation rate of the desired inflow spectrum.

Creation of STGRand.dat

Creating STGRand.dat is done within the chooseSTGRand.m MATLAB script. This script is meant to be run at the particular case's run directory (ie. above the n-procs_case dir). This script contains eight sections:

  • Choose STGRands
  • Parameter set
  • Set up random sets and collect spectra data
  • Collect Target STG profiles
  • Set a custom spectra
  • interpolate the target cholesky decomposition to the mesh grid in geombc
  • Begin the choice of random number sets
  • Print STGRand.dat

Of these sections, the layman user should be concerned with the first two.


%% Choose STGRands % This script chooses Random varaibles For STGRand.dat. The output will be % npool number of optimized random number sets, saved in STGRand files, As well as % a display of the bias accourding to developed error measures for bias. % Each set is measured against a specified spectra, and target covaraince.

% Authors: Ken Jansen, John Patterson % Version: 1.0 % Last mod: 6/30/2020 % Order Spec: Sigma first, intellegent design d, intellegent design % low-to-high wavemode tic clear all close all delete(gcp('nocreate')) %% Parameter set %These set the number of proccesses will search for optimal random number %sets (npool) and the number of random number sets each procces will %search through (nRand). NOTE:

   %1) viz002 and viz003 have 8 and 10 proccesses respectivally for matlab.
   %2) nRand must be greater than or equal to the nkwave that PHASTA
   %produces from getSpectra.m

npool=12; nRand=100000; %This choice will allow the user to specify a costom spectra, IF we want %the spectra from PHASTA set this to 'none' specChoice='none'%max3';%'mid8%';

% nprocs: # in #-procs directory the spectral data is to be % pulled from. If you want to recreate the spectral content via PHASTA, it % is reccommended that the user chooses the largest partition they have % availible % The spectraPATH parameter sets one of a few things: %---------USE 1 for this script if the version of PHASTA lacks a readin from STGSpectra.dat---------------------------------------- % 1) If the user has no prior knowledge of the spectra created from % PHASTA then make this parameter the path to the run directory with % RECREATE appended to the end. %---------USE 2 for this script if the version of PHASTA has a readin from STGSpectra.dat---------------------------------------- % 2) If the user has Spectral output from PHASTA (IE if (1) was choosen % and you wish to reuse the data) make this path the run dir OR if the % spectral output from STGspectra.m has been created for use in % PHASTA. nprocs=8; spectraPATH='/projects/tools/Models/BoeingBump/DNS/FlatPlate/Meshing/matchedReader_CRS_4delta6-15/Chef/8-8-Chef/RunPHASTA/'; run_Dir=strsplit(spectraPATH,'RECREATE');run_Dir=cell2mat(run_Dir(1)); % These weights will specify which target covarience quantities are % most-highly valued %Wstress: The applied penelty for a particular component of the reynolds stress that is % off %nlocs: The node number set in the spacial variation dir. that we choose to be the % control points (The points where we get the covariance correct) %weights: The applied penelty for a particular component of the reynolds stress that is % off, at the positions y(nlocs) Wstress=[1,25,1;25,5,1;1,1,1]; % start with equal on all nlocs= [44,57,72,75,85,105]; weights=[1, 2, 2, 2, 2, 1]; weights=weights./sum(weights) ; %physical quantites for normalized units rho=1; mu=1.2502E-5; nu=mu/rho; % Specify the output STGRand files to be made STGRand_basename='STGRand_REDO_6_12_hex_JP_nRand100k';


Choose STGRands

This section goes over the description of the script: This script chooses Random variables For STGRand.dat. The output will be npool number of optimized random number sets, saved in STGRand files, As well as a display of the bias according to developed error measures for bias. Each set is measured against a specified spectra, and target covariance.

Parameter set

This section of the code are the primary variables to set when optimizing a particular random number set for a particular case. The script has descriptions of each of the variables but this documentation will attempt to provide more detail with regard to each one. A few variables that pertain to the particular case you wish to optimize to:

  • specChoice: This string will determine which spectra you wish to optimize to, the entire set of choices are the cases in Set a custom spectra section of the code
    • 'none' is the most common choice for this option because the user is not commonly using their own spectra that hasn't been calculated in the proceeding getSpectra.m function call.
    • 'max3' is using the the maximal intensity wavenumbers as their spectra to optimize to.
    • 'mid8%' is using the middle region of the spectra to optimize to
  • nprocs: This integer is the number of processes that the case will have. This is mostly used for read-in scripts of the STGSpectra.dat and STGInflow.dat files
  • spectraPATH: This string is the path to where the spectra MATLAB file has been created from the previous step, or the PHASTA run that prints out the spectra file 'spectra00n'.
  • run_Dir: This string is the path to the run directory containing the n-procs case that you wish to investigate.
  • STGRand_basename: This string will be the name that will specify the npool random number output filenames.
  • rho: This is the physical density of the fluid.
  • mu: This is the physical viscosity of the fluid.
  • u0: this double is the free-stream velocity of the fluid

In addition there are a few parameters that pertain to 1) what the optimization process is optimizes to, 2) the amount of searching to de, and 3) what computational resources the user wishes to give to MATLAB to perform the search. Some choices are better than others. In the order in the script:

  • npool: This integer is the number of processes that the user wishes to allow MATLAB to use to perform the search. The maximum that the user can ask for is 8 on viz002 and 12 on viz003.
  • nRand: This integer is the amount of random number sets that each of the MATLAB proccesses will choose from. These random number sets only pertain to the sigma vector. The d-vector is a unique set based off of the best set of random sigmas.
  • Wstress: This 3x3 matrix of doubles instructs the optimization to which stress components to preferable to. A choice of [1,25,1;25,5,1;1,1,1]; is good for a flat plate case where the stream-wise direction is aligned with x_1 and span-wise direction is aligned with x_3. This is the case because 1) the <u_1u_2> component of the Reynold's stress contributes much more to PHASTAs ability to recover downstream, and 2) the diagonal components in the tensor are the easiest to get correct so often a sufficient <u_1u_2> implies sufficient diagonal components .
  • nlocs: This array of integers are the node numbers from the wall that the method chooses to optimize to. The preferable nodes to optimize to are the nodes that approximate the peak of the Target Reynolds stress components. The length of this array can be up to the number of nodes in the y-direction.
  • weights: This array of integers is how much importance each of these nlocs get when optimizing. The length of this array is the length of the nlocs array.

Output and what to lookout for

The result of this file will output npool number of valid STGRand.dat number sets named according to the STG_basename and the process that created it. Additionally, the method will output in the command window the Dmag for each process. The lowest of these numbers is the best STGRand.dat file that was created from the MATLAB proccesses.

Pre-Simulation-Analyzation

Running the code

Solver.inp