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)

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 09:18.