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

Initialization of symmTensor by a coded function

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 2 Post By Tobi
  • 1 Post By Tobi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 10, 2016, 13:42
Default Initialization of symmTensor by a coded function
  #1
New Member
 
Javier Sierra Ausin
Join Date: Jul 2016
Location: Toulouse
Posts: 1
Rep Power: 0
jsagg is on a distinguished road
Hi, I am trying to implement an utility that calculate time averages of different fields. So what I am doing is to compute the fields I need with a coded function in my ControlDict and after I use fieldAverage function Object.

By now, I am being inspired by this post where eelcovv and gschaider prupose different solutions for a similar issue.

My final goal is to be able to write volSymmTensorFields, volScalarFields and volVectorFields. However, I am not able to figure out the way to initialize volSymmTensorFields.

what I do to initialize a volScalarField is as follows:

Quote:
const volScalarField& TMod = mesh().lookupObject<volScalarField>("THigh");
const volScalarField& TModMean = mesh().lookupObject<volScalarField>("THighMean_w1" );
static autoPtr<volScalarField> TModpField;


if(!TModpField.valid())
{
Info << "Creating TModp" << nl;

TModpField.set
(
new volScalarField
(
IOobject
(
"TModp",
mesh().time().timeName(),
TMod.mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
TMod-TModMean
)
);
}

volScalarField &TModp = TModpField();

TModp.checkIn();

TModp = TMod-TModMean;
Info << " TModp perturbated max " << max(TModp) << nl;
where TMod, TModMean and TModpField are the scalar fields. The trick here it is that I can initialize it directly by the expression TMod-TModMean.

Nevertheless, this is not the case for volsymmTensorFields.

So what I do so far for symmTensorFields is:

Quote:
if(!UpOUpField.valid())
{
Info << "Creating UpOUp" << nl;

UpOUpField.set
(
new volSymmTensorField
(
IOobject
(
"UpOUp",
mesh().time().timeName(),
U.mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedSymmTensor
(
"UpOUp",
dimensionSet(0,2,-2,0,0,0,0),
symmTensor::zero
)
)
);


}

volSymmTensorField &UpOUp = UpOUpField();

UpOUp.checkIn();
forAll( Up.internalField(), i)
{
UpOUp.internalField()[i].component(symmTensor::XX) = Up.internalField()[i].component(vector::X)*Up.internalField()[i].component(vector::X);
UpOUp.internalField()[i].component(symmTensor::XY) = Up.internalField()[i].component(vector::X)*Up.internalField()[i].component(vector::Y);
UpOUp.internalField()[i].component(symmTensor::XZ) = Up.internalField()[i].component(vector::X)*Up.internalField()[i].component(vector::Z);
UpOUp.internalField()[i].component(symmTensor::YY) = Up.internalField()[i].component(vector::Y)*Up.internalField()[i].component(vector::Y);
UpOUp.internalField()[i].component(symmTensor::YZ) = Up.internalField()[i].component(vector::Y)*Up.internalField()[i].component(vector::Z);
UpOUp.internalField()[i].component(symmTensor::ZZ) = Up.internalField()[i].component(vector::Z)*Up.internalField()[i].component(vector::Z);
}
forAll( Up.boundaryField(), boundaryI)
{
forAll( Up.boundaryField()[boundaryI], i)
{
UpOUp.boundaryField()[boundaryI][i].component(symmTensor::XX) = Up.boundaryField()[boundaryI][i].component(vector::X)*Up.boundaryField()[boundaryI][i].component(vector::X);
UpOUp.boundaryField()[boundaryI][i].component(symmTensor::XY) = Up.boundaryField()[boundaryI][i].component(vector::X)*Up.boundaryField()[boundaryI][i].component(vector::Y);
UpOUp.boundaryField()[boundaryI][i].component(symmTensor::XZ) = Up.boundaryField()[boundaryI][i].component(vector::X)*Up.boundaryField()[boundaryI][i].component(vector::Z);
UpOUp.boundaryField()[boundaryI][i].component(symmTensor::YY) = Up.boundaryField()[boundaryI][i].component(vector::Y)*Up.boundaryField()[boundaryI][i].component(vector::Y);
UpOUp.boundaryField()[boundaryI][i].component(symmTensor::YZ) = Up.boundaryField()[boundaryI][i].component(vector::Y)*Up.boundaryField()[boundaryI][i].component(vector::Z);
UpOUp.boundaryField()[boundaryI][i].component(symmTensor::ZZ) = Up.boundaryField()[boundaryI][i].component(vector::Z)*Up.boundaryField()[boundaryI][i].component(vector::Z);
}
}
the issue it is that it seems that set member does not follows this syntax, since I get as error

Quote:
error: invalid use of non-static member function
to the line of
Quote:
dimensionSet(0,2,-2,0,0,0,0)
So summarizing does anybody knows how to initialize a symmTensor on the fly? As well, if anybody has a better idea to compute the fields an after feed fieldAverage is also welcome.

Thank you very much.
jsagg is offline   Reply With Quote

Old   August 12, 2016, 11:45
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi,

to initialize a symmTensorField:

Code:
//- Create a symmTensorField with 100 entries
symmTensorField a(100);

forAll(a, i)
{
    a[i] = symmTensor(1,2,3,4,5,6);
}

// or simpler
symmTensorField a(100, symmTensor(1,2,3,4,5,6));
By the way, why you want to write the tensor field? The only logical stuff would be, that you have an own post-processing tool that can handle that information.
gu1 and shiyu like this.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   January 9, 2019, 09:02
Default
  #3
gu1
Senior Member
 
Guilherme
Join Date: Apr 2017
Posts: 245
Rep Power: 10
gu1 is on a distinguished road
Tobi,

I would like to know how to extract the xy element from the strain rate tensor:

Quote:
volSymmTensorField D = symm(fvc::grad(U()));
Could you help me write the code?
I wrote like this:

Quote:
forAll(D , i)
{
Dxy = D[i].xy();
}
...but:
Quote:
error: ‘Dxy’ was not declared in this scope Dxy = D[i].xy();
I used Dxy wanting it to be a variable and I could use that value stored in snippets of other equations.

ty
gu1 is offline   Reply With Quote

Old   January 9, 2019, 12:12
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi, you have to define the variable before.

Code:
// Option 1 
forAll(D , i)
{
    const Dxy = D[i].xy();

    //- Use Dxy inside the forAll loop
}

// Option 2
scalarField Dxy(0, D.size());      // Not sure if the initialization is correct, but should be

forAll(D , i)
{
    const Dxy[i] = D[i].xy();
}

//- Use Dxy outside the forAll loop
Hope it helps.
gu1 likes this.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   January 9, 2019, 13:19
Default
  #5
gu1
Senior Member
 
Guilherme
Join Date: Apr 2017
Posts: 245
Rep Power: 10
gu1 is on a distinguished road
Quote:
Originally Posted by Tobi View Post

Hope it helps.
Thanks Tobi,

It worked, but I did it "differently", because I need to extract those values later.
However, I noticed that the gradient on the wall (Dxy) is giving zero, which is not right, since I need tauxy. I have attached the snippet of my code, maybe you can help me in this 'error'.

Quote:
Dxy_
(
IOobject
(
IOobject::groupName("Dxy", U.group()),
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
U.mesh(),
dimensionSet(0, 0, -1, 0, 0, 0, 0)
),

volSymmTensorField D = symm(gradU);

forAll(D , i)
{
Dxy_[i] = D[i].xy();
}
And for this reason I have floating point error.

Quote:
boundaryField
{
walls
{
type calculated;
value nonuniform List<scalar>
80
(
6.94742323e-310
6.94742323e-310
1.69314479e-316
1.69314479e-316
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
5.13828272e-321
1.02765654e-321
6.94742436e-310
0
0
1.69319894e-316
5.92878775e-323
5.98652015e+175
8.90145759e-315
0
6.94742436e-310
1.6932689e-316
4.39718425e-322
4.39718425e-322
0
1.69325901e-316
1.69325901e-316
0
2.71615461e-312
1.69320724e-316
1.70249014e-316
0
0
0
0
0
0
6.17087992e-321
1.70279053e-316
6.94742323e-310
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
)
;
}
frontAndBack
{
type empty;
}
inlet
{
type cyclic;
}
outlet
{
type cyclic;
}
}
gu1 is offline   Reply With Quote

Old   April 22, 2023, 07:21
Default symmTensorField + codedFixedValue
  #6
Member
 
Join Date: Apr 2019
Location: India
Posts: 81
Rep Power: 7
Pavithra is on a distinguished road
Hi Everyone,

Is it possible to use codedFixedValue boundary condition to define boundary value of a symmTensor field ?

I am working on rheoTool and I need to set Poiseuille stress profile at the inlet.

Code:
    inlet
    {
	type            codedFixedValue;
	value		uniform (0 0 0 0 0 0);
	
	name 		poisStress;
	
	code
	#{
			const vectorField& Cf = patch().Cf();
			vectorField& field = *this;
			
			const scalar q = 1e-06;
			const scalar h0 = 0.4e-03;
			const scalar l = 0.4e-03;
					
			forAll(Cf, faceI)
			{
				const scalar y = Cf[faceI][1];
				
				field[faceI] = symmTensor((1 + 4.50 * ((l*q*y)/(h0*h0*h0)) * ((l*q*y)/(h0*h0*h0))),(-(3*l*q*y)/(2*h0*h0*h0)),0,1,0,0);
			}
			
	#};       
    }
This is what I have tried and I am geting the following error.

Code:
Using dynamicCode for codedFixedValue poisStress at line 24 in "/home/pavi/OpenFOAM/pavi-9/run/De03/0/tau/boundaryField/inlet"
Creating new library in "dynamicCode/poisStress/platforms/linux64GccDPInt32Opt/lib/libpoisStress_abc86e80ab96b5188231ac88cede6087b6e5bd77.so"
"/opt/openfoam9/etc/codeTemplates/dynamicCode/codedFixedValueFvPatchFieldTemplate.C" "/home/pavi/OpenFOAM/pavi-9/run/De03/dynamicCode/poisStress/codedFixedValueFvPatchFieldTemplate.C"
"/opt/openfoam9/etc/codeTemplates/dynamicCode/codedFixedValueFvPatchFieldTemplate.H" "/home/pavi/OpenFOAM/pavi-9/run/De03/dynamicCode/poisStress/codedFixedValueFvPatchFieldTemplate.H"
Invoking "wmake -s libso /home/pavi/OpenFOAM/pavi-9/run/De03/dynamicCode/poisStress"
wmake libso /home/pavi/OpenFOAM/pavi-9/run/De03/dynamicCode/poisStress
    ln: ./lnInclude
    wmkdep: codedFixedValueFvPatchFieldTemplate.C
    Ctoo: codedFixedValueFvPatchFieldTemplate.C
/home/pavi/OpenFOAM/pavi-9/run/De03/0/tau/boundaryField/inlet: In member function ‘virtual void Foam::poisStressFixedValueFvPatchSymmTensorField::updateCoeffs()’:
/home/pavi/OpenFOAM/pavi-9/run/De03/0/tau/boundaryField/inlet:32:25: error: invalid initialization of reference of type ‘Foam::vectorField&’ {aka ‘Foam::Field<Foam::Vector<double> >&’} from expression of type ‘Foam::poisStressFixedValueFvPatchSymmTensorField’
/home/pavi/OpenFOAM/pavi-9/run/De03/0/tau/boundaryField/inlet:42:42: error: no match for ‘operator=’ (operand types are ‘Foam::Vector<double>’ and ‘Foam::symmTensor’ {aka ‘Foam::SymmTensor<double>’})
I understand that the error message states that I am initializing a vector field as a tensor field. Someone please help me with the right syntax.

Thank You.
Pavithra is offline   Reply With Quote

Reply

Tags
controldict, fieldaverage, function, initialization, tensor


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
[blockMesh] edges not aligned with or perpendicular to non-empty directions ynos OpenFOAM Meshing & Mesh Conversion 6 March 26, 2020 16:02
Question about Initialization of Signed Distance Function (LEVEL SET) jl21_87 Main CFD Forum 0 January 10, 2012 22:50
channelFoam for a 3D pipe AlmostSurelyRob OpenFOAM 3 June 24, 2011 14:06
Compilation errors in ThirdPartymallochoard feng_w OpenFOAM Installation 1 January 25, 2009 07:59
Problem with compile the setParabolicInlet ivanyao OpenFOAM Running, Solving & CFD 6 September 5, 2008 21:50


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