|
1 |
| -import configparser |
2 | 1 | import json
|
3 | 2 | import logging
|
4 | 3 | import typing
|
@@ -262,184 +261,6 @@ def from_json(cls, filename: str):
|
262 | 261 | cad_to_csg.export_csg()
|
263 | 262 | return cad_to_csg
|
264 | 263 |
|
265 |
| - # TODO add tests as set_configuration is not currently tested |
266 |
| - def set_configuration(self, configFile=None): |
267 |
| - |
268 |
| - if configFile is None: |
269 |
| - return |
270 |
| - |
271 |
| - config = configparser.ConfigParser() |
272 |
| - config.optionxform = str |
273 |
| - config.read(configFile) |
274 |
| - for section in config.sections(): |
275 |
| - if section == "Files": |
276 |
| - for key in config["Files"].keys(): |
277 |
| - if key in ("geometryName", "matFile", "title"): |
278 |
| - self.set(key, config.get("Files", key)) |
279 |
| - |
280 |
| - elif key == "stepFile": |
281 |
| - value = config.get("Files", key).strip() |
282 |
| - lst = value.split() |
283 |
| - if value[0] in ("(", "[") and value[-1] in ("]", ")"): |
284 |
| - data = value[1:-1].split(",") |
285 |
| - data = [x.strip() for x in data] |
286 |
| - self.set(key, data) |
287 |
| - elif len(lst) > 1: |
288 |
| - self.set(key, lst) |
289 |
| - else: |
290 |
| - self.set(key, value) |
291 |
| - |
292 |
| - elif key == "outFormat": |
293 |
| - raw = config.get("Files", key).strip() |
294 |
| - values = tuple(x.strip() for x in raw.split(",")) |
295 |
| - outFormat = [] |
296 |
| - for v in values: |
297 |
| - if v.lower() == "mcnp": |
298 |
| - outFormat.append("mcnp") |
299 |
| - elif v.lower() == "openmc_xml": |
300 |
| - outFormat.append("openmc_xml") |
301 |
| - elif v.lower() == "openmc_py": |
302 |
| - outFormat.append("openmc_py") |
303 |
| - elif v.lower() == "serpent": |
304 |
| - outFormat.append("serpent") |
305 |
| - elif v.lower() == "phits": |
306 |
| - outFormat.append("phits") |
307 |
| - self.set(key, tuple(outFormat)) |
308 |
| - |
309 |
| - elif section == "Parameters": |
310 |
| - for key in config["Parameters"].keys(): |
311 |
| - if key in ( |
312 |
| - "voidGen", |
313 |
| - "debug", |
314 |
| - "compSolids", |
315 |
| - "volSDEF", |
316 |
| - "volCARD", |
317 |
| - "dummyMat", |
318 |
| - "cellSummaryFile", |
319 |
| - "cellCommentFile", |
320 |
| - "sort_enclosure", |
321 |
| - ): |
322 |
| - self.set(key, config.getboolean("Parameters", key)) |
323 |
| - elif key in ( |
324 |
| - "minVoidSize", |
325 |
| - "maxSurf", |
326 |
| - "maxBracket", |
327 |
| - "startCell", |
328 |
| - "startSurf", |
329 |
| - ): |
330 |
| - self.set(key, config.getint("Parameters", key)) |
331 |
| - elif key in ("exportSolids", "UCARD", "simplify"): |
332 |
| - self.set(key, config.get("Parameters", key)) |
333 |
| - elif key == "voidMat": |
334 |
| - value = config.get("Parameters", key).strip() |
335 |
| - data = value[1:-1].split(",") |
336 |
| - self.set(key, (int(data[0]), float(data[1]), data[2])) |
337 |
| - else: |
338 |
| - value = config.get("Parameters", key).strip() |
339 |
| - data = value[1:-1].split(",") |
340 |
| - self.set(key, tuple(map(int, data))) |
341 |
| - |
342 |
| - elif section == "Options": |
343 |
| - attributes_and_types = get_type_hints(Options()) |
344 |
| - for key in config["Options"].keys(): |
345 |
| - if key in attributes_and_types.keys(): |
346 |
| - if attributes_and_types[key] is bool: |
347 |
| - value = config.getboolean("Options", key) |
348 |
| - elif attributes_and_types[key] is float or attributes_and_types[key] is int: |
349 |
| - value = config.getfloat("Options", key) |
350 |
| - setattr(self.options, key, value) |
351 |
| - |
352 |
| - elif section == "Tolerances": |
353 |
| - attributes_and_types = get_type_hints(Tolerances()) |
354 |
| - for key in config["Tolerances"].keys(): |
355 |
| - if key in attributes_and_types.keys(): |
356 |
| - if attributes_and_types[key] is bool: |
357 |
| - value = config.getboolean("Tolerances", key) |
358 |
| - elif attributes_and_types[key] is float: |
359 |
| - value = config.getfloat("Tolerances", key) |
360 |
| - setattr(self.tolerances, key, value) |
361 |
| - |
362 |
| - elif section == "MCNP_Numeric_Format": |
363 |
| - attributes_and_types = get_type_hints(NumericFormat()) |
364 |
| - PdEntry = False |
365 |
| - for key in config["MCNP_Numeric_Format"].keys(): |
366 |
| - if key in attributes_and_types.keys(): |
367 |
| - value = config.get("MCNP_Numeric_Format", key) |
368 |
| - setattr(self.numeric_format, key, value) |
369 |
| - if key == "P_d": |
370 |
| - PdEntry = True |
371 |
| - |
372 |
| - else: |
373 |
| - logger.info(f"bad section name : {section}") |
374 |
| - |
375 |
| - if self.__dict__["geometryName"] == "": |
376 |
| - self.__dict__["geometryName"] = self.__dict__["stepFile"][:-4] |
377 |
| - |
378 |
| - # TODO see if we can find another way to do this |
379 |
| - if self.options.prnt3PPlane and not PdEntry: |
380 |
| - self.NumericFormat.P_d = "22.15e" |
381 |
| - |
382 |
| - logger.info(self.__dict__) |
383 |
| - |
384 |
| - # TODO add tests as set is not currently tested |
385 |
| - def set(self, kwrd, value): |
386 |
| - |
387 |
| - if kwrd == "stepFile": |
388 |
| - if isinstance(value, (list, tuple)): |
389 |
| - for v in value: |
390 |
| - if not isinstance(v, str): |
391 |
| - logger.info(f"elemt in {kwrd} list should be string") |
392 |
| - return |
393 |
| - elif not isinstance(value, str): |
394 |
| - logger.info(f"{kwrd} should be string or tuple of strings") |
395 |
| - return |
396 |
| - |
397 |
| - elif kwrd == "UCARD": |
398 |
| - if value == "None": |
399 |
| - value = None |
400 |
| - elif value.isdigit(): |
401 |
| - value = int(value) |
402 |
| - else: |
403 |
| - logger.info(f"{kwrd} value should be None or integer") |
404 |
| - return |
405 |
| - elif kwrd == "outFormat": |
406 |
| - if len(value) == 0: |
407 |
| - return |
408 |
| - elif kwrd in ("geometryName", "matFile", "exportSolids"): |
409 |
| - if not isinstance(value, str): |
410 |
| - logger.info(f"{kwrd} value should be str instance") |
411 |
| - return |
412 |
| - elif kwrd in ("cellRange", "voidMat", "voidExclude"): |
413 |
| - if not isinstance(value, (list, tuple)): |
414 |
| - logger.info(f"{kwrd} value should be list or tuple") |
415 |
| - return |
416 |
| - elif kwrd in ("minVoidSize", "maxSurf", "maxBracket", "startCell", "startSurf"): |
417 |
| - if not isinstance(value, int): |
418 |
| - logger.info(f"{kwrd} value should be integer") |
419 |
| - return |
420 |
| - elif kwrd in ( |
421 |
| - "voidGen", |
422 |
| - "debug", |
423 |
| - "compSolids", |
424 |
| - "simplifyCTable", |
425 |
| - "volSDEF", |
426 |
| - "volCARD", |
427 |
| - "dummyMat", |
428 |
| - "cellSummaryFile", |
429 |
| - "cellCommentFile", |
430 |
| - "sort_enclosure", |
431 |
| - ): |
432 |
| - if not isinstance(value, bool): |
433 |
| - logger.info(f"{kwrd} value should be boolean") |
434 |
| - return |
435 |
| - |
436 |
| - self.__dict__[kwrd] = value |
437 |
| - if kwrd == "stepFile" and self.__dict__["geometryName"] == "": |
438 |
| - if isinstance(value, (tuple, list)): |
439 |
| - self.__dict__["geometryName"] == "joined_step_files" |
440 |
| - else: |
441 |
| - self.__dict__["geometryName"] == value[:-4] |
442 |
| - |
443 | 264 | def load_step_file(
|
444 | 265 | self,
|
445 | 266 | filename: typing.Union[str, typing.Sequence[str]],
|
|
0 commit comments