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

Problem: Foam::fvMesh& in new class.

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 11, 2022, 04:45
Default Problem: Foam::fvMesh& in new class.
  #1
New Member
 
Zhang Yan
Join Date: Nov 2021
Posts: 15
Rep Power: 4
Erikaaa is on a distinguished road
Hi, Foamers!

I'm using openFoam v2106 to program a new C++ class.

In order to get access to cell centers. I set the variable [const Foam::fvMesh& B_mesh;] and use the function [const Foam::vectorField& meshCenters = B_mesh.cellCentres();].

in .H
Code:
const Foam::fvMesh& B_mesh;
in .C
Code:
const Foam::vectorField& meshCenters = mesh.cellCentres();
When I complie the new class alone, I get the following errors:
Code:
IBSystem.H:22:5: error: uninitialized reference member in ‘const class Foam::fvMesh&’ [-fpermissive]
   22 |     IBSystem()
      |     ^~~~~~~~
IBSystem.H:19:25: note: ‘const Foam::fvMesh& IBSystem::B_mesh’ should be initialized
   19 |     const Foam::fvMesh& B_mesh;
      |                         ^~~~~~
I don't know how to modify it. If someone can help me, I will be very grateful. Thank you!
Erikaaa is offline   Reply With Quote

Old   April 24, 2022, 12:21
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,695
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by Erikaaa View Post
Hi, Foamers!

I'm using openFoam v2106 to program a new C++ class.

In order to get access to cell centers. I set the variable [const Foam::fvMesh& B_mesh;] and use the function [const Foam::vectorField& meshCenters = B_mesh.cellCentres();].

in .H
Code:
const Foam::fvMesh& B_mesh;
in .C
Code:
const Foam::vectorField& meshCenters = mesh.cellCentres();
When I complie the new class alone, I get the following errors:
Code:
IBSystem.H:22:5: error: uninitialized reference member in ‘const class Foam::fvMesh&’ [-fpermissive]
   22 |     IBSystem()
      |     ^~~~~~~~
IBSystem.H:19:25: note: ‘const Foam::fvMesh& IBSystem::B_mesh’ should be initialized
   19 |     const Foam::fvMesh& B_mesh;
      |                         ^~~~~~
I don't know how to modify it. If someone can help me, I will be very grateful. Thank you!

If you have it as a reference, this is something that you will need to initialize when constructing your class, which means that you need to pass in a reference to the constructor.
Have you looked at any of the OpenFOAM source code? There are plenty of places using this type of thing.
olesen 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
area does not match neighbour by ... % -- possible face ordering problem St.Pacholak OpenFOAM 10 February 7, 2024 21:50
[OpenFOAM.com] Installing superThermo with Allwmake command Dekkers OpenFOAM Installation 0 January 28, 2022 05:32
Large problem partitioner tzy CFX 3 February 7, 2018 17:11
class element problem nellosamr OpenFOAM Programming & Development 3 September 11, 2017 06:42
natural convection problem for a CHT problem Se-Hee CFX 2 June 10, 2007 06:29


All times are GMT -4. The time now is 09:55.