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

create volTensorField out of volScalarFields

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

Reply
 
LinkBack Thread Tools Display Modes
Old   January 25, 2013, 04:48
Default create volTensorField out of volScalarFields
  #1
New Member
 
Join Date: Mar 2012
Posts: 18
Rep Power: 5
anton_lias is on a distinguished road
Hello everybody,
I want to create a volTensorField out of a couple of volScalarFields. The tensor should look (for example) like this JacobiMatrix=(m1, m2+m1, 0, m5*m3, m4, 0, m0, m2/m1, m2).

The Moments m0-m5 are defined like this
Code:
	Info<< "Reading field m0" << endl;
	volScalarField m0
	(
		IOobject
		(
			"m0",
			runTime.timeName(),
			mesh,
			IOobject::MUST_READ,
			IOobject::AUTO_WRITE
		),
		mesh
	);
I have tried a lot of things, but I do not manage to create the Tensor.
For example:

Code:
	Info<< "Define tensorfield jacobiMatrix" << endl;
	volTensorField jacobiMatrix
	(
		IOobject
		(
			"jacobiMatrix",
			runTime.timeName(),
			mesh,
			IOobject::NO_READ,
			IOobject::NO_WRITE
		),
		mesh,
		dimensionedTensor
		(
			"zero",
			dimensionSet(0, 0, 0, 0, 0, 0, 0),
			tensor::zero
		)
	);
and
Code:
jacobiMatrix.component(0) = m1;
jacobiMatrix.component(1) = m2+m1;
The Solver is compiling, but when I use it, an error message appears.

Quote:
--> FOAM FATAL ERROR:
attempted to assign to a const reference to constant object
Does anyone know, how I could create a volTensorField out of the volScalarFields?
anton_lias is offline   Reply With Quote

Old   January 25, 2013, 05:50
Default
  #2
Member
 
Jim Knopf
Join Date: Dec 2010
Posts: 60
Rep Power: 6
JimKnopf is on a distinguished road
You could do a loop over all cells and then compute your components like:

Code:
// const Foam::cellList cells = mesh.cells()
forAll(cells,cellI)
{
JacobiMatrix[cellI].component(0) = m1[cellI]+m2[cellI];
// same for all the others
}
This probably no good style but it should work.

Best Regards
Jim
JimKnopf is offline   Reply With Quote

Old   January 25, 2013, 08:40
Default
  #3
New Member
 
Join Date: Mar 2012
Posts: 18
Rep Power: 5
anton_lias is on a distinguished road
Thanks a lot, it is working.
But I have to write
forAll(mesh.cells(),cellI)
{...

I already read that it's not a good style. But I did not find an answer on the question, how a good style would look like.

Last edited by anton_lias; January 25, 2013 at 09:33. Reason: mesh.cells
anton_lias is offline   Reply With Quote

Old   December 21, 2014, 00:10
Default
  #4
Member
 
Jack
Join Date: Aug 2012
Posts: 42
Rep Power: 4
JackW is on a distinguished road
I know this is an old post, but did you (or anyone else) find a more compact solution to this problem? Would be much appreciated!
JackW is offline   Reply With Quote

Old   December 22, 2014, 10:13
Default
  #5
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 386
Rep Power: 15
deepsterblue will become famous soon enough
What you're looking for here is the replace() member function:

Code:
jacobiMatrix.replace(0, m0);
jacobiMatrix.replace(1, m1);
jacobiMatrix.replace(2, m2);
...
...
jacobiMatrix.replace(8, m8);
No need to loop over all cells.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   December 22, 2014, 11:44
Default
  #6
Member
 
Jack
Join Date: Aug 2012
Posts: 42
Rep Power: 4
JackW is on a distinguished road
Brilliant, thanks!
JackW 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] how to create a 2d tri mesh with quad mesh in the boundary layer seal2013 ANSYS Meshing & Geometry 3 October 6, 2013 16:09
Problems with Mirror tools when create block nigel332 Pointwise & Gridgen 4 September 26, 2013 20:21
Possible to create cyliner baffle (internal) using topoSet or stl Mesh? keepfit OpenFOAM 3 August 1, 2013 11:49
About create interface! xinzhiyu2008 STAR-CCM+ 2 August 6, 2010 20:47
create the file *.foam phongstar OpenFOAM 11 July 26, 2010 19:23


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