-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconfig.py
69 lines (53 loc) · 2.19 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
This is the configuration module of fenicsxadapter
"""
import json
import os
import sys
class Config:
"""
Handles reading of config. parameters of the fenicsxadapter based on JSON
configuration file. Initializer calls read_json() method. Instance attributes
can be accessed by provided getter functions.
"""
def __init__(self, adapter_config_filename):
self._config_file_name = None
self._participant_name = None
self._coupling_mesh_name = None
self._read_data_name = None
self._write_data_name = None
self.read_json(adapter_config_filename)
def read_json(self, adapter_config_filename):
"""
Reads JSON adapter configuration file and saves the data to the respective instance attributes.
Parameters
----------
adapter_config_filename : string
Name of the JSON configuration file
"""
folder = os.path.dirname(os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), adapter_config_filename))
path = os.path.join(folder, os.path.basename(adapter_config_filename))
read_file = open(path)
data = json.load(read_file)
self._config_file_name = os.path.join(folder, data["config_file_name"])
self._participant_name = data["participant_name"]
self._coupling_mesh_name = data["interface"]["coupling_mesh_name"]
try:
self._write_data_name = data["interface"]["write_data_name"]
except KeyError:
self._write_data_name = None # not required for one-way coupling, if this participant reads data
try:
self._read_data_name = data["interface"]["read_data_name"]
except KeyError:
self._read_data_name = None # not required for one-way coupling, if this participant writes data
read_file.close()
def get_config_file_name(self):
return self._config_file_name
def get_participant_name(self):
return self._participant_name
def get_coupling_mesh_name(self):
return self._coupling_mesh_name
def get_read_data_name(self):
return self._read_data_name
def get_write_data_name(self):
return self._write_data_name