From 12cff064c907680d64c79ffac2647ae546ddd920 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Mon, 29 Jan 2024 14:39:01 +0100 Subject: [PATCH 01/33] initial commit with overview --- .../Optimization_Application/General/Overview.md | 7 +++++++ .../Optimization_Application/menu_info.json | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/General/Overview.md create mode 100644 docs/pages/Applications/Optimization_Application/menu_info.json diff --git a/docs/pages/Applications/Optimization_Application/General/Overview.md b/docs/pages/Applications/Optimization_Application/General/Overview.md new file mode 100644 index 000000000000..7e33bac5441a --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/Overview.md @@ -0,0 +1,7 @@ +--- +title: Overview +keywords: +tags: [Overview.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/menu_info.json b/docs/pages/Applications/Optimization_Application/menu_info.json new file mode 100644 index 000000000000..5f0c30a0a264 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/menu_info.json @@ -0,0 +1,11 @@ +{ + "side_bar_name": "optimization_application", + "landing_page": "General/Overview.md", + "additional_menu_options": { + "product": "Optimization Application", + "title": "sidebar" + }, + "custom_entries": [ + "General" + ] +} \ No newline at end of file From 966d296df4586814997fdddfc517a26d5a2f8b9e Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Mon, 29 Jan 2024 17:38:51 +0100 Subject: [PATCH 02/33] add folder structure --- .../Optimization_Application/Algorithms/Overview.md | 7 +++++++ .../Optimization_Application/Controls/Overview.md | 7 +++++++ .../Execution_Policies/Overview.md | 7 +++++++ .../Optimization_Application/Filtering/Overview.md | 7 +++++++ .../Model_Part_Controllers/Overview.md | 7 +++++++ .../Optimization_Application/Processes/Overview.md | 7 +++++++ .../Optimization_Application/Responses/Overview.md | 7 +++++++ .../Applications/Optimization_Application/menu_info.json | 9 ++++++++- 8 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 docs/pages/Applications/Optimization_Application/Algorithms/Overview.md create mode 100644 docs/pages/Applications/Optimization_Application/Controls/Overview.md create mode 100644 docs/pages/Applications/Optimization_Application/Execution_Policies/Overview.md create mode 100644 docs/pages/Applications/Optimization_Application/Filtering/Overview.md create mode 100644 docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Overview.md create mode 100644 docs/pages/Applications/Optimization_Application/Processes/Overview.md create mode 100644 docs/pages/Applications/Optimization_Application/Responses/Overview.md diff --git a/docs/pages/Applications/Optimization_Application/Algorithms/Overview.md b/docs/pages/Applications/Optimization_Application/Algorithms/Overview.md new file mode 100644 index 000000000000..7e33bac5441a --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Algorithms/Overview.md @@ -0,0 +1,7 @@ +--- +title: Overview +keywords: +tags: [Overview.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/Controls/Overview.md b/docs/pages/Applications/Optimization_Application/Controls/Overview.md new file mode 100644 index 000000000000..7e33bac5441a --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Controls/Overview.md @@ -0,0 +1,7 @@ +--- +title: Overview +keywords: +tags: [Overview.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/Execution_Policies/Overview.md b/docs/pages/Applications/Optimization_Application/Execution_Policies/Overview.md new file mode 100644 index 000000000000..7e33bac5441a --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Execution_Policies/Overview.md @@ -0,0 +1,7 @@ +--- +title: Overview +keywords: +tags: [Overview.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/Filtering/Overview.md b/docs/pages/Applications/Optimization_Application/Filtering/Overview.md new file mode 100644 index 000000000000..7e33bac5441a --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Filtering/Overview.md @@ -0,0 +1,7 @@ +--- +title: Overview +keywords: +tags: [Overview.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Overview.md b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Overview.md new file mode 100644 index 000000000000..7e33bac5441a --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Overview.md @@ -0,0 +1,7 @@ +--- +title: Overview +keywords: +tags: [Overview.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/Processes/Overview.md b/docs/pages/Applications/Optimization_Application/Processes/Overview.md new file mode 100644 index 000000000000..7e33bac5441a --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Processes/Overview.md @@ -0,0 +1,7 @@ +--- +title: Overview +keywords: +tags: [Overview.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/Responses/Overview.md b/docs/pages/Applications/Optimization_Application/Responses/Overview.md new file mode 100644 index 000000000000..7e33bac5441a --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Responses/Overview.md @@ -0,0 +1,7 @@ +--- +title: Overview +keywords: +tags: [Overview.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/menu_info.json b/docs/pages/Applications/Optimization_Application/menu_info.json index 5f0c30a0a264..587e590835da 100644 --- a/docs/pages/Applications/Optimization_Application/menu_info.json +++ b/docs/pages/Applications/Optimization_Application/menu_info.json @@ -6,6 +6,13 @@ "title": "sidebar" }, "custom_entries": [ - "General" + "General", + "Algorithms", + "Responses", + "Controls", + "Filtering", + "Model_Part_Controllers", + "Processes", + "Examples" ] } \ No newline at end of file From 14d76702e34b420766ff4f8e040d45f21011af37 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 13:59:58 +0100 Subject: [PATCH 03/33] initial pages --- .../Algorithms/steepest_descent.drawio | 27 ++++ .../General/Algorithm.md | 7 ++ .../General/Control.md | 7 ++ .../General/Execution_Policy.md | 7 ++ .../General/Master_Control.md | 7 ++ .../General/Optimization_Problem.md | 7 ++ .../General/Response_Function.md | 7 ++ .../General/Response_Routine.md | 7 ++ .../General/Work_Flow.md | 118 ++++++++++++++++++ .../General/menu_info.json | 13 ++ .../General/overall_execution.drawio | 51 ++++++++ .../General/overall_execution.svg | 1 + 12 files changed, 259 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Algorithms/steepest_descent.drawio create mode 100644 docs/pages/Applications/Optimization_Application/General/Algorithm.md create mode 100644 docs/pages/Applications/Optimization_Application/General/Control.md create mode 100644 docs/pages/Applications/Optimization_Application/General/Execution_Policy.md create mode 100644 docs/pages/Applications/Optimization_Application/General/Master_Control.md create mode 100644 docs/pages/Applications/Optimization_Application/General/Optimization_Problem.md create mode 100644 docs/pages/Applications/Optimization_Application/General/Response_Function.md create mode 100644 docs/pages/Applications/Optimization_Application/General/Response_Routine.md create mode 100644 docs/pages/Applications/Optimization_Application/General/Work_Flow.md create mode 100644 docs/pages/Applications/Optimization_Application/General/menu_info.json create mode 100644 docs/pages/Applications/Optimization_Application/General/overall_execution.drawio create mode 100644 docs/pages/Applications/Optimization_Application/General/overall_execution.svg diff --git a/docs/pages/Applications/Optimization_Application/Algorithms/steepest_descent.drawio b/docs/pages/Applications/Optimization_Application/Algorithms/steepest_descent.drawio new file mode 100644 index 000000000000..ad831a4331c1 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Algorithms/steepest_descent.drawio @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/pages/Applications/Optimization_Application/General/Algorithm.md b/docs/pages/Applications/Optimization_Application/General/Algorithm.md new file mode 100644 index 000000000000..ac6444b7ef63 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/Algorithm.md @@ -0,0 +1,7 @@ +--- +title: Algorithm +keywords: +tags: [Algorithm.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/General/Control.md b/docs/pages/Applications/Optimization_Application/General/Control.md new file mode 100644 index 000000000000..a714e752e315 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/Control.md @@ -0,0 +1,7 @@ +--- +title: Control +keywords: +tags: [Control.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/General/Execution_Policy.md b/docs/pages/Applications/Optimization_Application/General/Execution_Policy.md new file mode 100644 index 000000000000..ec3ae40e5cbb --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/Execution_Policy.md @@ -0,0 +1,7 @@ +--- +title: Execution Policy +keywords: +tags: [Execution_Policy.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/General/Master_Control.md b/docs/pages/Applications/Optimization_Application/General/Master_Control.md new file mode 100644 index 000000000000..824d34643cfb --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/Master_Control.md @@ -0,0 +1,7 @@ +--- +title: Master Control +keywords: +tags: [Master_Control.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/General/Optimization_Problem.md b/docs/pages/Applications/Optimization_Application/General/Optimization_Problem.md new file mode 100644 index 000000000000..a283f6402072 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/Optimization_Problem.md @@ -0,0 +1,7 @@ +--- +title: Optimization Problem +keywords: +tags: [Optimization_Problem.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/General/Response_Function.md b/docs/pages/Applications/Optimization_Application/General/Response_Function.md new file mode 100644 index 000000000000..ff93218f1eeb --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/Response_Function.md @@ -0,0 +1,7 @@ +--- +title: Response Function +keywords: +tags: [Response_Function.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/General/Response_Routine.md b/docs/pages/Applications/Optimization_Application/General/Response_Routine.md new file mode 100644 index 000000000000..1bcd551212b3 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/Response_Routine.md @@ -0,0 +1,7 @@ +--- +title: Response Routine +keywords: +tags: [Response_Routine.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/General/Work_Flow.md b/docs/pages/Applications/Optimization_Application/General/Work_Flow.md new file mode 100644 index 000000000000..b24599ee56f3 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/Work_Flow.md @@ -0,0 +1,118 @@ +--- +title: Work Flow +keywords: +tags: [optimization, work flow] +sidebar: optimization_application +summary: +--- + +## Introduction + +An optimization problem is run by calling ```OptimizationAnalysis::Run``` method. Following python code snippet illustrates how to run an optimization problem. +```python +import KratosMultiphysics as Kratos +from KratosMultiphysics.OptimizationApplication.optimization_analysis import OptimizationAnalysis + +# open the optimization parameters json file +with open("OptimizationParameters.json", "r") as params_file: + parameters = Kratos.Parameters(params_file.read()) + +# creates the Kratos::Model +model = Kratos.Model() + +# creates the OptimizationAnalysis +opt_analysis = OptimizationAnalysis(model, parameters) + +# run the optimization analysis +opt_analysis.Run() +``` + +Even though the ```OptimizationAnalysis``` is not derived from ```AnalysisStage```, it has a similar interface to replicate the methods in ```AnalysisStage```. Therefore, ```OptimizationAnalysis``` can also used in ```Ochestrator```. + +## Json settings +Following json snippet illustrates basic settings which can be found in a json settings file used by ```OptimizationAnalysis```. +```json +{ + "problem_data" : {}, + "model_parts" : [], + "analyses" : [], + "responses" : [], + "controls" : [], + "algorithm_settings": {}, + "processes" : { + "kratos_processes" : {}, + "optimization_data_processes": {} + } +} +``` + +### Problem data + +```problem_data``` section of the json settings can be used to add data to identify the optimization problem. The only mandatory sub-setting is ```echo_level```, which is used to indicate overall echo level to be used in the optimization analysis. Higher the value, more verbose the output. Following json-snippet illustrate an example use case. +```json +{ + "name" : "optimization_problem_name", + "echo_level": 1 +} +``` + +### Model Parts + +```model_parts``` section of the json settings can be used to read/create meshes. This sections is **not a must** to be used in an optimization analysis. If a central place is required to read/create all the meshes which will be used in the optimization analysis, this can be used. Otherwise, the meshes can be read in their respective places making this section empty. Following code snippet illustrate an example use case of one single entry in the list. + +Following ```ModelPartController``` does not need to be within Kratos. You can write your own ```ModelPartController```, and put it within your working directory. If that is the case then, change ```module``` to blank. +```json +{ + "type": "mdpa_model_part_controller", // type of the ModelPartController + "module": "KratosMultiphysics.OptimizationApplication.model_part_controllers", // Where to find the ModelPartController + "settings": { // ModelPartController specific settings + "model_part_name": "Structure", + "domain_size": 3, + "input_filename": "mdpa_file_name" + } +} +``` + +### Analyses + +```analyses``` section is used to list all the analyses which will be used in the optimization analysis. These analyses can be any type of analysis from Kratos or from an external solver. Analyses are added using the ```ExecutionPolicy``` objects. In the case of an external solver, an ```ExecutionPolicy``` may be developed to use it within the ```OptimizationAnalysis```. ```ExecutionPolicy``` can also be custom and found in your working directory of the problem. In this case, ```module``` should be a blank string. + +**```name``` field should be a unique string entry for the whole optimization problem** + +Following json snippet illustrates one use case. +```json +{ + "name": "Structure_static", // Name of the analysis. needs to be unique. + "type": "kratos_analysis_execution_policy", // Type of the execution policy. + "module": "KratosMultiphysics.OptimizationApplication.execution_policies", // Where to find the ExecutionPolicy. + "settings": { // Execution policy specific settings. + "model_part_names": [ + "Structure" + ], + "analysis_module": "KratosMultiphysics.StructuralMechanicsApplication", + "analysis_type": "StructuralMechanicsAnalysis", + "analysis_settings": { + "@include_json": "PrimalParametersCase2A.json" + } + } +} +``` + +### Responses +```responses``` section is to list all the responses which will be used by the algorithm. All the objectives and constraints should be listed in here. As mentioned in other sections, custom responses can be defines as well and put in to the working directory. In that case the ```module``` should be a blank string. + +**```name``` field should be a unique string entry for the whole optimization problem** + +Following json-snippet illustrates an example use case. +```json +{ + "name": "mass", + "type": "mass_response_function", + "module": "KratosMultiphysics.OptimizationApplication.responses", + "settings": { + "evaluated_model_part_names": [ + "Structure" + ] + } +} +``` diff --git a/docs/pages/Applications/Optimization_Application/General/menu_info.json b/docs/pages/Applications/Optimization_Application/General/menu_info.json new file mode 100644 index 000000000000..5914784f4160 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/menu_info.json @@ -0,0 +1,13 @@ +{ + "custom_entries": [ + "Overview.md", + "Work_Flow.md", + "Algorithm.md", + "Response_Routine.md", + "Response_Function.md", + "Execution_Policy.md", + "Master_Control.md", + "Control.md", + "Optimization_Problem.md" + ] +} \ No newline at end of file diff --git a/docs/pages/Applications/Optimization_Application/General/overall_execution.drawio b/docs/pages/Applications/Optimization_Application/General/overall_execution.drawio new file mode 100644 index 000000000000..749a4d87104f --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/overall_execution.drawio @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/pages/Applications/Optimization_Application/General/overall_execution.svg b/docs/pages/Applications/Optimization_Application/General/overall_execution.svg new file mode 100644 index 000000000000..8735f2fa777b --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/overall_execution.svg @@ -0,0 +1 @@ +
Start
Start
End
End
Construction of components
Construction of...
Initialization of components
Initialization o...
Checking of components
Checking of comp...
Running optimization algorithm
Running optimiza...
Finalizing of components
Finalizing of co...
Text is not SVG - cannot display
\ No newline at end of file From 6c3534bf2452b5c78ab5480e6c1444905564d25d Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 14:37:07 +0100 Subject: [PATCH 04/33] update work_flow.md docs --- .../General/Work_Flow.md | 102 +++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/docs/pages/Applications/Optimization_Application/General/Work_Flow.md b/docs/pages/Applications/Optimization_Application/General/Work_Flow.md index b24599ee56f3..4cc228149c72 100644 --- a/docs/pages/Applications/Optimization_Application/General/Work_Flow.md +++ b/docs/pages/Applications/Optimization_Application/General/Work_Flow.md @@ -56,7 +56,7 @@ Following json snippet illustrates basic settings which can be found in a json s } ``` -### Model Parts +### Model parts ```model_parts``` section of the json settings can be used to read/create meshes. This sections is **not a must** to be used in an optimization analysis. If a central place is required to read/create all the meshes which will be used in the optimization analysis, this can be used. Otherwise, the meshes can be read in their respective places making this section empty. Following code snippet illustrate an example use case of one single entry in the list. @@ -116,3 +116,103 @@ Following json-snippet illustrates an example use case. } } ``` + +### Controls +```controls``` section is to list all of the controls to be used by the algorithm. + +**```name``` field should be a unique string entry for the whole optimization problem** + +Following code-snippet illustrates an example use case. +```json +{ + "name": "thickness_control", + "type": "thickness.shell_thickness_control", + "settings": { + "controlled_model_part_names": [ + "Structure.Parts_Shell_structure" + ], + "filter_settings": { + "type": "implicit", + "radius": 0.2, + "linear_solver_settings": { + "solver_type": "LinearSolversApplication.amgcl" + } + }, + "output_all_fields": false, + "beta_value": 25.0, + "initial_physical_thickness": 0.15, + "physical_thicknesses": [ + 0.1, + 0.2 + ] + } +} +``` + +### Algorithm settings + +```algorithm_settings``` section holds all the necessary information for algorithms such as which controls, which responses to be used, what type of convergence criteria, etc. + + +### Processes +```processes``` section is allowed to have two type of processes. One is, processes you find anywhere in Kratos which is not in hte OptimizationApplication. If these processes are required to be used in the optimization analysis to input or output data, then they should go in the ```kratos_processes```. + +There are some specific processes which are implemented in OptimizationApplication which requires not only ```Kratos::Model``` and ```Kratos::Parameters```, but also ```OptimizationProblem``` to construct an object. These processes needs to be included under ```optimization_data_processes```. + + +## Work flow + +

+ Overall execution flow +

+

Figure 1: Overall execution flow

+ +Figure 1 illustrates the overall execution of an optimization problem. + +### Construction of components + +This step will construct all following components in the listed order. +1. ```OptimizationProblem``` data container. +2. [```ModelPartControllers```](#model-parts) +3. [```Analyses```](#analyses) +4. [```Controls```](#controls) +5. [```Responses```](#responses) +6. [```Algorithm```](#algorithm-settings) +7. [```Processes```](#processes) + +Each type of component will read its respective part of the json to create the component. + +### Initialization of components + +Initialization of components will be done in the following listed order. + +1. Fill in the model parts specified by [```ModelPartControllers```](#model-parts) by calling ```ModelPartController::ImportModelPart```. +2. Initialize ```ModelPartController``` by calling ```ModelPartController::Initialize``` +3. Initialize Processes. +4. Initialize ```Algorithm``` + +Initialization of ```ResponseFunction``` and ```Controls``` are done within the ```Algorithm::Initialize```. + +### Checking of components + +Checking of components will be done in the following listed order. + +1. Checks processes +2. Check ```Algorithm``` + +Checking of ```ResponseFunction``` and ```Controls``` are done within the ```Algorithm::Check```. + + +### Running optimization algorithm + +This step will call [```Algorithm::Solve```](Algorithm.html) method. + + +### Finalizing of components + +Finalization of components will be done in the following listed order. + +1. Initialize ```Algorithm```. +2. Initialize Processes. + +Finalization of ```ResponseFunction``` and ```Controls``` are done within the ```Algorithm::Finalize```. \ No newline at end of file From f4c9663704814b566d5fd7a79b851151090590a0 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 15:37:53 +0100 Subject: [PATCH 05/33] add algorithm comments --- .../python_scripts/algorithms/algorithm.py | 38 ++++++++++++++++++ .../General/Algorithm.md | 40 ++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/applications/OptimizationApplication/python_scripts/algorithms/algorithm.py b/applications/OptimizationApplication/python_scripts/algorithms/algorithm.py index 095182505fff..d3639163cb06 100644 --- a/applications/OptimizationApplication/python_scripts/algorithms/algorithm.py +++ b/applications/OptimizationApplication/python_scripts/algorithms/algorithm.py @@ -4,26 +4,64 @@ from KratosMultiphysics.OptimizationApplication.utilities.helper_utilities import CallOnAll class Algorithm(ABC): + """Base class for algorithm. + + Algorithm works purely in the control space. Hence, the ResponseRoutine which + the algorithm is associated with should convert all physical space gradients to + control space and control space designs to physical space designs. + + The purpose of the algorithm is to solve a minimization problem. Hence, the used + ResponseRoutine should standardize the values and gradients it computes accordingly. + + Algorithm should create one MasterControl from all the require controls, and share + it among all the ResponseRoutines. + + Once it received the objective/constraint values and their gradients, the algorithm + will compute the new design and request new objective/constraints values and their + gradients until the specified convergence criteria is met. + """ def __init__(self, optimization_problem: OptimizationProblem) -> None: self._optimization_problem = optimization_problem @abstractmethod def Initialize(self) -> None: + """Initializes the algorithm, ResponseRoutines and MasterControl. + """ pass @abstractmethod def Check(self) -> None: + """Checks algorithm, ResponseRoutines and MasterControl. + """ pass @abstractmethod def Finalize(self) -> None: + """Finalizes algorithm ResponseRoutines and MasterControl. + """ pass @abstractmethod def Solve(self) -> bool: + """Solves the optimization problem. + + This method will have a loop which iterates until the specified + convergence for the given optimization problem. + + Returns: + bool: Convergence status. True for converged, False for non-converged. + """ pass def GetProcessesOrder(self) -> 'list[str]': + """The order of execution of the process categories. + + This defines the order of execution of the processes defined under "processes" + in either "kratos_process" or "optimization_data_processes". + + Returns: + list[str]: List of strings for process categories. + """ return ["auxiliary_processes", "output_processes"] def CallOnAllProcesses(self, process_types: 'list[str]', *args, **kwargs): diff --git a/docs/pages/Applications/Optimization_Application/General/Algorithm.md b/docs/pages/Applications/Optimization_Application/General/Algorithm.md index ac6444b7ef63..7635d09a08b1 100644 --- a/docs/pages/Applications/Optimization_Application/General/Algorithm.md +++ b/docs/pages/Applications/Optimization_Application/General/Algorithm.md @@ -1,7 +1,43 @@ --- title: Algorithm -keywords: +keywords: tags: [Algorithm.md] sidebar: optimization_application -summary: +summary: --- + +## Introduction + +Figure 1 illustrates hwo an algorithm operates when ```OptimizationAnalysis``` executes ```Algorithm::Solve``` method. Overview of the existing algorithms can be found [here](../Algorithms/Overview.html). + +

+ Algorithm +

+

Figure 1: Algorithm

+ +## Working space. + +As illustrated in the Figure 1, ```Algorithm``` purely works in the control space. Hence, all the inputs to the ```Algorithm``` should be in the control space. Therefore, all the outputs from it also will be in the control space. + +## Supporting components + +When an ```Algorithm``` is constructed by the ```OptimizationAnalysis```, +1. It will create the ```MasterControl``` which links all the ```Control```s used by the ```Algorithm```. +2. It will create all the necessary ```ResponseRoutine```s for the algorithm. It will not create any ```ResponseFunction```s, it will merely link a ```ResponseRoutine``` with a ```ResponseFunction```. +3. Thereafter, it will create all the other necessary components. + +## Data flow and work flow + +```Algorithm``` is developed basically to perform minimization. Therefore, it is the duty of the ```ResponseRoutine``` to standardize the objective and constraint values (i.e. $$\tilde{J}_1$$ and $$\tilde{J}_2$$ and the gradients (i.e. $$\frac{d\tilde{J}_1}{d\underline{\hat{\phi}}}$$, $$\frac{d\tilde{J}_2}{d\underline{\hat{\phi}}}$$) accordingly and send it to the algorithm which will be based on physical space response values (i.e. $$J_1$$, $$J_2$$) and their gradients (i.e. $$\frac{dJ_1}{d\underline{\phi}}$$, $$\frac{dJ_2}{d\underline{\phi}}$$). Then using the algorithm, it will compute the new design in control space (i.e. $$\hat{\underline{\phi}}$$) which needs to mapped to a design in the physical space (i.e. $$\underline{\phi}$$) by the ```ResponseRoutine```. ```ResponseRoutine``` then should update its design surfaces using ```MasterControl``` for the next iteration computations. + + +## Notes + +1. Since each algorithm is specific, they can have their own specific types of ```ResponseRoutine```s developed. Therefore, the methods being called by an ```Algorithm``` to ```ResponseRoutine``` may differ depending on the type of the ```Algorithm```. +2. ```OptimizationApplication``` supports linking with third party libraries for various algorithms. In that case, one needs to develop the ```Algorithm``` wrapper, ```ResponseRoutine``` and ```MasterControl``` for that third party library. + +## Source files +* [applications/OptimizationApplication/python_scripts/algorithms/algorithm.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/algorithms/algorithm.py) +* [Doxygen](TODO) + + From d86bffd8f3bcdd47b8e79b1911f3273ee0162266 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 16:16:08 +0100 Subject: [PATCH 06/33] response routine --- .../General/Algorithm.md | 10 +++--- .../General/Response_Routine.md | 32 ++++++++++++++++++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/docs/pages/Applications/Optimization_Application/General/Algorithm.md b/docs/pages/Applications/Optimization_Application/General/Algorithm.md index 7635d09a08b1..d5627ec1baee 100644 --- a/docs/pages/Applications/Optimization_Application/General/Algorithm.md +++ b/docs/pages/Applications/Optimization_Application/General/Algorithm.md @@ -1,14 +1,14 @@ --- title: Algorithm -keywords: -tags: [Algorithm.md] +keywords: +tags: [algorithm, optimization] sidebar: optimization_application -summary: +summary: --- ## Introduction -Figure 1 illustrates hwo an algorithm operates when ```OptimizationAnalysis``` executes ```Algorithm::Solve``` method. Overview of the existing algorithms can be found [here](../Algorithms/Overview.html). +Figure 1 illustrates how an algorithm operates when ```OptimizationAnalysis``` executes ```Algorithm::Solve``` method. Overview of the existing algorithms can be found [here](../Algorithms/Overview.html).

Algorithm @@ -38,6 +38,6 @@ When an ```Algorithm``` is constructed by the ```OptimizationAnalysis```, ## Source files * [applications/OptimizationApplication/python_scripts/algorithms/algorithm.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/algorithms/algorithm.py) -* [Doxygen](TODO) +* [Doxygen](TODO) TODO diff --git a/docs/pages/Applications/Optimization_Application/General/Response_Routine.md b/docs/pages/Applications/Optimization_Application/General/Response_Routine.md index 1bcd551212b3..9fa0f0681461 100644 --- a/docs/pages/Applications/Optimization_Application/General/Response_Routine.md +++ b/docs/pages/Applications/Optimization_Application/General/Response_Routine.md @@ -1,7 +1,37 @@ --- title: Response Routine keywords: -tags: [Response_Routine.md] +tags: [response routine, response function, optimization] sidebar: optimization_application summary: --- +## Introduction + +Figure 1 illustrates how a ```ResponseRoutine``` operates. + +

+ Response routine +

+

Figure 1: Response routine

+ +## Working space. + +As illustrated in the Figure 1, ```ResponseRoutine``` will work in the control space and physical space. It uses ```MasterControl``` to transform control space to physical space and wise versa. + +## Supporting components + +Each ```ResponseRoutine``` will not create its own ```ResponseFunction```s. It should use ```ResponseFunction```s given by the ```OptimizationProblem``` data container. Once assigned, ```ResponseRoutine``` has the authority on how to control the ```ResponseFunction``` (such as calling methods for ```ResponseFunction```). + +**```ResponseRoutine``` does not own the ```MasterControl```. It should merely use the shared ```MasterControl```.** + +## Data flow and work flow + +```ResponseRoutine``` will receive new design in the control space (i.e. $$\underline{\hat{\phi}}$$). Then it should use the ```MasterControl``` to convert the new design to physical space (i.e. $$\underline{\phi}$$) and update the mesh. Thereafter, it will request the new objective/constraint values (i.e. $$J_1$$) and their gradients in the physical space (i.e. $$\frac{dJ_1}{d\underline{\phi}}$$). Thereafter, it will convert the physical space gradients to control space gradients (i.e. $$\frac{dJ_1}{d\underline{\hat{\phi}}}$$). Finally it will return the standardized objective/constraint values (i.e. $$\tilde{J}_1$$) and their gradients (i.e. $$\frac{d\tilde{J}_1}{d\underline{\hat{\phi}}}$$) + +## Notes +* One of the major duties of the ```ResponseRoutine``` is to request the physical control variables +used in the ```MasterControl``` for each domain, and find out what gradients should be requested from the ```ResponseFunction```s. + +## Source files +* [applications/OptimizationApplication/python_scripts/responses/response_routine.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/responses/response_routine.py) +* [Doxygen](TODO) TODO \ No newline at end of file From 7bcfb67d7b58f434bf321ec2a7139fb6127f6a0d Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 16:30:16 +0100 Subject: [PATCH 07/33] add response function docs --- .../General/Response_Function.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/pages/Applications/Optimization_Application/General/Response_Function.md b/docs/pages/Applications/Optimization_Application/General/Response_Function.md index ff93218f1eeb..094023700450 100644 --- a/docs/pages/Applications/Optimization_Application/General/Response_Function.md +++ b/docs/pages/Applications/Optimization_Application/General/Response_Function.md @@ -1,7 +1,21 @@ --- title: Response Function keywords: -tags: [Response_Function.md] +tags: [response function, optimization] sidebar: optimization_application summary: --- + +## Introduction + +Response function is used to compute the objective/constraint values and their respective gradients. It purely lives within the physical space, hence all the computed values will be in the physical space. + +## Notes +* It will have methods to compute gradients for variables as requested. If a variable is requested, and the gradient computation is not implemented, then it should throw an error. +* ResponseFunction should implement all the variables it depends on. If something is hard to be implemented at the moment of the ```ResponseFunction``` development, then put that variable and throw and error saying not yet implemented. +* ```ResponseFunction``` may or may not use ```ExecutionPolicies```. If it required to have an primal analysis, it must use ```ExecutionPolicy``` to obtain the primal analysis. In this case ```ResponseFunction```. In this case, the ```ResponseFunction::GetEvaluatedModelPart``` will be the domain on which the response is evaluated on and ```ResponseFunction::GetAnalysisModelPart``` will be the domain on which the adjoints may be computed [If no adjoints are used, this method returns None]. + +## Source files +* [applications/OptimizationApplication/python_scripts/responses/response_function.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/responses/response_function.py) +* [Doxygen](TODO) TODO + From 7356a9514eb1b0e7e3382dd59e92b8c021d980b9 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 17:44:31 +0100 Subject: [PATCH 08/33] execution policy --- .../execution_policies/execution_policy.py | 17 ++++++++++++++++ .../General/Execution_Policy.md | 20 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/applications/OptimizationApplication/python_scripts/execution_policies/execution_policy.py b/applications/OptimizationApplication/python_scripts/execution_policies/execution_policy.py index 7516953b3c16..27ccaa6d6792 100644 --- a/applications/OptimizationApplication/python_scripts/execution_policies/execution_policy.py +++ b/applications/OptimizationApplication/python_scripts/execution_policies/execution_policy.py @@ -2,6 +2,13 @@ import KratosMultiphysics as Kratos class ExecutionPolicy(ABC): + """Base class for execution policy + + This represents the base class for the execution policy which + can be used to execute primal analysis to obtain response function + values and their gradients. + + """ def __init__(self, execution_policy_name: str) -> None: self.__name = execution_policy_name @@ -22,8 +29,18 @@ def Finalize(self) -> None: @abstractmethod def GetAnalysisModelPart(self) -> Kratos.ModelPart: + """Returns the analysis model part. + + Each execution policy will be using a domain to compute the primal model part. + This method should return that domain as a Kratos::ModelPart. + + Returns: + Kratos.ModelPart: Domain used to compute the primal solution. + """ pass @abstractmethod def Execute(self) -> None: + """Solves the associated primal problem. + """ pass \ No newline at end of file diff --git a/docs/pages/Applications/Optimization_Application/General/Execution_Policy.md b/docs/pages/Applications/Optimization_Application/General/Execution_Policy.md index ec3ae40e5cbb..7cfd61bf9e05 100644 --- a/docs/pages/Applications/Optimization_Application/General/Execution_Policy.md +++ b/docs/pages/Applications/Optimization_Application/General/Execution_Policy.md @@ -1,7 +1,25 @@ --- title: Execution Policy keywords: -tags: [Execution_Policy.md] +tags: [execution policy, optimization] sidebar: optimization_application summary: --- + +## Introduction + +Execution policies are used to execute an analysis which will be used to compute response values +and/or gradients. Overview of available ```ExecutionPolicy```s can be found [here](../Execution_Policies/Overview.html). + +These analysis may be: +* Kratos static analysis +* Kratos dynamic analysis +* External analysis + +Depending on the analysis, you may have to develop your won ```ExecutionPolicy``` to be used with optimization analysis. + +All the information about new design updates are passed via ```Kratos::ModelPart```, hence no additional information will be passed to this except for ```OptimizationProblem``` data container. + +## Source files +* [applications/OptimizationApplication/python_scripts/execution_policies/execution_policy.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/execution_policies/execution_policy.py) +* [Doxygen](TODO) TODO From 4bd36a726a3d996f61f2a6485d8ab04714858dcb Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 17:44:42 +0100 Subject: [PATCH 09/33] master control docs --- .../General/Master_Control.md | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/pages/Applications/Optimization_Application/General/Master_Control.md b/docs/pages/Applications/Optimization_Application/General/Master_Control.md index 824d34643cfb..20ff04a0deb6 100644 --- a/docs/pages/Applications/Optimization_Application/General/Master_Control.md +++ b/docs/pages/Applications/Optimization_Application/General/Master_Control.md @@ -1,7 +1,34 @@ --- title: Master Control keywords: -tags: [Master_Control.md] +tags: [master control, control, optimization] sidebar: optimization_application summary: --- +## Introduction + +```MasterControl``` is a collection of ```Control```s used by an ```Algorithm```. It is owned by ```Algorithm``` and shared among all the ```ResponseRoutine```s used by that ```Algorithm```. It does not own any of the ```Control```s, it just links to appropriate ```Control```s found in ```OptimizationProblem```. Thereafter, ```MasterControl``` can govern over these ```Control```s. + +## Data flow and work flow + +It is responsible for converting control space designs (i.e. $$\underline{\hat{\phi}}$$) to physical space designs (i.e. $$\underline{\phi}$$). This is done via the ```MasterControl::Update``` method as illustrated in Figure 1. It disassemble the control domain ```CollectiveExpression``` (i.e. $$\underline{\hat{\phi}}$$) passed to the master control, to smaller ```ContainerExpressions``` control domains (i.e. $$\underline{\hat{\phi}}_1$$, $$\underline{\hat{\phi}}_2$$) and then use respective ```Control``` to transform to smaller physical domains ```ContainerExpressions``` (i.e. $$\underline{\phi}_1$$, $$\underline{\phi}_1$$). Then another ```CollectiveExpression``` is built aggregating all the smaller physical domains to a larger physical domain (i.e $$\underline{\phi}$$) to get the final physical domain. + +

+ Update method of Master Control +

+

Figure 1: Update method of Master Control

+ +It is also responsible for converting physical domain gradients given in a ```CollectiveExpression``` (i.e. $$\frac{dJ_1}{d\underline{\phi}}$$) to the control domain gradients given by again a ```CollectiveExpression``` (i.e. $$\frac{dJ_1}{d\underline{\hat{\phi}}}$$) by calling ```MasterControl::MapGradient``` as illustrated in Figure 2. There, the passed ```CollectiveExpression``` is disassembled to smaller physical domain ```ContainerExpressions``` (i.e. $$\frac{dJ_1}{d\underline{\phi}_1}$$, $$\frac{dJ_1}{d\underline{\phi}_2}$$). Thereafter, these are passed through their respective ```Control```s to convert to control domain ```ContainerExpressions``` (i.e. $$\frac{dJ_1}{d\underline{\hat{\phi}}_1}$$, $$\frac{dJ_1}{d\underline{\hat{\phi}}_2}$$). Thereafter, final gradient is computed as a ```CollectiveExpression``` by aggregating all the control domain gradients (i.e. $$\frac{dJ_1}{d\underline{\hat{\phi}}}$$). +

+ MapGradient method of Master Control +

+

Figure 2: MapGradient method of Master Control

+ +## Notes + +1. ```MasterControl``` does not own any of the ```Control```s, but once assigned, these ```Control```s are governed by ```MasterControl```. +2. There should be only one ```MasterControl``` for an optimization analysis. + +## Source files +* [applications/OptimizationApplication/python_scripts/controls/master_control.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/controls/master_control.py) +* [Doxygen](TODO) TODO \ No newline at end of file From c55d372f80f6de3731a4d93d6395d6fad575a1b3 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 17:58:52 +0100 Subject: [PATCH 10/33] update master control --- .../Optimization_Application/General/Master_Control.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/pages/Applications/Optimization_Application/General/Master_Control.md b/docs/pages/Applications/Optimization_Application/General/Master_Control.md index 20ff04a0deb6..c1caf596a019 100644 --- a/docs/pages/Applications/Optimization_Application/General/Master_Control.md +++ b/docs/pages/Applications/Optimization_Application/General/Master_Control.md @@ -9,6 +9,10 @@ summary: ```MasterControl``` is a collection of ```Control```s used by an ```Algorithm```. It is owned by ```Algorithm``` and shared among all the ```ResponseRoutine```s used by that ```Algorithm```. It does not own any of the ```Control```s, it just links to appropriate ```Control```s found in ```OptimizationProblem```. Thereafter, ```MasterControl``` can govern over these ```Control```s. +## Working space + +As explained above ```MasterControl``` will work in the control space and physical space. + ## Data flow and work flow It is responsible for converting control space designs (i.e. $$\underline{\hat{\phi}}$$) to physical space designs (i.e. $$\underline{\phi}$$). This is done via the ```MasterControl::Update``` method as illustrated in Figure 1. It disassemble the control domain ```CollectiveExpression``` (i.e. $$\underline{\hat{\phi}}$$) passed to the master control, to smaller ```ContainerExpressions``` control domains (i.e. $$\underline{\hat{\phi}}_1$$, $$\underline{\hat{\phi}}_2$$) and then use respective ```Control``` to transform to smaller physical domains ```ContainerExpressions``` (i.e. $$\underline{\phi}_1$$, $$\underline{\phi}_1$$). Then another ```CollectiveExpression``` is built aggregating all the smaller physical domains to a larger physical domain (i.e $$\underline{\phi}$$) to get the final physical domain. From cff41b396010792c476ca6759f44ff269f0abba4 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 17:58:59 +0100 Subject: [PATCH 11/33] add control docs --- .../General/Control.md | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/pages/Applications/Optimization_Application/General/Control.md b/docs/pages/Applications/Optimization_Application/General/Control.md index a714e752e315..6551e1ebdf3b 100644 --- a/docs/pages/Applications/Optimization_Application/General/Control.md +++ b/docs/pages/Applications/Optimization_Application/General/Control.md @@ -1,7 +1,34 @@ --- title: Control keywords: -tags: [Control.md] +tags: [control, optimization] sidebar: optimization_application summary: --- + +## Introduction + +```Control``` is used to control the design surface with the updates given by the ```Algorithm``` as illustrated in Figure 1. This is also used to transform data between physical and control spaces. +

+ Control data flow +

+

Figure 1: Control data flow

+ +## Working space + +As explained above ```Control``` will work in the control space and physical space. + +## Data flow and work flow + +```Control``` is responsible for updating the domain (i.e. mesh, domain values) with the new design given by the ```Algorithm```. First it will map the control space design (i.e. $$\underline{\hat{\phi}}$$) to physical space (i.e. $$\underline{\phi}$$) using the ```Filtering```. Then these physical space values are used to update the mesh or the domain values. + +```Control``` is also responsible for mapping physical space gradients (i.e. $$\frac{dJ_1}{d\underline{\phi}}$$) to control space (i.e. $$\frac{dJ_1}{d\underline{\hat{\phi}}}$$) using the ```Filtering``` method as illustrated in the Figure 1. + +## Notes + +1. A control should only work in one domain (or ```Kratos::ModelPart```). If more than one domain is required control (or ```Kratos::ModelPart```) then, they should made to one domain using union utilities. + +## Source files +* [applications/OptimizationApplication/python_scripts/controls/control.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/controls/control.py) +* [Doxygen](TODO) TODO + From 4e245ba07a569db9d2ecf594bc933feb763e60ea Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 18:22:39 +0100 Subject: [PATCH 12/33] add optimization problem docs --- .../General/Optimization_Problem.md | 72 ++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/docs/pages/Applications/Optimization_Application/General/Optimization_Problem.md b/docs/pages/Applications/Optimization_Application/General/Optimization_Problem.md index a283f6402072..ad932ae9bb0a 100644 --- a/docs/pages/Applications/Optimization_Application/General/Optimization_Problem.md +++ b/docs/pages/Applications/Optimization_Application/General/Optimization_Problem.md @@ -1,7 +1,77 @@ --- title: Optimization Problem keywords: -tags: [Optimization_Problem.md] +tags: [optimization problem, optimization] sidebar: optimization_application summary: --- + +## Introduction + +The ```OptimizationProblem``` is a data container which is used to pass information between components used in the ```OptimizationAnalysis```. There is only one ```OptimizationProblem``` per ```OptimizationAnalysis``` + +## Data storage + +It has two types of data containers. +1. Static data storage. +2. Historical data storage. +3. Component storage. + +### Static data storage + +Static data storage can only have one value for the whole optimization analysis. Overwriting is not allowed. If required to overwrite, then one should first delete the exiting data, and then write new data. This uses an instance of [BufferedDict](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/utilities/buffered_dict.py). + +### Historical data storage + +Historical data storage can have different values for different iterations of the whole optimization analysis. Overwriting is not allowed by default (it can be specified). This uses an instance of [BufferedDict](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/utilities/buffered_dict.py). + +### Component storage + +```OptimizationProblem``` will also store all the instances of ```ExecutionPolicy```s, ```ResponseFunction```s and ```Control```s. Each of the component can have its own data storage within the ```OptimizationProblem```. + +The component specific storage can be accessed by the use of [```ComponentDataView```](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/utilities/component_data_view.py). Following python code snippet illustrates a use case +```python +import KratosMultiphysics as Kratos +from KratosMultiphysics.OptimizationApplication.utilities.optimization_problem import OptimizationProblem +from KratosMultiphysics.OptimizationApplication.execution_policies.execution_policy_decorator import ExecutionPolicyDecorator +from KratosMultiphysics.OptimizationApplication.utilities.component_data_view import ComponentDataView + +model = Kratos.Model() + +echo_level = 1 +opt_problem = OptimizationProblem(echo_level) + +parameters = Kratos.Parameters("""{ + "name" : "test", + "type" : "independent_analysis_execution_policy", + "settings": { + "analysis_type" : "orchestrators.SequentialOrchestrator", + "analysis_settings": { + "orchestrator": { + "settings": { + "stage_checkpoints": false + } + }, + "stages":[] + } + } +}""") +execution_policy = ExecutionPolicyDecorator(model, parameters, opt_problem) + +## add the component to opt problem +opt_problem.AddComponent(execution_policy) + +# retrieve the component specific data container from opt_problem +data_view = ComponentDataView(execution_policy, opt_problem) + +## set buffer to store data for 2 iterations in memory +data_view.SetDataBuffer(2) + +## get the historical BufferedDict +historical_data = data_view.GetBufferedData() +print(historical_data) + +## get the static BufferedDict +static_data = data_view.GetUnBufferedData() +print(static_data) +``` \ No newline at end of file From 90df22a6c4e2e9b8a721194b53ee7638576dc9a6 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 18:35:48 +0100 Subject: [PATCH 13/33] add collective expressions --- .../General/Collective_Expressions.md | 43 +++++++++++++++++++ .../General/menu_info.json | 1 + 2 files changed, 44 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/General/Collective_Expressions.md diff --git a/docs/pages/Applications/Optimization_Application/General/Collective_Expressions.md b/docs/pages/Applications/Optimization_Application/General/Collective_Expressions.md new file mode 100644 index 000000000000..885ac553716a --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/General/Collective_Expressions.md @@ -0,0 +1,43 @@ +--- +title: Collective Expressions +keywords: +tags: [collective expressions, expressions, optimization] +sidebar: optimization_application +summary: +--- + + +## Introduction + +```CollectiveExpressions``` as name suggests is a collection of ```NodalExpression``` and/or ```ConditionExpression``` and/or ```ElementExpression```. You can assume the ```CollectiveExpression``` as a flat vector flattening all the ```Expressions``` it hold. It also allows doing all the arithmetic and other operations which are defined for ```Expressions```. Even though they appear as a flat double vector, A ```CollectiveExpression``` can easily return the underlying ```Expression```s if required. + +## Adding and removing ```Expression```s and retrieving expressions. + +Following code snippet illustrates how to add and remove ```Expression```s to ```CollectiveExpression``` +```python +import KratosMultiphysics as Kratos +import KratosMultiphysics.OptimizationApplication as KratosOA + +model = Kratos.Model() +model_part = model.CreateModelPart("test") + +nodal_expression = Kratos.Expression.NodalExpression(model_part) +cond_expression = Kratos.Expression.ConditionExpression(model_part) + +collective_expression = KratosOA.CollectiveExpression() + +# adds a nodal expression and condition expression +collective_expression.Add(nodal_expression) +collective_expression.Add(cond_expression) + +# retrieves expressions in the order they were added +for exp in collective_expression.GetContainerExpressions(): + print(exp) + +# clears all the expressions +collective_expression.Clear() +``` + +## Source files +* [Doxygen](TODO) TODO +* [applications/OptimizationApplication/tests/test_collective_expressions.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/tests/test_collective_expressions.py) diff --git a/docs/pages/Applications/Optimization_Application/General/menu_info.json b/docs/pages/Applications/Optimization_Application/General/menu_info.json index 5914784f4160..7ea0064469af 100644 --- a/docs/pages/Applications/Optimization_Application/General/menu_info.json +++ b/docs/pages/Applications/Optimization_Application/General/menu_info.json @@ -8,6 +8,7 @@ "Execution_Policy.md", "Master_Control.md", "Control.md", + "Collective_Expressions.md", "Optimization_Problem.md" ] } \ No newline at end of file From c44f7e72998b3f1b39e8cce9667106de77b68eee Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Thu, 1 Feb 2024 22:34:34 +0100 Subject: [PATCH 14/33] add response function docs --- .../Linear_Strain_Energy_Response_Function.md | 44 +++++++++++++++++++ .../Responses/Mass_Response_Function.md | 41 +++++++++++++++++ .../Responses/menu_info.json | 5 +++ 3 files changed, 90 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Responses/Linear_Strain_Energy_Response_Function.md create mode 100644 docs/pages/Applications/Optimization_Application/Responses/Mass_Response_Function.md create mode 100644 docs/pages/Applications/Optimization_Application/Responses/menu_info.json diff --git a/docs/pages/Applications/Optimization_Application/Responses/Linear_Strain_Energy_Response_Function.md b/docs/pages/Applications/Optimization_Application/Responses/Linear_Strain_Energy_Response_Function.md new file mode 100644 index 000000000000..8867bb347707 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Responses/Linear_Strain_Energy_Response_Function.md @@ -0,0 +1,44 @@ +--- +title: Linear Strain Energy Response Function +keywords: +tags: [strain energy, response function, optimization] +sidebar: optimization_application +summary: +--- +## Introduction + +This computes the summation of strain energy from each element as the response value and its gradient. + +## Formulation + +Following formulation is used to compute the summation of strain energy from each element in the chosen model part where $$\underline{u}$$ is the displacement vector for the element and $$\mathbf{K}$$ is the stiffness matrix of the element. +

$$ J = \frac{1}{2}\sum_{\forall \Omega_i \in \Omega} \underline{u}^T_i \mathbf{K}_i \underline{u}_i $$

+ +## Json settings +Following code snippet illustrates json settings used in this response function. +```json +{ + "name": "strain_energy", + "type": "linear_strain_energy_response_function", + "settings": { + "evaluated_model_part_names": [ + "Structure" + ], + "primal_analysis_name": "Structure_static", + "perturbation_size": 1e-8 + } +} +``` + +| Option | Allowed values | +| ------------- | ------------- | +| name | A unique string | +| type | "linear_strain_energy_response_function" | +| evaluated_model_part_names | List of model part names to compute strain energy | +| primal_analysis_name | Name of the analysis from the list of analysis to be used for strain energy computation | +| perturbation_size | Perturbation size to be used in the semi-analytic method | + +## Source files + +* [applications/OptimizationApplication/python_scripts/responses/linear_strain_energy_response_function.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/responses/linear_strain_energy_response_function.py) +* [Doxygen](doxygen) TODO diff --git a/docs/pages/Applications/Optimization_Application/Responses/Mass_Response_Function.md b/docs/pages/Applications/Optimization_Application/Responses/Mass_Response_Function.md new file mode 100644 index 000000000000..48a5ee95e81b --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Responses/Mass_Response_Function.md @@ -0,0 +1,41 @@ +--- +title: Mass Response Function +keywords: +tags: [mass, response function, optimization] +sidebar: optimization_application +summary: +--- + +## Introduction + +This response function computes the mass of the given list of model parts. + +## Formulation + +Following formulation is used. +

$$ J = \sum_{\forall \Omega_i \in \Omega} m_i $$

+ +## Json settings +Following code snippet illustrates json settings used in this response function. +```json +{ + "name": "mass", + "type": "mass_response_function", + "settings": { + "evaluated_model_part_names": [ + "Structure" + ] + } +} +``` + +| Option | Allowed values | +| ------------- | ------------- | +| name | A unique string | +| type | "mass_response_function" | +| evaluated_model_part_names | List of model part names to compute mass | + +## Source files + +* [applications/OptimizationApplication/python_scripts/responses/mass_response_function.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/responses/mass_response_function.py) +* [Doxygen](doxygen) TODO \ No newline at end of file diff --git a/docs/pages/Applications/Optimization_Application/Responses/menu_info.json b/docs/pages/Applications/Optimization_Application/Responses/menu_info.json new file mode 100644 index 000000000000..0cc207564821 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Responses/menu_info.json @@ -0,0 +1,5 @@ +{ + "custom_entries": [ + "Overview.md" + ] +} \ No newline at end of file From 62c21cddf7f1c96cd4f507019f95d676825581e3 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 09:22:21 +0100 Subject: [PATCH 15/33] complete vertex morphing --- .../Filtering/Vertex_Morphing.md | 139 ++++++++++++++++++ .../Filtering/menu_info.json | 5 + 2 files changed, 144 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Filtering/Vertex_Morphing.md create mode 100644 docs/pages/Applications/Optimization_Application/Filtering/menu_info.json diff --git a/docs/pages/Applications/Optimization_Application/Filtering/Vertex_Morphing.md b/docs/pages/Applications/Optimization_Application/Filtering/Vertex_Morphing.md new file mode 100644 index 000000000000..d8ee581ee22f --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Filtering/Vertex_Morphing.md @@ -0,0 +1,139 @@ +--- +title: Vertex morphing +keywords: +tags: [vertex morphing, filtering, optimization] +sidebar: optimization_application +summary: +--- + +## Introduction + +Vertex morphing is a filtering method to filter out noise present in a gradient field or design field. Noisy gradient field is a common challenge in optimization problems which makes updated designs non-intuitive. They may also make the updated meshes based on updated design space with bad elements which eventually result in failure in primal and adjoint solution computation. Therefore it is crucial to apply a filtering technique to obtain a smooth gradient field. An example of a noisy field is shown in figure 1. + +

+ Noisy design field +

+

Figure 1: Noisy design field

+ +### Definition + +Figure 2 illustrates the filtering methodology applied in vertex morphing. Control field (i.e. sensitivity field) is demonstrated by $$S\left(\xi\right)$$. Filtering domain is identified by the used $$r$$ filter radii for each mesh coordinate. Then a filtering function of $$A\left(\xi-\xi_0\right)$$ is applied on the filtering domain to obtain smoothened and filtered design control field of $$z\left(\xi_o\right)$$ as illustrated in the figure. + +

+ Vertex morphing filtering +

+

Figure 2: Vertex morphing filtering

+ +Following equation is used to obtain the final filtered design control field. + +

$$ z\left(x_0\right) = \int_{x_0-r}^{x_0+r} A\left(x, x_0, r\right)s\left(x\right) d\Gamma $$

+ +Figure 2 illustrates obtained filtered and smoothened design field of the noist design field illustrated in figure 1. + +

+ Filtered design field +

+

Figure 2: Filtered design field

+ +It is important to note that the variability of the resulting shape is characterized by the density of the design grid used to discretize the physical field $$s$$. The filter helps to control the continuity properties of the resulting shape. The filter does not affect the global and local solutions and leaves them unchanged. Typically, of course, in the case of non-convex problems different local solutions are found for different filters as they modify the descent directions. The physical space and its variety of alternative local optima are easily explored with repeated optimization and varied filters. + +### Effect of filter radii + +Higher filter radii (i.e. $$r$$) results in smoothened design field over a circular area in 2D and a spherical area in 3D with radius $$r$$. It may loose the local effect which are significant in obtaining design field which is capable of optimizing the given objective(s). This is illustrated in figure 3. In there, green plot illustrates the noisy design field in physical space, blue plot illustrates filtered design field in control space with $$r=4$$ and red plots illustrate filtered design fields with $$r=6$$ (left) and $$r=16$$ (right). + +

+ +

+

Figure 3: Filter radii effect on smoothened design field

+ +### Filter functions + +Following is a list of supported filter functions and their definitions. + +#### Gaussian filter function + +

$$ A\left(\mathbf{x},\mathbf{x_0},r\right) = \max\left\lbrace 0.0, e^{\frac{-9\left|\mathbf{x}-\mathbf{x_0}\right|^2}{2r^2}}\right\rbrace$$

+ +#### Linear filter function +

$$ A\left(x,x_0,r\right) = \max\left\lbrace 0.0, \frac{r-\left|\mathbf{x}-\mathbf{x_0}\right|}{r}\right\rbrace$$

+ +#### Constant filter function +

$$ A\left(x,x_0,r\right) = 1.0$$

+ +#### Cosine filter function +

$$ A\left(x,x_0,r\right) = \max\left\lbrace 0.0, 1-0.5\left(1-\cos\left(\pi\frac{\left|\mathbf{x}-\mathbf{x_0}\right|}{r}\right)\right)\right\rbrace$$

+ + +#### Quartic filter function +

$$ A\left(x,x_0,r\right) = \max\left\lbrace 0.0, \left(\frac{\left|\mathbf{x}-\mathbf{x_0}\right|-r}{r}\right)^4\right\rbrace$$

+ +#### Area weighted sum integration method + +This method modifies chosen ``filter_function_type`` based on the nodal area averaging methodology. $$B\left(x, x_0, r\right)$$ is the nodal area of the neighbour node at $$x$$ position, $$N$$ is the number of neighbour nodes. + +

$$ A\left(x,x_0,r\right) = A\left(x,x_0,r\right)\times \frac{B\left(x, x_0, r\right)}{\sum_{n=1}^{N}\left[B\left(x, x_0, r\right)\right]}$$

+ +## Damping + +An optimized design is obtained by changing the design variables in the opposite direction of the objective gradient (if a minimization problem is considered). Then the next question is, what if the user wants to retain the initial design in some parts of the design surface (i.e. damping regions as in the left half of the line segment in figure 4.). The most simplistic way to achieve this would be to disregard the gradient information on those regions (refer figure 5). The main issue with this approach is, it creates steep gradients between these damped and undamped regions making the obtained optimized design un-natural and with a poor quality to perform **FEM** analysis afterwards. Therefore, to overcome this problem, damping is used. Damping uses smooth functional to dampen the gradient information in the damped regions such that there does not exist any steep gradients between damped and undamped regions (refer figure 6). +

+ Physical space gradients +

+

Figure 4: Physical space gradients along the line left half to be restricted.)

+ +

+ Cut gradients +

+

Figure 5: Sensitivities along the line when damped region sensitivities are set to zero (left half to be restricted.)

+ +

+ Damped gradients +

+

Figure 6: Gradients along the line when damped region is damped using a damping methodology. (left half to be restricted.)

+ +### Damping functions + +Following damping functions are supported: + +#### Gaussian filter function + +

$$ A\left(\mathbf{x},\mathbf{x_0},r\right) = \max\left\lbrace 0.0, e^{\frac{-9\left|\mathbf{x}-\mathbf{x_0}\right|^2}{2r^2}}\right\rbrace$$

+ +#### Linear filter function +

$$ A\left(x,x_0,r\right) = \max\left\lbrace 0.0, \frac{r-\left|\mathbf{x}-\mathbf{x_0}\right|}{r}\right\rbrace$$

+ +#### Constant filter function +

$$ A\left(x,x_0,r\right) = 1.0$$

+ +#### Cosine filter function +

$$ A\left(x,x_0,r\right) = \max\left\lbrace 0.0, 1-0.5\left(1-\cos\left(\pi\frac{\left|\mathbf{x}-\mathbf{x_0}\right|}{r}\right)\right)\right\rbrace$$

+ + +#### Quartic filter function +

$$ A\left(x,x_0,r\right) = \max\left\lbrace 0.0, \left(\frac{\left|\mathbf{x}-\mathbf{x_0}\right|-r}{r}\right)^4\right\rbrace$$

+ +## Vertices for different containers +This vertex morphing and damping are used to compute vertex morphed and constrained gradients of objectives and constraints. The vertex morphing and damping requires always a vertices to compute the smoothen control field in control space. +1. In the case physical field is in the ```Kratos::NodesContainerType```, then it uses nodal locations as the vertices. +2. In the case physical field is in the ```Kratos::ConditionsContainerType```, then it uses conditions' underlying geometry's center as the vertices. +3. In the case physical field is in the ```Kratos::ElementsContainerType```, then it uses elements' underlying geometry's center as the vertices. + +## Damping methodology + +Damping factors (i.e. $$\beta_{i, damp}$$) are computed for each $$i^{th}$$ vertex in the damping regions as follows. First neighbours of each vertex in the damping region is found using a KDTree search. +

$$ \beta_{i, damp} = \min_{x_j \in \Omega_{i, neighbours}} 1.0 - A(x_i, x_j, r) $$

+ +Thereafter, the gradient of the vertex is multiplied by the damping factor to compute the damped sensitivities as shown in the following equation: +

$$ \left(\frac{dh}{d\underline{s}}\right)_{i, damped} = \beta_{i, damp}\left(\frac{dh}{d\underline{s}}\right)_i $$

+ +## Vertex morphing methodology + +Then for each vertex's (i.e. $$i^{th}$$) neigbhour vertices (i.e. $$j^{th}$$) the weights are computed using filter functions mentioned above (i.e. $$A_{ij}$$). Thereafter, the vertex morphed gradients for each gradient is computed as given in the following equation. + +

$$ \left(\frac{df}{d\underline{s}}\right)_{i, morphed} = \frac{1}{\sum_{j=1}^N A_{ij}}\sum_{j=1}^{N} A_{ij}\left(\frac{df}{d\underline{s}}\right)_j$$

+ +## Source files +* [Doxygen](TODO) TODO +* [applications/OptimizationApplication/custom_utilities/filtering/filter_function.h](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/custom_utilities/filtering/filter_function.h) +* [applications/OptimizationApplication/custom_utilities/filtering/damping_function.h](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/custom_utilities/filtering/damping_function.h) +* [applications/OptimizationApplication/custom_utilities/filtering/explicit_filter.h](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/custom_utilities/filtering/explicit_filter.h) \ No newline at end of file diff --git a/docs/pages/Applications/Optimization_Application/Filtering/menu_info.json b/docs/pages/Applications/Optimization_Application/Filtering/menu_info.json new file mode 100644 index 000000000000..0cc207564821 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Filtering/menu_info.json @@ -0,0 +1,5 @@ +{ + "custom_entries": [ + "Overview.md" + ] +} \ No newline at end of file From e983a224afb55fa7d518bac99d6f2094d7a5f901 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 09:25:45 +0100 Subject: [PATCH 16/33] minor --- ...{Vertex_Morphing.md => Explicit_Vertex_Morphing.md} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename docs/pages/Applications/Optimization_Application/Filtering/{Vertex_Morphing.md => Explicit_Vertex_Morphing.md} (93%) diff --git a/docs/pages/Applications/Optimization_Application/Filtering/Vertex_Morphing.md b/docs/pages/Applications/Optimization_Application/Filtering/Explicit_Vertex_Morphing.md similarity index 93% rename from docs/pages/Applications/Optimization_Application/Filtering/Vertex_Morphing.md rename to docs/pages/Applications/Optimization_Application/Filtering/Explicit_Vertex_Morphing.md index d8ee581ee22f..0ddb3e53a471 100644 --- a/docs/pages/Applications/Optimization_Application/Filtering/Vertex_Morphing.md +++ b/docs/pages/Applications/Optimization_Application/Filtering/Explicit_Vertex_Morphing.md @@ -1,14 +1,14 @@ --- -title: Vertex morphing -keywords: -tags: [vertex morphing, filtering, optimization] +title: Explicit Vertex Morphing +keywords: +tags: [explicit, vertex morphing, filtering, optimization] sidebar: optimization_application -summary: +summary: --- ## Introduction -Vertex morphing is a filtering method to filter out noise present in a gradient field or design field. Noisy gradient field is a common challenge in optimization problems which makes updated designs non-intuitive. They may also make the updated meshes based on updated design space with bad elements which eventually result in failure in primal and adjoint solution computation. Therefore it is crucial to apply a filtering technique to obtain a smooth gradient field. An example of a noisy field is shown in figure 1. +Explicit Vertex morphing (here onwards called as vertex morphing) is a filtering method to filter out noise present in a gradient field or design field. Noisy gradient field is a common challenge in optimization problems which makes updated designs non-intuitive. They may also make the updated meshes based on updated design space with bad elements which eventually result in failure in primal and adjoint solution computation. Therefore it is crucial to apply a filtering technique to obtain a smooth gradient field. An example of a noisy field is shown in figure 1.

Noisy design field From e7d3e3326fe27d0e9fb459a5d1d2d19e3d2d60be Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 11:23:36 +0100 Subject: [PATCH 17/33] update explict vm --- .../Filtering/Explicit_Vertex_Morphing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pages/Applications/Optimization_Application/Filtering/Explicit_Vertex_Morphing.md b/docs/pages/Applications/Optimization_Application/Filtering/Explicit_Vertex_Morphing.md index 0ddb3e53a471..593d1840e2e1 100644 --- a/docs/pages/Applications/Optimization_Application/Filtering/Explicit_Vertex_Morphing.md +++ b/docs/pages/Applications/Optimization_Application/Filtering/Explicit_Vertex_Morphing.md @@ -1,9 +1,9 @@ --- title: Explicit Vertex Morphing -keywords: +keywords: tags: [explicit, vertex morphing, filtering, optimization] sidebar: optimization_application -summary: +summary: --- ## Introduction From 6a8213ad36977a625004d25e7b794a455513407c Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 11:23:47 +0100 Subject: [PATCH 18/33] add mdpa mp controller docs --- .../Mdpa_ModelPart_Controller.md | 39 +++++++++++++++++++ .../Model_Part_Controllers/menu_info.json | 5 +++ 2 files changed, 44 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Mdpa_ModelPart_Controller.md create mode 100644 docs/pages/Applications/Optimization_Application/Model_Part_Controllers/menu_info.json diff --git a/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Mdpa_ModelPart_Controller.md b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Mdpa_ModelPart_Controller.md new file mode 100644 index 000000000000..f58eeb43578b --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Mdpa_ModelPart_Controller.md @@ -0,0 +1,39 @@ +--- +title: Mdpa ModelPart Controller +keywords: +tags: [mdpa, model part controller, optimization] +sidebar: optimization_application +summary: +--- + +## Introduction + +This ```MdpaModelPartController``` is used to read model parts from mdpa files. + + +## Json settings +Following json-snippet illustrates an example use case +```json +{ + "type": "mdpa_model_part_controller", + "module": "KratosMultiphysics.OptimizationApplication.model_part_controllers", + "settings": { + "model_part_name": "Structure", + "domain_size": 3, + "input_filename": "Structure" + } +} +``` + +| Option | Allowed values | +| ------------- | ------------- | +| type | "mdpa_model_part_controller" | +| module | "KratosMultiphysics.OptimizationApplication.model_part_controllers" | +| model_part_name | Model part name to be used. If not found, it will be created | +| domain_size | Dimensionality of the mesh. Either 2 or 3 | +| input_filename | mdpa file name without the .mdpa extension | + +## Source files +* [Doxygen](TODO) TODO +* [applications/OptimizationApplication/python_scripts/model_part_controllers/mdpa_model_part_controller.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/model_part_controllers/mdpa_model_part_controller.py) + diff --git a/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/menu_info.json b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/menu_info.json new file mode 100644 index 000000000000..0cc207564821 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/menu_info.json @@ -0,0 +1,5 @@ +{ + "custom_entries": [ + "Overview.md" + ] +} \ No newline at end of file From 1b4c55c512aabb7c7bebf9628d0e23e0a2461806 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 11:36:11 +0100 Subject: [PATCH 19/33] add connectivity presering model part dup docs --- ...erving_ModelPart_Duplication_Controller.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md diff --git a/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md new file mode 100644 index 000000000000..59e8810945c7 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md @@ -0,0 +1,38 @@ +--- +title: Connectivity Preserving ModelPart Duplication Controller +keywords: +tags: [connectivity preserving modeller, model part controller, optimization] +sidebar: optimization_application +summary: +--- +## Introduction + +This ```ConnectivityPreservingModelPartDuplicationController``` is used to create a new model part or fill an existing model part with specified elements and conditions. All of these elements and conditions in the destination model part will have the same shared geometry and nodes with the source model part. Hence, the connectivities are preserved in the destination model part. + +## Json settings +Following json-snippet illustrates an example use case +```json +{ + "type": "connectivity_preserving_model_part_duplication_controller", + "module": "KratosMultiphysics.OptimizationApplication.model_part_controllers", + "settings": { + "source_model_part_name" : "", + "destination_model_part_name" : "", + "destination_element_name" : "", + "destination_condition_name" : "" + } +} +``` + +| Option | Allowed values | +| ------------- | ------------- | +| type | "connectivity_preserving_model_part_duplication_controller" | +| module | "KratosMultiphysics.OptimizationApplication.model_part_controllers" | +| source_model_part_name | Source model part name to read the nodes and the connectivities. | +| destination_model_part_name | Destination model part name. If not found, it will be created.| +| destination_element_name | Elements to be used in the destination model part | +| destination_condition_name | Conditions to be used in the destination model part | + +## Source files +* [Doxygen](TODO) TODO +* [applications/OptimizationApplication/python_scripts/model_part_controllers/connectivity_preserving_model_part_duplication_controller.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/model_part_controllers/connectivity_preserving_model_part_duplication_controller.py) \ No newline at end of file From 3ad09550ceecd574c1be09975ed6ef06b75e0b57 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 11:38:14 +0100 Subject: [PATCH 20/33] minor --- ...ctivity_Preserving_ModelPart_Duplication_Controller.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md index 59e8810945c7..139b25caaa68 100644 --- a/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md +++ b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md @@ -16,10 +16,10 @@ Following json-snippet illustrates an example use case "type": "connectivity_preserving_model_part_duplication_controller", "module": "KratosMultiphysics.OptimizationApplication.model_part_controllers", "settings": { - "source_model_part_name" : "", - "destination_model_part_name" : "", - "destination_element_name" : "", - "destination_condition_name" : "" + "source_model_part_name" : "AdjointStructure", + "destination_model_part_name" : "Structure", + "destination_element_name" : "SolidElement3D4N", + "destination_condition_name" : "SurfaceCondition3D3N" } } ``` From b3fb6d061507eb063880b9539f3b69241eca0915 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 12:27:34 +0100 Subject: [PATCH 21/33] add vertex morphing shape control --- .../Controls/Vertex_Morphing_Shape_Control.md | 94 +++++++++++++++++++ .../Controls/menu_info.json | 5 + 2 files changed, 99 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Controls/Vertex_Morphing_Shape_Control.md create mode 100644 docs/pages/Applications/Optimization_Application/Controls/menu_info.json diff --git a/docs/pages/Applications/Optimization_Application/Controls/Vertex_Morphing_Shape_Control.md b/docs/pages/Applications/Optimization_Application/Controls/Vertex_Morphing_Shape_Control.md new file mode 100644 index 000000000000..c61d1ac95a01 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Controls/Vertex_Morphing_Shape_Control.md @@ -0,0 +1,94 @@ +--- +title: Vertex Morphing Shape Control +keywords: +tags: [Vertex_Morphing_Shape_Control.md] +sidebar: optimization_application +summary: +--- + +## Introduction + +```VertexMorphingShapeControl``` is used to control the shape of a specified domain (given by a model part). This control can use either [Explicit Vertex Morphing](../Filtering/Explicit_Vertex_Morphing.html) or Implicit Vertex Morphing as the filtering method. Therefore, the physical space gradients will be transformed to smoothened vertex morphed control space gradients. + +This has an inbuilt mesh motion solver to solve for the mesh once the shape is changed. Therefore, it requires to have mesh motion settings as well. + +## Json settings + +### Explicit vertex morphing +Following json snippet illustrates one use case of explicit vertex morphing +```json +{ + "name": "explicit_shape_control", + "type": "shape.vertex_morphing_shape_control", + "module" : "KratosMultiphysics.OptimizationApplication.controls", + "settings":{ + "controlled_model_part_names": [], + "filter_settings": { + "type" : "surface_explicit", + "filter_function_type" : "linear", + "damping_function_type" : "sigmoidal", + "radius": 0.000000000001, + "max_nodes_in_filter_radius": 1000 + }, + "mesh_motion_settings" : {}, + "output_all_fields": false, + "fixed_model_parts": {}, + } +} +``` + +| Option | Allowed values | +| ------------- | ------------- | +| name | A unique string name | +| type | "shape.vertex_morphing_shape_control" | +| module | "KratosMultiphysics.OptimizationApplication.model_part_controllers" | +| controlled_model_part_names | List of model part names of which the shape should be controlled. | +| filter_settings::type | "surface_explicit" | +| filter_settings::filter_function_type | Types of filter functions to be used. ["gaussian"](../Filtering/Explicit_Vertex_Morphing.html#gaussian-filter-function), ["linear"](../Filtering/Explicit_Vertex_Morphing.html#linear-filter-function), ["constant"](../Filtering/Explicit_Vertex_Morphing.html#constant-filter-function), ["cosine"](../Filtering/Explicit_Vertex_Morphing.html#cosine-filter-function), ["quartic"](../Filtering/Explicit_Vertex_Morphing.html#quartic-filter-function) are supported.| +| filter_settings::damping_function_type | Type of the damping function to be used. ["gaussian"](../Filtering/Explicit_Vertex_Morphing.md#gaussian-filter-function-1), ["linear"](../Filtering/Explicit_Vertex_Morphing.md#linear-filter-function-1), ["constant"](../Filtering/Explicit_Vertex_Morphing.md#constant-filter-function-1), ["cosine"](../Filtering/Explicit_Vertex_Morphing.md#constant-filter-function-1), ["quartic"](../Filtering/Explicit_Vertex_Morphing.md#quartic-filter-function-1) "sigmoidal" are supported. | +| filter_settings::radius| Filter radius | +| filter_settings::max_nodes_in_filter_radius| Number of max nodes to be found in the filter radius. This specifies maximum number of neighbours will be searched for. If the radii is higher, or mesh is refined, then this number should be increased. | +| mesh_motion_settings | Mesh motion solver settings | +| output_all_fields | Output intermediate results also to the ```OptimizationProblem``` data container. | +| fixed_model_parts | List of model part names to be dampened | + +### Implicit vertex morphing +Following json snippet illustrates one use case of explicit vertex morphing +```json +{ + "name": "implicit_shape_control", + "type": "shape.vertex_morphing_shape_control", + "module" : "KratosMultiphysics.OptimizationApplication.controls", + "settings":{ + "controlled_model_part_names": [], + "filter_settings": { + "type" : "bulk_surface_implicit", + "radius": 0.000000000001, + "linear_solver_settings" : {} + }, + "mesh_motion_settings" : {}, + "output_all_fields": false, + "fixed_model_parts": {}, + } +} +``` + +| Option | Allowed values | +| ------------- | ------------- | +| name | A unique string name | +| type | "shape.vertex_morphing_shape_control" | +| module | "KratosMultiphysics.OptimizationApplication.model_part_controllers" | +| controlled_model_part_names | List of model part names of which the shape should be controlled. | +| filter_settings::type | "bulk_surface_implicit" | +| filter_settings::radius| Filter radius | +| filter_settings::linear_solver_settings | Linear solver to be used in the implicit vertex morphing solver | +| mesh_motion_settings | Mesh motion solver settings | +| output_all_fields | Output intermediate results also to the ```OptimizationProblem``` data container. | +| fixed_model_parts | List of model part names to be dampened | + +## Source files +* [Doxygen](TODO) TODO +* [applications/OptimizationApplication/python_scripts/controls/shape/vertex_morphing_shape_control.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/controls/shape/vertex_morphing_shape_control.py) +* [applications/OptimizationApplication/python_scripts/filtering/helmholtz_analysis.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/filtering/helmholtz_analysis.py) + + diff --git a/docs/pages/Applications/Optimization_Application/Controls/menu_info.json b/docs/pages/Applications/Optimization_Application/Controls/menu_info.json new file mode 100644 index 000000000000..0cc207564821 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Controls/menu_info.json @@ -0,0 +1,5 @@ +{ + "custom_entries": [ + "Overview.md" + ] +} \ No newline at end of file From ed1c10f7d57514bea22513d892210ba8983c99fc Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 12:58:37 +0100 Subject: [PATCH 22/33] add optprob ascii output process --- ...timization_Problem_Ascii_Output_Process.md | 57 +++++++++++++++++++ .../Processes/menu_info.json | 5 ++ 2 files changed, 62 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Processes/Optimization_Problem_Ascii_Output_Process.md create mode 100644 docs/pages/Applications/Optimization_Application/Processes/menu_info.json diff --git a/docs/pages/Applications/Optimization_Application/Processes/Optimization_Problem_Ascii_Output_Process.md b/docs/pages/Applications/Optimization_Application/Processes/Optimization_Problem_Ascii_Output_Process.md new file mode 100644 index 000000000000..2622bc946f59 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Processes/Optimization_Problem_Ascii_Output_Process.md @@ -0,0 +1,57 @@ +--- +title: Optimization Problem Ascii Output Process +keywords: +tags: [output, ascii, optimization] +sidebar: optimization_application +summary: +--- + +## Introduction + +```OptimizationProblemAsciiOutputProcess`` is used to output ASCII data in the ```OptimizationProblem``` data container to a single file, where each optimization iteration data will be written to a new line in the output file. + +The optimization iteration data is taken from the [historical data storage of the optimization problem](../General/Optimization_Problem.html#historical-data-storage). The [static data in the optimization problem](../General/Optimization_Problem.html#static-data-storage) is used as the initial data when writing. + +The output will be written in the CSV format. + +## Json settings +Following json snippet explains a single use case. +```json +{ + "type": "optimization_problem_ascii_output_process", + "module": "KratosMultiphysics.OptimizationApplication.processes", + "settings": { + "output_file_name" : "SPECIFY_OUTPUT_FILE_NAME", + "write_kratos_version" : true, + "write_time_stamp" : true, + "write_initial_values" : true, + "list_of_output_components": ["all"], + "format_info": { + "int_length" : 7, + "float_precision": 9, + "bool_values" : ["no", "yes"], + "string_length" : 10 + } + } +} +``` + +| Option | Allowed values | +| ------------- | ------------- | +| type | "optimization_problem_ascii_output_process" | +| module | "KratosMultiphysics.OptimizationApplication.processes" | +| output_file_name | Output file name. | +| write_kratos_version | true to write the Kratos version used in the optimization analysis, false will not write anything. | +| write_time_stamp | true to write the time stamp of the starting point, false will not write anything | +| write_initial_values | true to write the initial data. | +| list_of_output_components | list of component names to write data. You can specify here either "all" to write data from all the components, or specify names of the response functions, controls, execution policies to write data from those components only. | +| int_length | Length of the integer values when converted to strings | +| float_precision | Floating point value precision to be used when converting to strings | +| bool_values | The keywords to be used if bool is true and false. | +| string_length | String length to be used to write string data. | + +## Source files +* [Doxygen](TODO) TODO +* [applications/OptimizationApplication/python_scripts/processes/optimization_problem_ascii_output_process.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/processes/optimization_problem_ascii_output_process.py) + + diff --git a/docs/pages/Applications/Optimization_Application/Processes/menu_info.json b/docs/pages/Applications/Optimization_Application/Processes/menu_info.json new file mode 100644 index 000000000000..0cc207564821 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Processes/menu_info.json @@ -0,0 +1,5 @@ +{ + "custom_entries": [ + "Overview.md" + ] +} \ No newline at end of file From fbc8b5c64fe8995f7d1223208526e514500ffff1 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 12:58:47 +0100 Subject: [PATCH 23/33] add vtu output process --- ...Optimization_Problem_Vtu_Output_Process.md | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Processes/Optimization_Problem_Vtu_Output_Process.md diff --git a/docs/pages/Applications/Optimization_Application/Processes/Optimization_Problem_Vtu_Output_Process.md b/docs/pages/Applications/Optimization_Application/Processes/Optimization_Problem_Vtu_Output_Process.md new file mode 100644 index 000000000000..9318d654acfd --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Processes/Optimization_Problem_Vtu_Output_Process.md @@ -0,0 +1,51 @@ +--- +title: Optimization Problem Vtu Output Process +keywords: +tags: [output, vtu, optimization] +sidebar: optimization_application +summary: +--- + +## Introduction + +```OptimizationProblemVtuOutputProcess``` is used to output field data in the ```OptimizationProblem``` data container in the format vtu. + +The optimization iteration data is taken from the [static data in the optimization problem](../General/Optimization_Problem.html#static-data-storage) since field data is stored in this container. + +## Json settings +Following json snippet explains a single use case. +```json +{ + "type": "optimization_problem_vtu_output_process", + "module": "KratosMultiphysics.OptimizationApplication.processes", + "settings": { + "file_name" : "_", + "file_format" : "binary", + "output_path" : "Optimization_Results", + "save_output_files_in_folder" : true, + "write_deformed_configuration": false, + "list_of_output_components" : ["all"], + "output_precision" : 7, + "output_interval" : 1, + "echo_level" : 0 + } +} +``` + +| Option | Allowed values | +| ------------- | ------------- | +| type | "optimization_problem_vtu_output_process" | +| module | "KratosMultiphysics.OptimizationApplication.processes" | +| file_name | Output file name. It is allowed to use and tags. Then tag will be replaced by the model part full name of the data field and tag will be replaced by the optimization iteration.| +| file_format | "ascii" to write vtu in ascii format or "binary" to write vtu in binary format. | +| save_output_files_in_folder | Will create the output path | +| output_path | Output path to be used to store all the vtu files. | +| write_deformed_configuration | true to write the deformed configuration, false to write the initial configuration of the mesh | +| list_of_output_components | list of component names to write data. You can specify here either "all" to write data from all the components, or specify names of the response functions, controls, execution policies to write data from those components only. | +| output_precision | Precision of the data fields to be written out | +| output_interval | Interval between two consecutive vtu output writes | +| echo_level | Echo level | + +## Source files +* [Doxygen](TODO) TODO +* [applications/OptimizationApplication/python_scripts/processes/optimization_problem_vtu_output_process.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/processes/optimization_problem_vtu_output_process.py) \ No newline at end of file From 04f0f507eca97f2d5ed8cdb80adda9dae6be5df3 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 12:58:56 +0100 Subject: [PATCH 24/33] minor --- .../Controls/Shell_Thickness_Control.md | 7 +++++++ ...ectivity_Preserving_ModelPart_Duplication_Controller.md | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 docs/pages/Applications/Optimization_Application/Controls/Shell_Thickness_Control.md diff --git a/docs/pages/Applications/Optimization_Application/Controls/Shell_Thickness_Control.md b/docs/pages/Applications/Optimization_Application/Controls/Shell_Thickness_Control.md new file mode 100644 index 000000000000..076ac1eacb79 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Controls/Shell_Thickness_Control.md @@ -0,0 +1,7 @@ +--- +title: Shell Thickness Control +keywords: +tags: [Shell_Thickness_Control.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md index 139b25caaa68..9946865917c5 100644 --- a/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md +++ b/docs/pages/Applications/Optimization_Application/Model_Part_Controllers/Connectivity_Preserving_ModelPart_Duplication_Controller.md @@ -1,9 +1,9 @@ --- title: Connectivity Preserving ModelPart Duplication Controller -keywords: +keywords: tags: [connectivity preserving modeller, model part controller, optimization] sidebar: optimization_application -summary: +summary: --- ## Introduction From f719c21b82dd05e2b9f9878ce5bf783315e56b50 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 13:21:13 +0100 Subject: [PATCH 25/33] add menu info for exec poli --- .../Execution_Policies/menu_info.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Execution_Policies/menu_info.json diff --git a/docs/pages/Applications/Optimization_Application/Execution_Policies/menu_info.json b/docs/pages/Applications/Optimization_Application/Execution_Policies/menu_info.json new file mode 100644 index 000000000000..0cc207564821 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Execution_Policies/menu_info.json @@ -0,0 +1,5 @@ +{ + "custom_entries": [ + "Overview.md" + ] +} \ No newline at end of file From 71508451ad37e9359afea061a9e28436ebd8864d Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 13:21:26 +0100 Subject: [PATCH 26/33] add independent analysis execpolicy --- .../Independent_Analysis_Execution_Policy.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Execution_Policies/Independent_Analysis_Execution_Policy.md diff --git a/docs/pages/Applications/Optimization_Application/Execution_Policies/Independent_Analysis_Execution_Policy.md b/docs/pages/Applications/Optimization_Application/Execution_Policies/Independent_Analysis_Execution_Policy.md new file mode 100644 index 000000000000..ed67f04d4c3d --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Execution_Policies/Independent_Analysis_Execution_Policy.md @@ -0,0 +1,38 @@ +--- +title: Independent Analysis Execution Policy +keywords: +tags: [independent, execution policy, optimization] +sidebar: optimization_application +summary: +--- + +## Introduction + +```IndependentAnalysisExecutionPolicy``` is used to execute a primal analysis which needs to be independent from the model parts of the origin. But they both share the same ```Kratos::Model```. + +## Json settings +Following json-snippet illustrates an example use case +```json +{ + "type": "independent_analysis_execution_policy", + "module": "KratosMultiphysics.OptimizationApplication.execution_policies", + "settings": { + "analysis_module" : "KratosMultiphysics", + "analysis_type" : "", + "analysis_model_part_name": "", + "analysis_settings" : {} + } +} +``` + +| Option | Allowed values | +| ------------- | ------------- | +| type | "independent_analysis_execution_policy" | +| module | "KratosMultiphysics.OptimizationApplication.model_part_controllers" | +| analysis_module | Where to find the module for `analysis_type`. | +| analysis_type | Analysis type to used to solve the primal analysis. | +| analysis_settings | Settings for the analysis | + +## Source files +* [Doxygen](TODO) TODO +* [applications/OptimizationApplication/python_scripts/execution_policies/independent_analysis_execution_policy.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/execution_policies/independent_analysis_execution_policy.py) \ No newline at end of file From 825292b1a33e35bc3813174afd27fae300c700b6 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 13:21:36 +0100 Subject: [PATCH 27/33] add kratos execpolicy --- .../Kratos_Analysis_Execution_Policy.md | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Execution_Policies/Kratos_Analysis_Execution_Policy.md diff --git a/docs/pages/Applications/Optimization_Application/Execution_Policies/Kratos_Analysis_Execution_Policy.md b/docs/pages/Applications/Optimization_Application/Execution_Policies/Kratos_Analysis_Execution_Policy.md new file mode 100644 index 000000000000..d530073694e4 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Execution_Policies/Kratos_Analysis_Execution_Policy.md @@ -0,0 +1,55 @@ +--- +title: Kratos Analysis Execution Policy +keywords: +tags: [kratos, execution policy, optimization] +sidebar: optimization_application +summary: +--- + +## Introduction + +```KratosAnalysisExecutionPolicy``` is used to execute a primal analysis which may or not need to be independent from the model parts of the origin. But they both share the same ```Kratos::Model```. + +In this execution policy, when ```Execute``` method is called, following variables in the specified model parts are made to zero. +* STEP +* TIME +* DELTA_TIME + +## Json settings +Following json-snippet illustrates an example use case +```json +{ + "type": "independent_analysis_execution_policy", + "module": "KratosMultiphysics.OptimizationApplication.execution_policies", + "settings": { + "model_part_names" : [], + "analysis_module" : "KratosMultiphysics", + "analysis_type" : "", + "analysis_settings": {}, + "analysis_output_settings": { + "nodal_solution_step_data_variables": [], + "nodal_data_value_variables" : [], + "element_data_value_variables" : [], + "condition_data_value_variables" : [] + } + } +} +``` + +| Option | Allowed values | +| ------------- | ------------- | +| type | "independent_analysis_execution_policy" | +| module | "KratosMultiphysics.OptimizationApplication.model_part_controllers" | +| model_part_names | Model part names to be used for outputting data and resetting variables. | +| analysis_module | Where to find the module for `analysis_type`. | +| analysis_type | Analysis type to used to solve the primal analysis. | +| analysis_settings | Settings for the analysis | +| analysis_output_settings | Output settings for variables in the model parts listed in `model_part_names`. An [OptimizationProblemVtuOutputProcess](../Processes/Optimization_Problem_Vtu_Output_Process.html) needs to be used to write these fields to files. | +| nodal_solution_step_data_variables | List of nodal solution step variable names | +| nodal_data_value_variables | List of nodal non-historical variable names | +| element_data_value_variables | Element data value variable names | +| condition_data_value_variables | Condition data value variable names | + +## Source files +* [Doxygen](TODO) TODO +* [applications/OptimizationApplication/python_scripts/execution_policies/kratos_analysis_execution_policy.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/execution_policies/kratos_analysis_execution_policy.py) From 664346f3fb0659b0872c6a524f1f527f74922465 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 13:21:48 +0100 Subject: [PATCH 28/33] add stepping exec policy --- .../Stepping_Analysis_Execution_Policy.md | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 docs/pages/Applications/Optimization_Application/Execution_Policies/Stepping_Analysis_Execution_Policy.md diff --git a/docs/pages/Applications/Optimization_Application/Execution_Policies/Stepping_Analysis_Execution_Policy.md b/docs/pages/Applications/Optimization_Application/Execution_Policies/Stepping_Analysis_Execution_Policy.md new file mode 100644 index 000000000000..587ad517c21e --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Execution_Policies/Stepping_Analysis_Execution_Policy.md @@ -0,0 +1,44 @@ +--- +title: Stepping Analysis Execution Policy +keywords: +tags: [stepping kratos, execution policy, optimization] +sidebar: optimization_application +summary: +--- + +## Introduction + +```SteppingAnalysisExecutionPolicy``` is used to execute a primal analysis which may or not need to be independent from the model parts of the origin. But they both share the same ```Kratos::Model```. + +In this execution policy, when ```Execute``` method is called, following variables in the specified model parts are made to zero before and thereafter, original values are restored after running the primal analysis. +* STEP +* TIME +* DELTA_TIME + +## Json settings +Following json-snippet illustrates an example use case +```json +{ + "type": "independent_analysis_execution_policy", + "module": "KratosMultiphysics.OptimizationApplication.execution_policies", + "settings": { + "model_part_names" : [], + "analysis_module" : "KratosMultiphysics", + "analysis_type" : "", + "analysis_settings": {} + } +} +``` + +| Option | Allowed values | +| ------------- | ------------- | +| type | "independent_analysis_execution_policy" | +| module | "KratosMultiphysics.OptimizationApplication.model_part_controllers" | +| model_part_names | Model part names to be used for outputting data and resetting variables. | +| analysis_module | Where to find the module for `analysis_type`. | +| analysis_type | Analysis type to used to solve the primal analysis. | +| analysis_settings | Settings for the analysis | + +## Source files +* [Doxygen](TODO) TODO +* [applications/OptimizationApplication/python_scripts/execution_policies/stepping_analysis_execution_policy.py](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/python_scripts/execution_policies/stepping_analysis_execution_policy.py) \ No newline at end of file From a3fff7008a4f076faee28a9a3a4c2aa18cb2b2b2 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 13:21:57 +0100 Subject: [PATCH 29/33] minor --- .../pages/Applications/Optimization_Application/menu_info.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/pages/Applications/Optimization_Application/menu_info.json b/docs/pages/Applications/Optimization_Application/menu_info.json index 587e590835da..ff73ba4b4326 100644 --- a/docs/pages/Applications/Optimization_Application/menu_info.json +++ b/docs/pages/Applications/Optimization_Application/menu_info.json @@ -12,7 +12,6 @@ "Controls", "Filtering", "Model_Part_Controllers", - "Processes", - "Examples" + "Processes" ] } \ No newline at end of file From 0acb903df6fa5aac98328e744a9dea68897575b7 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Fri, 2 Feb 2024 13:28:09 +0100 Subject: [PATCH 30/33] minor --- .../Algorithms/Gradient_Projection.md | 7 +++++ .../Algorithms/Steepest_Descent.md | 7 +++++ .../Algorithms/menu_info.json | 5 ++++ .../Algorithms/steepest_descent.drawio | 27 ------------------- 4 files changed, 19 insertions(+), 27 deletions(-) create mode 100644 docs/pages/Applications/Optimization_Application/Algorithms/Gradient_Projection.md create mode 100644 docs/pages/Applications/Optimization_Application/Algorithms/Steepest_Descent.md create mode 100644 docs/pages/Applications/Optimization_Application/Algorithms/menu_info.json delete mode 100644 docs/pages/Applications/Optimization_Application/Algorithms/steepest_descent.drawio diff --git a/docs/pages/Applications/Optimization_Application/Algorithms/Gradient_Projection.md b/docs/pages/Applications/Optimization_Application/Algorithms/Gradient_Projection.md new file mode 100644 index 000000000000..5cf1f4aa7422 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Algorithms/Gradient_Projection.md @@ -0,0 +1,7 @@ +--- +title: Gradient Projection +keywords: +tags: [gradient_projection.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/Algorithms/Steepest_Descent.md b/docs/pages/Applications/Optimization_Application/Algorithms/Steepest_Descent.md new file mode 100644 index 000000000000..24315e7d9780 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Algorithms/Steepest_Descent.md @@ -0,0 +1,7 @@ +--- +title: Steepest Descent +keywords: +tags: [steepest_descent.md] +sidebar: optimization_application +summary: +--- diff --git a/docs/pages/Applications/Optimization_Application/Algorithms/menu_info.json b/docs/pages/Applications/Optimization_Application/Algorithms/menu_info.json new file mode 100644 index 000000000000..0cc207564821 --- /dev/null +++ b/docs/pages/Applications/Optimization_Application/Algorithms/menu_info.json @@ -0,0 +1,5 @@ +{ + "custom_entries": [ + "Overview.md" + ] +} \ No newline at end of file diff --git a/docs/pages/Applications/Optimization_Application/Algorithms/steepest_descent.drawio b/docs/pages/Applications/Optimization_Application/Algorithms/steepest_descent.drawio deleted file mode 100644 index ad831a4331c1..000000000000 --- a/docs/pages/Applications/Optimization_Application/Algorithms/steepest_descent.drawio +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From acce59a9231cd065c4a4994ead16231b3e24af1f Mon Sep 17 00:00:00 2001 From: Suneth Warnakulasuriya Date: Tue, 6 Feb 2024 16:58:43 +0100 Subject: [PATCH 31/33] Update docs/pages/Applications/Optimization_Application/General/Control.md Co-authored-by: IAntonau --- .../Applications/Optimization_Application/General/Control.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/Applications/Optimization_Application/General/Control.md b/docs/pages/Applications/Optimization_Application/General/Control.md index 6551e1ebdf3b..87d42e72ada1 100644 --- a/docs/pages/Applications/Optimization_Application/General/Control.md +++ b/docs/pages/Applications/Optimization_Application/General/Control.md @@ -8,7 +8,7 @@ summary: ## Introduction -```Control``` is used to control the design surface with the updates given by the ```Algorithm``` as illustrated in Figure 1. This is also used to transform data between physical and control spaces. +```Control``` is used to regularize the design variables updates, which are given by the ```Algorithm``` as illustrated in Figure 1. It also updates the properties of the ```model_part```. This is also used to transform data between physical and control spaces.

Control data flow

From 890214e3b2bed068bc4a4e0ba051dc53817a8479 Mon Sep 17 00:00:00 2001 From: Suneth Warnakulasuriya Date: Tue, 6 Feb 2024 16:58:57 +0100 Subject: [PATCH 32/33] Update docs/pages/Applications/Optimization_Application/General/Control.md Co-authored-by: IAntonau --- .../Applications/Optimization_Application/General/Control.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/Applications/Optimization_Application/General/Control.md b/docs/pages/Applications/Optimization_Application/General/Control.md index 87d42e72ada1..094c7d6d296c 100644 --- a/docs/pages/Applications/Optimization_Application/General/Control.md +++ b/docs/pages/Applications/Optimization_Application/General/Control.md @@ -20,7 +20,7 @@ As explained above ```Control``` will work in the control space and physical spa ## Data flow and work flow -```Control``` is responsible for updating the domain (i.e. mesh, domain values) with the new design given by the ```Algorithm```. First it will map the control space design (i.e. $$\underline{\hat{\phi}}$$) to physical space (i.e. $$\underline{\phi}$$) using the ```Filtering```. Then these physical space values are used to update the mesh or the domain values. +```Control``` is responsible for updating the ```model_part```and its properties (i.e. mesh, domain values) with the new design given by the ```Algorithm```. First it will map the control space design (i.e. $$\underline{\hat{\phi}}$$) to physical space (i.e. $$\underline{\phi}$$) using the ```Filtering```. Then these physical space values are used to update the mesh or the domain values. ```Control``` is also responsible for mapping physical space gradients (i.e. $$\frac{dJ_1}{d\underline{\phi}}$$) to control space (i.e. $$\frac{dJ_1}{d\underline{\hat{\phi}}}$$) using the ```Filtering``` method as illustrated in the Figure 1. From 5213f7a9b43f285fac3ca1c50de7ef1df1897f16 Mon Sep 17 00:00:00 2001 From: sunethwarna Date: Tue, 6 Feb 2024 16:59:17 +0100 Subject: [PATCH 33/33] fixes --- .../Filtering/Explicit_Vertex_Morphing.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/pages/Applications/Optimization_Application/Filtering/Explicit_Vertex_Morphing.md b/docs/pages/Applications/Optimization_Application/Filtering/Explicit_Vertex_Morphing.md index 593d1840e2e1..a6d52432ade5 100644 --- a/docs/pages/Applications/Optimization_Application/Filtering/Explicit_Vertex_Morphing.md +++ b/docs/pages/Applications/Optimization_Application/Filtering/Explicit_Vertex_Morphing.md @@ -1,14 +1,14 @@ --- title: Explicit Vertex Morphing -keywords: +keywords: tags: [explicit, vertex morphing, filtering, optimization] sidebar: optimization_application -summary: +summary: --- ## Introduction -Explicit Vertex morphing (here onwards called as vertex morphing) is a filtering method to filter out noise present in a gradient field or design field. Noisy gradient field is a common challenge in optimization problems which makes updated designs non-intuitive. They may also make the updated meshes based on updated design space with bad elements which eventually result in failure in primal and adjoint solution computation. Therefore it is crucial to apply a filtering technique to obtain a smooth gradient field. An example of a noisy field is shown in figure 1. +Explicit Vertex morphing (here onwards called as vertex morphing) is a discrete filtering method to regularize optimization problem. Non-smooth discrete gradient field is a common challenge in optimization problems which makes design updates noisy and non-applicable for numerical model, for instance, bad elements which eventually result in failure in primal and adjoint solution computation. Therefore it is crucial to apply a filtering technique to obtain a smooth design updates. An example of a noisy field is shown in figure 1.

Noisy design field @@ -132,8 +132,12 @@ Then for each vertex's (i.e. $$i^{th}$$) neigbhour vertices (i.e. $$j^{th}$$) th

$$ \left(\frac{df}{d\underline{s}}\right)_{i, morphed} = \frac{1}{\sum_{j=1}^N A_{ij}}\sum_{j=1}^{N} A_{ij}\left(\frac{df}{d\underline{s}}\right)_j$$

+## References +TODO: + + ## Source files * [Doxygen](TODO) TODO * [applications/OptimizationApplication/custom_utilities/filtering/filter_function.h](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/custom_utilities/filtering/filter_function.h) * [applications/OptimizationApplication/custom_utilities/filtering/damping_function.h](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/custom_utilities/filtering/damping_function.h) -* [applications/OptimizationApplication/custom_utilities/filtering/explicit_filter.h](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/custom_utilities/filtering/explicit_filter.h) \ No newline at end of file +* [applications/OptimizationApplication/custom_utilities/filtering/explicit_filter.h](https://github.com/KratosMultiphysics/Kratos/blob/master/applications/OptimizationApplication/custom_utilities/filtering/explicit_filter.h)