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/)
-   -   Copy boundaryField into adjacent cell (https://www.cfd-online.com/Forums/openfoam-programming-development/200600-copy-boundaryfield-into-adjacent-cell.html)

ec91 April 7, 2018 23:23

Copy boundaryField into adjacent cell
 
Hello everyone,

I have a volScalarField E, and I need to copy the boundary field (i.e., the value defined as bc in the 0 folder) into the cells adjacent to the boundary.

In other words, for every patch and for every face of the patch:

internalField of E = boundary field of E, for that patch and that face.

I tried different solutions, but I deleted them since none of them worked.

Someone can help me?

Thank you and best regards.

piu58 April 8, 2018 01:22

One easy solution may be:

Let the simulation run for a sohrt time. In the result folder you find a result for your fields. This replaces the original "internal field uniform .." line.

Analyze this field to find out which values belongs to which part of the geometry. If you use blockMesh und your geometry is not very complicated, this is not an hard task.

Write a little program in any programming language which sets the initial field the way you need it.

ec91 April 8, 2018 05:34

Thanks Uwe,

but the mesh is complex and I need some loop who does it automatically. I was trying this one, but it doesn't work:

Code:

forAll (mesh.boundaryMesh(), patchI)
{   
    forAll (mesh.boundaryMesh()[patchI], faceI)
    {
        label ownerI = mesh.faceOwner()[faceI];
        E[ownerI] = E.boundaryField()[patchI][faceI];    //E is the volScalarField I want to modify

    }
}

but it doesn't work at all. It loop over the patches, in every patch he misses a lot of faces and at some point I have a segmentation error.

The boundaryFields containes eiher zeros or positive numbers (they are ficedValue BC's).

Any idea?

Thanks.

jherb April 8, 2018 08:35

You are probably looking for the method patchInternalField(). Here is an example (actually doing the opposite of what you want to do: Set the boundary values based on the internal values): https://github.com/OpenFOAM/OpenFOAM...FvPatchField.C

Jibran April 13, 2018 05:50

Quote:

Originally Posted by ec91 (Post 688016)
Thanks Uwe,

but the mesh is complex and I need some loop who does it automatically. I was trying this one, but it doesn't work:

Code:

forAll (mesh.boundaryMesh(), patchI)
{   
    forAll (mesh.boundaryMesh()[patchI], faceI)
    {
        label ownerI = mesh.faceOwner()[faceI];
        E[ownerI] = E.boundaryField()[patchI][faceI];    //E is the volScalarField I want to modify

    }
}

but it doesn't work at all. It loop over the patches, in every patch he misses a lot of faces and at some point I have a segmentation error.

The boundaryFields containes eiher zeros or positive numbers (they are ficedValue BC's).

Any idea?

Thanks.

Hi,

I think this should do the job for you

Code:

forAll(mesh.boundary(), patchI)
{   
    forAll(mesh.boundaryMesh()[patchI],faceI)
    {
        const label& bCellID = mesh.boundaryMesh()[patchI].faceCells()[faceI];             
        E[bCellID] = E.boundaryField()[patchI][faceI];                           
    }   
}



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