CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Initialization of symmTensor by a coded function (https://www.cfd-online.com/Forums/openfoam-programming-development/176071-initialization-symmtensor-coded-function.html)

jsagg August 10, 2016 12:42

Initialization of symmTensor by a coded function
 
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.

Tobi August 12, 2016 10:45

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 January 9, 2019 08:02

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

Tobi January 9, 2019 11:12

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 January 9, 2019 12:19

Quote:

Originally Posted by Tobi (Post 721436)

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;
}
}

Pavithra April 22, 2023 06:21

symmTensorField + codedFixedValue
 
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.


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