update of same solver variable

Numerical methods and mathematical models of Elmer
Post Reply
spacedout
Posts: 177
Joined: 30 Mar 2020, 23:27
Antispam: Yes

update of same solver variable

Post by spacedout »

Hello to all

I am solving for the same variable potential by two different PDEs with the following two solvers. I checked that ElmerSolver does not complain about the dual use of potential. The simulation is transient. The question is whether Solver 2 uses the updated value potential from Solver 1 or on the other hand if it uses the value of potential before Solver 1 is called. (After all, one cycle of Solver 1 and 2 belongs to the same time step ).

Best regards

...

Simulation
Coordinate System = "Cartesian 2D"
Coordinate Mapping(3) = 1 2 3
Simulation Type = Transient

TimeStepping Method = BDF
BDF Order = 1
Timestep Intervals(1) = 1000
Timestep Size = .001
...

End
...

Equation 1
Name = "whatever"

Active Solvers(2) = 1 2

End

...

Initial Condition 1

Potential = Real 0.0

End

....

Solver 1
Equation = "blabla"
Procedure = "MySolver" "SolverRoutine"

Variable = Potential
Exec Solver = Always
....

End

Solver 2
Equation = "blabla2"
Procedure = "MySolver2" "SolverRoutine2"

Variable = Potential
Exec Solver = Always
...

End
raback
Site Admin
Posts: 4832
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: update of same solver variable

Post by raback »

Hi

Usually different solvers solver for different field. I can see dangers here.

It might be that both get different fields and then the values are not updated.

Or it could be that they refer to the same field but things go south when each solver takes a new timestep.

Without looking at a code I would give <10% chance that everthing works out as you hope. Frankly I would probably even try to make it work but rather warn the user... Maybe you can share the original issue. There might be a more natural approach for Elmer.

-Peter
spacedout
Posts: 177
Joined: 30 Mar 2020, 23:27
Antispam: Yes

Re: update of same solver variable

Post by spacedout »

Good day
For the sake of argument and to make it very simpler let us say Solver 1 and 2 are both the standard AdvectionDiffusionSolver with the very minor change

dt = Timestep/2. (instead of dt = Timestep)

In other words I am calling the same solver twice during the same time step which is the reason why the timestep is halved for each.

Yes I know, I could have simply halved the timestep in the Simulation section and called only one solver instead of two but like I said in the original post, the PDEs will be different in the final case: Solver 1 will be AdvectionDiffusionSolver with a zero load and a non zero convection velocity and a non zero diffusivity whereas Solver 2 will be AdvectionDiffusionSolver with a non zero load and a zero convection velocity and a zero diffusivity. Both solvers update the same concentration field variable.

Hope this clarifies what I want to achieve
Any reply welcome
spacedout
Posts: 177
Joined: 30 Mar 2020, 23:27
Antispam: Yes

Re: update of same solver variable

Post by spacedout »

Digging into SolverUtils.F90 and DefUtils.F90 for the definition of subroutines Default1stOrderTime and Add1stOrderTime , I discovered that not only we have the values of the current field variable in Solver % Variable % Values but also the former values in Solver % Variable % Prevalues.

So when starting Solver 2, we could update its % Prevalues with the % Values computed by Solver 1 !

Maybe that solves my problem.
raback
Site Admin
Posts: 4832
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: update of same solver variable

Post by raback »

Hi

Ok, so let's say you have du/dt=Lu and want to solve this in two parts.

du/(dt/2)=L(u)
du/(dt/2)=L(u)

Now obviously the problem here is that you should update u for the 2nd instance from the 1st equation. Field u gets updated for the current timestep but the PrevValues that you found gets updated only at the end of the timestep when all the fields are advanced. Advancing the timestep manually after the 1st might be ok for 1st order timestepping but certainly not for higher order schemes.

So I would rather
1) Add some control on the assembly routines such that
IF(MODULO(NINT(GetTimestep(),2)==0) THEN
! do even assembly
ELSE
! do odd assembly
END IF

Or really create two different equations with their own variables etc. and use the intermediate variable explicitely. Typically your type of problems occurs when doing some operator splitting or predictor-corrector stuff. Often the equations may require somewhat different linear solver strategies (e.g. mass matrix vs. diffusion matrix).

-Peter
Post Reply