|
12 | 12 | import os |
13 | 13 |
|
14 | 14 | # Third-party imports |
| 15 | +from numpy import ndarray |
15 | 16 |
|
16 | 17 | # Local imports |
17 | 18 | from .dataiterfile import DataIterFile |
@@ -107,27 +108,46 @@ def readfile(self, fname: str) -> dict: |
107 | 108 | # Read the data.iter |
108 | 109 | data = DataIterFile(fname) |
109 | 110 | # Unpack component name |
110 | | - comp = self.comp |
| 111 | + comp = self.comp.lower() |
111 | 112 | # Initialize data for output |
112 | 113 | db = basedata.BaseData() |
113 | 114 | # Identify iteration column to use |
114 | 115 | icol = "nt" if "nt" in data else "iter" |
115 | 116 | # Force coeff prefix |
116 | | - fpre = "c" if f"cx_{comp}" in data else "cf" |
| 117 | + infix = '' if (f'cx_{comp}' in data or f"fx_{comp}" in data) else 'f' |
117 | 118 | # Save data |
118 | 119 | db.save_col("i", data[icol]) |
119 | 120 | db.save_col("solver_iter", data[icol]) |
120 | | - db.save_col("CL", data[f"cl_{comp}"]) |
121 | | - db.save_col("CD", data[f"cd_{comp}"]) |
122 | | - db.save_col("CA", data[f"{fpre}x_{comp}"]) |
123 | | - db.save_col("CY", data[f"{fpre}y_{comp}"]) |
124 | | - db.save_col("CN", data[f"{fpre}z_{comp}"]) |
125 | | - db.save_col("CLL", data[f"cmx_{comp}"]) |
126 | | - db.save_col("CLM", data[f"cmy_{comp}"]) |
127 | | - db.save_col("CLN", data[f"cmz_{comp}"]) |
| 121 | + # Save coefficients |
| 122 | + db.save_col("CL", self.get_datacol(data, '', 'l')) |
| 123 | + db.save_col("CD", self.get_datacol(data, '', 'd')) |
| 124 | + db.save_col("CA", self.get_datacol(data, infix, 'x')) |
| 125 | + db.save_col("CY", self.get_datacol(data, infix, 'y')) |
| 126 | + db.save_col("CN", self.get_datacol(data, infix, 'z')) |
| 127 | + db.save_col("CLL", self.get_datacol(data, '', 'mx', '')) |
| 128 | + db.save_col("CLM", self.get_datacol(data, '', 'my', '')) |
| 129 | + db.save_col("CLN", self.get_datacol(data, '', 'mz', '')) |
128 | 130 | # Output |
129 | 131 | return db |
130 | 132 |
|
| 133 | + def get_datacol( |
| 134 | + self, |
| 135 | + data: dict, |
| 136 | + infix: str, |
| 137 | + coeff: str, |
| 138 | + prefix: str = 'f') -> ndarray: |
| 139 | + # Possible col names |
| 140 | + col = f"{coeff}_{self.comp.lower()}" |
| 141 | + col1 = f"c{infix}{col}" |
| 142 | + col2 = f"{prefix}{col}" |
| 143 | + # Use best |
| 144 | + if col1 in data: |
| 145 | + # Coefficient defined directly |
| 146 | + return data[col1] |
| 147 | + else: |
| 148 | + # Use force |
| 149 | + return data.get(col2) |
| 150 | + |
131 | 151 |
|
132 | 152 | # Iterative residual history |
133 | 153 | class CaseResid(cdbook.CaseResid): |
|
0 commit comments