CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Writing OpenFoam header to the sampled output data to use as inlet b.c (https://www.cfd-online.com/Forums/openfoam/182437-writing-openfoam-header-sampled-output-data-use-inlet-b-c.html)

Eman. January 10, 2017 02:19

Writing OpenFoam header to the sampled output data to use as inlet b.c
 
Hi,

I want to use the sample utility to get U and P and later use them as inlet values for another simulation using timeVaryingMappedFixedValue. The problem is the sampled data don't have any OpenFoam headers and the timeVaryingMappedFixedValue needs all the fields data to have proper headers. Is there any way to automatically write the headers while sampling the data?

Thanks

CliftonReed January 26, 2017 12:16

Writing OpenFoam header to the sampled output data to use as inlet b.c
 
If you have access to Matlab I can provide a script that takes instantaneous data from multiple files and places it into time directories for the timeVaryingMappedFixedValue BC.

Eman. January 26, 2017 12:43

Quote:

Originally Posted by CliftonReed (Post 634769)
If you have access to Matlab I can provide a script that takes instantaneous data from multiple files and places it into time directories for the timeVaryingMappedFixedValue BC.

Hi Xander,

Thanks a lot for your response. It would be great if you could share your code.

CliftonReed January 27, 2017 05:08

The code is below. In this case j refers to the time step, k is the number of sampling positions. Also note that the necessary header has been placed in one column of the table.

I am not particularly experienced with Matlab and there may be less clunky solutions available.

%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%

clc
clear all
close all

for j=1:800

uOld = zeros(10,1);
for k=1:10

myfilename1 = sprintf('../samples/z%d_U.xy', k)

%%%%%%%%%%
%%%

data = importdata(myfilename1);

x{k} = data(j,1)*25;

u{k} = (data(j,2))*2;

t{k} = x{k};

v{k} =(data(j,3))*2;

w{k} =(data(j,4))*2;


end

headerLine = sprintf('FoamFile { version 2.0; format ascii; class vectorAverageField; object values; } (0 0 0) 10 (');

oldFolder = cd('C:\Users\restOfFilePath')

a = t{k}
s = num2str(a)

mkdir(s);
cd(s)

header = {headerLine;' ';' ';' '; '';' ';' ';' ';' ';' '};

oBracket = {'(';'(';'(';'(';'(';'(';'(';'(';'(';'('};
Ucol = [u{1};u{2};u{3};u{4};u{5};u{6};u{7};u{8};u{9};u{10}];
Vcol = [v{1};v{2};v{3};v{4};v{5};v{6};v{7};v{8};v{9};v{10}];
Wcol = [w{1};w{2};w{3};w{4};w{5};w{6};w{7};w{8};w{9};w{10}];
cBracket = {')';')';')';')';')';')';')';')';')'; ')'};
closeLine = {' ';' ';' ';' ';' ';' ';' ';' ';' ';' )'};

T = table( header, oBracket,Ucol,Vcol,Wcol,cBracket, closeLine)

writetable(T,'U','Delimiter','\t','WriteVariableNa mes',false)

movefile('U.txt','U')

cd(oldFolder)
end


All times are GMT -4. The time now is 01:44.