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/)
-   -   Access to field which is evaluated at the moment (https://www.cfd-online.com/Forums/openfoam-programming-development/186205-access-field-evaluated-moment.html)

Tobi April 12, 2017 17:51

Access to field which is evaluated at the moment
 
Hey everybody,

after a lot of suggestions from Philip Cardiff, I implement non-orthogonal corrections to the symmetry patches. In foam-extend it is straight forward and it is already implemented. However in FOAM-4.x it was not as straight forward than in extend or maybe I did it in an complex way. However, I build my own solidSymmetric boundary condition. Based on the fact that the class is a template one, I have to make some checks:
  • Displacement field -> do non-ortho corrections
  • Temperature field -> don't do non-ortho corrections (or differently)
Example given. The surface normal gradient function is given as:
Code:

template<class Type>                                                           
Foam::tmp<Foam::Field<Type>>                                                   
Foam::solidSymmetryFvPatchField<Type>::snGrad() const                         
{                                                                                                                                 
    const vectorField nHat(this->patch().nf());                               
                                                                               
    Field<Type> iF(this->patchInternalField());                               
                                                                               
    //- Non-orthogonal correctors   

    if ("Displacement field")
    {                                       
        vectorField delta(this->patch().delta());                                 
        vectorField k = delta - nHat * (nHat & delta);                             
                                                                               
        const fvPatchTensorField& gradD =                                         
        this->patch().template lookupPatchField<volTensorField, tensor>       
        (                                                                     
            "grad(D)"                                                         
        ); 



        //- Correct iF
        iF ...                                                                 
    }                         
                                                                               
    return                                                                     
        (transform(I - 2.0*sqr(nHat), iF) - iF)                               
      *(this->patch().deltaCoeffs()/2.0);                                     
}

As you can see, I need some check if the actual field is the displacement field but I could not figure out how I can check the field name from the patch here. I went through Doxygen to figure out which class could have access to the field name (T, D, ...) but could not find anything till now. Does anyone does know how to get access which volField is calling the function at the moment?


Any feedback would be warmly welcomed and I hope I pointed out what I want to do.

Tobi April 12, 2017 18:07

Okay solved in an easy way. I added a boolean for switching on and off the nonOrthoCorrection in the boundary of each field (default = false). So the solution is:
Code:

    //- Non-orthogonal correctors                                             
    if (nonOrthoCorrection_)                                                   
    {                                                                         
        vectorField delta(this->patch().delta());                             
        vectorField k = delta - nHat * (nHat & delta);                         
                                                                               
        const fvPatchTensorField& gradD =                                     
            this->patch().template lookupPatchField<volTensorField, tensor>   
            (                                                                 
                "gradD"                                                       
            );                                                                 
                                                                               
        const vectorField corrector = (k & gradD.patchInternalField());       
       
        //- PROBLEM                                                                     
        iF += corrector;                                                       
    }

However, the last problem is to cast the corrector into a <Type> form. The corrector loop is always done for a vector loop but based on the template I have to cast it somehow. Any idea, - tomorrow I will hopefully figure it out (maybe with some input of you).

Good night.

Tobi April 13, 2017 06:59

Hey all,

solved in the way that I derived a new class without using a template. Finally, now it is like in foam-extend but you have to take a bit more care (things are not 100% similar, as we would expect). Everything is working now :)

chriss85 April 19, 2017 03:16

Have you done any tests to check for the influence of this correction at the boundary?

Tobi April 19, 2017 03:33

Of course...


Sent from my HTC One mini using CFD Online Forum mobile app

chriss85 April 19, 2017 04:15

So, are there any relevant differences or is this a minor effect? I'm wondering if it's important to consider this when nonorthogonal meshes with symmetries are used.

Tobi April 19, 2017 13:09

To keep everything clear. I consider only solid stress calculation. And yes it accelerates the convergence. In fluid dynamics I would say, that you can not see the difference but I did not checked that.

Sent from my HTC One mini using CFD Online Forum mobile app


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