Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/fem/tests/1dtests_MeshLevels/Source.f90
5253 views
1
FUNCTION Source( Model, n, f ) RESULT(h)
2
USE Lists
3
TYPE(Model_t) :: Model
4
INTEGER :: n
5
REAL(KIND=dp) :: f, h, x, s
6
7
INTEGER :: i, Step, OldStep = -1
8
TYPE(Variable_t), POINTER :: T, P
9
10
T => VariableGet( Model % Variables, 'Time' )
11
Step = NINT( T % Values(1) )
12
13
P => VariableGet( Model % Variables, 'Potential' )
14
15
! First check the previous result
16
! -------------------------------
17
IF ( Step>1 .AND. Step /= OldStep ) THEN
18
DO i=1,Model % NumberOfNodes
19
x = Model % Nodes % x(i)
20
s = P % Values( P % Perm(i) )
21
SELECT CASE(Step)
22
CASE(2) ! can we solve a zero field ?
23
IF ( s /= 0 ) &
24
CALL Fatal( 'Source', 'Not able to integrate a zero field ?')
25
CASE(3) ! how about a parabola ?
26
IF ( ABS(s+(x**2-PI*x)/2) > 1.0d-8 ) &
27
CALL Fatal( 'Source', 'Not able to integrate parabola ?' )
28
CASE(4) ! how about a third degree polynomial
29
IF ( ABS(s+(x**3-PI**2*x)/6) > 1.0d-8 ) &
30
CALL Fatal( 'Source', 'Not able to integrate 3d deg polynomial?' )
31
CASE(5) ! how about a sine
32
IF ( ABS(s-2*sin(x)) > 1.0d-4 ) &
33
CALL Fatal( 'Source', 'Not able to integrate sine?' )
34
END SELECT
35
END DO
36
OldStep = Step
37
END IF
38
39
! Then define new one
40
! -------------------
41
x = Model % Nodes % x(n)
42
43
SELECT CASE(Step)
44
CASE(1) ! can we solve a zero field ?
45
h = 0
46
CASE(2) ! how about a parabola ?
47
h = 1
48
CASE(3) ! how about a third degree polynomial
49
h = x
50
CASE(4) ! how about a sine
51
h = f
52
CASE(5) ! how about a sine
53
h = f
54
END SELECT
55
END FUNCTION Source
56
57