In this blog, quick reference notes about OpenFOAM are posted in a form of a summary to address a specific topic per post.
-
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 mergePosted October 31, 2019 at 21:04 by SamMallinson -
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);
#};
}
.
.
.
.
.
}Posted July 5, 2017 at 07:11 by vsammartano -
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,
SamPosted February 5, 2015 at 01:21 by SamMallinson
Updated February 24, 2015 at 18:25 by SamMallinson (Figured out how to do what I asked) -
Gnuplot Vector Probes from the funtionObject
Quote:
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???Posted April 22, 2014 at 03:25 by jeicek -
Posted March 10, 2013 at 09:48 by Hisham -
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
- The alias command you're mentioning:
Code:OFver=source /home/MrX/openfoamver/etc/bashrc
Code:alias OFver='source /home/MrX/openfoamver/etc/bashrc'
- The following links are for some of my posts on the topic of transferring a personal installation to a global installation:
BrunoPosted March 10, 2013 at 07:14 by wyldckat - The alias command you're mentioning:
-
Gnuplot Vector Probes from the funtionObject
Quote:
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!Posted September 4, 2012 at 09:01 by Hisham -
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?Posted August 8, 2012 at 08:19 by iznal