From f66f069a535c51facfee58418f29ee4b21cc4177 Mon Sep 17 00:00:00 2001 From: Lynn Munday Date: Tue, 6 Sep 2022 18:21:49 -0600 Subject: [PATCH] steady state hessian force inversion using zachs interpolation VectorNearestPointFunction function There is a bug in optimizationReporter that loops over measurement_data which is missing on the main app unless it is transferred. This is fixed in the optimization module so it is not going to be fixed here. closes #54 --- examples/simpleSteady/adjoint.i | 113 ++++++++++++++++ examples/simpleSteady/forward.i | 127 ++++++++++++++++++ .../main_out_OptimizationReporter_0001.csv | 11 ++ examples/simpleSteady/main.i | 99 ++++++++++++++ examples/simpleSteady/source_params.csv | 5 + examples/simpleSteady/syntheticLineData.csv | 11 ++ .../simpleSteady/synthetic_source_params.csv | 5 + examples/simpleSteady/tests | 16 +++ 8 files changed, 387 insertions(+) create mode 100644 examples/simpleSteady/adjoint.i create mode 100644 examples/simpleSteady/forward.i create mode 100644 examples/simpleSteady/gold/main_out_OptimizationReporter_0001.csv create mode 100644 examples/simpleSteady/main.i create mode 100644 examples/simpleSteady/source_params.csv create mode 100644 examples/simpleSteady/syntheticLineData.csv create mode 100644 examples/simpleSteady/synthetic_source_params.csv create mode 100644 examples/simpleSteady/tests diff --git a/examples/simpleSteady/adjoint.i b/examples/simpleSteady/adjoint.i new file mode 100644 index 00000000..4e4df08a --- /dev/null +++ b/examples/simpleSteady/adjoint.i @@ -0,0 +1,113 @@ +[Mesh] + [gmg] + type = GeneratedMeshGenerator + dim = 2 + nx = 20 + ny = 25 + xmin = -1 + xmax = 1 + ymin = -1 + ymax = 1.5 + [] +[] + +[Problem] + extra_tag_vectors = 'ref' +[] + +[AuxVariables] + [residual_src] + [] +[] + +[AuxKernels] + [residual_src] + type = TagVectorAux + vector_tag = 'ref' + v = 'u' + variable = 'residual_src' + [] +[] + + +[Variables] + [u] + [] +[] + +[Kernels] + [diff] + type = Diffusion + variable = u + [] +[] + +[BCs] + [dirichlet] + type = DirichletBC + variable = u + boundary = 'left right top bottom' + value = 0 + [] +[] + +[Reporters] + [measured_data] + type = OptimizationData + measurement_file = syntheticLineData.csv + file_xcoord = x + file_ycoord = y + file_zcoord = z + file_value = u + [] +[] + +[DiracKernels] + [misfit] + type = VectorPointSource + variable = u + value = measured_data/misfit_values + coord_x = measured_data/measurement_xcoord + coord_y = measured_data/measurement_ycoord + coord_z = measured_data/measurement_zcoord + extra_vector_tags = 'ref' + [] +[] + +[VectorPostprocessors] + [src_values] + type = CSVReader + csv_file = source_params.csv + header = true + [] +[] + +[Functions] + [source] + type = VectorNearestPointFunction + coord_x = src_values/coordx + coord_y = src_values/coordy + time = src_values/time + value = src_values/values + [] +[] + +[VectorPostprocessors] + [adjoint] + type = ElementOptimizationSourceFunctionInnerProduct + variable = u + function = source + [] +[] + +[Executioner] + type = Steady + solve_type = NEWTON + line_search=none + petsc_options_iname = '-pc_type' + petsc_options_value = 'lu' +[] + +[Outputs] + console = false +[] diff --git a/examples/simpleSteady/forward.i b/examples/simpleSteady/forward.i new file mode 100644 index 00000000..483d39cc --- /dev/null +++ b/examples/simpleSteady/forward.i @@ -0,0 +1,127 @@ +[Mesh] + [gmg] + type = GeneratedMeshGenerator + dim = 2 + nx = 20 + ny = 25 + xmin = -1 + xmax = 1 + ymin = -1 + ymax = 1.5 + [] +[] + +[Problem] + extra_tag_vectors = 'ref' +[] + +[AuxVariables] + [residual_src] + [] +[] + +[AuxKernels] + [residual_src] + type = TagVectorAux + vector_tag = 'ref' + v = 'u' + variable = 'residual_src' + [] +[] + +[Variables] + [u] + [] +[] + +[VectorPostprocessors] + #---------- BEGIN: VPP for optimization + [src_values] + type = CSVReader + csv_file = source_params.csv + header = true + [] + #---------- END: VPP for optimization + + # #---------- BEGIN: VPP for synthetic data simulations + # [src_values] + # type = CSVReader + # csv_file = synthetic_source_params.csv + # header = true + # [] + # [line1] + # type = LineValueSampler + # start_point = '0.5 -0.9 0' + # end_point = '0.5 1.4 0' + # num_points = 5 + # sort_by = id + # variable = u + # [] + # [line2] + # type = LineValueSampler + # start_point = '-0.5 -0.9 0' + # end_point = '-0.5 1.4 0' + # num_points = 5 + # sort_by = id + # variable = u + # [] + # #----- END: VPP for synthetic data simulations +[] + + +[Kernels] + [diff] + type = Diffusion + variable = u + [] + [src] + type = BodyForce + variable = u + function = source + extra_vector_tags = 'ref' + [] +[] + +[BCs] + [dirichlet] + type = DirichletBC + variable = u + boundary = 'left right top bottom' + value = 0 + [] +[] + +[Functions] + [source] + type = VectorNearestPointFunction + coord_x = src_values/coordx + coord_y = src_values/coordy + time = src_values/time + value = src_values/values + [] +[] + +[Executioner] + type = Steady + solve_type = NEWTON + line_search=none + petsc_options_iname = '-pc_type' + petsc_options_value = 'lu' +[] + +[Reporters] + [measured_data] + type = OptimizationData + measurement_file = syntheticLineData.csv + file_xcoord = x + file_ycoord = y + file_zcoord = z + file_value = u + variable = u + execute_on = timestep_end + [] +[] + +[Outputs] + console = false +[] diff --git a/examples/simpleSteady/gold/main_out_OptimizationReporter_0001.csv b/examples/simpleSteady/gold/main_out_OptimizationReporter_0001.csv new file mode 100644 index 00000000..ddb8192a --- /dev/null +++ b/examples/simpleSteady/gold/main_out_OptimizationReporter_0001.csv @@ -0,0 +1,11 @@ +adjoint,measurement_time,measurement_values,measurement_xcoord,measurement_ycoord,measurement_zcoord,misfit_values,simulation_values,source +0,0,0.12167978288653,0,0,0,0,0.12167978288653,1 +0,0,0.45533154094397,0,0,0,0,0.45533154094397,2 +0,0,0.47326307589773,0,0,0,0,0.47326307589773,-1 +0,0,0.3925248098792,0,0,0,0,0.3925248098792,3 +0,0,0.09631748263822,0,0,0,0,0.09631748263822,0 +0,0,-0.0034929354865351,0,0,0,0,-0.0034929354865347,0 +0,0,0.085617624411979,0,0,0,0,0.085617624411979,0 +0,0,0.27245239918046,0,0,0,0,0.27245239918046,0 +0,0,0.27032670013135,0,0,0,0,0.27032670013135,0 +0,0,0.06274715505589,0,0,0,0,0.06274715505589,0 diff --git a/examples/simpleSteady/main.i b/examples/simpleSteady/main.i new file mode 100644 index 00000000..8a1958a9 --- /dev/null +++ b/examples/simpleSteady/main.i @@ -0,0 +1,99 @@ +[StochasticTools] +[] + +[OptimizationReporter] + type = ObjectiveGradientMinimize + + parameter_names = 'source' + num_values = '4' +[] + +[Executioner] + type = Optimize + # tao_solver = taolmvm + # petsc_options_iname='-tao_gatol' + # petsc_options_value='1e-3' + + tao_solver = taonls + petsc_options_iname = '-tao_gttol -tao_nls_pc_type -tao_nls_ksp_type' + petsc_options_value = '1e-5 none cg' + + verbose = true +[] + +[MultiApps] + [forward] + type = OptimizeFullSolveMultiApp + input_files = forward.i + execute_on = FORWARD + [] + [adjoint] + type = OptimizeFullSolveMultiApp + input_files = adjoint.i + execute_on = ADJOINT + [] + [homogeneous_forward] + type = OptimizeFullSolveMultiApp + input_files = forward.i + execute_on = "HOMOGENEOUS_FORWARD" + [] +[] + +[Transfers] + [to_forward] + type = MultiAppReporterTransfer + to_multi_app = forward + from_reporters = 'OptimizationReporter/source' + to_reporters = 'src_values/values' + [] + [from_forward] + type = MultiAppReporterTransfer + from_multi_app = forward + from_reporters = 'measured_data/misfit_values + measured_data/simulation_values + measured_data/measurement_values + measured_data/measurement_time' + to_reporters = 'OptimizationReporter/misfit_values + OptimizationReporter/simulation_values + OptimizationReporter/measurement_values + OptimizationReporter/measurement_time' + [] + + [to_adjoint] + type = MultiAppReporterTransfer + to_multi_app = adjoint + from_reporters = 'OptimizationReporter/source OptimizationReporter/misfit_values' + to_reporters = 'src_values/values measured_data/misfit_values' + [] + [from_adjoint] + type = MultiAppReporterTransfer + from_multi_app = adjoint + from_reporters = 'adjoint/inner_product' + to_reporters = 'OptimizationReporter/adjoint' + [] + + [to_homogeneous_forward] + type = MultiAppReporterTransfer + to_multi_app = homogeneous_forward + from_reporters = 'OptimizationReporter/source' + to_reporters = 'src_values/values' + [] + + [from_homogeneous_forward] + type = MultiAppReporterTransfer + from_multi_app = homogeneous_forward + from_reporters = 'measured_data/misfit_values + measured_data/simulation_values + measured_data/measurement_values + measured_data/measurement_time' + to_reporters = 'OptimizationReporter/misfit_values + OptimizationReporter/simulation_values + OptimizationReporter/measurement_values + OptimizationReporter/measurement_time' + [] + +[] + +[Outputs] + csv=true +[] diff --git a/examples/simpleSteady/source_params.csv b/examples/simpleSteady/source_params.csv new file mode 100644 index 00000000..26ae594b --- /dev/null +++ b/examples/simpleSteady/source_params.csv @@ -0,0 +1,5 @@ +coordx,coordy,time,values +-0.5,0.5,0.0,.0 +0.5,0.5,0.0,.0 +-0.5,-0.5,0.0,.0 +0.5,-0.5,0.0,.0 diff --git a/examples/simpleSteady/syntheticLineData.csv b/examples/simpleSteady/syntheticLineData.csv new file mode 100644 index 00000000..67881d75 --- /dev/null +++ b/examples/simpleSteady/syntheticLineData.csv @@ -0,0 +1,11 @@ +id,u,x,y,z +0,0.12167978288653,0.5,-0.9,0 +0.575,0.45533154094397,0.5,-0.325,0 +1.15,0.47326307589773,0.5,0.25,0 +1.725,0.3925248098792,0.5,0.825,0 +2.3,0.09631748263822,0.5,1.4,0 +0,-0.0034929354865351,-0.5,-0.9,0 +0.575,0.085617624411979,-0.5,-0.325,0 +1.15,0.27245239918046,-0.5,0.25,0 +1.725,0.27032670013135,-0.5,0.825,0 +2.3,0.06274715505589,-0.5,1.4,0 diff --git a/examples/simpleSteady/synthetic_source_params.csv b/examples/simpleSteady/synthetic_source_params.csv new file mode 100644 index 00000000..11d41fd5 --- /dev/null +++ b/examples/simpleSteady/synthetic_source_params.csv @@ -0,0 +1,5 @@ +coordx,coordy,time,values +-0.5,0.5,0.0,1.0 +0.5,0.5,0.0,2.0 +-0.5,-0.5,0.0,-1.0 +0.5,-0.5,0.0,3.0 diff --git a/examples/simpleSteady/tests b/examples/simpleSteady/tests new file mode 100644 index 00000000..fa13244d --- /dev/null +++ b/examples/simpleSteady/tests @@ -0,0 +1,16 @@ +[Tests] + [Steady] + design = 'VectorNearestPointFunction.md' + issues = '#52' + [hessian] + type = CSVDiff + input = main.i + csvdiff = main_out_OptimizationReporter_0001.csv + rel_err = 0.01 + max_threads = 1 + # steady solve + recover = false + requirement = 'The system shall be able to perform hessian based steady state force-inversion optimization for a body force described by the VectorNearestPointFunction' + [] + [] +[]