CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums

Comments

Register Blogs Community New Posts Updated Threads Search

In this blog, quick reference notes about OpenFOAM are posted in a form of a summary to address a specific topic per post.
  1. Old Comment

    Set (Initial) Internal Fields Using #codeStream

    For OpenFOAM-7, the following works

    ===
    velocity #codeStream
    {
    code
    #{
    double h = 5.0;
    double Umax = 2.0;
    const IOdictionary& d = static_cast<const IOdictionary&>(dict);
    const fvMesh& mesh = refCast<const fvMesh>(d.db());
    vectorField fld(mesh.nCells(), vector(0.0, 0.0, 0.0));

    // to set a position-dependent value
    forAll(mesh.C(), i)
    {
    double yloc = mesh.C()[i].y();
    fld[i] = vector(Umax * (1.0 - pow(2.0 * yloc / h, 2)), 0.0, 0.0);
    }
    writeEntry(os,"",fld);

    #};

    codeInclude
    #{
    #include "fvCFD.H"
    #};

    codeOptions
    #{
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude
    #};
    codeLibs
    #{
    -lfiniteVolume \
    -lmeshTools
    #};
    };

    #inputMode merge
    permalink
    Posted October 31, 2019 at 21:04 by SamMallinson SamMallinson is offline
  2. Old Comment
    vsammartano's Avatar

    codedFixedValue Boundary Condition

    Dear Hisham,
    thank you for your little template. I would ask you something. If I need to use inside the code block a constant from a file how can I proceed? I tried different ways, but any of these have had good results.
    Do you have any idea to perform this?
    Thank you in advance,
    Vincenzo

    PS:
    Here an example:

    #include "<fileIncludingVariables>"
    boundaryField
    {
    PatchName
    {
    type codedFixedValue;
    value uniform (0 0 0); //$internalField;
    redirectType BC_Given_Name;
    code
    #{
    fixedValueFvPatchVectorField myPatch (*this);
    forAll(myPatch, celli)
    {
    myPatch[celli] = $amplitude*(this->db().time().value()/*TIME*/ * this->patch().Cf()[celli]/*centers of patch faces (for x-value use this->patch().Cf()[celli][0])*/ );
    }
    operator==(myPatch);
    #};
    }
    .
    .
    .
    .
    .
    }
    permalink
    Posted July 5, 2017 at 07:11 by vsammartano vsammartano is offline
  3. Old Comment

    Set (Initial) Internal Fields Using #codeStream

    set initial vector field

    Hi Hisham,

    I was interested to read this post of yours.

    Here is how you do the same for a vector field: put the following in a file called "initialCondition" and then #include it in the file 0/U and set internalField as $velocity. NB, it sets a Poiseuille profile for a parallel plate channel with the walls at +/- h/2.

    =====

    velocity #codeStream
    {
    code
    #{
    double h = 1;
    double Umax = 0.5;
    const IOdictionary& d = dynamicCast<const IOdictionary>(dict);
    const objectRegistry& db = d.db();

    volVectorField& fld =
    const_cast<volVectorField&>(db.lookupObject<volVec torField>("U"));

    const fvMesh& mesh = fld.mesh();

    // to set a position-dependent value
    forAll(mesh.C(), i)
    {
    double yloc = mesh.C()[i].y();
    fld[i] = vector(Umax * (1.0 - pow(2.0 * yloc / h, 2)), 0.0, 0.0);
    }
    os << fld.internalField();
    #};

    codeInclude
    #{
    #include "fvCFD.H"
    #};

    codeOptions
    #{
    -I$(LIB_SRC)/finiteVolume/lnInclude
    #};
    codeLibs
    #{
    -lfiniteVolume
    #};
    };

    #inputMode merge

    =====

    Cheers,

    Sam
    permalink
    Posted February 5, 2015 at 01:21 by SamMallinson SamMallinson is offline
    Updated February 24, 2015 at 18:25 by SamMallinson (Figured out how to do what I asked)
  4. Old Comment

    Gnuplot Vector Probes from the funtionObject

    Quote:
    Originally Posted by Hisham View Comment
    Hi

    I think it should be something like:
    Code:
    plot 'File' using "%lf (%lf %*lf %*lf) (%*lf %*lf %*lf)"
    for plotting the X component of the first vector and so on!
    Hello Hisham

    Thank you very much for this helpful idea. I have one question: I want to plot the velocity vector compnonest(Ux , Uy and Uz) vs time for three points but there is small problem:
    My case looks like this:
    Time
    1 (1 -4 4) (2 1 3) (0 1 7)
    2 (1 -2 0) (1 3 6) (2 1 9)
    ...

    I can plot (Ux1, Uy1, Uz1) and also (Ux2, Uy2, Uz2) ,or in other words datas till column 7, using plot 'File' using "%lf (%lf %*lf %*lf) (%*lf %*lf %*lf)"
    BUT when I use 1:8 '%lf (%lf %lf %lf) (%lf %lf %lf) (%lf %lf %lf)' title 'Ux3' to plot the vlocity components of third point I get this ERROR:

    "U3plot", line 6: Please use between 1 and 7 conversions, of type double (%lf)

    Does anyone have any IDea???
    permalink
    Posted April 22, 2014 at 03:25 by jeicek jeicek is offline
  5. Old Comment
    Hisham's Avatar

    OpenFOAM Installation for Multiple Users

    Thanks a lot Bruno. The post has been corrected
    permalink
    Posted March 10, 2013 at 09:48 by Hisham Hisham is offline
  6. Old Comment

    OpenFOAM Installation for Multiple Users

    Hi Hisham,

    Nice blog post! I've been meaning to do a blog post similar to this one (actually, to write a wiki page on the topic), but I haven't found the time for it yet.
    So I'll take the opportunity to leave some helpful comments
    Best regards,
    Bruno
    permalink
    Posted March 10, 2013 at 07:14 by wyldckat wyldckat is offline
  7. Old Comment
    Hisham's Avatar

    Gnuplot Vector Probes from the funtionObject

    Quote:
    Originally Posted by iznal View Comment
    Hi Hisham
    Thanks for your Post. Right now I got a Problem with plotting those vectors.

    My file looks like:
    # Time vector01 vector02 1.20 (2.14 8.512 1.005) (2.15 0.23 1.24))Could you please give me some tipps?
    Hi

    I think it should be something like:
    Code:
    plot 'File' using "%lf (%lf %*lf %*lf) (%*lf %*lf %*lf)"

    for plotting the X component of the first vector and so on!
    permalink
    Posted September 4, 2012 at 09:01 by Hisham Hisham is offline
  8. Old Comment

    Gnuplot Vector Probes from the funtionObject

    Hi Hisham
    Thanks for your Post. Right now I got a Problem with plotting those vectors.

    My file looks like:
    # Time vector01 vector02 1.20 (2.14 8.512 1.005) (2.15 0.23 1.24))Could you please give me some tipps?
    permalink
    Posted August 8, 2012 at 08:19 by iznal iznal is offline

All times are GMT -4. The time now is 16:12.