CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [swak4Foam] FunkySetFields for OF 141 (https://www.cfd-online.com/Forums/openfoam-community-contributions/61981-funkysetfields-141-a.html)

mer February 26, 2008 15:54

FunkySetFields for OF 141
 
Hi,
Did the latest version of FunkySetFields.r7568 work with OF 1.4.1. I try to compile it, but there are some errors?

I hope that I find a quick response.

Djemai

gschaider February 27, 2008 06:37

Hi Djemai! That's right. Th
 
Hi Djemai!

That's right. That version only compiles with 1.4. Get the svn-version with the command described above the file that you downloaded

Bernhard

mer February 27, 2008 16:47

Thank you Bernhard.
 
Thank you Bernhard.

mer March 1, 2008 07:58

Hi all, I have recently compi
 
Hi all,
I have recently compiled funkySetfields for OF 1.4.1, but when I run the utility I get some errors:
-------------------------------------------------
#0 Foam::error::printStack(Foam:http://www.cfd-online.com/OpenFOAM_D...part/proud.gifstream&) in "/home/mer/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/libOpenFOAM.so"
#1 Foam::sigFpe::sigFpeHandler(int) in "/home/mer/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/libOpenFOAM.so"
#2 Uninterpreted: [0x6d6420]
#3 Foam::sqrt(Foam::Field<double>&, Foam::UList<double> const&) in "/home/mer/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/libOpenFOAM.so"
#4 Foam::tmp<foam::geometricfield<double,> > Foam::sqrt<foam::fvpatchfield,>(Foam::GeometricFie ld<double,> const&) in "/home/mer/OpenFOAM/mer-1.4.1/applications/bin/linuxGccDPOpt/funkySetFields"
#5 .L30835 at ValueExpressionParser.C:0
#6 ValueExpressionDriver::parse(std::string const&) in "/home/mer/OpenFOAM/mer-1.4.1/applications/bin/linuxGccDPOpt/funkySetFields"
#7 doAnExpression(Foam::fvMesh const&, Foam::word const&, Foam::string const&, Foam::string const&, Foam::Time const&, bool, bool, Foam::dimensionSet const&, bool, Foam::List<foam::word> const&) in "/home/mer/OpenFOAM/mer-1.4.1/applications/bin/linuxGccDPOpt/funkySetFields"
#8 main in "/home/mer/OpenFOAM/mer-1.4.1/applications/bin/linuxGccDPOpt/funkySetFields"
#9 __libc_start_main in "/lib/i686/nosegneg/libc.so.6"
#10 Foam::regIOobject::readIfModified() in "/home/mer/OpenFOAM/mer-1.4.1/applications/bin/linuxGccDPOpt/funkySetFields"
Floating point exception
-------------------------------------------------
Did anyone have an idea how to resolve this problem?

Thanks
Djemai

gschaider March 1, 2008 08:53

What is the expression you're
 
What is the expression you're calculating? Is there a sqrt in it? By any chance a squareroot of a negative value? Because that is my suspicion when I look at #4 in your stacktrace

mer March 1, 2008 12:30

Hi Bernhard, Yes in my expres
 
Hi Bernhard,
Yes in my expression there is a sqrt, but there is no negative value inside because all terms are powered to 2. simply it is an equation of a sphere add to other positive terms.

Djemai

gschaider March 3, 2008 04:34

Could you please post the expr
 
Could you please post the expression anyway? The problem is definitly happening during the evaluation of the sqrt. On possibility to check: Let the utility calculate the expression INSIDE the sqrt and check the result (for NaNs etc)

tspon March 3, 2008 07:56

Hi Bernhard, I downloaded y
 
Hi Bernhard,

I downloaded your svn-Version of funkySetFields from the wiki and renamed all files in order to get C-Files etc.
But I do not know how to compile. I already tried "bison ValueExpressionParser.yy" to get .tab-Files but doesn't help (version 2.3). I also tried a wmake but it stopped and make writes: no rule to make target "funkySetFields.dep".
Could you please help me?
I use OF1.4.1.

Regards,
Thomas

mer March 3, 2008 09:29

Hi Bernhard, Excuse me to tak
 
Hi Bernhard,
Excuse me to take your time. Yes, it is my error. I put a sqrt in place of sqr inside the expression: sqrt(sqr(pos().x -2.*pow(10.,-2.))+sqr(pos().y -2.*pow(10.,-2.))+ sqr(pos().z -3.*pow(10.,-2.)))<=0.0001 ? 1:0
But I have another problem. using this expression with funkySetFields it doesn't initiate my field. I verify the same equation with setGammaDamBreak and it works. What is the problem.

mer March 3, 2008 11:07

Hi Thomas, I have compiled th
 
Hi Thomas,
I have compiled the last svn-Version of funkySetFields without any errors. To be sure that you are in the good way:
1) try to see if you have bison: bison -V
2) don't forget to run insertGenerated.sh
3) wmake should be inside the
funkySetFields directory with the presence of Make directory.
Hope this will help.

Djemai

gschaider March 3, 2008 14:18

Hi Djemal! At first: it sho
 
Hi Djemal!

At first: it should be possible to write 2e-2 instead of 2*pow(10.,-2). This would a) make the expression simpler and b) reduce the computation time (because 2*pow(10,-2) will be computed for every cell. Have you tried to make the radius (which is 2 orders of magnitude smaller than the coordinates of the midpoint) much larger? I mean: how large are your cells? With that difference in magnitudes it might be possible, that no cell-center fits your condition

Bernhard

----

Hi Thomas!

Did you download it using svn or via the web-browser? Because I was weondering why there was any need to rename the C-files?

Bernhard

tspon March 4, 2008 04:29

Hi Bernhard an Djemai, than
 
Hi Bernhard an Djemai,

thanks for your help. It works now. I had some problems with my browser, therefore I had to rename all the files. But after downloading them from anonther pc the files remained unchanged and wiki-instructions worked fine.

Regards,

Thomas

tspon March 4, 2008 07:52

Hi Bernhard and Djemai, it
 
Hi Bernhard and Djemai,

it works now. I had some problems with my browser therefore I had to change the filenames. But using another pc the files remained unchanged and wiki instructions worked fine. Thanks for your help and the quick replies.

Regards,
Thomas

gschaider March 4, 2008 10:19

Hi Thomas! With SVN-Archive
 
Hi Thomas!

With SVN-Archives the browser is only good for looking at the stuff. Use the svn-command to actually "download" it.

Bernhard

mer March 7, 2008 04:12

Hi Bernhard ! thank you, I un
 
Hi Bernhard !
thank you, I understand and it works.
Djemai

sega May 18, 2008 03:28

I used funkySetFields to creat
 
I used funkySetFields to create a spherical initial condition:

funkySetFields . . -field gamma -expression 1 -condition "pos().x*pos().x + pos().y*pos().y <= 1" -time 0

I didn't had the chance to say if the condition is right, because there was this error:

--> FOAM FATAL ERROR : This mesh contains patches of type empty but is not 1D or 2D
by virtue of the fact that the number of faces of this
empty patch is not divisible by the number of cells.

From function emptyFvPatchField<type>::updateCoeffs()
in file fields/fvPatchFields/constraint/empty/emptyFvPatchField.C at line 1

Looks like there is a problem with the mesh.
Does anybody know, what went wrong?

http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif blockMeshDict

7islands May 18, 2008 07:11

Hi Sebastian, You can read th
 
Hi Sebastian,
You can read the error message straightforwardly: patch (1 2 14 13) is missing in leftAndBottom.

And don't forget to scale the expression given to FSF, e. g. pos().x*pos().x + pos().y*pos().y <= 0.02*0.02,
since there's convertToMeter 0.01; in your blockMeshDict.

Takuya

sega May 18, 2008 12:56

Hello Takuya. Of course. Th
 
Hello Takuya.

Of course. That solved the problem.
But the simulation is not running as planned.

As this has nothing to do with funkySetFields I will talk about it in another thread the next days.

Thanks. S.

ngj May 29, 2008 06:16

Hi all Lately I have been w
 
Hi all

Lately I have been working with waves over submerged bars, and I have experienced a problem when initializing the gamma-field. I am using hex-cells and initializing with setFields (SF), but as I can see that the problem would arise from using funkySetField (FSF) as well. The problem is seen in the following figure:

http://www.cfd-online.com/OpenFOAM_D...ges/1/7856.png

SF and FSF initializes based on the cell center coordinate, thus a cell might be partly full but the fraction of gamma is only set to either 0 or 1, which results in the step-like feature of the attached figure.

I am considering making a routine - even though it might be some time into the future, as its priority is very low - which calculates the wet and dry fractions of these partially full cells. This would enable an initialization of the surface, which is perfectly flat and thus the fast moving surface waves, which I am struggling with at the moment, will be history.

Thus my questions are two-fold:

1. Would people be interested in such a tool?

2. The mesh generator has some routine to calculate the cell volumes based on an arbitrary shape. Could any of you point me to where it happens, as I am not strong in calculating the volume of arbitrarily shaped cells.

Best regards,

Niels

gschaider May 29, 2008 08:35

Hi Niels! Maybe a quick fix
 
Hi Niels!

Maybe a quick fix could be the following expression in funkySetFields (havn't got the time to try this out so the syntax might be slightly wrong):

"average(fpos().y < 0 ? 1 : 0)"

This constructs a face-field according to the criterium and then creates the cell field by averaging the values on the faces. This should smoothen things out a bit

All the functions are described on http://openfoamwiki.net/index.php/Co...funkySetFields

Bernhard

PS: Let me know if you have any problems. This part of FSF is not too well tested

ngj May 29, 2008 08:50

Hi Bernhard Thanks for the
 
Hi Bernhard

Thanks for the fast replyhttp://www.cfd-online.com/OpenFOAM_D...part/happy.gif That will certainly give a smoother surface. Will try it out and report any success / failure / etc.

- Niels

gschaider May 29, 2008 09:31

Hi Niels. Just discovered that
 
Hi Niels. Just discovered that I was bragging. There are essential things missing for that to work

ngj May 29, 2008 09:53

Okay. With respect to the v
 
Okay.

With respect to the volume section, I found the following:

http://www.cfd-online.com/Wiki/Arbit...yhedral_Volume

With that in place, I will begin considering how to make the implementation - actually the recent f(x) = 0 posted by Hrv could come handy.

Best regards,

Niels

gschaider May 29, 2008 13:00

Now it works (new version just
 
Now it works (new version just went to the SVN. Get it from there)

The expression would be:
"average(fpos().y < surf(0.) ? surf(1.) : surf(0.))"

The surf-functions generates surface-fields.

ngj May 30, 2008 03:45

Hi Bernhard Thanks, it work
 
Hi Bernhard

Thanks, it works right out of the box. Though the expression in itself still gives rise to almost the same pattern, i.e. surface waves will still be present - see attached:

http://www.cfd-online.com/OpenFOAM_D...ges/1/7870.png

Thanks for your help!

/ Niels

gschaider May 30, 2008 04:35

I think waves like that can no
 
I think waves like that can not fully be avoided as long as you don't align the grid with the surface of the initial conditions.
The particular pattern in your picture seems to come from the fact that the faces are sharply switched (the way cells were before that). Try experimenting with a function that has a trancition area in the order of the cell size where faces get a value between 0 and 1 (that might even work for cell centers). The tools are there (have fun with the ?:-expressions)

Bernhard

ngj May 30, 2008 04:54

Yeah, I actually had the same
 
Yeah, I actually had the same thought that I needed to have the grid aligned like that, but I would like to avoid such extra considerations in the grid-generation.
The transition thought might be helpful.

Thanks,

Niels

gschaider May 30, 2008 04:54

Something else Niels: "I'll wa
 
Something else Niels: "I'll wash your hands, you wash mine"
Should you get a satisfactory result using funkySF, could you add it to the section "Usage examples" on the Wiki page?

ngj May 30, 2008 05:15

Of course ... and if I at some
 
Of course ... and if I at some point make a routine which calculates the fraction of water / air in each cell, would you be interested in the code to be implemented in FSF as an alternative way of setting the field?

Enjoy your weekend,

Niels

ngj June 9, 2008 12:37

Hi Bernhard I have been loo
 
Hi Bernhard

I have been looking at a way of making these more refined weighting functions, and it seems that I need one more piece of information, which I do not know how to retrieve. So I hope you can help me.

The needed information is an approximate extend of the individual cell in the three dimensions. I think a reasonably approximation could be achieved by something like this (even though somewhat crude):

len = vector(max(fpos.x) - min(fpos.x),max(fpos.y) - min(fpos.y),max(fpos.z) - min(fpos.z))

Actually I only need the y-component. Hope you can help me.

Thanks for your help,

Niels

gschaider June 11, 2008 15:36

Hi Niels! I think this won'
 
Hi Niels!

I think this won't work the way you want to. You want the max/min of the faces on a cell. But what you get is the total max/min.

Something that might work with the existing facilities (but I havn't tried, so it might give similar patterns to your last pictur) might be:

average(interpolate(pos().y<0 ? 1 : 0))

the conversion cellValue->faceValue->cellValue might blur out the border a bit

Bernhard

gschaider June 11, 2008 15:40

Hi! One last thing (and the
 
Hi!

One last thing (and then I will shut up). If you can assume that the cells are approximately cubes then you might get their characteristic length with "pow(vol(),0.3333)"

Bernhard

ngj June 11, 2008 15:58

Hi Bernhard Oh, I sincerely
 
Hi Bernhard

Oh, I sincerely appreciate you talking, thus you don't have to shut uphttp://www.cfd-online.com/OpenFOAM_D...part/happy.gif
I have been around the cube-assumption, but my mesh is far from having uniform cells and the ratios of the characteristic lengths varies from cell to cell, thus it would not work (and would prefer a more genenic formulation).

Since writing you last time I have been looking into the code, and I have come up with a more clear and robust formulation of my problem. What I actually needs is the maximum projection of the face extend in the three cartesian coordinates. I will try to make an implementation of such a projection and if I get it to work post the code-snippet and make the wiki.
Because assuming edges aligned with the 'z'-axis, completely valid for 2D and also for my 3D-problems, the local ratio of intersected faces is easily written as

(fpos().y - 0.5 * proj().y) / proj().y

where proj is the projected face-extend and the surface is placed at y=0.

Keep you posted and thanks for your help,

Niels

ngj June 13, 2008 04:48

Hi Bernhard I have made a s
 
Hi Bernhard

I have made a small 'reverse-engineering' and implemented a new part which gives the projection of the individual face. It looks like this:

Foam::surfaceVectorField *ValueExpressionDriver::makeFaceProjectionField()
{
Foam::dimensionSet nullDim(0,0,0,0,0);
Foam::surfaceVectorField *f=new Foam::surfaceVectorField(
Foam::IOobject
(
"fproj",
time,
mesh,
Foam::IOobject::NO_READ,
Foam::IOobject::NO_WRITE
),
mesh,
Foam::vector(0,0,0)
);
f->dimensions().reset(mesh.Cf().dimensions());

Foam::vector fmin(0,0,0);
Foam::vector fmax(0,0,0);

forAll(*f,faceI)
{
const Foam::face &fProp = mesh.faces()[faceI];
fmin = mesh.points()[fProp[0]];
fmax = fmin;
forAll(fProp,pointI)
{
forAll(mesh.points()[0],compI)
{
if(mesh.points()[fProp[pointI]].component(compI) < fmin.component(compI))
fmin.component(compI) = mesh.points()[fProp[pointI]].component(compI);
if(mesh.points()[fProp[pointI]].component(compI) > fmax.component(compI))
fmax.component(compI) = mesh.points()[fProp[pointI]].component(compI);
}
}
(*f)[faceI] = fmax - fmin;
}
f->dimensions().reset(nullDim);
return f;
}

It works perfectly when multiplying, addition and substraction, but dividing fails. The part which fails is:

... : (fproj().y <= surf(0.00001) ? surf(0.5) : (surf(0.5) - fpos().y / fproj().y))))"

It fails with a floating point exception, thus my guess is that I am somehow dividing by 0, even though I have my fail-safe, where I specify the value if the projected value is to small.

I am a little bit in the dark here, so I would appreciate your help.

Have a nice weekend,

Niels

gschaider June 13, 2008 07:47

Hi Niels! The problem ist t
 
Hi Niels!

The problem ist the following: for the ?:-operator FSF evaluates all three fields (the condition, the true and the false-value) and then chooses the value for each cell according to the value of the condition in that cell. The only fix I can think of is to add a very small value to the divisor. For large values it won't matter, for small values it will be abandoned anyway.
Fixing it in FSF would mean a major rewrite, I think

Once you got it successfully tested would you commit the changed files to the SVN-repository (in other words: are you configured for write access to the SVN? If no: could you send me an EMail with the name of your sourceforge-account and I'll add you)

Bernhard

ngj June 13, 2008 08:56

Hi Bernhard, It solved it,
 
Hi Bernhard,

It solved it, thankshttp://www.cfd-online.com/OpenFOAM_D...part/happy.gif So now I can bring a small comparison. In the picture below the top figure is a setField equivalent, the middle it using the approach suggested by you the 29th of May and the bottom figure is where the length of the face above and below the waterline is taken into consideration. Not surprisingly, the more information used the better the result.

http://www.cfd-online.com/OpenFOAM_D...ges/1/8022.png

I will verify my implementation and return to you.

Enjoy,

Niels

ngj June 13, 2008 09:48

Wiki updated. / Niels
 
Wiki updated.

/ Niels

ngj June 16, 2008 10:03

Hi I actually thought that
 
Hi

I actually thought that I had it figured out, and I did for the internal faces. The boundary faces on the other hand is not treated in the loop.

Therefor I have made an extra loop which loops over boundary-patches and faces in these. All works well, but I do not know how to assign the calculated value to the boundaryField.

I would very much appreciate any help in how to assign values to a boundaryPatch in a face per face approch.

Thanks,

Niels

ngj June 17, 2008 05:57

Hi Bernhard The functionali
 
Hi Bernhard

The functionality fproj has now been tested. I cannot see your email-address. My address is ngj@mek.dtu.dk.

Best regards,

Niels

carlodean June 28, 2008 04:42

Hi, i used seccessfully funkys
 
Hi, i used seccessfully funkysetFields to set an initial gamma field, but I would like to know if it's possible to set even an initial hydrostatic pressure field, something like pd=pd*rho*pos().z.
Someone could help me?
thank you very much


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