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

Create 2D array with all zero value

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By DoQuocVu
  • 1 Post By ankur_garg

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 11, 2017, 11:44
Default Create 2D array with all zero value
  #1
Member
 
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 9
DoQuocVu is on a distinguished road
Hi everyone,

I want to create an array of 2 vectorField, for example,

List<vectorField> Ub;

If I know already the size of Ub, how can I assign all zero values for Ub?
DoQuocVu is offline   Reply With Quote

Old   September 13, 2017, 03:36
Default
  #2
New Member
 
ANKUR GARG
Join Date: Mar 2017
Posts: 23
Rep Power: 9
ankur_garg is on a distinguished road
List<vectorField> Ub(2, Zero);
Where 2 denotes the Size of the list, and Zero is like (0 0 0 ) for the two vector fields. It can also be defined as an initialization of the list.

Let me know if it doesn't work.

Thank you.

Regards,
Ankur
ankur_garg is offline   Reply With Quote

Old   September 13, 2017, 12:08
Default
  #3
Member
 
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 9
DoQuocVu is on a distinguished road
Hi Ankur,

Thanks a lot for your suggestion,

Unfortunately, It does not work.

I know about the the definition of Ub(2, vector::zero), it will give me a List of 2 vector (0 0 0) rather than two vectorField with all vectors are zero.

Do you have any other idea?
DoQuocVu is offline   Reply With Quote

Old   September 13, 2017, 12:48
Default
  #4
New Member
 
ANKUR GARG
Join Date: Mar 2017
Posts: 23
Rep Power: 9
ankur_garg is on a distinguished road
Will this bunch of code will help you? Please let me know.

List<vectorField>Ub(2);
forAll(Ub, Lctr)
{
vectorField vf(1);
vf[0] = Zero;
Ub[Lctr] = vf;

}
forAll(Ub, Lctr)
{
Info<< '\t' << "List = "<<Ub[Lctr]<<'\t'<<nl;
}



Thank you.

Regards,
Ankur
ankur_garg is offline   Reply With Quote

Old   September 14, 2017, 02:25
Default
  #5
Member
 
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 9
DoQuocVu is on a distinguished road
Hi ankur,

Thanks again for your kindness. Actually i'm using this way to define my array which is quite similar to what you said:
Code:
List<vectorField> Ub(2)
forAll(Ub, i)
{
    vectorField Utemp(n, vector::zero);
    Ub[i] = Utemp;
}
n is the field size that I know already.
I want to know if there is a shorter way to achieve that though. I've gone through the source code but couldn't find any appropriate constructor, so maybe this is the only way to do that I think
anhkenyt likes this.
DoQuocVu is offline   Reply With Quote

Old   September 14, 2017, 06:46
Default
  #6
New Member
 
ANKUR GARG
Join Date: Mar 2017
Posts: 23
Rep Power: 9
ankur_garg is on a distinguished road
Welcome DoQuocVu. I am Sorry actually for not being able to give some shorter way. I am not that proficient with OpenFOAM till now, I am just learning, and you also taught me something by putting this query.

Thank you very much for your kindness.

Regards,
Ankur
DoQuocVu likes this.
ankur_garg is offline   Reply With Quote

Reply


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
[General] Extracting ParaView Data into Python Arrays Jeffzda ParaView 30 November 6, 2023 21:00
create the file *.foam phongstar OpenFOAM 12 October 14, 2018 18:06
[General] Contour plot: celldata2pointdata dmaz ParaView 1 April 28, 2014 16:05
[ICEM] how to create a 2d tri mesh with quad mesh in the boundary layer seal2013 ANSYS Meshing & Geometry 3 October 6, 2013 16:09
Actuator disk model audrich FLUENT 0 September 21, 2009 07:06


All times are GMT -4. The time now is 13:36.