Skip to content

Commit a83e2d1

Browse files
committed
matrix and fourier example update
1 parent 23f88ef commit a83e2d1

File tree

3 files changed

+41
-42
lines changed

3 files changed

+41
-42
lines changed

examples/examples_shape/pwm/run_fourier.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,22 @@ def _solve_peec(folder_example, folder_config):
3939
# define the input
4040
file_geometry = os.path.join(folder_example, "geometry.yaml")
4141
file_problem = os.path.join(folder_example, "problem.yaml")
42-
43-
# define the configuration
4442
file_tolerance = os.path.join(folder_config, "tolerance.yaml")
4543

46-
# define the output
47-
file_voxel = os.path.join(folder_example, "voxel.pkl")
48-
file_solution = os.path.join(folder_example, "solution.pkl")
44+
# load the input
45+
data_geometry = scisave.load_config(file_geometry)
46+
data_problem = scisave.load_config(file_problem)
47+
data_tolerance = scisave.load_config(file_tolerance)
4948

50-
# run the workflow and load the solution
51-
pypeec.run_mesher_file(
52-
file_geometry=file_geometry,
53-
file_voxel=file_voxel,
49+
# run the workflow (mesher and solver)
50+
data_voxel = pypeec.run_mesher_data(
51+
data_geometry=data_geometry,
5452
)
55-
pypeec.run_solver_file(
56-
file_voxel=file_voxel,
57-
file_problem=file_problem,
58-
file_tolerance=file_tolerance,
59-
file_solution=file_solution,
53+
data_solution = pypeec.run_solver_data(
54+
data_voxel=data_voxel,
55+
data_problem=data_problem,
56+
data_tolerance=data_tolerance,
6057
)
61-
data_solution = scisave.load_data(file_solution)
6258

6359
return data_solution
6460

@@ -69,10 +65,12 @@ def _get_impedance_peec(data_solution):
6965
"""
7066

7167
# extract the data
68+
status = data_solution["status"]
7269
data_init = data_solution["data_init"]
7370
data_sweep = data_solution["data_sweep"]
7471

7572
# check solution
73+
assert status, "invalid solution"
7674
assert isinstance(data_init, dict), "invalid solution"
7775
assert isinstance(data_sweep, dict), "invalid solution"
7876

@@ -82,13 +80,15 @@ def _get_impedance_peec(data_solution):
8280

8381
# find the impedance for the different frequencies
8482
for idx, data_sweep_tmp in enumerate(data_sweep.values()):
85-
# extract the data
83+
# extract the frequency
8684
freq = data_sweep_tmp["freq"]
87-
source = data_sweep_tmp["source"]
85+
86+
# extract the terminal properties
87+
source_values = data_sweep_tmp["source_values"]
8888

8989
# extract the impedance
90-
voltage = source["src"]["V"] - source["sink"]["V"]
91-
current = (source["src"]["I"] - source["sink"]["I"]) / 2
90+
voltage = source_values["src"]["V"] - source_values["sink"]["V"]
91+
current = (source_values["src"]["I"] - source_values["sink"]["I"]) / 2
9292
impedance = voltage / current
9393

9494
# assign

examples/examples_stl/transformer_air/run_matrix.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,22 @@ def _solve_peec(folder_example, folder_config):
3333
# define the input
3434
file_geometry = os.path.join(folder_example, "geometry.yaml")
3535
file_problem = os.path.join(folder_example, "problem.yaml")
36-
37-
# define the configuration
3836
file_tolerance = os.path.join(folder_config, "tolerance.yaml")
3937

40-
# define the output
41-
file_voxel = os.path.join(folder_example, "voxel.pkl")
42-
file_solution = os.path.join(folder_example, "solution.pkl")
38+
# load the input
39+
data_geometry = scisave.load_config(file_geometry)
40+
data_problem = scisave.load_config(file_problem)
41+
data_tolerance = scisave.load_config(file_tolerance)
4342

44-
# run the workflow and load the solution
45-
pypeec.run_mesher_file(
46-
file_geometry=file_geometry,
47-
file_voxel=file_voxel,
43+
# run the workflow (mesher and solver)
44+
data_voxel = pypeec.run_mesher_data(
45+
data_geometry=data_geometry,
4846
)
49-
pypeec.run_solver_file(
50-
file_voxel=file_voxel,
51-
file_problem=file_problem,
52-
file_tolerance=file_tolerance,
53-
file_solution=file_solution,
47+
data_solution = pypeec.run_solver_data(
48+
data_voxel=data_voxel,
49+
data_problem=data_problem,
50+
data_tolerance=data_tolerance,
5451
)
55-
data_solution = scisave.load_data(file_solution)
5652

5753
return data_solution
5854

pypeec/utils/matrix.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def _get_symmetry_expand(data, symmetry):
199199
return data_all
200200

201201

202-
def _get_extract_sweep(source, terminal_list):
202+
def _get_extract_sweep(source_values, terminal_list):
203203
"""
204204
Get the terminal currents and voltages for a specific sweep.
205205
"""
@@ -215,8 +215,8 @@ def _get_extract_sweep(source, terminal_list):
215215
sink = terminal["sink"]
216216

217217
# extract the terminal quantities
218-
V_vec[idx] = source[src]["V"] - source[sink]["V"]
219-
I_vec[idx] = (source[src]["I"] - source[sink]["I"]) / 2
218+
V_vec[idx] = source_values[src]["V"] - source_values[sink]["V"]
219+
I_vec[idx] = (source_values[src]["I"] - source_values[sink]["I"]) / 2
220220

221221
# assign the data
222222
V_vec = np.array(V_vec, dtype=np.complex128)
@@ -282,10 +282,12 @@ def get_extract(data_solution, sweep_list, terminal_list):
282282
"""
283283

284284
# extract the data
285+
status = data_solution["status"]
285286
data_init = data_solution["data_init"]
286287
data_sweep = data_solution["data_sweep"]
287288

288289
# check solution
290+
assert status, "invalid solution"
289291
assert isinstance(data_init, dict), "invalid solution"
290292
assert isinstance(data_sweep, dict), "invalid solution"
291293

@@ -300,13 +302,14 @@ def get_extract(data_solution, sweep_list, terminal_list):
300302

301303
# extract data
302304
for idx, sweep in enumerate(sweep_list):
303-
# extract the data
304-
data_sweep_tmp = data_sweep[sweep]
305-
freq = data_sweep_tmp["freq"]
306-
source = data_sweep_tmp["source"]
305+
# extract the frequency
306+
freq = data_sweep[sweep]["freq"]
307+
308+
# extract the terminal properties
309+
source_values = data_sweep[sweep]["source_values"]
307310

308311
# compute
309-
(V_vec, I_vec) = _get_extract_sweep(source, terminal_list)
312+
(V_vec, I_vec) = _get_extract_sweep(source_values, terminal_list)
310313

311314
# assign
312315
V_mat[:, idx] = V_vec

0 commit comments

Comments
 (0)