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

create volTensorField out of volScalarFields

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By deepsterblue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 25, 2013, 03:48
Default create volTensorField out of volScalarFields
  #1
New Member
 
Join Date: Mar 2012
Posts: 18
Rep Power: 14
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, 04:50
Default
  #2
Member
 
Jim Knopf
Join Date: Dec 2010
Posts: 60
Rep Power: 15
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, 07:40
Default
  #3
New Member
 
Join Date: Mar 2012
Posts: 18
Rep Power: 14
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 08:33. Reason: mesh.cells
anton_lias is offline   Reply With Quote

Old   December 20, 2014, 23:10
Default
  #4
Member
 
Jack
Join Date: Aug 2012
Posts: 47
Rep Power: 13
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, 09:13
Default
  #5
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
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.
alejo_88 likes this.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   December 22, 2014, 10:44
Default
  #6
Member
 
Jack
Join Date: Aug 2012
Posts: 47
Rep Power: 13
JackW is on a distinguished road
Brilliant, thanks!
JackW 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
create the file *.foam phongstar OpenFOAM 12 October 14, 2018 18:06
Possible to create cyliner baffle (internal) using topoSet or stl Mesh? keepfit OpenFOAM 4 February 19, 2017 14:40
[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
About create interface! xinzhiyu2008 STAR-CCM+ 2 August 6, 2010 20:47


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