Skip to content

Commit 822c174

Browse files
authored
Add private attr dictionary for solver (#630)
* Add private attr dictionary * Address comments
1 parent 395aaf4 commit 822c174

File tree

3 files changed

+9
-36
lines changed

3 files changed

+9
-36
lines changed

flow360/component/simulation/models/solver_numerics.py

+2-22
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from __future__ import annotations
1111

1212
from abc import ABCMeta
13-
from typing import Annotated, Literal, Optional, Union
13+
from typing import Annotated, Dict, Literal, Optional, Union
1414

1515
import numpy as np
1616
import pydantic as pd
@@ -23,7 +23,6 @@
2323
)
2424
from flow360.component.simulation.framework.entity_base import EntityList
2525
from flow360.component.simulation.primitives import Box
26-
from flow360.component.types import Coordinate
2726

2827
# from .time_stepping import UnsteadyTimeStepping
2928

@@ -78,6 +77,7 @@ class GenericSolverSettings(Flow360BaseModel, metaclass=ABCMeta):
7877
1, description="Frequency at which to solve the equation."
7978
)
8079
linear_solver: LinearSolver = pd.Field(LinearSolver())
80+
private_attribute_dict: Optional[Dict] = pd.Field(None)
8181

8282

8383
class NavierStokesSolver(GenericSolverSettings):
@@ -144,26 +144,6 @@ class NavierStokesSolver(GenericSolverSettings):
144144
+ "updated every pseudo step.",
145145
)
146146

147-
private_attribute_debug_type: Optional[
148-
Literal[
149-
"minDensity",
150-
"minPressure",
151-
"maxVelocity",
152-
"maxResCont",
153-
"maxResMomX",
154-
"maxResMomY",
155-
"maxResMomZ",
156-
"maxResEnergy",
157-
]
158-
] = pd.Field(None)
159-
private_attribute_debug_point: Optional[Coordinate] = pd.Field(None)
160-
161-
model_config = pd.ConfigDict(
162-
conflicting_fields=[
163-
Conflicts(field1="private_attribute_debug_type", field2="private_attribute_debug_point")
164-
]
165-
)
166-
167147

168148
class SpalartAllmarasModelConstants(Flow360BaseModel):
169149
"""

flow360/component/simulation/translator/solver_translator.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@
7373

7474
def dump_dict(input_params):
7575
"""Dumping param/model to dictionary."""
76-
return input_params.model_dump(by_alias=True, exclude_none=True)
76+
77+
result = input_params.model_dump(by_alias=True, exclude_none=True)
78+
if result.pop("privateAttributeDict", None) is not None:
79+
result.update(input_params.private_attribute_dict)
80+
return result
7781

7882

7983
def init_non_average_output(
@@ -899,16 +903,6 @@ def get_solver_json(
899903
input_params.operating_condition.mach
900904
)
901905
translated["navierStokesSolver"] = dump_dict(model.navier_stokes_solver)
902-
if model.navier_stokes_solver.private_attribute_debug_type is not None:
903-
replace_dict_key(
904-
translated["navierStokesSolver"], "privateAttributeDebugType", "debugType"
905-
)
906-
if model.navier_stokes_solver.private_attribute_debug_point is not None:
907-
replace_dict_key(
908-
translated["navierStokesSolver"], "privateAttributeDebugPoint", "debugPoint"
909-
)
910-
dp = translated["navierStokesSolver"]["debugPoint"]
911-
translated["navierStokesSolver"]["debugPoint"] = list(dp)
912906
replace_dict_key(translated["navierStokesSolver"], "typeName", "modelType")
913907
replace_dict_key(
914908
translated["navierStokesSolver"],

tests/simulation/translator/test_solver_translator.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,14 @@ def test_om6wing_tutorial(get_om6Wing_tutorial_param):
196196

197197
def test_om6wing_debug(get_om6Wing_tutorial_param):
198198
params = get_om6Wing_tutorial_param
199-
params.models[0].navier_stokes_solver.private_attribute_debug_type = "minDensity"
199+
params.models[0].navier_stokes_solver.private_attribute_dict = {"debugType": "minDensity"}
200200
translate_and_compare(
201201
get_om6Wing_tutorial_param,
202202
mesh_unit=0.8059 * u.m,
203203
ref_json_file="Flow360_om6Wing_debug_type.json",
204204
)
205205

206-
params.models[0].navier_stokes_solver.private_attribute_debug_type = None
207-
params.models[0].navier_stokes_solver.private_attribute_debug_point = (1.0, 2.0, 3.0)
206+
params.models[0].navier_stokes_solver.private_attribute_dict = {"debugPoint": [1.0, 2.0, 3.0]}
208207
translate_and_compare(
209208
get_om6Wing_tutorial_param,
210209
mesh_unit=0.8059 * u.m,

0 commit comments

Comments
 (0)