CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Vector Mathematics

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By ngj

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 15, 2014, 12:52
Default Vector Mathematics
  #1
New Member
 
Will
Join Date: Dec 2011
Posts: 17
Rep Power: 14
willzyba is on a distinguished road
I'm sure there must be a neater way to do this, but I can't find the documentation and nothing I've tried works. This is just ugly

Code:
const vector offset((endCorner_.x() - startCorner_.x())/(nPoints_.x() - 1),
                        (endCorner_.y() - startCorner_.y())/(nPoints_.y() - 1),
                        (endCorner_.z() - startCorner_.z())/(nPoints_.z() - 1) );
where startCorner and endCorner are both vectors that define opposite corners of a box.
And nPoints is an integer vector, which simply contains the number of points I want in each direction.

I really just want to say:
offset = (endCorner - startCorner)/(nPoints -1)

And hopefully C++ would figure that as nPoints is a vector, then when I subtract 1, that should remain a vector. And the subtraction of two vectors should be vector; and dividing one against the other give me my offsets in each direction. But it refused to compile.

So the final offset vector should contain the steps I need to take in each principal direction in order to fill a box with a lot of points. Just finishing off my development of LPT btw, that requires points throughout the domain which we're running through waveFOAM.



Finally function we're adding to solidParticleCloud.C looks like
Code:
void Foam::solidParticleCloud::seed(const dimensionedVector& g)
{
    // http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2011/OF_kurs_LPT_120911.pdf

    const vector offset((endCorner_.x() - startCorner_.x())/(nPoints_.x() - 1),
                        (endCorner_.y() - startCorner_.y())/(nPoints_.y() - 1),
                        (endCorner_.z() - startCorner_.z())/(nPoints_.z() - 1) );
  
    int Nz= int(nPoints_.z());
    int Ny= int(nPoints_.y());
    int Nx= int(nPoints_.x());

    // Hope this produces a line of particle points.
    for(int k=0; k<Nz; k++)
    {
        for(int j=0; j<Ny; j++)
        {
            for(int i=0; i<Nx; i++)
            { 
                vector pos(startCorner_.x() + offset.x()*i,
                           startCorner_.y() + offset.y()*j,
                           startCorner_.z() + offset.z()*k );

                label cellI =-1;
                label tetFaceI =-1;
                label tetPtI = -1;
                mesh_.findCellFacePt(pos, cellI, tetFaceI, tetPtI);
                if(cellI>0)
                {
                    solidParticle* pt= new solidParticle(mesh_, pos ,cellI, tetFaceI, tetPtI, 0.01, vector::zero );
                    Cloud<solidParticle>::addParticle(pt);
                }
                pos = pos + offset;
            }
        }
    }
}
willzyba is offline   Reply With Quote

Old   September 15, 2014, 14:25
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hallo,

I think that the only thing you lack is the Foam::cmptDivide functionality. The vector minus vector and vector minus scalar does already work.

Have fun playing with waves2Foam; curious to know how the Lagrangian particles will behave across the free surface.

Kind regards,

Niels
willzyba likes this.
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   September 16, 2014, 06:57
Default
  #3
New Member
 
Will
Join Date: Dec 2011
Posts: 17
Rep Power: 14
willzyba is on a distinguished road
Thanks.

Just for the record, I replace:
Code:
const vector offset((endCorner_.x() - startCorner_.x())/(nPoints_.x() - 1),
                        (endCorner_.y() - startCorner_.y())/(nPoints_.y() - 1),
                        (endCorner_.z() - startCorner_.z())/(nPoints_.z() - 1) );
with
Code:
const vector offset(Foam::cmptDivide(endCorner_ - startCorner_, nPoints_ - vector(1,1,1)));
and
Code:
vector pos(startCorner_.x() + offset.x()*i,
                           startCorner_.y() + offset.y()*j,
                           startCorner_.z() + offset.z()*k );
with just
Code:
vector pos(startCorner_ + Foam::cmptMultiply(offset, vector(i,j,k)));
Certainly compiles and works as intended, but we still get an annoying
Quote:
*** glibc detected *** waveFoamLPT: corrupted double-linked list: 0x0000000002898a50 ***
bug at the end of the run. I've posted a question about this on a new thread.

As for WaveFoam. Preliminary results look amazing and I think our physical understanding of what we're doing will be greatly enhanced. We're loosing a few particles to the atmosphere, mostly due to wave splashing onto a surface, but that aside it seems acceptable. Will post some pictures when we're happier.
willzyba is offline   Reply With Quote

Reply

Tags
vector mathematics


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 19:09.