From 2d95fb9af749ca5843f821f5e0788cd61bd698ae Mon Sep 17 00:00:00 2001 From: Sebastian Eibl <sebastian.eibl@fau.de> Date: Mon, 6 Jul 2020 10:57:05 +0200 Subject: [PATCH] fixed smaller formatting issues in mesa_pd --- python/mesa_pd/Module.py | 7 +++--- python/mesa_pd/__init__.py | 2 +- python/mesa_pd/data/ContactHistory.py | 6 ++--- python/mesa_pd/data/ContactStorage.py | 6 ++--- python/mesa_pd/data/LinkedCells.py | 1 - python/mesa_pd/data/ParticleStorage.py | 7 +++--- python/mesa_pd/data/ShapeStorage.py | 1 - python/mesa_pd/data/SparseLinkedCells.py | 1 - python/mesa_pd/data/__init__.py | 1 + python/mesa_pd/kernel/VelocityVerlet.py | 2 +- python/mesa_pd/mpi/Notifications.py | 27 +++++++++++----------- python/mesa_pd/mpi/PropertyNotification.py | 2 +- python/mesa_pd/mpi/__init__.py | 1 + python/mesa_pd/utility.py | 2 +- 14 files changed, 30 insertions(+), 36 deletions(-) diff --git a/python/mesa_pd/Module.py b/python/mesa_pd/Module.py index 64c307c46..e0359f92e 100644 --- a/python/mesa_pd/Module.py +++ b/python/mesa_pd/Module.py @@ -2,7 +2,6 @@ from pathlib import Path import shutil -import os class Module: @@ -32,14 +31,14 @@ class Module: def rename(self): for filename in (f for f in self.context['module_path'].glob('**/*') if f.is_file()): filedata = None - #print(f'renaming module name: {filename}') + # print(f'renaming module name: {filename}') with open(filename, encoding="utf-8") as fin: - filedata = fin.read() + filedata = fin.read() filedata = filedata.replace('mesa_pd', self.context['name']) with open(filename, 'w', encoding="utf-8") as fout: - fout.write(filedata) + fout.write(filedata) def generate(self, folder_check=True): print(f"This operation will overwrite the content of: {self.context['module_path']}") diff --git a/python/mesa_pd/__init__.py b/python/mesa_pd/__init__.py index d68cd8086..afd5f1063 100644 --- a/python/mesa_pd/__init__.py +++ b/python/mesa_pd/__init__.py @@ -1,3 +1,3 @@ from .Module import Module -__all__ = ['Module'] \ No newline at end of file +__all__ = ['Module'] diff --git a/python/mesa_pd/data/ContactHistory.py b/python/mesa_pd/data/ContactHistory.py index 08e80a6f4..4189f6648 100644 --- a/python/mesa_pd/data/ContactHistory.py +++ b/python/mesa_pd/data/ContactHistory.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import numpy as np from ..utility import TerminalColor, find, generate_file @@ -25,7 +24,7 @@ class ContactHistory(): def add_property(self, name, type, defValue=""): prop = find(lambda x: x['name'] == name, self.context['properties']) - if (prop == None): + if (prop is None): # print(f"{TerminalColor.GREEN} creating property: {name} {TerminalColor.DEFAULT}") self.context['properties'].append(create_contact_history_property(name, type, defValue=defValue)) else: @@ -54,8 +53,7 @@ class ContactHistory(): print("=" * 90) def generate(self, module): - ctx = {} - ctx['module'] = module + ctx = {'module': module} ctx.update(self.context) generate_file(module['module_path'], 'data/ContactHistory.templ.h', ctx, filename='data/ContactHistory.h') diff --git a/python/mesa_pd/data/ContactStorage.py b/python/mesa_pd/data/ContactStorage.py index 9dd669381..2d68864c9 100644 --- a/python/mesa_pd/data/ContactStorage.py +++ b/python/mesa_pd/data/ContactStorage.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import numpy as np from ..utility import TerminalColor, find, generate_file @@ -26,7 +25,7 @@ class ContactStorage(): def add_property(self, name, type, defValue=""): prop = find(lambda x: x['name'] == name, self.context['properties']) - if (prop == None): + if (prop is None): # print(f"{TerminalColor.GREEN} creating property: {name} {TerminalColor.DEFAULT}") self.context['properties'].append(create_contact_storage_property(name, type, defValue=defValue)) else: @@ -55,8 +54,7 @@ class ContactStorage(): print("=" * 90) def generate(self, module): - ctx = {} - ctx['module'] = module + ctx = {'module': module} ctx.update(self.context) generate_file(module['module_path'], 'data/ContactStorage.templ.h', ctx, filename='data/ContactStorage.h') diff --git a/python/mesa_pd/data/LinkedCells.py b/python/mesa_pd/data/LinkedCells.py index 5ff4c9b8d..04e2f8064 100644 --- a/python/mesa_pd/data/LinkedCells.py +++ b/python/mesa_pd/data/LinkedCells.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import numpy as np from ..utility import generate_file diff --git a/python/mesa_pd/data/ParticleStorage.py b/python/mesa_pd/data/ParticleStorage.py index 65193bab2..e41e89790 100644 --- a/python/mesa_pd/data/ParticleStorage.py +++ b/python/mesa_pd/data/ParticleStorage.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import numpy as np from ..utility import find, TerminalColor, generate_file @@ -27,8 +26,8 @@ def create_particle_property(name, type, access="grs", defValue="", syncMode="AL """ if (type == 'bool'): - raise RuntimeError(f"Due to flaws in the implementation of std::vector<bool>, bool is not supported as a " - f"property type! Please use char instead.") + raise RuntimeError("Due to flaws in the implementation of std::vector<bool>, bool is not supported as a " + "property type! Please use char instead.") # sort access specifier and remove duplicates foo = "".join(sorted(access)) @@ -65,7 +64,7 @@ class ParticleStorage(): def add_property(self, name, type, access="grs", defValue="", syncMode="ALWAYS"): prop = find(lambda x: x['name'] == name, self.context['properties']) - if (prop == None): + if (prop is None): # print(f"{TerminalColor.GREEN} creating particle property: {name} {TerminalColor.DEFAULT}") self.context['properties'].append( create_particle_property(name, type, access=access, defValue=defValue, syncMode=syncMode)) diff --git a/python/mesa_pd/data/ShapeStorage.py b/python/mesa_pd/data/ShapeStorage.py index 512cb2b29..b72534aa7 100644 --- a/python/mesa_pd/data/ShapeStorage.py +++ b/python/mesa_pd/data/ShapeStorage.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import numpy as np from ..utility import generate_file diff --git a/python/mesa_pd/data/SparseLinkedCells.py b/python/mesa_pd/data/SparseLinkedCells.py index b0ee85de8..30af89a34 100644 --- a/python/mesa_pd/data/SparseLinkedCells.py +++ b/python/mesa_pd/data/SparseLinkedCells.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import numpy as np from ..utility import generate_file diff --git a/python/mesa_pd/data/__init__.py b/python/mesa_pd/data/__init__.py index b75df12ce..64ba6a95e 100644 --- a/python/mesa_pd/data/__init__.py +++ b/python/mesa_pd/data/__init__.py @@ -11,4 +11,5 @@ __all__ = ['ContactHistory', 'ContactStorage', 'LinkedCells', 'ParticleStorage', + 'ShapeStorage', 'SparseLinkedCells'] diff --git a/python/mesa_pd/kernel/VelocityVerlet.py b/python/mesa_pd/kernel/VelocityVerlet.py index 74eca6c13..7ec132056 100644 --- a/python/mesa_pd/kernel/VelocityVerlet.py +++ b/python/mesa_pd/kernel/VelocityVerlet.py @@ -5,7 +5,7 @@ from mesa_pd.utility import generate_file class VelocityVerlet: - def __init__(self, integrate_rotation = True): + def __init__(self, integrate_rotation=True): self.context = {'bIntegrateRotation': integrate_rotation, 'interface': []} self.context['interface'].append(create_access("position", "walberla::mesa_pd::Vec3", access="gs")) self.context['interface'].append(create_access("linearVelocity", "walberla::mesa_pd::Vec3", access="gs")) diff --git a/python/mesa_pd/mpi/Notifications.py b/python/mesa_pd/mpi/Notifications.py index 5be06cbf4..cea6a3aac 100644 --- a/python/mesa_pd/mpi/Notifications.py +++ b/python/mesa_pd/mpi/Notifications.py @@ -2,19 +2,20 @@ from ..utility import generate_file + class Notifications: - def __init__(self, particle_storage): - self.ps = particle_storage + def __init__(self, particle_storage): + self.ps = particle_storage - def generate(self, module): - ctx = {'module': module, 'particle' : self.ps.get_context()} + def generate(self, module): + ctx = {'module': module, 'particle': self.ps.get_context()} - generate_file(module['module_path'], 'mpi/notifications/ParseMessage.templ.h', ctx) - generate_file(module['module_path'], 'mpi/notifications/ParticleCopyNotification.templ.h', ctx) - generate_file(module['module_path'], 'mpi/notifications/ParticleGhostCopyNotification.templ.h', ctx) - generate_file(module['module_path'], 'mpi/notifications/NewGhostParticleNotification.templ.h', ctx) - generate_file(module['module_path'], 'mpi/notifications/ParticleMigrationNotification.templ.h', ctx) - generate_file(module['module_path'], 'mpi/notifications/ParticleRemoteMigrationNotification.templ.h', ctx) - generate_file(module['module_path'], 'mpi/notifications/ParticleRemovalInformationNotification.templ.h', ctx) - generate_file(module['module_path'], 'mpi/notifications/ParticleRemovalNotification.templ.h', ctx) - generate_file(module['module_path'], 'mpi/notifications/ParticleUpdateNotification.templ.h', ctx) + generate_file(module['module_path'], 'mpi/notifications/ParseMessage.templ.h', ctx) + generate_file(module['module_path'], 'mpi/notifications/ParticleCopyNotification.templ.h', ctx) + generate_file(module['module_path'], 'mpi/notifications/ParticleGhostCopyNotification.templ.h', ctx) + generate_file(module['module_path'], 'mpi/notifications/NewGhostParticleNotification.templ.h', ctx) + generate_file(module['module_path'], 'mpi/notifications/ParticleMigrationNotification.templ.h', ctx) + generate_file(module['module_path'], 'mpi/notifications/ParticleRemoteMigrationNotification.templ.h', ctx) + generate_file(module['module_path'], 'mpi/notifications/ParticleRemovalInformationNotification.templ.h', ctx) + generate_file(module['module_path'], 'mpi/notifications/ParticleRemovalNotification.templ.h', ctx) + generate_file(module['module_path'], 'mpi/notifications/ParticleUpdateNotification.templ.h', ctx) diff --git a/python/mesa_pd/mpi/PropertyNotification.py b/python/mesa_pd/mpi/PropertyNotification.py index f7bced94f..0e027cd1e 100644 --- a/python/mesa_pd/mpi/PropertyNotification.py +++ b/python/mesa_pd/mpi/PropertyNotification.py @@ -9,7 +9,7 @@ class PropertyNotification: def add_property(self, name, type, reset_value): prop = find(lambda x: x['name'] == name, self.context['properties']) - if (prop == None): + if (prop is None): self.context['properties'].append({'name': name, 'type': type, 'resetValue': reset_value}) else: if not (prop['type'] == type and prop['name'] == name and prop['resetValue'] == reset_value): diff --git a/python/mesa_pd/mpi/__init__.py b/python/mesa_pd/mpi/__init__.py index e74f708e8..bc467408f 100644 --- a/python/mesa_pd/mpi/__init__.py +++ b/python/mesa_pd/mpi/__init__.py @@ -15,6 +15,7 @@ from .SyncNextNeighborsNoGhosts import SyncNextNeighborsNoGhosts __all__ = ['BroadcastProperty', 'ClearGhostOwnerSync', 'ClearNextNeighborSync', + 'Notifications', 'PropertyNotification', 'ReduceContactHistory', 'ReduceProperty', diff --git a/python/mesa_pd/utility.py b/python/mesa_pd/utility.py index b5a86337d..7af8daf50 100644 --- a/python/mesa_pd/utility.py +++ b/python/mesa_pd/utility.py @@ -31,7 +31,7 @@ def get_jinja_environment(): def generate_file(path, template, context={}, filename=None): - if filename == None: + if filename is None: filename = template.replace(".templ", "") env = get_jinja_environment() print(f"generating: {(path / filename)}") -- GitLab