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/)
-   -   Vector Center Face ---> Cells (https://www.cfd-online.com/Forums/openfoam-programming-development/179766-vector-center-face-cells.html)

FlyBob91 November 7, 2016 04:53

Vector Center Face ---> Cells
 
Hello to all,
i'm going to modify the equations at the boundary to run an adjoint simulation.
One of these equations includes a term r which is defined as the position vector starting from the center of the outlet surface.
I know the face center can be accessed by the function Cf() but i don't know how to set it for the entire outlet boundary and for the single cell.
Could someone help me defyning it?

Thanks for help,
Roberto

FlyBob91 November 9, 2016 09:21

Sorry for Bump,
i have not resolved the problem yet

here my equation:

Code:

u_tw = 1/(v_n - nu/h)*(-nu/h*u_(tw-1) + 2*(n x r)/|| r x v_t ||^(3) )
and here what i implemented

Code:

void Foam::adjointOutletVelocityFvPatchVectorField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

//    const fvsPatchField<scalar>& phiap =
//        patch().lookupPatchField<surfaceScalarField, scalar>("phia");

    const fvPatchField<vector>& Up =
        patch().lookupPatchField<volVectorField, vector>("U");

    const fvPatchField<vector>& Uap =
        patch().lookupPatchField<volVectorField, vector>("Ua");

    const scalarField& deltainv = patch().deltaCoeffs(); // Distance^(-1)

    vectorField Uaneigh  = Uap.patchInternalField();              // Vettore
    vectorField Uaneigh_n = (Uaneigh & patch().nf())*patch().nf();  // Normale
    vectorField Uaneigh_t = Uaneigh - Uaneigh_n;                    // Tangente

    vectorField Up_n = (Up & patch().nf())*patch().nf();  // Normale
    vectorField Up_t = Up - Up_n;                        // Tangente

    scalarField U_t = mag(Up_t);
    scalarField U_n = mag(Up_n);

    vectorField n = patch().nf();

 
    scalar nu = readScalar(db().lookupObject<IOdictionary>("transportProperties").lookup 
    ("nu"));

    vectorField :: operator = (1 /(U_n - nu * deltainv) * (-nu * Uaneigh_t * deltainv + 2*(n^Uaneigh) / pow (mag(Uaneigh ^ Up_t),3)));

    fixedValueFvPatchVectorField::updateCoeffs();
}


I have only to define r

FlyBob91 November 10, 2016 05:39

Hi again,

Can i use something like this? Is it right for my scope?

Code:

vectorField r = patch().Cf()-(10 15 30);
Where
Code:

patch().Cf()
is the face cell center (if i understood the command) coordinates and (10 15 30) the center coordinates of my boundary. Unfortunately it gives me an error i think it could derived from how i define the vector (10 15 30);


Regards,
Roberto

anishtain4 November 14, 2016 13:41

Hi,
To get the center of the patch try using a bounding box, then average the limits. it would be your center. For the code you have up there, change it to this:

Quote:

vectorField r = patch().Cf()-vector(10 15 30);

FlyBob91 November 15, 2016 05:29

Hi Mahdi, thanks for your reply.
Your solution is almost perfect but it's necessary to insert a comma between the elements vectors.

Code:

vectorField r = patch().Cf()-vector(10,15,30);
Many thanks.

Best Regards,
Roberto


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