... | ... | @@ -107,6 +107,115 @@ Another stopping criterion can be defined on the $`p^\text{th}`$ increment $`\ma |
|
|
\frac{||\mathbf{\delta x}_p||}{||\mathbf{x}_p||} < \varepsilon.
|
|
|
```
|
|
|
|
|
|
## User-defined nonlinear solver
|
|
|
|
|
|
The Newton-Raphson or Picard iterations can be written directly in the `Operations` of a `Resolution`, using a `While` loop. Convergence can be assessed with the `GetResidual` function.
|
|
|
|
|
|
Examples:
|
|
|
* [Nonlinear magnetic law in b- and h-conforming magnetostatics](https://gitlab.onelab.info/getdp/getdp/blob/master/templates/Lib_Magnetostatics_a_phi.pro)
|
|
|
* [Nonlinear magnetic law for magnetodynamics](https://gitlab.onelab.info/getdp/getdp/blob/master/templates/Lib_Magnetostatics_a_phi.pro)
|
|
|
* [Nonlinear electric law for magnetodynamics] (https://gitlab.onelab.info/doc/models/blob/master/Superconductors/helix.pro)
|
|
|
|
|
|
## Built-in `IterativeLoop` function
|
|
|
|
|
|
This section will explain the the `GenerateJac` and `SolveJac` functions, that can help automate the implementation of Newton-Raphson and Picard iteration in conjunction with the `JacNL` equation term specifier and the `IterativeLoop` resolution function.
|
|
|
|
|
|
|
|
|
## Built-in `IterativeLoopN` function
|
|
|
|
|
|
This section will explain the the `IterativeLoopN` resolution function. A typical usage of `IterativeLoopN` is shown in the following piece of code:
|
|
|
|
|
|
```cpp
|
|
|
Resolution {
|
|
|
{ Name ElectroThermal;
|
|
|
System {
|
|
|
{ Name SystemT; NameOfFormulation FormulationT; }
|
|
|
{ Name SystemV; NameOfFormulation FormulationV; }
|
|
|
}
|
|
|
Operation {
|
|
|
InitSolution[SystemT];
|
|
|
InitSolution[SystemV];
|
|
|
|
|
|
IterativeLoopN[NbrMaxIter, NL_Relax,
|
|
|
System { { SystemT, ReltolT, AbstolT, Solution LinfNorm }
|
|
|
{ SystemV, ReltolV, AbstolV, Solution MeanL2Norm } }
|
|
|
PostOperation { { V_Top, ReltolP, AbstolP, MeanL1Norm } } ]
|
|
|
{
|
|
|
Generate[SystemV];
|
|
|
Solve[SystemV];
|
|
|
Generate[SystemT];
|
|
|
Solve[SystemT];
|
|
|
}
|
|
|
|
|
|
SaveSolution[SystemV];
|
|
|
SaveSolution[SystemT];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
The parameters are:
|
|
|
|
|
|
* Maximum iterations: Maximum number of iterations
|
|
|
* NL_Relax: Relaxation factor (multiplies the iterative correction \deltax for Newton's method)
|
|
|
* System / PostOperation: Keyword System indicates that the quantity of interest are all DOFs of the given system. In addition or as an alternative you can specify post-operation results as quantities of interest by the keyword PostOperation.
|
|
|
* System / post-operation name: Here the name of the system / post-operation of interest is declared.
|
|
|
* Relative tolerance: Relative tolerance for the quantity of interest.
|
|
|
* Absolute tolerance: Absolute tolerance for the quantity of interest.
|
|
|
* Assessed object: Possible choices in case of a specified system: Solution, Residual, RecalcResidual. For specified post-operations this has to be omitted. Residual and RecalcResidual can only be used for Newton's method. Residual assesses the residual from the last iteration whereas RecalcResidual calculates the residual once again after each iteration. This means that with Residual usually one extra iteration is performed, but RecalcResidual causes higher computational effort per iteration.
|
|
|
* Error norm: Type of the error norm. Possible choices are: L1Norm, MeanL1Norm, L2Norm, MeanL2Norm, LinfNorm (see definitions below).
|
|
|
|
|
|
### Comparison of system vs. post-operation
|
|
|
|
|
|
* When a system is specified then all DOFs of this system are assessed, but they do not necessarily correspond to the values of the quantities of the formulation directly (e.g. in case of higher order basis functions).
|
|
|
* In case of several quantities in a formulation they can be assessed individually by a specified post-operation.
|
|
|
* With post-operations it's also possible to assess different regions individually.
|
|
|
* Also derived quantities can be assessed with a specified post-operation.
|
|
|
* Performing a post-operation each iteration can be time consuming for large problems.
|
|
|
|
|
|
### Error Norm
|
|
|
|
|
|
For each quantity of interest $`x_i`$ an error ratio $`q_i`$ is calculated:
|
|
|
|
|
|
$`q_i = \frac{|\Delta x_i|}{\epsilon_{abs} + \epsilon_{rel}|x_i|}`$
|
|
|
|
|
|
As the error ratio is calculated for each quantity of interest (e.g. one q per DOF of a given system) we need a norm in order to assess the overall error ratio. There are several norm types available for `IterativeLoopN`:
|
|
|
|
|
|
* L1 Norm: $`\|q\|_{L1} = \sum_{i=1}^n |q_i|`$
|
|
|
* Mean L1 Norm: $`\|q\|_{Mean L1} = \frac 1n \sum_{i=1}^n |q_i|`$
|
|
|
* L2 Norm: $`\|q\|_{L2} = \sqrt{\sum_{i=1}^n \left( q_i \right)^2}`$
|
|
|
* Mean L2 Norm: $`\|q\|_{Mean L2} = \sqrt{\frac 1n \sum_{i=1}^n \left( q_i \right)^2}`$
|
|
|
* Linfinity Norm: $`\|q\|_\infty = \max \left( |q_i| \right)`$
|
|
|
|
|
|
### General Hints
|
|
|
|
|
|
* If you specify several Systems and/or post-operations then usually only the largest $`\|q\|`$ is printed. If the verbosity level is set higher than 5 then $`\|q\|`$ is printed for each system or post-operation.
|
|
|
* If you start GetDP within Gmsh then the largest $\`|q\|`$ (ILmaxErrorRatio) can be plotted nicely.
|
|
|
|
|
|
### Complete Example
|
|
|
|
|
|
Here a complete example is given for a electro-thermal problem. We have an object consisting of two materials. On top a uniform current source is applied. The dissipated power is heating the body. The bottom of the body is kept at a fix temperature. The electrical conductivity is temperature dependent.
|
|
|
|
|
|
* Geometry: [ElectroThermal_Sim.geo](ElectroThermal_Sim.geo)
|
|
|
* Problem definition: [ElectroThermal_Sim.pro](ElectroThermal_Sim.pro)
|
|
|
|
|
|
<img src="ElectroThermal_Sim.jpg" width=50%>
|
|
|
|
|
|
---
|
|
|
*Written by @geuzaine and @AsamMich.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
|
== Implementation of nonlinear problems in GetDP ==
|
... | ... | @@ -421,110 +530,3 @@ Resolution{ |
|
|
|
|
|
###########################################################################################
|
|
|
--> |
|
|
|
|
|
|
|
|
## User-defined nonlinear solver
|
|
|
|
|
|
To be written.
|
|
|
|
|
|
Small example.
|
|
|
|
|
|
Explain `GetResidual`.
|
|
|
|
|
|
See the
|
|
|
[`helix.pro`](https://gitlab.onelab.info/doc/models/blob/master/Superconductors/helix.pro)
|
|
|
high-temperature superconducting cable model for an example.
|
|
|
|
|
|
|
|
|
## Built-in `IterativeLoop` function
|
|
|
|
|
|
Explain difference between `Generate` and `GenerateJac`
|
|
|
|
|
|
Explain difference between `Solve` and `SolveJac`
|
|
|
|
|
|
Explain `JacNL` qualifier in equation term.
|
|
|
|
|
|
To be written.
|
|
|
|
|
|
## Built-in `IterativeLoopN` function
|
|
|
|
|
|
A typical usage of IterativeLoopN is shown in the following piece of code:
|
|
|
|
|
|
```cpp
|
|
|
Resolution {
|
|
|
{ Name ElectroThermal;
|
|
|
System {
|
|
|
{ Name SystemT; NameOfFormulation FormulationT; }
|
|
|
{ Name SystemV; NameOfFormulation FormulationV; }
|
|
|
}
|
|
|
Operation {
|
|
|
InitSolution[SystemT];
|
|
|
InitSolution[SystemV];
|
|
|
|
|
|
IterativeLoopN[NbrMaxIter, NL_Relax,
|
|
|
System { { SystemT, ReltolT, AbstolT, Solution LinfNorm }
|
|
|
{ SystemV, ReltolV, AbstolV, Solution MeanL2Norm } }
|
|
|
PostOperation { { V_Top, ReltolP, AbstolP, MeanL1Norm } } ]
|
|
|
{
|
|
|
Generate[SystemV];
|
|
|
Solve[SystemV];
|
|
|
Generate[SystemT];
|
|
|
Solve[SystemT];
|
|
|
}
|
|
|
|
|
|
SaveSolution[SystemV];
|
|
|
SaveSolution[SystemT];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
The parameters are:
|
|
|
|
|
|
* Maximum iterations: Maximum number of iterations
|
|
|
* NL_Relax: Relaxation factor (multiplies the iterative correction \deltax for Newton's method)
|
|
|
* System / PostOperation: Keyword System indicates that the quantity of interest are all DOFs of the given system. In addition or as an alternative you can specify post-operation results as quantities of interest by the keyword PostOperation.
|
|
|
* System / post-operation name: Here the name of the system / post-operation of interest is declared.
|
|
|
* Relative tolerance: Relative tolerance for the quantity of interest.
|
|
|
* Absolute tolerance: Absolute tolerance for the quantity of interest.
|
|
|
* Assessed object: Possible choices in case of a specified system: Solution, Residual, RecalcResidual. For specified post-operations this has to be omitted. Residual and RecalcResidual can only be used for Newton's method. Residual assesses the residual from the last iteration whereas RecalcResidual calculates the residual once again after each iteration. This means that with Residual usually one extra iteration is performed, but RecalcResidual causes higher computational effort per iteration.
|
|
|
* Error norm: Type of the error norm. Possible choices are: L1Norm, MeanL1Norm, L2Norm, MeanL2Norm, LinfNorm (see definitions below).
|
|
|
|
|
|
### Comparison of system vs. post-operation
|
|
|
|
|
|
* When a system is specified then all DOFs of this system are assessed, but they do not necessarily correspond to the values of the quantities of the formulation directly (e.g. in case of higher order basis functions).
|
|
|
* In case of several quantities in a formulation they can be assessed individually by a specified post-operation.
|
|
|
* With post-operations it's also possible to assess different regions individually.
|
|
|
* Also derived quantities can be assessed with a specified post-operation.
|
|
|
* Performing a post-operation each iteration can be time consuming for large problems.
|
|
|
|
|
|
### Error Norm
|
|
|
|
|
|
For each quantity of interest $`x_i`$ an error ratio $`q_i`$ is calculated:
|
|
|
|
|
|
$`q_i = \frac{|\Delta x_i|}{\epsilon_{abs} + \epsilon_{rel}|x_i|}`$
|
|
|
|
|
|
As the error ratio is calculated for each quantity of interest (e.g. one q per DOF of a given system) we need a norm in order to assess the overall error ratio. There are several norm types available for `IterativeLoopN`:
|
|
|
|
|
|
* L1 Norm: $`\|q\|_{L1} = \sum_{i=1}^n |q_i|`$
|
|
|
* Mean L1 Norm: $`\|q\|_{Mean L1} = \frac 1n \sum_{i=1}^n |q_i|`$
|
|
|
* L2 Norm: $`\|q\|_{L2} = \sqrt{\sum_{i=1}^n \left( q_i \right)^2}`$
|
|
|
* Mean L2 Norm: $`\|q\|_{Mean L2} = \sqrt{\frac 1n \sum_{i=1}^n \left( q_i \right)^2}`$
|
|
|
* Linfinity Norm: $`\|q\|_\infty = \max \left( |q_i| \right)`$
|
|
|
|
|
|
### General Hints
|
|
|
|
|
|
* If you specify several Systems and/or post-operations then usually only the largest $`\|q\|`$ is printed. If the verbosity level is set higher than 5 then $`\|q\|`$ is printed for each system or post-operation.
|
|
|
* If you start GetDP within Gmsh then the largest $\`|q\|`$ (ILmaxErrorRatio) can be plotted nicely.
|
|
|
|
|
|
### Complete Example
|
|
|
|
|
|
Here a complete example is given for a electro-thermal problem. We have an object consisting of two materials. On top a uniform current source is applied. The dissipated power is heating the body. The bottom of the body is kept at a fix temperature. The electrical conductivity is temperature dependent.
|
|
|
|
|
|
* Geometry: [ElectroThermal_Sim.geo](ElectroThermal_Sim.geo)
|
|
|
* Problem definition: [ElectroThermal_Sim.pro](ElectroThermal_Sim.pro)
|
|
|
|
|
|
<img src="ElectroThermal_Sim.jpg" width=50%>
|
|
|
|
|
|
---
|
|
|
*Initially written by @AsamMich.* |
|
|
\ No newline at end of file |