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

Power Regulation Infrastructure #224

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added doc/content/media/multi_period_mean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/content/media/periodic_modification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions doc/content/source/auxkernels/LinearCombinationAuxKernel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# LinearCombinationAuxKernel

`LinearCombinationAuxKernel` allows you to calculate the linear combination of several coupled variables.

\begin{equation}
f = \sum_{i=1}^n w_i x_i + b
\end{equation}

Where $w$ is the weighting factor per coupled variable, $x$ is an array of coupled variables to be summed, the subscript $i$ is the ith component of the weighted summands, and b is the linear shift of the weighted sum.



## Example Input File Syntax

!listing test/tests/auxkernels/linear_combination_aux/linear_combination.i block=AuxKernels

!syntax parameters /AuxKernels/LinearCombinationAuxKernel

!syntax inputs /AuxKernels/LinearCombinationAuxKernel

!syntax children /AuxKernels/LinearCombinationAuxKernel
25 changes: 25 additions & 0 deletions doc/content/source/postprocessors/MultiPeriodAverager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# MultiPeriodAverager

`MultiPeriodAverager` calculates the the period average of values of periodic fuctions at the end of each period, such that:
\begin{equation}
P = \frac{\sum_i^{N_\text{T}} f(\text{T})_i }{N_\text{T}}
\end{equation}
Where $P$ is the value of `MultiPeriodAverager`, $N_\text{T}$ is the number of periods to average over, and $f(\text{T})_i$ is the value of the periodic value at the end of a period. Until the number of periods over which you are averaging has passed the value of the Postprocessor will reflect the previously calculated average.

!alert warning
Before the first average is calculated the value of this post processor will be 0.


!alert note title=Proper Usage Hint
`MultiPeriodAverager` is intended to be used with the [PeriodicTimeIntegratedPostprocessor.md].

## Example Input File Syntax

!listing test/tests/postprocessors/multi_period_averaging/multi_period_averager.i block=Postprocessors
gsgall marked this conversation as resolved.
Show resolved Hide resolved


!syntax parameters /Postprocessors/MultiPeriodAverager

!syntax inputs /Postprocessors/MultiPeriodAverager

!syntax children /Postprocessors/MultiPeriodAverager
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# MultipliedTimeIntegratedPostprocessor

`MultipliedTimeIntegratedPostprocessor` provides the same functionationlity as [TimeIntegratedPostprocessor.md] except you can multiply the time integral by a constant coefficient.

If the value of [TimeIntegratedPostprocessor.md] is given by

\begin{equation}
I = \int_0^t
f(t) dt
\end{equation}

The value returned by `MultipliedTimeIntegratedPostprocessor` will be given by


\begin{equation}
I =
C
\int_0^t
f(t) dt
\end{equation}

Where $C$ is the constant factor to scale the time integration.

## Example Input File Syntax

In this example, the variable `v` is integrated over the spatial domain using [ElementIntegralVariablePostprocessor.md], resulting in the variable `a`, and then integrated over time by a factor of $2$ using `MultipliedTimeIntegratedPostprocessor`. For reference, `a` was also integrated over time using [TimeIntegratedPostprocessor.md].

gsgall marked this conversation as resolved.
Show resolved Hide resolved
!listing test/tests/postprocessors/multiplied_time_integration/multiplied_integral.i block=Postprocessors


!syntax parameters /Postprocessors/MultipliedTimeIntegratedPostprocessor

!syntax inputs /Postprocessors/MultipliedTimeIntegratedPostprocessor

!syntax children /Postprocessors/MultipliedTimeIntegratedPostprocessor
40 changes: 40 additions & 0 deletions doc/content/source/postprocessors/PeriodicAmplitudeRegulator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# PeriodicAmplitudeRegulator

`PeriodicAmplitudeRegulator` periodical updates its value based on the ratio of a coupled Postprocessor value and a reference value. The value of `PeriodicAmplitudeRegulator` is updated with the following scheme

\begin{equation}
V_n =
\frac{P_\text{ref}}{P_\text{actual}}
V_{n-1}
\end{equation}

Where $V_n$ is the new value of the `PeriodicAmplitudeRegulator` Postprocessor, $P_\text{ref}$ is the reference value, $P_\text{actual}$ is the value of the coupled Postprocessor, $V_{n-1}$ is the pervious value of the `PeriodicAmplitudeRegulator` Postprocessor, and the subscript $n$ is some multiplicative integer of the period.


## Example Amplitude Regulation

`PeriodicAmplitudeRegulator` is intended to be used to modify the value of a control parameter to force another Postprocessor value to be equal a refernce value. For the test example [periodic_modifier.i](test/tests/postprocessors/periodic_amplitude_regulator/periodic_modifier.i), the reference value was $10$ and the coupled Postprocessor was [MultiPeriodAverager.md], which takes multiple period averages of a periodic integral that depends on the value of `PeriodicAmplitudeRegulator`. The results in the figure below are from the test example [periodic_modifier.i](test/tests/postprocessors/periodic_amplitude_regulator/periodic_modifier.i) with a more refined time step of `dt = 1e-2`. In this case, the Function Magnitude is the value of `PeriodicAmplitudeRegulator` with an initial value of $-4$ and the Periodic Integral is the value of the coupled Postprocessor, [MultiPeriodAverager.md].

!row!
!col! small=12 medium=6 large=6
!style halign=center
!media media/periodic_modification.png
style=width:100%;display:block;margin-top:3em;margin-left:auto;margin-right:auto;
!col-end!

!col! small=12 medium=6 large=6
!style halign=right
!media media/multi_period_mean.png
style=width:97%;display:block;margin-top:3em;margin-left:auto;margin-right:auto;
!col-end!
!row-end!

## Example Input File Syntax

!listing test/tests/postprocessors/periodic_amplitude_regulator/periodic_modifier.i block=Functions Postprocessors

!syntax parameters /Postprocessors/PeriodicAmplitudeRegulator

!syntax inputs /Postprocessors/PeriodicAmplitudeRegulator

!syntax children /Postprocessors/PeriodicAmplitudeRegulator
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# PeriodicTimeIntegratedPostprocessor

`PeriodicTimeIntegratedPostprocessor` provides the same functionationlity as [MultipliedTimeIntegratedPostprocessor.md] except this integrals value will periodically be set to 0 in order to integrate values over a single period.

\begin{equation}
I \approx
C
\int_0^t
f(t) dt
\:\:
\text{mod}
\left(
\text{T}
\right)
\end{equation}

Where $f(t)$ is a time dependent function and $\text{T}$ is the period of the cycle.




!alert note title=Proper Usage Hint
[MultipliedTimeIntegratedPostprocessor.md] uses the trapezoid rule for time integration and since this object inherits from the [MultipliedTimeIntegratedPostprocessor.md] this integration is also performed by trapezoid rule. The integration is also reset after the next time which is appoximately greater than or equal to the next period start. Users should also take care to ensure that the period they want to integrate over is sufficiently resolved. Additionally, if users would like to ensure that the time time steps hit the start of each period the [AddPeriodicControllers.md] action can be used in the following manner. The parameter `num_contoller_set` should be set to a number of periods that is greater than or equal to the number of periods you are simulating.

```
[PeriodicControllers]
[enforcer]
name = enforcer
starting_cycle = 0
cycles_between_controls = 0
num_controller_set = 2000
[]
[]
```


## Example Input File Syntax

In this example, the variable `v` is integrated over the spatial domain using [ElementIntegralVariablePostprocessor.md], resulting in the variable `a`, and then periodically integrated over time using `PeriodicTimeIntegratedPostprocessor`.

gsgall marked this conversation as resolved.
Show resolved Hide resolved
!listing test/tests/postprocessors/periodic_integration/periodic_integral.i block=Postprocessors


!syntax parameters /Postprocessors/PeriodicTimeIntegratedPostprocessor

!syntax inputs /Postprocessors/PeriodicTimeIntegratedPostprocessor

!syntax children /Postprocessors/PeriodicTimeIntegratedPostprocessor
30 changes: 30 additions & 0 deletions include/auxkernels/LinearCombinationAuxKernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//* This file is part of Zapdos, an open-source
//* application for the simulation of plasmas
//* https://github.com/shannon-lab/zapdos
//*
//* Zapdos is powered by the MOOSE Framework
//* https://www.mooseframework.org
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "AuxKernel.h"

class LinearCombinationAuxKernel : public AuxKernel
{
public:
LinearCombinationAuxKernel(const InputParameters & parameters);

static InputParameters validParams();

virtual Real computeValue() override;

protected:
const std::vector<Real> _weights;
const unsigned int _num_vars;
const Real _bias;
std::vector<const MooseVariable *> _vars;
std::vector<const VariableValue *> _var_vals;
};
44 changes: 44 additions & 0 deletions include/postprocessors/MultiPeriodAverager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//* This file is part of Zapdos, an open-source
//* application for the simulation of plasmas
//* https://github.com/shannon-lab/zapdos
//*
//* Zapdos is powered by the MOOSE Framework
//* https://www.mooseframework.org
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "GeneralPostprocessor.h"

class MultiPeriodAverager : public GeneralPostprocessor
{
public:
static InputParameters validParams();

MultiPeriodAverager(const InputParameters & parameters);

virtual void initialize() override {}
virtual void execute() override;
using Postprocessor::getValue;
virtual Real getValue() const override;

protected:
/// The current post-processor value
Real _value;
/// Where we are going to be storing the next average while we calculate it
Real _temp_value;
/// The number of periods that have passed
Real _period_count;
/// The time when the next period starts
Real _next_period_start;
/// The counter for how many periods have passed since we last updated
Real _cyclic_period_count;
/// inverse of the frequency
const Real _period;
/// the number of periods over which we are averaging
Real _num_periods;
/// The previous post process value of the post processor we are averaging over several periods
const PostprocessorValue & _pps_value_old;
};
44 changes: 44 additions & 0 deletions include/postprocessors/MultipliedTimeIntegratedPostprocessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//* This file is part of Zapdos, an open-source
//* application for the simulation of plasmas
//* https://github.com/shannon-lab/zapdos
//*
//* Zapdos is powered by the MOOSE Framework
//* https://www.mooseframework.org
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "GeneralPostprocessor.h"

/**
* Integrate a post-processor value multiplied by a normalization factor
* over time using trapezoidal rule
*/
class MultipliedTimeIntegratedPostprocessor : public GeneralPostprocessor
{
public:
static InputParameters validParams();

MultipliedTimeIntegratedPostprocessor(const InputParameters & parameters);

virtual void initialize() override {}
virtual void execute() override;
using Postprocessor::getValue;
virtual Real getValue() const override;

protected:
/// The total value of the variable
Real _value;
/// The normalization factor
const Real _coeff;
/// My old value
const PostprocessorValue & _value_old;

/// The current post-processor value
const PostprocessorValue & _pps_value;

/// The old post-processor value
const PostprocessorValue & _pps_value_old;
};
47 changes: 47 additions & 0 deletions include/postprocessors/PeriodicAmplitudeRegulator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//* This file is part of Zapdos, an open-source
//* application for the simulation of plasmas
//* https://github.com/shannon-lab/zapdos
//*
//* Zapdos is powered by the MOOSE Framework
//* https://www.mooseframework.org
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "GeneralPostprocessor.h"

class PeriodicAmplitudeRegulator : public GeneralPostprocessor
{
public:
static InputParameters validParams();

PeriodicAmplitudeRegulator(const InputParameters & parameters);

virtual void initialize() override {}
virtual void execute() override;
virtual Real getValue() const override;

protected:
/// the value you want _pps_value to be
const Real _reff_value;
/// the number of cycles after which this starts to modify its value
const Real _start_cycle;
/// the number of cycles between value modifications
const Real _cycles_between;
/// the previous post processor value
/// using this since we intend to use this with a periodic integrateor
/// and that sets the value to 0 on the start of a new cycle
const PostprocessorValue & _pps_value;
/// The period of the cycles
const Real _period;
/// The number of periods that have passed
Real _period_count;
/// The next periods start time
Real _next_period_start;
/// The time at which we will modify the value next
Real _next_modification_start;
/// The postprocessor value
Real _value;
};
28 changes: 28 additions & 0 deletions include/postprocessors/PeriodicTimeIntegratedPostprocessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//* This file is part of Zapdos, an open-source
//* application for the simulation of plasmas
//* https://github.com/shannon-lab/zapdos
//*
//* Zapdos is powered by the MOOSE Framework
//* https://www.mooseframework.org
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "MultipliedTimeIntegratedPostprocessor.h"

class PeriodicTimeIntegratedPostprocessor : public MultipliedTimeIntegratedPostprocessor
{
public:
static InputParameters validParams();

PeriodicTimeIntegratedPostprocessor(const InputParameters & parameters);

virtual void execute() override;

protected:
const Real _period;
Real _period_count;
Real _next_period_start;
};
Loading