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

Nested Field usage

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 13, 2019, 07:12
Default Nested Field usage
  #1
New Member
 
/
Join Date: Jan 2019
Posts: 7
Rep Power: 3
CFDMi is on a distinguished road
Hi all!
I got used to working with a Field of vectors such as:

Field<vector> someVectorField(LengthOfField, vector::zero);

Now I need 5 "coordinates so instead of a vector field i would use a field of fields. Didn't find anything on the topic, so I just tried to approach it logically:

Field<Field<scalar>> someFieldField(LengthOfOuterField, (LengthOfInnerField, 0.0);

Unfortunately this does not work. I can however define it as such:

Field<Field<scalar> > someFieldField[LengthOfOuterField][LengthOfInnerField];

but I have no idea how to declare it afterwards. Tried = 0 or = {0} and such. Also someFieldField[0][0] = someScalar; does not work since seemingly the left hand side is still a field and not a scalar...

I appreciate every bit of help. Thx in advance!
CFDMi is offline   Reply With Quote

Old   September 16, 2019, 06:18
Default
  #2
Member
 
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 81
Rep Power: 10
einstein_zee is on a distinguished road
Hii there,

I have no idea what you are trying to do however, looking at the code I got an idea which might be useful. looking into "https://cpp.openfoam.org/v7/Field_8H_source.html" section for constructors. you may initialize the outer Field normally (Field<Field<scalar>> someFieldField(outerFieldSize). This should create a Field with size of outerFieldSize in which each element now would be another Field which you can populate it later. Then you may loop through all the elements of this Field and try assigning your desired Field WRT valid operators (see the same link section Member Operators). sth like this
for (label i = 0; i < outerFieldSize; i++)
{
someFieldField[i] = (now RHS is a Field of scalars check Member Operators for assignment)
}

The logic is pretty much like creating 2D matrices in C++ with raw pointers.
einstein_zee is offline   Reply With Quote

Old   September 19, 2019, 12:39
Default
  #3
New Member
 
/
Join Date: Jan 2019
Posts: 7
Rep Power: 3
CFDMi is on a distinguished road
Thanks for your reply einstein!

I now figured it out and gonna leave it here for future reference.

To declare a list of 5 dimensional vectors I used an outer list (I do not need the functionality of a field there, but can be exchanged):

List<Field<scalar> bananaList( lengthOfOuterList, Field<scalar>(lengthOfInnerField, values)

To populate it with values other than zero, one can then as you mentionend just access it as one would a normal array.

for (int i = 0; i < lengthOfOuterList; i++)
{
bananaList[i][0] = someScalar;
bananaList[i][1] = someScalar;
bananaList[i][2] = someScalar;
etc.....
}
CFDMi is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
simpleDyMFoam on v1806 gamemakerh OpenFOAM Programming & Development 0 November 8, 2018 08:15
potential flows, helmholtz decomposition and other stuffs pigna Main CFD Forum 1 October 26, 2017 08:34
Access to field which is evaluated at the moment Tobi OpenFOAM Programming & Development 6 April 19, 2017 13:09
[General] How to create an additional vector with {Field 4, Field 5, Field 6} Bombacar ParaView 1 August 15, 2015 18:05
Demagnetization field jan0385 ANSYS 0 April 12, 2012 09:09


All times are GMT -4. The time now is 18:57.