# Information about the two methods of \`internalnorm\`

**URL:** https://discourse.julialang.org/t/information-about-the-two-methods-of-internalnorm/119383
**Category:** General Usage
**Tags:** question, diffeq, ode, differentialequation
**Created:** [September 13, 2024, 6:27pm UTC](https://discourse.julialang.org/t/information-about-the-two-methods-of-internalnorm/119383 "2024-09-13T18:27:15Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![lieskjur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lieskjur/32/27611_2.png) [@lieskjur](https://discourse.julialang.org/u/lieskjur)
#### Post date: [September 13, 2024, 6:27pm UTC](https://discourse.julialang.org/t/information-about-the-two-methods-of-internalnorm/119383/1 "2024-09-13T18:27:15Z")

</div>

Hi, I am using DifferentialEquations.jl and want to implement my own `internalnorm` function with specific weights for the purpose of timestep adaptation. I would appreciate some extra information about how the function is used as [“Required are two dispatches: one dispatch for the state variable and the other on the elements of the state variable (scalar norm)”](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/#solver_options) creates more questions than answers.

I think I quite correctly assume that the two signatures of the function should be along the lines of `custom_norm(u::AbstractArray, t)` and `custom_norm(u::Number, t)` but I’m not quite sure when they are called. I am almost certain the first is called while adapting the timestep ([as mentioned here](https://docs.sciml.ai/DiffEqDocs/stable/extras/timestepping/#Common-Setup)) but I am unsure about the second. Also there might be other times when they are called I am oblivious to.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [September 14, 2024, 6:30am UTC](https://discourse.julialang.org/t/information-about-the-two-methods-of-internalnorm/119383/3 "2024-09-14T06:30:28Z")

</div>

This isn’t a really well-defined or a simple question because when talking over 200 methods, yes there are more than a few ways it’s used. But it’s for initialization of dt, time step adaptivity, sometimes stiffness detection, instability checking, convergence checking in nonlinear solvers, consistent initialization checking in DAEs, etc.

---

<div class="post-metadata">

### Author: ![lieskjur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lieskjur/32/27611_2.png) [@lieskjur](https://discourse.julialang.org/u/lieskjur)
#### Post date: [September 15, 2024, 12:04am UTC](https://discourse.julialang.org/t/information-about-the-two-methods-of-internalnorm/119383/4 "2024-09-15T00:04:08Z")

</div>

Your answer makes me think I should come up with a better solution for saving and interpolating additional values (by-products) after the fact, than adding them to the state vector. I know it is a hacky solution but “dense” output is in my eyes such a brilliant idea and ComponentArrays.jl also makes the implementation convenient.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [September 15, 2024, 1:36am UTC](https://discourse.julialang.org/t/information-about-the-two-methods-of-internalnorm/119383/5 "2024-09-15T01:36:56Z")

</div>

a SavingCallback sounds like what you want.

---

<div class="post-metadata">

### Author: ![lieskjur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lieskjur/32/27611_2.png) [@lieskjur](https://discourse.julialang.org/u/lieskjur)
#### Post date: [September 15, 2024, 8:22am UTC](https://discourse.julialang.org/t/information-about-the-two-methods-of-internalnorm/119383/6 "2024-09-15T08:22:01Z")

</div>

AFAIK SavingCallback saves values only at the end of each step. Dense output on the other hand uses individual stages of each step and therefore interpolates using much finer data (for example in the case of Tsit5).

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [September 15, 2024, 8:27am UTC](https://discourse.julialang.org/t/information-about-the-two-methods-of-internalnorm/119383/7 "2024-09-15T08:27:13Z")

</div>

> [@lieskjur](#):
>
> nterpolating additional values (by-products) after the fact

That’s what ModelingToolkit’s system effectively does.
