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

Example of sending a struct over a Pstream?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 22, 2019, 16:07
Default Example of sending a struct over a Pstream?
  #1
New Member
 
Gavin Ridley
Join Date: Jan 2019
Location: Tennessee, USA
Posts: 25
Rep Power: 7
gridley2 is on a distinguished road
Hi all,


I am working on a solver where I have some structs (just a few pieces of data, about 5 integers and a handful of booleans) that sometimes need to be sent across processor boundaries. It's being used to track whether cells are in the vicinity of the liquid/gas interface in VOF calculations.



Can anyone point me to an example of sending a new struct or class using Pstreams? From what I have gathered, you just need to defined a operator>> and operator<< for the IPStream and OPstreams, but I seem to have made a mistake in doing this.


In particular, I'm confused about the order that stuff in the struct should be packed and unpacked into the Pstream. I can provide an example of what my current code looks like if needed. The specific error which arises is a segfault.
gridley2 is offline   Reply With Quote

Old   July 23, 2019, 12:03
Default
  #2
New Member
 
Gavin Ridley
Join Date: Jan 2019
Location: Tennessee, USA
Posts: 25
Rep Power: 7
gridley2 is on a distinguished road
For anyone else who encounters an issue with this, the solution is to make something look like this:
Code:
struct ProcessorRequest
{
    label swagLevel;
    label originalProcessor;
    label neighborProcessor;
    Pair<bool> result;
    bool done;
};

Ostream& operator<<(Ostream& os, const ProcessorRequest& pr)
{
    os << pr.swagLevel;
     << pr.originalProcessor;
     << pr.neighborProcessor;
     << pr.result;
     << pr.done;
    return os;
}

Istream& operator>>(Istream& is, ProcessorRequest& me)
{
    is >> me.swagLevel 

        >> me.originalProcessor 

        >> me.neighborProcessor
        >> me.depth
        >> me.result
        >> me.done;
    return is;

 }
Then it will go through Pstreams just like any other OpenFOAM primitive.
gridley2 is offline   Reply With Quote

Reply

Tags
pstream library, pstreams


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
big difference between clockTime and executionTime LM4112 OpenFOAM Running, Solving & CFD 21 February 15, 2019 04:05
long error when using make-install SU2_AD. tomp1993 SU2 Installation 3 March 17, 2018 07:25
Sending a large bufffer between processes (with Pstream?) knuckles OpenFOAM Programming & Development 4 January 11, 2016 20:55
Accessing phi from a fvPatchField at same patch johndeas OpenFOAM 1 September 13, 2010 21:23
[Netgen] Compiling Netgen on Fedora Core is driving me crazy jango OpenFOAM Meshing & Mesh Conversion 3 November 9, 2007 14:29


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