Coverage for yaptide/converter/converter/fluka/cards/region_card.py: 88%

25 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-07-01 12:55 +0000

1from dataclasses import dataclass, field 

2from converter.fluka.helper_parsers.region_parser import BoolOperation, FlukaRegion 

3 

4 

5@dataclass 

6class RegionsCard: 

7 """Class representing description of zones in Fluka input""" 

8 

9 data: list[FlukaRegion] = field(default_factory=lambda: []) 

10 

11 def __str__(self) -> str: 

12 """Return the card as a string.""" 

13 result = "" 

14 for index, region in enumerate(self.data): 

15 if index == 0: 

16 line = "" 

17 else: 

18 line = "\n" 

19 line += f"{region.name} 5" 

20 # The '5' is the NAZ value for the region 

21 # From Fluka documentation: 

22 # NAZ is a rough guess for the number of regions which can be entered 

23 # leaving the current region, normally 5 

24 for zone_index, zone in enumerate(region.figures_operators): 

25 for operation, figure_name in zone: 

26 if operation == BoolOperation.INTERSECTION: 

27 line += f" +{figure_name}" 

28 elif operation == BoolOperation.SUBTRACTION: 

29 line += f" -{figure_name}" 

30 if len(line) >= 120: # Ensure that line is not longer than 132 characters 

31 result += line 

32 line = "\n" 

33 # We connect Fluka zones into regions with union operator 

34 if zone_index < len(region.figures_operators) - 1: 

35 line += " |" 

36 result += line 

37 

38 return result