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

PtrList with shape of mesh or something similar

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By chrisb2244

Reply
 
LinkBack Thread Tools Display Modes
Old   April 9, 2014, 15:54
Default PtrList with shape of mesh or something similar
  #1
Senior Member
 
Join Date: Jan 2012
Posts: 159
Rep Power: 5
maybee is on a distinguished road
hi,

in one of the equations I am implementing is a really complex source term where one equation part returns 4 values for each cell of the mesh that are currently stored in an object of type "Mat<double>" (Matrix class of library armadillo) :/.

Is it possible to create a PtrList with the shape of mesh where each pointer points to a matrix or something similar?

The main reason is, that I need to multiplicate these matrices with another part of the equation for each cell and if I want to use matrix operations it would be best if I could keep the matrices in a kind of PtrList or List with the shape of mesh.

greetings maybee
maybee is offline   Reply With Quote

Old   April 10, 2014, 01:13
Default
  #2
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 84
Rep Power: 4
chrisb2244 is on a distinguished road
Not quite sure what you mean here, but I'm guessing you have a matrix for each cell in your mesh, and you want to be able to easily find each matrix?

My (third or fourth) thought on this is that you might be able to use a
Code:
PtrList<Matrix> pointerList (nCells)
forAll(pointerList, i)
{
     pointerList[i] = MatrixList[i] // Not sure if you can
     // get a list of your matrices very easily - perhaps not or else this
     // would be fairly trivial?
     // If you create the matrices by formula which depends on your value
     // of i, you could use pointerList.append(matrixI) instead, and probably
     // construct the PtrList as null?
}
and write a function with something like the code used in Kmesh for referencing, where nn is the size of the dimensions, eg 3(2 4 5) for a 2x4x5 matrix.
Code:
inline Foam::label Foam::Kmesh::index
(
    const label i,
    const label j,
    const label k,
    const labelList& nn
)
{
    return (k + j*nn[2] + i*nn[1]*nn[2]);
}
Taken a step further, you could probably define an operator overload for the [] operator? Not sure, but seems doable in principle?
chrisb2244 is offline   Reply With Quote

Old   April 10, 2014, 06:36
Default
  #3
Senior Member
 
Join Date: Jan 2012
Posts: 159
Rep Power: 5
maybee is on a distinguished road
hi,

thx for the help.

1.I also thought about doing something like your first code, but there is one specific reason I asked this question. Will it be sufficient to create a PtrList with the size of the mesh cells? I thought it would also be necessary to pass some kind of "global cell structure" (shape of the mesh) to the list (?). How is the structure of the mesh preserved within fields like volScalarField, surfaceScalarField, i.e. how does OpenFOAM know which value of the field (in my case PtrList) will belong to which cell? -> Therefore I was not sure if it will be sufficient just to create the PtrList with the cell number.

To me it generally would be nice to know how OpenFOAM handles its field, especially how it assigns the values to the right cells/surfaces.

2. What exactly do you mean by your second code ? If I have stored the matrices in a PtrList where each matrice is "stored in the right cell" I can already access them like

Code:
forAll (PtrListMatrices, celli)
{
...
}
-> mission accomplished .

greetings
maybee
maybee is offline   Reply With Quote

Old   April 10, 2014, 20:35
Default
  #4
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 84
Rep Power: 4
chrisb2244 is on a distinguished road
I wouldn't swear to it, but I'm pretty sure that the fields have no knowledge of the shape of the mesh by themselves. The mesh class (whichever you're using, eg fvMesh) holds the positions of cells, along with their connectivity (connected-ness? I know that isn't a word, but seems like connectivity might describe a different concept?). The owners and neighbours of faces, at least This allows the calculation of fluxes, I suppose?

The fields are as far as I know, just lists of vectors, values, etc.
maybee likes this.
chrisb2244 is offline   Reply With Quote

Old   April 10, 2014, 20:37
Default
  #5
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 84
Rep Power: 4
chrisb2244 is on a distinguished road
Oh, and as for the 2nd piece of code, I thought you were wanting to access the members by coordinate, like
Code:
matrix[1, 4, 2]
or something - the second piece of code would allow
Code:
matrix[index(1,4,2,nn)]
or similar, whereas an overloading of the []operator might allow you to directly use the first example, matrix[x,y,z].
chrisb2244 is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ICEM] Hexa mesh, curve mesh setup, bunching law Anorky ANSYS Meshing & Geometry 4 November 12, 2014 01:27
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
[ICEM] Orthogonality/Skew issues in 3D unstructured mesh eddyy19g ANSYS Meshing & Geometry 3 February 13, 2014 10:36
how to set periodic boundary conditions Ganesh FLUENT 13 January 22, 2014 05:11
[ICEM] Problem making structural mesh on a surface froztbear ANSYS Meshing & Geometry 1 November 10, 2011 09:52


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