Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions preciceconfigcheck/rules/compositional_coupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
from networkx import Graph
from precice_config_graph.nodes import (
CouplingSchemeNode,
MultiCouplingSchemeNode,
ParticipantNode,
CouplingSchemeType,
)
import precice_config_graph.enums as e
from preciceconfigcheck.rule import Rule
from preciceconfigcheck.rule_utils import format_list
from preciceconfigcheck.severity import Severity
Expand Down Expand Up @@ -40,8 +39,8 @@ def check(self, graph: Graph) -> list[Violation]:
g1 = nx.subgraph_view(graph, filter_node=filter_coupling_scheme_nodes)
for coupling in g1.nodes():
if (
coupling.type == CouplingSchemeType.SERIAL_EXPLICIT
or coupling.type == CouplingSchemeType.SERIAL_IMPLICIT
coupling.type == e.CouplingSchemeType.SERIAL_EXPLICIT
or coupling.type == e.CouplingSchemeType.SERIAL_IMPLICIT
):
# Directed edge between first and second participant
coupling_edges += [
Expand Down
20 changes: 10 additions & 10 deletions preciceconfigcheck/rules/coupling_scheme_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
ExchangeNode,
MeshNode,
MappingNode,
Direction,
DataNode,
)
import precice_config_graph.enums as e

from preciceconfigcheck.rule import Rule
from preciceconfigcheck.severity import Severity
Expand Down Expand Up @@ -41,15 +41,15 @@ def __init__(
self.exchange_mesh = exchange_mesh
if exchange_mesh in from_participant.provide_meshes:
# from_participant writes to own mesh, sends it to to_participant, who maps it to his own mesh, and reads from it
self.direction = Direction.READ
self.direction = e.Direction.READ
self.mapper = to_participant
self.non_mapper = from_participant
self.mesh_owner = from_participant
self.from_string = f"from {self.exchange_mesh.name}"
self.to_string = f"to a mesh provided by {to_participant.name}"
else:
# from_participant writes to own mesh, maps it to to_participants mesh, sends it to to_participant, who reads from it
self.direction = Direction.WRITE
self.direction = e.Direction.WRITE
self.mapper = from_participant
self.non_mapper = to_participant
self.mesh_owner = to_participant
Expand Down Expand Up @@ -93,13 +93,13 @@ def __init__(
self.exchange_mesh = exchange_mesh
if exchange_mesh in from_participant.provide_meshes:
# from_participant writes to own mesh, sends it to to_participant, who maps it to his own mesh, and reads from it
self.direction = Direction.READ
self.direction = e.Direction.READ
self.mapper = to_participant
self.non_mapper = from_participant
self.mesh_owner = from_participant
else:
# from_participant writes to own mesh, maps it to to_participants mesh, sends it to to_participant, who reads from it
self.direction = Direction.WRITE
self.direction = e.Direction.WRITE
self.mapper = from_participant
self.non_mapper = to_participant
self.mesh_owner = to_participant
Expand Down Expand Up @@ -150,7 +150,7 @@ def check(self, graph: Graph) -> list[Violation]:
has_correct_mapping: bool = any(
mapping_fits_exchange(
mapping,
Direction.READ,
e.Direction.READ,
from_participant,
to_participant,
exchange_mesh,
Expand Down Expand Up @@ -184,7 +184,7 @@ def check(self, graph: Graph) -> list[Violation]:
has_correct_mapping: bool = any(
mapping_fits_exchange(
mapping,
Direction.WRITE,
e.Direction.WRITE,
from_participant,
to_participant,
exchange_mesh,
Expand Down Expand Up @@ -235,7 +235,7 @@ def filter_coupling_nodes(

def mapping_fits_exchange(
mapping: MappingNode,
direction: Direction,
direction: e.Direction,
from_participant: ParticipantNode,
to_participant: ParticipantNode,
exchange_mesh: MeshNode,
Expand All @@ -252,13 +252,13 @@ def mapping_fits_exchange(
"""
if mapping.direction != direction:
return False
if direction == Direction.WRITE:
if direction == e.Direction.WRITE:
# For direction-write, the mesh used in the exchange needs to be by to-participant
if exchange_mesh not in to_participant.provide_meshes:
return False
if exchange_mesh != mapping.to_mesh:
return False
elif direction == Direction.READ:
elif direction == e.Direction.READ:
# For direction-read, the mesh used in the exchange needs to be by from-participant
if exchange_mesh not in from_participant.provide_meshes:
return False
Expand Down
55 changes: 27 additions & 28 deletions preciceconfigcheck/rules/data_use_read_write.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections import defaultdict
import networkx as nx
from networkx import Graph
from precice_config_graph.nodes import (
Expand Down Expand Up @@ -73,7 +72,7 @@ class DataUsedNotReadWrittenViolation(Violation):
severity = Severity.WARNING

def __init__(
self, data_node: DataNode, mesh: MeshNode, writers: list[ParticipantNode]
self, data_node: DataNode, mesh: MeshNode, writers: list[ParticipantNode]
):
self.data_node = data_node
self.mesh = mesh
Expand Down Expand Up @@ -108,7 +107,7 @@ class DataUsedReadNotWrittenViolation(Violation):
severity = Severity.ERROR

def __init__(
self, data_node: DataNode, mesh: MeshNode, readers: list[ParticipantNode]
self, data_node: DataNode, mesh: MeshNode, readers: list[ParticipantNode]
):
self.data_node = data_node
self.mesh = mesh
Expand Down Expand Up @@ -141,7 +140,7 @@ class DataNotExchangedViolation(Violation):
severity = Severity.ERROR

def __init__(
self, data_node: DataNode, writer: ParticipantNode, reader: ParticipantNode
self, data_node: DataNode, writer: ParticipantNode, reader: ParticipantNode
):
self.data_node = data_node
self.writer = writer
Expand Down Expand Up @@ -175,7 +174,7 @@ def check(self, graph: Graph) -> list[Violation]:
meshes: list[MeshNode] = []
writers: list[ParticipantNode] = []
readers: list[ParticipantNode] = []
readers_per_writer: dict[ParticipantNode : list[ParticipantNode]] = {}
readers_per_writer: dict[ParticipantNode: list[ParticipantNode]] = {}
readers_per_mesh: dict[MeshNode, list[ParticipantNode]] = {}
writers_per_mesh: dict[MeshNode, list[ParticipantNode]] = {}

Expand Down Expand Up @@ -275,8 +274,8 @@ def check(self, graph: Graph) -> list[Violation]:
for provide_mesh_neighbor in graph.neighbors(provide_mesh):
# Only use read-data if it reads current data_node
if (
isinstance(provide_mesh_neighbor, ReadDataNode)
and provide_mesh_neighbor.data == data_node
isinstance(provide_mesh_neighbor, ReadDataNode)
and provide_mesh_neighbor.data == data_node
):
readers_per_writer[writer].append(
provide_mesh_neighbor.participant
Expand Down Expand Up @@ -307,36 +306,36 @@ def check(self, graph: Graph) -> list[Violation]:
if len(potential_reader.exports) > 0:
readers_per_writer[writer].append(potential_reader)
for potential_reader_neighbor in graph.neighbors(
potential_reader
potential_reader
):
if (
isinstance(
potential_reader_neighbor, ReadDataNode
)
and potential_reader_neighbor.data == data_node
isinstance(
potential_reader_neighbor, ReadDataNode
)
and potential_reader_neighbor.data == data_node
):
readers_per_writer[writer].append(
potential_reader
)
# Watchpoint, Watch-integral and export do not specify data
elif isinstance(
potential_reader_neighbor, WatchPointNode
potential_reader_neighbor, WatchPointNode
):
readers_per_writer[writer].append(
potential_reader
)
elif isinstance(
potential_reader_neighbor, WatchIntegralNode
potential_reader_neighbor, WatchIntegralNode
):
readers_per_writer[writer].append(
potential_reader
)
elif isinstance(
potential_reader_neighbor, ActionNode
potential_reader_neighbor, ActionNode
):
# Actions can have many source data; check for current data_node
for (
source
source
) in potential_reader_neighbor.source_data:
if source == data_node:
readers_per_writer[writer].append(
Expand Down Expand Up @@ -373,8 +372,8 @@ def check(self, graph: Graph) -> list[Violation]:
# Otherwise, there needs to be an exchange of data between them.
else:
if (
writer not in data_flow_graph.nodes
or reader not in data_flow_graph.nodes
writer not in data_flow_graph.nodes
or reader not in data_flow_graph.nodes
):
# One of writer/reader is not connected through an exchange involving data_node
violations.append(
Expand Down Expand Up @@ -432,7 +431,7 @@ def check(self, graph: Graph) -> list[Violation]:


def get_provide_meshes_for_data(
participant: ParticipantNode, data: DataNode
participant: ParticipantNode, data: DataNode
) -> list[MeshNode]:
"""
This method returns all meshes provided by the given participant that use the given data.
Expand Down Expand Up @@ -464,14 +463,14 @@ def filter_use_read_write_data(node) -> bool:
True, if the node is a data-, read-/write-, action- or mesh node.
"""
return (
isinstance(node, DataNode)
or isinstance(node, MeshNode)
or isinstance(node, ReadDataNode)
or isinstance(node, ExportNode)
or isinstance(node, WatchPointNode)
or isinstance(node, WatchIntegralNode)
or isinstance(node, WriteDataNode)
or isinstance(node, ActionNode)
isinstance(node, DataNode)
or isinstance(node, MeshNode)
or isinstance(node, ReadDataNode)
or isinstance(node, ExportNode)
or isinstance(node, WatchPointNode)
or isinstance(node, WatchIntegralNode)
or isinstance(node, WriteDataNode)
or isinstance(node, ActionNode)
)


Expand All @@ -485,7 +484,7 @@ def filter_data_exchange(node) -> bool:


def append_participant_to_map(
dictionary: dict[MeshNode : list[ParticipantNode]], mesh, participant
dictionary: dict[MeshNode: list[ParticipantNode]], mesh, participant
):
"""
This method appends the given participant to the given map for an entry 'mesh'.
Expand Down
36 changes: 18 additions & 18 deletions preciceconfigcheck/rules/m2n_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def check(self, graph: Graph) -> list[Violation]:
k2l_connector: ParticipantNode = k2l.connector
# Duplicates with same connector and same acceptor participants
if (
m2n_acceptor == k2l_acceptor
and m2n_connector == k2l_connector
and not self.contains_violation(
violations, m2n_acceptor, m2n_connector
)
m2n_acceptor == k2l_acceptor
and m2n_connector == k2l_connector
and not self.contains_violation(
violations, m2n_acceptor, m2n_connector
)
):
violations.append(
self.DuplicateM2NExchangeViolation(
Expand All @@ -99,11 +99,11 @@ def check(self, graph: Graph) -> list[Violation]:
# Check for duplicates "in the other direction":
# This can be removed if acceptor / connector roles do matter in the future.
elif (
m2n_acceptor == k2l_connector
and m2n_connector == k2l_acceptor
and not self.contains_violation(
violations, m2n_acceptor, m2n_connector
)
m2n_acceptor == k2l_connector
and m2n_connector == k2l_acceptor
and not self.contains_violation(
violations, m2n_acceptor, m2n_connector
)
):
violations.append(
self.DuplicateM2NExchangeViolation(
Expand All @@ -115,10 +115,10 @@ def check(self, graph: Graph) -> list[Violation]:

# Helper functions
def contains_violation(
self,
violations: list[Violation],
participant1: ParticipantNode,
participant2: ParticipantNode,
self,
violations: list[Violation],
participant1: ParticipantNode,
participant2: ParticipantNode,
) -> bool:
"""
This function tests whether there already exists a DuplicateM2NExchangeViolation between two participants.
Expand All @@ -131,13 +131,13 @@ def contains_violation(
if isinstance(violation, self.DuplicateM2NExchangeViolation):
# Check if any DuplicateM2NExchangeViolation contains these two participants
if (
violation.participant1 == participant1
and violation.participant2 == participant2
violation.participant1 == participant1
and violation.participant2 == participant2
):
return True
elif (
violation.participant1 == participant2
and violation.participant2 == participant1
violation.participant1 == participant2
and violation.participant2 == participant1
):
return True
return False
Loading