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

Assign values in an array to each cell of volscalarfield

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 3, 2020, 17:22
Default Assign values in an array to each cell of volscalarfield
  #1
New Member
 
Join Date: Jun 2020
Posts: 10
Rep Power: 6
Yongqiang66 is on a distinguished road
Hi Foamers,

I got an output array in Openfoam7. The values in the array correspond to each cell of the mesh.

I want to output the values in the array to a volscalarfield and write to files for visualization.

I have defined the field in "createfields.H". But I don't know how to assign values between array and volscalarfields.

Regards,
Yongqiang
Yongqiang66 is offline   Reply With Quote

Old   June 3, 2020, 18:53
Default
  #2
New Member
 
Join Date: Jun 2020
Posts: 10
Rep Power: 6
Yongqiang66 is on a distinguished road
In other words, is it allowed to assign values cell by cell in OpenFOAM?

Quote:
Originally Posted by Yongqiang66 View Post
Hi Foamers,

I got an output array in Openfoam7. The values in the array correspond to each cell of the mesh.

I want to output the values in the array to a volscalarfield and write to files for visualization.

I have defined the field in "createfields.H". But I don't know how to assign values between array and volscalarfields.

Regards,
Yongqiang
Yongqiang66 is offline   Reply With Quote

Old   June 3, 2020, 19:59
Default
  #3
Member
 
Hasan Celik
Join Date: Sep 2016
Posts: 64
Rep Power: 10
PositronCascade is on a distinguished road
Are you trying to do something like this?

Code:
volScalarField p
(
    IOobject
    (
        "p",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    p_rgh + rho*gh
);
For instance, here the solver iterates p_rgh and then, using the expression
Code:
p = p_rgh + rho*gh
it converts p_rgh to p. So, you can define an expression like this at that line, if I understood your aim correctly.
PositronCascade is offline   Reply With Quote

Old   June 4, 2020, 04:17
Default
  #4
New Member
 
Join Date: Jun 2020
Posts: 10
Rep Power: 6
Yongqiang66 is on a distinguished road
Hi Positron,

Thank you for your reply.
I coupled OpenFOAM with another chemical simulator. They chemical simulator outputs an array. However, I aim to transfer the data in an array to an volscalarfield so that I can do visualization in ParaView.

It is to assign value for each of volscalarfield from an array. It seems that the following code is not what intends to do.

Thanks,
Yongqiang


Quote:
Originally Posted by PositronCascade View Post
Are you trying to do something like this?

Code:
volScalarField p
(
    IOobject
    (
        "p",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    p_rgh + rho*gh
);
For instance, here the solver iterates p_rgh and then, using the expression
Code:
p = p_rgh + rho*gh
it converts p_rgh to p. So, you can define an expression like this at that line, if I understood your aim correctly.
Yongqiang66 is offline   Reply With Quote

Old   June 7, 2020, 03:44
Default
  #5
Senior Member
 
Yogesh Bapat
Join Date: Oct 2010
Posts: 102
Rep Power: 16
ybapat is on a distinguished road
You can use forAll loop.
ybapat is offline   Reply With Quote

Old   June 7, 2020, 10:13
Default
  #6
New Member
 
Join Date: Jun 2020
Posts: 10
Rep Power: 6
Yongqiang66 is on a distinguished road
Hi ybapat,

Thanks for your reply. I have solved this problem. The code can be run successfully.

Regards,
Yongqiang

Quote:
Originally Posted by ybapat View Post
You can use forAll loop.
Yongqiang66 is offline   Reply With Quote

Old   June 7, 2020, 10:16
Default
  #7
Member
 
Hasan Celik
Join Date: Sep 2016
Posts: 64
Rep Power: 10
PositronCascade is on a distinguished road
Quote:
Originally Posted by Yongqiang66 View Post
Hi ybapat,

Thanks for your reply. I have solved this problem. The code can be run successfully.

Regards,
Yongqiang
Would you share the solution for the future possible visitors to this thread, so they can find a solution as well?
PositronCascade is offline   Reply With Quote

Old   June 7, 2020, 10:19
Default
  #8
New Member
 
Join Date: Jun 2020
Posts: 10
Rep Power: 6
Yongqiang66 is on a distinguished road
It's just as you suggested. Use forAll to loop over all the volscalarfield and = to directly assign values from the array . It is straightforward.

Quote:
Originally Posted by PositronCascade View Post
Would you share the solution for the future possible visitors to this thread, so they can find a solution as well?
Yongqiang66 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
Setting cell variable values in a fluid zone using UDF eromon84 Fluent UDF and Scheme Programming 6 March 28, 2021 12:59
Set cell volume integrated field values to preserve integral Diro7 OpenFOAM Pre-Processing 2 June 3, 2018 11:44
How to scale a volScalarField by cell volume? tgvosk OpenFOAM Running, Solving & CFD 2 July 9, 2012 11:25
Ensight - node values -cell values leo FLUENT 1 May 12, 2010 09:47
Cell face values computation un unstructured grids Sergio Rossi Main CFD Forum 2 May 28, 2006 11:04


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