Skip to content

Commit

Permalink
Using function for transient interpolation instead idaholab#42
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmprince authored and dschwen committed Aug 19, 2022
1 parent 13386bf commit b57cc12
Show file tree
Hide file tree
Showing 15 changed files with 381 additions and 296 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# VectorNearestPointFunction

!syntax description /Functions/VectorNearestPointFunction

## Overview

This function computes values based on coordinate and time data. This data comes in the form of vector reporter or vectorpostprocessor values. The required parameter [!param](/Functions/VectorNearestPointFunction/value) is the name of the vector containing the values used to set the variable to. [!param](/Functions/VectorNearestPointFunction/coord_x)/[!param](/Functions/VectorNearestPointFunction/coord_y)/[!param](/Functions/VectorNearestPointFunction/coord_z) are vectors with the x-/y-/z-coordinate data. The auxkernel will set the variable's nodal/elemental values based on the nearest point in this data. [!param](/Functions/VectorNearestPointFunction/time) is the name of the time data; the kernel will linearly interpolate between two closest times for a certain coordinate, without extrapolating. [!param](/Functions/VectorNearestPointFunction/coord_x), [!param](/Functions/VectorNearestPointFunction/coord_y), [!param](/Functions/VectorNearestPointFunction/coord_z), and [!param](/Functions/VectorNearestPointFunction/time) will assume to be 0 when not specified. When specified, [!param](/Functions/VectorNearestPointFunction/coord_x), [!param](/Functions/VectorNearestPointFunction/coord_y), [!param](/Functions/VectorNearestPointFunction/coord_z), and [!param](/Functions/VectorNearestPointFunction/time) must all be the same length as [!param](/Functions/VectorNearestPointFunction/value).

## Example Input File Syntax

Here are several examples different combinations of x, y, z, and time data is specified:

!listing vector_nearest_point.i block=Functions Reporters

Run this test to see how the function interpolates the data between specified times.

!syntax parameters /Functions/VectorNearestPointFunction

!syntax inputs /Functions/VectorNearestPointFunction

!syntax children /Functions/VectorNearestPointFunction
30 changes: 9 additions & 21 deletions modules/optimization/examples/simpleTransient/forward.i
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,6 @@
[]
[]

[AuxVariables]
[source]
family = MONOMIAL
order = CONSTANT
[]
[]

[AuxKernels]
[source_aux]
type = ReporterNearestPointAux
variable = source
coord_x = src_values/coordx
coord_y = src_values/coordy
time = src_values/time
value = src_values/values
execute_on = 'initial timestep_begin'
[]
[]

[VectorPostprocessors]
[src_values]
type = CSVReader
Expand All @@ -61,9 +42,9 @@
variable = u
[]
[src]
type = CoupledForce
type = BodyForce
variable = u
v = source
function = source
[]
[]

Expand All @@ -81,6 +62,13 @@
type = ParsedFunction
value = '2*exp(-2.0*(x - sin(2*pi*t))^2)*exp(-2.0*(y - cos(2*pi*t))^2)*cos((1/2)*x*pi)*cos((1/2)*y*pi)/pi'
[]
[source]
type = VectorNearestPointFunction
coord_x = src_values/coordx
coord_y = src_values/coordy
time = src_values/time
value = src_values/values
[]
[]

[Executioner]
Expand Down
46 changes: 0 additions & 46 deletions modules/optimization/include/auxkernels/ReporterNearestPointAux.h

This file was deleted.

27 changes: 27 additions & 0 deletions modules/optimization/include/functions/OptimizationFunction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "Function.h"

/**
* Base class for functions used in inverse optimization
* The parameterDerivative function is used in adjoint calculation to compute
* gradients.
*/
class OptimizationFunction : public Function
{
public:
static InputParameters validParams();

OptimizationFunction(const InputParameters & parameters);

virtual std::vector<Real> parameterGradient(Real t, const Point & pt) const = 0;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "OptimizationFunction.h"
#include "ReporterInterface.h"

class VectorNearestPointFunction : public OptimizationFunction, public ReporterInterface
{
public:
static InputParameters validParams();

VectorNearestPointFunction(const InputParameters & parameters);

using Function::value;
virtual Real value(Real t, const Point & p) const override;
virtual RealGradient gradient(Real t, const Point & p) const override;
virtual Real timeDerivative(Real t, const Point & p) const override;
virtual std::vector<Real> parameterGradient(Real t, const Point & p) const override;

protected:
/**
* Builds _coord_mapping object with coordinates from inputted vectors
*/
void buildCoordinateMapping() const;

/**
* With an inputted time and point, gets the closest point and two closest times in
* _coord_mapping. See ::value on how the return value is used.
*/
std::array<std::pair<Real, std::size_t>, 2> findNearestPoint(Real t, const Point & p) const;

/// x-coordinates from reporter
const std::vector<Real> & _coordx;
/// y-coordinates from reporter
const std::vector<Real> & _coordy;
/// z-coordinates from reporter
const std::vector<Real> & _coordz;
/// time-coordinates from reporter
const std::vector<Real> & _coordt;
/// values from reporter
const std::vector<Real> & _values;

/// Number of values from coordinate vectors
mutable std::size_t _nval;
/// Data structure for all current data
mutable std::map<Point, std::vector<std::pair<Real, std::size_t>>> _coord_mapping;

private:
const std::vector<Real> _empty_vec = {};
};
154 changes: 0 additions & 154 deletions modules/optimization/src/auxkernels/ReporterNearestPointAux.C

This file was deleted.

Loading

0 comments on commit b57cc12

Please sign in to comment.