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

How to change fvPatchField type of volume Field

Register Blogs Community New Posts Updated Threads Search

Like Tree10Likes
  • 8 Post By zhulianhua
  • 2 Post By Garysimpson

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 4, 2014, 10:52
Default How to change fvPatchField type of volume Field
  #1
Member
 
Lianhua Zhu
Join Date: Aug 2011
Location: Wuhan, China
Posts: 35
Rep Power: 15
zhulianhua is on a distinguished road
Hi, all!

How can I change the patchField type of a specific patch?
I need to do this because for the calculated temporary field, all of the patch is set to "calculated" automatically, except those "empty" type. For example:
Code:
    volScalarField p
    (
        IOobject
        (
            "p",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );
    Info << "=================Field p ====================" << endl;
    Info << p << endl;

    volScalarField a = 2*p;
    Info << "=================Field a ====================" << endl;
    Info << a << endl;

The output would be:
Code:
=================Field p ====================
dimensions      [0 2 -2 0 0 0 0];

internalField   uniform 0;

boundaryField
{
    movingWall
    {
        type            fixedValue;
        value           uniform 7;
    }
    fixedWalls
    {
        type            fixedValue;
        value           uniform 1;
    }
    frontAndBack
    {
        type            empty;
    }
}

=================Field a ====================
dimensions      [0 2 -2 0 0 0 0];

internalField   uniform 0;

boundaryField
{
    movingWall
    {
        type            calculated;
        value           uniform 14;
    }
    fixedWalls
    {
        type            calculated;
        value           uniform 2;
    }
    frontAndBack
    {
        type            empty;
    }
}
Problem 1.How can I change the "calculated" type to "FixedValueFvPatchField"?

After reading the souce code of GeometricField class, I have tried to construct the a object with the patchFields of p to circumvent this problem, but failed to compile it.
The code is:
Code:
    volScalarField a
    (
        IOobject
        (
            "a",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh,
        p.dimensions(),
        scalar(0),
        p.boundaryField()
    );
which I think uses this construct function of the GeometricField Class:
Code:
Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
(
	const Foam::IOobject&, 
	const typename GeoMesh::Mesh&, 
	const Foam::dimensionSet&, 
	const Foam::Field<Type>&,
	const Foam::PtrList<PatchField<Type> >&
)
But the compiler says:
Code:
No matching function for call to 

Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField
(
	Foam::IOobject, 
	Foam::fvMesh&, 
	Foam::dimensionSet&, 
	Foam::scalar, 
	Foam::GeometricField<double, Foam::fvPatchField, 
        Foam::volMesh>::GeometricBoundaryField&
)
The problems seems to be that the GeometricBoundaryField type can not be cast to PtrList<PatchField<Type>, but as far as I can know, the GeometricBoundaryField is inherited from the FieldField<PatchField, Type> , which is inherited from the PtrList<Field<Type> >.
So:
Problem 2. How to use this Constructing function properly?

Sorry for the long post...

Any information would be great!

Bests,

Lianhua
zhulianhua is offline   Reply With Quote

Old   August 5, 2014, 09:08
Default
  #2
Member
 
Lianhua Zhu
Join Date: Aug 2011
Location: Wuhan, China
Posts: 35
Rep Power: 15
zhulianhua is on a distinguished road
I found the answer for the Problem 1.

suppose patchi is the patch I want to change to PatchField type, and name is the
PatchField type name. I can simply do this:

Code:
a.boundaryField().set(patchi, fvPatchField<scalar>::New(name, mesh.boundary()[patchi], a));
After assigning the PatchField type, I may want to assign the PatchField value. For example, After I set the patch 0 to fixedValue type, I want to assign the boundary filed value the the patch, than I can do this :
Code:
  a.boundaryField()[0][0] = 1; //first boundary face of the 0th patch
  a.boundaryField()[0][1] = 2; //first boundary face of the 0th patch
  a.boundaryField()[0][2] = 3;
  ...
or patch a uniform boundary field by:
Code:
  a.boundaryField()[0] == 4;
Reply to myself here just to help those new users who may encounter the same problem as I do.

Lianhua.
zhulianhua is offline   Reply With Quote

Old   August 23, 2018, 12:40
Default
  #3
Senior Member
 
Reviewer #2
Join Date: Jul 2015
Location: Knoxville, TN
Posts: 141
Rep Power: 11
randolph is on a distinguished road
Quote:
Originally Posted by zhulianhua View Post
Hi, all!

How can I change the patchField type of a specific patch?
I need to do this because for the calculated temporary field, all of the patch is set to "calculated" automatically, except those "empty" type. For example:
Code:
    volScalarField p
    (
        IOobject
        (
            "p",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );
    Info << "=================Field p ====================" << endl;
    Info << p << endl;

    volScalarField a = 2*p;
    Info << "=================Field a ====================" << endl;
    Info << a << endl;

The output would be:
Code:
=================Field p ====================
dimensions      [0 2 -2 0 0 0 0];

internalField   uniform 0;

boundaryField
{
    movingWall
    {
        type            fixedValue;
        value           uniform 7;
    }
    fixedWalls
    {
        type            fixedValue;
        value           uniform 1;
    }
    frontAndBack
    {
        type            empty;
    }
}

=================Field a ====================
dimensions      [0 2 -2 0 0 0 0];

internalField   uniform 0;

boundaryField
{
    movingWall
    {
        type            calculated;
        value           uniform 14;
    }
    fixedWalls
    {
        type            calculated;
        value           uniform 2;
    }
    frontAndBack
    {
        type            empty;
    }
}
Problem 1.How can I change the "calculated" type to "FixedValueFvPatchField"?

After reading the souce code of GeometricField class, I have tried to construct the a object with the patchFields of p to circumvent this problem, but failed to compile it.
The code is:
Code:
    volScalarField a
    (
        IOobject
        (
            "a",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh,
        p.dimensions(),
        scalar(0),
        p.boundaryField()
    );
which I think uses this construct function of the GeometricField Class:
Code:
Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
(
	const Foam::IOobject&, 
	const typename GeoMesh::Mesh&, 
	const Foam::dimensionSet&, 
	const Foam::Field<Type>&,
	const Foam::PtrList<PatchField<Type> >&
)
But the compiler says:
Code:
No matching function for call to 

Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField
(
	Foam::IOobject, 
	Foam::fvMesh&, 
	Foam::dimensionSet&, 
	Foam::scalar, 
	Foam::GeometricField<double, Foam::fvPatchField, 
        Foam::volMesh>::GeometricBoundaryField&
)
The problems seems to be that the GeometricBoundaryField type can not be cast to PtrList<PatchField<Type>, but as far as I can know, the GeometricBoundaryField is inherited from the FieldField<PatchField, Type> , which is inherited from the PtrList<Field<Type> >.
So:
Problem 2. How to use this Constructing function properly?

Sorry for the long post...

Any information would be great!

Bests,

Lianhua
change the p.boundaryField() to p.boundaryField().types() should do the job.
randolph is offline   Reply With Quote

Old   October 2, 2018, 05:44
Default
  #4
New Member
 
Y H Tang
Join Date: Nov 2014
Posts: 2
Rep Power: 0
Garysimpson is on a distinguished road
Hi Lianhua,
Thanks for your self-reply. It enlightened me to look more into run time change of boundary conditions, so that now it all be done on-the-fly IN PARALLEL without the annoying reconstruction-change-decompose every time

The setting of boundary patch type you explained is very useful. However, for some reason your method of assigning the value at each boundary mesh surface is not working for me, which leads to solution singularity.

I assume the problem is that the face value is only enforced at the moment of the assignment, while the original b.c. is still applied when the partial differential equations later being solved. So I did some research myself, and I found that to change the boundary value, a good way is to use refCast, e.g.
Code:
label patchID = mesh.boundaryMesh().findPatchID("ports");
fixedValueFvPatchVectorField& UPatch = refCast<fixedValueFvPatchVectorField>(U.boundaryField()[patchID]);
vectorField& UField = UPatch;
UField = -10.0*mesh.Sf().boundaryField()[patchID]/mesh.magSf().boundaryField()[patchID];
So the above code would be equivalent to use SurfaceNormalFixedValue=-10 at the boundary named "ports". Notice the negative sign means inward to the domain.

Now I'm posting this reply and hope that someday, and that day may never come, someone will find it useful. Not sure this is the best way to do, but it definitely works for my case. GLTA

Below are ref. threads where I learned all these:
A general openfoam development question about boundary condition
Neumann boundary conditions
randolph and Michael@UW like this.
Garysimpson 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
Why Menter's SST model low-Re issue has not been seriously investigated? vkrastev OpenFOAM 58 January 8, 2018 16:20
interFoam/kOmegaSST tank filling with printStackError/Mules simpomann OpenFOAM Running, Solving & CFD 3 February 17, 2014 18:06
singularity? mihaipruna OpenFOAM Running, Solving & CFD 5 April 24, 2012 18:18
[blockMesh] BlockMesh FOAM warning gaottino OpenFOAM Meshing & Mesh Conversion 7 July 19, 2010 15:11
[blockMesh] Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Meshing & Mesh Conversion 10 April 2, 2007 15:00


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