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

Reference to portions of a field

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 10, 2022, 13:51
Default Reference to portions of a field
  #1
Member
 
Join Date: Mar 2021
Posts: 39
Rep Power: 5
trailer is on a distinguished road
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);
}

Last edited by trailer; March 11, 2022 at 05:57.
trailer 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
[swak4Foam] swakExpression not writing to log alexfells OpenFOAM Community Contributions 3 March 16, 2020 18:19
Domain Reference Pressure and mass flow inlet boundary AdidaKK CFX 75 August 20, 2018 05:37
Sig Density Based Solver installation with FOAM Extend 3.2 qjh888 OpenFOAM Bugs 0 September 21, 2016 08:16
OpenFoam-1.7.x on Suse 11.2 (64bit) does not compile val46 OpenFOAM Installation 4 August 27, 2010 03:43
Error with Wmake skabilan OpenFOAM Installation 3 July 28, 2009 00:35


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