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

Conversion matrix to VolScalarField

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 13, 2021, 06:00
Default Conversion matrix to VolScalarField
  #1
New Member
 
-Anon-
Join Date: Oct 2021
Posts: 2
Rep Power: 0
mmany is on a distinguished road
Hi,

I am developing an AI based solver for Openfoam and I am currrently trying to do the following thing:
1 - I have a rectangular mesh of dimension 256 * 128 * 1 cells ( adapted for a channel flow case) and some VolScalarFields.
2 - I have a neural network which gives a matrix of dimension 256 * 128.
3 - I want to assign the matrix values to the corresponding cell in OpenFoam
4 - I already have found a way to loop through the cells centers in a particular order to assign the matrix values and it works.

Code:
void CNN::updateFoamFieldChannelFlow(torch::Tensor &ai_output, Foam::volScalarField &field){
	int it = 0;
	forAll(field.mesh().C(), celli){
		int i = it / 256;
		int j = it % 256;
		field[celli] = ai_output[i][j];
		it++;
	}
}
5 - How can I also access the boundaries of the field[celli], to also change its value ? Is there a better way, more efficient to assign values to a VolScalarField ?

Thanks,
mmany
mmany 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
Error message Bruno_Jorge Main CFD Forum 1 February 5, 2019 11:12
namespace Foam Argen OpenFOAM 4 February 5, 2019 08:55
CFD by anderson, chp 10.... supersonic flow over flat plate varunjain89 Main CFD Forum 18 May 11, 2018 07:31
Making a PtrList<PtrList<volScalarField> > or making a square matrix volScalarField ChasingNeutrons OpenFOAM Programming & Development 4 July 6, 2016 19:45
writing execFlowFunctionObjects immortality OpenFOAM Post-Processing 30 September 15, 2013 06:16


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