Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Why is FortranModule a Singleton? #223

Open
smiet opened this issue Aug 6, 2024 · 1 comment
Open

Question: Why is FortranModule a Singleton? #223

smiet opened this issue Aug 6, 2024 · 1 comment

Comments

@smiet
Copy link
Contributor

smiet commented Aug 6, 2024

I see that the FortranModule class is implemented with __metaclass__=Singleton, such that only one instance can be created.

This creates some issues, if on the python side I want to do things like mymodule1 = mycode.mycode_f90wrapped and mymodule2 = mycode.mycode_f90wrapped.

We are using the FORTRAN module in optimization, and it would be nice to have several instances in memory at the same time, for example to: compare differences between initial and final state; plot the properties of two different objects in one script; run the fortran code with slightly different initial parameters.

The class docstring says

class FortranModule(object):
    """
    Baseclass for Fortran modules

    Metaclass is set to Singleton, so only one instance of each subclass of
    FortranModule can be created.
    """"

Before I go barking at the wrong dead horse, and trying to modify the code to allow for several instances, I wanted to ask what lead to the design choice to implement the module as a Singleton, and if there are insurmountable obstacles to allowing for several top-level modules of f90wrapped modules in python.

@jameskermode
Copy link
Owner

Fortran modules really are singletons, that is all module data is stored only once in memory. This is why I chose to mirror this in Python. If you want several different instances in memory, you will need to use a Fortran derived type, not a module. There is no problem with having multiple instances of FortranDerivedType since this does not implement the singleton pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants