Skip to content

Added postProcessing flag setter #1176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion flow360/component/simulation/simulation_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,15 @@ def initialize_variable_space(cls, value: dict):
return value
if isinstance(asset_cache["project_variables"], Iterable):
for variable_dict in asset_cache["project_variables"]:
UserVariable(name=variable_dict["name"], value=variable_dict["value"])
value_or_expression = {
key: value
for key, value in variable_dict["value"].items()
if key != "postProcessing"
}
UserVariable(
name=variable_dict["name"],
value=value_or_expression,
)
return value

# pylint: disable=no-self-argument
Expand Down
15 changes: 13 additions & 2 deletions flow360/component/simulation/user_code/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,27 @@ class VariableContextInfo(Flow360BaseModel):

name: str
value: ValueOrExpression[AnyNumericType]
model_config = pd.ConfigDict(extra="allow") # For front end support
postProcessing: bool = pd.Field()


def save_user_variables(params):
"""
Save user variables to the project variables.
Declared here since I do not want to import default_context everywhere.
"""
# Get all output variables:
post_processing_variables = set()
for item in params.outputs if params.outputs else []:
if not "output_fields" in item.__class__.model_fields:
continue
for item in item.output_fields.items:
if isinstance(item, UserVariable):
post_processing_variables.add(item.name)

params.private_attribute_asset_cache.project_variables = [
VariableContextInfo(name=name, value=value)
VariableContextInfo(
name=name, value=value, postProcessing=name in post_processing_variables
)
for name, value in default_context._values.items() # pylint: disable=protected-access
if "." not in name # Skipping scoped variables (non-user variables)
]
Expand Down
3 changes: 2 additions & 1 deletion tests/simulation/data/simulation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,8 @@
"value": {
"type_name": "number",
"value": 1
}
},
"postProcessing": false
}
]
}
Expand Down
9 changes: 6 additions & 3 deletions tests/simulation/ref/simulation_with_project_variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@
"type_name": "number",
"value": 12.0,
"units": "m/s"
}
},
"postProcessing": false
},
{
"name": "aaa",
Expand All @@ -259,7 +260,8 @@
null
],
"evaluated_units": "m/s"
}
},
"postProcessing": false
},
{
"name": "bbb",
Expand All @@ -273,7 +275,8 @@
],
"evaluated_units": "m/s",
"output_units": "km/ms"
}
},
"postProcessing": true
}
]
}
Expand Down