CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Taking the absolute value of a volVectorField or a volTensorField (https://www.cfd-online.com/Forums/openfoam/61021-taking-absolute-value-volvectorfield-voltensorfield.html)

kupiainen September 16, 2005 05:24

Hi, I wish to compute the abs
 
Hi,
I wish to compute the absolute value of a volVectorField gp componentwise. I have tried to loop over all cells:
forAll(centres, celli)
{
if ( gp[celli].x() < 0.0 )
{
gp[celli].x() = -gp[celli].x();
}
if ( gp[celli].y() < 0.0 )
{
gp[celli].y() = -gp[celli].y();
}
if ( gp[celli].z() < 0.0 )
{
gp[celli].z() = -gp[celli].z();
}
}

but when I take min(gp) it shows negative values. How does this work? What should I do instead?
best regards

hjasak September 16, 2005 07:22

Should be: volVectorField g
 
Should be:

volVectorField gpCmptMag = cmptMag(gp);

but it is not instantiated because it's not really appropriate for geometric fields. How about:

vectorField gpCmptMag = cmptMag(gp.internalField());

This gives you the internal part of the field.

Hrv

dela March 19, 2019 08:56

abs not working for me
 
Quote:

Originally Posted by hjasak (Post 189169)
Should be:

volVectorField gpCmptMag = cmptMag(gp);

but it is not instantiated because it's not really appropriate for geometric fields. How about:

vectorField gpCmptMag = cmptMag(gp.internalField());

This gives you the internal part of the field.

Hrv

I know this is an old thread but I am doing a similar thing without success. I am trying to find the absolute value of velocity U. I have tried all I can to no avail. Please help
I did "volVectorField U1CmptMag = Foam::cmptMag(U1);"

thank you

rsa July 25, 2019 13:00

Quote:

Originally Posted by dela (Post 728230)
I know this is an old thread but I am doing a similar thing without success. I am trying to find the absolute value of velocity U. I have tried all I can to no avail. Please help
I did "volVectorField U1CmptMag = Foam::cmptMag(U1);"

thank you


Hi Dela,

I am not sure if you have solved your problem or not but just in case:

cmptMag is not overloaded for volVectorField as the error message informs. So to overcome this problem you can do as follows:
First, define a new volVEctorField in the createFields.H like this:
volVectorField cmptMagU = U;
Then in the C-file you can add the following loop:
forAll ( U, index )
{
cmptMagU [ index ] = cmptMag ( U [ index ] );
}

This should work but I advise you to be cautious about the boundary cells. I would advise to use this on internalField() and take care of the boundary separately.

BR


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