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/)
-   -   Reference to portions of a field (https://www.cfd-online.com/Forums/openfoam-programming-development/241649-reference-portions-field.html)

trailer March 10, 2022 13:51

Reference to portions of a field
 
Hello to all,

I would like to know if the following is possible:

If I create a tensorField:
Code:

volTensorField gradU = fvc::grad(U);       

tensorField gradU_Internal = gradU.internalField();

Is it possible to create a new vectorField with references to selective entries in the tensorField?



Code:

vectorField a = SomeFunctionToSelectTensorField(0,1,2);
vectorField b (gradU_Internal.size(), {3,3,3});
a += b; // should change the 0,1,2 entries in the tensorField.


Edit: To complement, a C++ example:


Code:

#include <vector>
#include <iostream>
using namespace std;

int main(int argc, char** argv)
{

    vector<double> a = {1,2,3,4,5};
    vector<std::reference_wrapper<double>> b ={a[0], a[1], a[2]};

    vector<double> c = {1,2,3};

    for(int i = 0; i < 3; i++)
    {
        b[i] += c[i];
    }

    cout << "Done" << endl;
  return(0);
}



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