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

Deletion of volScalarField object in PimpleFoam Solver

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 8, 2018, 11:53
Default Deletion of volScalarField object in PimpleFoam Solver
  #1
New Member
 
Muhammad Arslan Ansari
Join Date: Aug 2018
Posts: 1
Rep Power: 0
m.arslansadiq is on a distinguished road
Hi,
I am rather new to OpenFOAM and currently I am working with PimpleFoam solver. For Testing purposes I have created a test field with the object named Test, besides pressure (p) and valocity (U) in createFields.H file. Now the thing is, after I finish my simulations I want to delete the test object of volScalarField. Now if I use the simple delete() function, the error which pops up, states that:

error: type ‘Foam::volScalarField {aka class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ argument given to ‘delete’, expected pointer
delete(Test);

Any suggestions how would I take care of this memory leak?

It is not important for the task which I am trying to do, but it would be nice to know about efficient memory management in OpenFOAM.
m.arslansadiq is offline   Reply With Quote

Old   August 9, 2018, 17:01
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Augsburg
Posts: 2,542
Blog Entries: 6
Rep Power: 46
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi,


a normal variable such as

Code:
int myNumber;
double myDouble;
scalarField foo;
will be destroyed automatically after the validity of the variables is not valid anymore. That means, the memory allocation and deallocation is done automatically. The delete function is used with pointers such as:


Code:
double* myDouble;
A pointer does allocate memory to store the pointer but the pointer points to some memory. In order to prohibit errors, you first should initialize the pointer with NULL or direct allocate memory and tell the pointer to point to the new allocated memory.

To deallocate the memory, you can use the delete function. Again, the volScalarField is not a pointer. To make it a pointer, you have to do it in a different way such as:


Code:

volScalarField* myNewField = new volScalarField(...);


.
.
.
.


 myNewField->delete();


// Or

delete(myNewField);
The code might be wrong - its just out of the box, but somehow like that. However, it is better to use smartPointer in C++. FOAM has a pointer class called autoPtr<>.

Summing up. The problem you have is a pure C++ problem. Not related to FOAM.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Reply

Tags
memoryleak, pimplefoam, volscalarfield

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Population Balance Modeling (PBM) - Ansys Fluent chittipo FLUENT 155 June 14, 2021 08:14
Star cd es-ice solver error ernarasimman STAR-CD 2 September 12, 2014 00:01
[General] 2 datas on one plot Akuji ParaView 46 December 1, 2013 14:06
engineFoam with layers - pressure problems when adding layers mturcios777 OpenFOAM Running, Solving & CFD 22 October 17, 2013 02:52
[OpenFOAM] Annoying issue of automatic "Rescale to Data Range " with paraFoam/paraview 3.12 keepfit ParaView 60 September 18, 2013 03:23


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