Skip to content

Unexpected behaviour after using SolverInterface destructor #378

@Dominanz

Description

@Dominanz

I have experienced a problem when allocating a SolverInterface object dynamically. The following lines of code reproduce my observation (at least on my machine):

SolverInterface* interface;
interface = new SolverInterface("SolverOne",0,1);
interface->configure("precice-config.xml");
delete interface;
interface = new SolverInterface("SolverOne",0,1);
interface->configure("precice-config.xml");

When doing this together with the config from the solverdummies, preCICE throws the following error:
Participant "SolverTwo" can read/write data "Velocities" only once!

I suspect that this behaviour is unintended. I would expect that, after destroying the old SolverInterface and deallocating its memory, I can allocate a new instance of SolverInterface and configure it again.
Searching the code of preCICE, I found that the error is thrown here. My guess would be that the destructor of the SolverInterface class doesn't work properly. It seems that the second SolverInterface created in the example code above encounters remnants of the previous one, causing it to throw the error.

This problem is probably very uncommon, since SolverInterfaces are allocated statically in most examples I have seen, so they are only destructed once the program exits anyway.
However, I encountered this problem while working on MATLAB bindings, where working with pointers is not really evitable. Since exiting MATLAB means ending the session, I encounter the problem whenever I try to run a program coupled with preCICE repeatedly in the same MATLAB session, which is very annoying (especially for testing and debugging). Therefore, I'd really appreciate a fix or a suggestion on how to prevent this error.

Thanks for any help!

Metadata

Metadata

Assignees

Labels

bugpreCICE does not behave the way we want and we should look into it (and fix it if possible)

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions