Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Gaussian Probe optimization #28872

Draft
wants to merge 13 commits into
base: next
Choose a base branch
from
Draft

Conversation

maxnezdyur
Copy link
Contributor

closes #28871

@moosebuild
Copy link
Contributor

moosebuild commented Oct 17, 2024

Job Documentation, step Docs: sync website on 8aa6266 wanted to post the following:

View the site here

This comment will be updated on new commits.

@maxnezdyur maxnezdyur force-pushed the line_obj branch 2 times, most recently from 6628c4d to c5bc150 Compare October 17, 2024 19:19
@moosebuild
Copy link
Contributor

moosebuild commented Oct 17, 2024

Job Coverage, step Generate coverage on 8aa6266 wanted to post the following:

Framework coverage

b3924e #28872 8aa626
Total Total +/- New
Rate 85.05% 85.05% +0.00% 94.74%
Hits 106298 106335 +37 36
Misses 18691 18692 +1 2

Diff coverage report

Full coverage report

Modules coverage

Optimization

b3924e #28872 8aa626
Total Total +/- New
Rate 88.55% 88.65% +0.10% 96.43%
Hits 1972 1999 +27 27
Misses 255 256 +1 1

Diff coverage report

Full coverage report

Full coverage reports

Reports

This comment will be updated on new commits.

@maxnezdyur maxnezdyur marked this pull request as draft October 21, 2024 23:55
@moosebuild
Copy link
Contributor

Job Precheck, step Clang format on b1fad52 wanted to post the following:

Your code requires style changes.

A patch was auto generated and copied here
You can directly apply the patch by running, in the top level of your repository:

curl -s https://mooseframework.inl.gov/docs/PRs/28872/clang_format/style.patch | git apply -v

Alternatively, with your repository up to date and in the top level of your repository:

git clang-format b3924ece4ed556a7ca9811a6e046eb5c4503df72

@maxnezdyur maxnezdyur force-pushed the line_obj branch 4 times, most recently from f01337f to f07deef Compare October 22, 2024 12:21
Copy link
Contributor

@lynnmunday lynnmunday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of ternaries, very clever!


!syntax description /Materials/ReporterOffsetFunctionMaterial

This can be used to create a material that is the sum of a function that is shifted by a set of points. This can be useful for creating a field of laser heat sources.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This can be used to create a material that is the sum of a function that is shifted by a set of points. This can be useful for creating a field of laser heat sources.
This can be used to create a material that is the sum of a function that is shifted by a set of points. This can be useful for creating a field containing multiple sources, see Figure??.

Comment on lines +35 to +43

/// x coordinate
const std::vector<Real> & _coordx;
/// y coordinate
const std::vector<Real> & _coordy;
///z coordinate
const std::vector<Real> & _coordz;
///xyz point
const std::vector<Point> & _points;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// x coordinate
const std::vector<Real> & _coordx;
/// y coordinate
const std::vector<Real> & _coordy;
///z coordinate
const std::vector<Real> & _coordz;
///xyz point
const std::vector<Point> & _points;
/**
* Reporter offset locations for function
*/
// @{
/// x coordinate
const std::vector<Real> & _coordx;
/// y coordinate
const std::vector<Real> & _coordy;
///z coordinate
const std::vector<Real> & _coordz;
///xyz point
const std::vector<Point> & _points;
// @}

/// The function being used for evaluation
const Function & _func;
/**
* Calculates the value of the offset function at the given point.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Calculates the value of the offset function at the given point.
* Calculates the value of the function at the given offset point.


private:
/// convenience vectors (these are not const because reporters can change their size)
std::vector<Real> _ones_vec;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need this one.

Comment on lines +46 to +51

private:
/// convenience vectors (these are not const because reporters can change their size)
std::vector<Real> _ones_vec;
std::vector<Real> _zeros_vec;
std::vector<Point> _zeros_pts;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private:
/// convenience vectors (these are not const because reporters can change their size)
std::vector<Real> _ones_vec;
std::vector<Real> _zeros_vec;
std::vector<Point> _zeros_pts;

"Computes the misfit and misfit gradient materials for inverse optimizations problems.");

params.addRequiredCoupledVar("sim_variable",
"Variable that is being for the simulation variable.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Variable that is being for the simulation variable.");
"Variable that is being used for the simulation variable.");

type = SideIntegralMaterialProperty
boundary = top
property = obj_misfit
execute_on = 'ADJOINT_TIMESTEP_END TIMESTEP_END'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need ADJOINT_TIMESTEP_END

Comment on lines +30 to +33
## THESE OPTIONS ARE FOR TESTING THE ADJOINT GRADIENT
# petsc_options_iname = '-tao_max_it -tao_fd_test -tao_test_gradient -tao_fd_gradient -tao_fd_delta -tao_gatol'
# petsc_options_value = '1 true true false 1e-3 1e-5'
# petsc_options = '-tao_test_gradient_view'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## THESE OPTIONS ARE FOR TESTING THE ADJOINT GRADIENT
# petsc_options_iname = '-tao_max_it -tao_fd_test -tao_test_gradient -tao_fd_gradient -tao_fd_delta -tao_gatol'
# petsc_options_value = '1 true true false 1e-3 1e-5'
# petsc_options = '-tao_test_gradient_view'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't put these in these commented out tao options for the fd gradient in new input files. I do find them helpful.

abs_zero = 1e-4
# steady solve
recover = false
detail = 'for side only measurements.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
detail = 'for side only measurements.'
detail = 'for side only measurements and fewer measurements than controllable parameters.'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to point out this problem is under constrained.

num_values = '3'
[]

[Reporters]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this reporter on the sub-app so that you don't have to transfer it.

Comment on lines +13 to +32
- Measurement values $\mathbf{u}_m = \{u_{m,1}, u_{m,2}, \ldots, u_{m,n}\}$
- Measurement Locations: $\mathbf{p}_m = \{\mathbf{p}_{m,1}, \mathbf{p}_{m,2}, \ldots, \mathbf{p}_{m,n}\}$, where $\mathbf{p}_{m,i} = (x_{m,i}, y_{m,i}, z_{m,i})$ for 3D data

- Simulation variable: $u(\mathbf{x})$
- Gaussian beam width: $w$
- Simulation point: $\mathbf{x}$

The `misfit` at a given simulation point $\mathbf{x}$ is calculated as:

$m(\mathbf{x}) = \sum_{i=1}^{n} \left( u_{m,i} g(\mathbf{p}_{m,i}, \mathbf{x}) - u(\mathbf{x}) g(\mathbf{p}_{m,i}, \mathbf{x}) \right)^2,$

where:

- $g(\mathbf{p}_{m,i}, \mathbf{x})$ is the Gaussian weighting function, defined as:

$g(\mathbf{p}_{m,i}, \mathbf{x}) = \exp\left( -\frac{2 \|\mathbf{p}_{m,i} - \mathbf{x}\|^2}{w^2} \right),$

and the `misfit gradient` with respect to the simulation variable $u(\mathbf{x})$ is:

$\frac{\partial m(\mathbf{x})}{\partial u(\mathbf{x})} = -2 \sum_{i=1}^{n} g(\mathbf{p}_{m,i}, \mathbf{x}) \left( u_{m,i} g(\mathbf{p}_{m,i}, \mathbf{x}) - u(\mathbf{x}) g(\mathbf{p}_{m,i}, \mathbf{x}) \right).$
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THis needs to be corrected for a general function and not just a gaussian. You can keep the gaussian as an example but its not really relevant anymore. Maybe reference the input file function:
!listing test/tests/optimizationreporter/function_misfit/forward_and_adjoint.i block=Functions

/// Simulation variable
const GenericVariableValue<is_ad> & _sim_var;

/// Gradient of misfit with respect to material properties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrt simulation variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Guassian probe type misfit for optimization
3 participants