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

Create vector from cell center to cell vertex

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 12, 2021, 06:22
Default Create vector from cell center to cell vertex
  #1
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
Hello everybody,

for a new hybrid turbulence model I want to code a new subgrid length scale delta where delta is defined as follows:

delta = (1 / sqrt(3)) * max | (I_n - I_m) | where n,m = 1,8 and stand for the vertices of a cell.

I_n is defined as follows and is the cross product of the vorticity vector and the vector from the cell center to the cell vertex:

I_n = n x r_n

Now I am looking for an efficient way of defining the new subgrid length scale. Since the vectors of the cell center to the cell vertices are constant I thought about saving them in a list in the createFields part and then call them in the solver. But I don't know how to realize it yet why I am asking you for your help. How do you think could the code be implemented and be structured? I am looking forward for your help. If you need additional information please let me know.

Many thanks and best regards,
Daniel

CFDanielGER is offline   Reply With Quote

Old   May 17, 2021, 04:37
Default
  #2
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
Anyone with an idea how to create vectors from cell center to cell vertices?
CFDanielGER is offline   Reply With Quote

Old   May 17, 2021, 06:56
Default
  #3
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
For each cell you can assess the labels of the points building the cell. See e.g. Point labels associated with a cell

The rest is up to you
mAlletto is offline   Reply With Quote

Old   May 17, 2021, 12:21
Default
  #4
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
My current implementation looks like this but I get some errors when creating the vectors r_n and I_n and r_m / I_m respectively.

Code:
template<class BasicTurbulenceModel>
tmp<volScalarField> SAEDES<BasicTurbulenceModel>::deltaOmega
(

) const
{
  volVectorField vorticity = fvc::curl(this->U());
  volScalarField magVorticity = mag(vorticity);
  volVectorField vorticityUnit = vorticity / magVorticity;

  const polyMesh& pMesh = this->mesh();
  const pointField& p = pMesh.points();
  volVectorField cellCenter = this->mesh().C();

  forAll(cellCenter, celli)
  {
    const labelList& cellPts = this->mesh().cellPoints()[celli];

    forAll(cellPts, pointi)
    {
      vector rn[pointi](cellCenter[celli].x() - p[cellPts[pointi]].x(), cellCenter[celli].y() - p[cellPts[pointi]].y(), cellCenter[celli].z() - p[cellPts[pointi]].z());

      volVectorField In[pointi] = (vorticityUnit[celli]  ^ rn[pointi]);

      forAll(cellPts, pointj)
      {
        vector rm[pointj](cellCenter[celli].x() - p[cellPts[pointj]].x(), cellCenter[celli].y() - p[cellPts[pointj]].y(), cellCenter[celli].z() - p[cellPts[pointj]].z());

        volVectorField Im[pointj] = (vorticityUnit[celli]  ^ rn[pointj]);
      }
    }

    volScalarField maxI[celli] = max(mag(In - Im));
  }

  return 1.0 / sqrt(3.0) * maxI;
}
The first loop loops over all cells, the second loop loops over all vertices for each cell and creates the vectors r_n (vector from the cell center to the cell vertices) and I_n (cross product of r_n with the vorticity vector). The third loop loops again over all vertices of each cell and creates r_m and I_m respectively. At the end of the first loop then the maximum of the difference between I_n and I_m is calculated.

I get following errors when creating I_m:
- array must be initialized with a brace-enclosed initializer

And some more errors when creating r_m and r_n respectively:
- array must be initialized with a brace-enclosed initializer
- expression list treated as compound expression in initializer [-fpermissive]
- value computed is not used [-Wunused-value]

Do you have an idea what the problem could be?

Many thanks for your help.

Best regards,
Daniel
CFDanielGER is offline   Reply With Quote

Old   May 17, 2021, 13:24
Default
  #5
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
Try to Google for the constructors of a vector and vectorfield in openfoam.
mAlletto is offline   Reply With Quote

Old   May 24, 2021, 10:56
Default
  #6
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
Thanks for your help, it is working now!
CFDanielGER is offline   Reply With Quote

Old   May 24, 2021, 11:04
Default
  #7
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
Can you post your solution here to help others who have the same problem
mAlletto is offline   Reply With Quote

Old   May 24, 2021, 11:07
Default
  #8
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
Sure, maybe not the "best" implementation but it is working

Code:
template<class BasicTurbulenceModel>
tmp<volScalarField> kOSSTEDES<BasicTurbulenceModel>::deltaOmega
(

) const
{
  volVectorField vorticity = fvc::curl(this->U());
  volScalarField magVorticity = mag(vorticity);
  volVectorField vorticityUnit = vorticity / magVorticity;

  const polyMesh& pMesh = this->mesh();
  const pointField& p = pMesh.points();
  volVectorField cellCenter = this->mesh().C();

  List<vector> In(8, vector::zero);
  List<vector> Im(8, vector::zero);

  volScalarField maxI
  (
    IOobject
    (
      "magI",
      this->mesh().time().timeName(),
      this->mesh(),
      IOobject::NO_READ,
      IOobject::NO_WRITE
    ),
    this->mesh(),
    dimensionedScalar("magI", dimensionSet(0, 1, 0, 0, 0, 0, 0), 0)
  );

  scalar previousMaxI = 0.0;

  forAll(cellCenter, celli)
  {
    const labelList& cellPts = this->mesh().cellPoints()[celli];

    forAll(cellPts, pointi)
    {
      label cellP = cellPts[pointi];
      vector pnt = p[cellP];
      vector rn(cellCenter[celli] - pnt);

      forAll(cellPts, pointj)
      {
        label cellP = cellPts[pointj];
        vector pnt = p[cellP];
        vector rm(cellCenter[celli] - pnt);

        In[pointj] = vorticityUnit[celli]  ^ rn;
        Im[pointj] = vorticityUnit[celli]  ^ rm;
      }

      maxI[celli] = max(max(mag(In - Im)), previousMaxI);

      previousMaxI = maxI[celli];

    }

  }

  return 1.0 / sqrt(3.0) * maxI;
CFDanielGER 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
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 11:04
UDF in case with DPM modle POSTHU Fluent UDF and Scheme Programming 0 March 3, 2021 07:21
[blockMesh] --> foam fatal error: lillo763 OpenFOAM Meshing & Mesh Conversion 0 March 5, 2014 10:27
Actuator disk model audrich FLUENT 0 September 21, 2009 07:06
Warning 097- AB Siemens 6 November 15, 2004 04:41


All times are GMT -4. The time now is 06:21.