CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   Circulare inlet from matlab (https://www.cfd-online.com/Forums/openfoam-pre-processing/193897-circulare-inlet-matlab.html)

Fridrik October 6, 2017 03:08

Circulare inlet from matlab
 
Hallo everyone

This post will take you through a method of creating a circular inlet condition. Where the inlet condition is made from an array generated in Matlab

This Matlab function can take an array and put into the right syntax for OpenFOAM.
Code:

%input syntax
% filename = 'data/test.txt';
%
% x = 0:.1:1;
% tal = [t.^2;t.^3;t.^4];
% output_file(x,tal,filename);

function output_file(t,val,filename)
%%% note this function only works on velocity bundary conditins.
A = [t;val];

% this defines the precision, if higher needed look up fprintf in matlab
% doc
formatSpec = '(  %4.2f    (%4.2f %4.2f %4.2f)  )\r\n';

fileID = fopen(filename,'w');

fprintf(fileID,'%1s\r\n','(')

fprintf(fileID,formatSpec,A);
fprintf(fileID,'%1s',');');

fclose(fileID);

end

The output from matlab are then saved in the general case directory (here named "myDataFile"), and has this syntax (for velocity):

Code:

(
    (  0  (0 0 1))
    (100  (0 0 2))
);

The boundary condition are then changed into:

Code:


    inlet
      {
          type            cylindricalInletVelocity;
          axis            (0 0 1);          // <-These two defines where the center axis is. 
          centre          (0 0 0);        // <-
          axialVelocity  constant 0;
          radialVelocity                    //<- Here the radial velocity is defined.
          {
            type            tableFile;
            file            "$FOAM_CASE/myDataFile";    //<- The path to the file which descripes the inlet speed
          }
          rpm            constant 0;      //<- This sets the swirl of inlet.
          value          uniform (0 0 0); //<- This will initialize the postproces and calculation, will be overwritten when the
                                                  //    boundary is accessed the first time
      }

(Credit to TomF for helping with the syntax of the import and debugging my code)

This should do it. Any improvements are welcome, so others easily can remake these inlet condition.

- Fridrik Magnusson

tomf October 9, 2017 04:14

Quote:

Originally Posted by Fridrik (Post 666730)
Code:

--> FOAM FATAL IO ERROR:
keyword file is undefined in dictionary "/--/--/--/--/OpenFOAM/Compressor_simpel/Circulare_inlet/0/U.boundaryField.inlet"

file: "/--/--/--/--/OpenFOAM/Compressor_simpel/Circulare_inlet/0/U.boundaryField.inlet from line 26 to line 46.

    From function const Foam::entry& Foam::dictionary::lookupEntry(const Foam::word&, bool, bool) const
    in file db/dictionary/dictionary.C at line 551.

FOAM exiting

- Fridrik Magnusson

Hi,

This indicates that OpenFOAM expects the keyword file, while you have the keyword fileName.

So I think changing that would solve this error.

Regards,
Tom

Fridrik October 9, 2017 04:56

Quote:

Originally Posted by tomf (Post 666966)
Hi,

This indicates that OpenFOAM expects the keyword file, while you have the keyword fileName.

Regards,
Tom

Thanks for the answer, will i sure did help me get the right syntax :) i will update the thread to incorporate the solution

Fridrik October 12, 2017 04:04

cylindricalInletVelocity
 
The derived boundary conditions: "cylindricalInletVelocity" should do the trick but it dosent seem to work.

from the website:
To test the inlet condition. I set the rpm and the axial velocity to 0. This will just have a radial component then.

Code:

  inlet
    {
        type            cylindricalInletVelocity;
        axis            (0 0 1);
        origin          (0 0 0);
        axialVelocity  constant 0;
        radialVelocity  constant 1;
        rpm            constant 0;
    }

but when i try to run this i get an error message:

Code:


--> FOAM FATAL IO ERROR:
Essential entry 'value' missing

file: /-/-/-/-/OpenFOAM/Circulare_inlet/0/U.boundaryField.inlet from line 26 to line 31.

    From function Foam::fvPatchField<Type>::fvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::dictionary&, bool) [with Type = Foam::Vector<double>]
    in file /home/pgh/OpenFOAM/OpenFOAM-v1706/src/finiteVolume/lnInclude/fvPatchField.C at line 131.

FOAM exiting

What does this error mean ?
How do i make this boundary condition work ?

tomf October 12, 2017 04:35

Quote:

Originally Posted by Fridrik (Post 667579)
but when i try to run this i get an error message:

Code:


--> FOAM FATAL IO ERROR:
Essential entry 'value' missing

file: /-/-/-/-/OpenFOAM/Circulare_inlet/0/U.boundaryField.inlet from line 26 to line 31.

What does this error mean ?
How do i make this boundary condition work ?

This error means that there is an entry missing and that entry is "value". This is needed for the start-up of your simulation or for post-processing tools, it will be overwritten in the first acces to the boundary. To make it work, I guess you need something like this:

Code:

  inlet
    {
        type            cylindricalInletVelocity;
        axis            (0 0 1);
        origin          (0 0 0);
        axialVelocity  constant 0;
        radialVelocity  constant 1;
        rpm            constant 0;
        value          uniform (1 1 0);
    }

Please adapt the value to something in the right order of magnitude.

Best Regards,
Tom

Fridrik October 12, 2017 05:37

Thanks again Tom

Since the value is only for postprocessing and only gives a value at t = 0, i put it to (0 0 0).

I think this pushed me over the finish line, i will update the post to be a tutorial for other users


All times are GMT -4. The time now is 15:49.