ElmerFoamFSI  2.0
ElmerFoamFSI is fluid-solid interaction simulation application built up from OpenFOAM CFD and Elmer CSM coupled through the IMPACT multiphysics software integration infrastructure.
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros Groups Pages
Finalize.F90
Go to the documentation of this file.
1 !/*****************************************************************************/
2 ! *
3 ! * Elmer, A Finite Element Software for Multiphysical Problems
4 ! *
5 ! * Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
6 ! *
7 ! * This library is free software; you can redistribute it and/or
8 ! * modify it under the terms of the GNU Lesser General Public
9 ! * License as published by the Free Software Foundation; either
10 ! * version 2.1 of the License, or (at your option) any later version.
11 ! *
12 ! * This library is distributed in the hope that it will be useful,
13 ! * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ! * Lesser General Public License for more details.
16 ! *
17 ! * You should have received a copy of the GNU Lesser General Public
18 ! * License along with this library (in file ../LGPL-2.1); if not, write
19 ! * to the Free Software Foundation, Inc., 51 Franklin Street,
20 ! * Fifth Floor, Boston, MA 02110-1301 USA
21 ! *
22 ! *****************************************************************************/
23 !
24 !/******************************************************************************
25 ! *
26 ! * ELMER/FEM Solver finalize program
27 ! *
28 ! ******************************************************************************
29 ! *
30 ! * Authors: Juha Ruokolainen
31 ! * Email: Juha.Ruokolainen@csc.fi
32 ! * Web: http://www.csc.fi/elmer
33 ! * Address: CSC - IT Center for Science Ltd.
34 ! * Keilaranta 14
35 ! * 02101 Espoo, Finland
36 ! *
37 ! * Original Date: 02 Jun 1997
38 ! *
39 ! *****************************************************************************/
40 
42 
44 
46 
48 
51 
52 !------------------------------------------------------------------------------
54 !------------------------------------------------------------------------------
55  SUBROUTINE elmerfinalize(runs)
56 !------------------------------------------------------------------------------
57 
58  USE generalmodule
59 
60 !------------------------------------------------------------------------------
61  IMPLICIT NONE
62 !------------------------------------------------------------------------------
63 
64 ! INTEGER :: Initialize
65 
66 !------------------------------------------------------------------------------
67 ! Local variables
68 !------------------------------------------------------------------------------
69 
70 ! INTEGER :: i,j,k,n,l,t,k1,k2,iter,Ndeg,istat,nproc,tlen,nthreads
71 ! CHARACTER(LEN=MAX_STRING_LEN) :: threads
72 !
73 ! REAL(KIND=dp) :: s,dt,dtfunc
74 ! REAL(KIND=dP), POINTER :: WorkA(:,:,:) => NULL()
75 ! REAL(KIND=dp), POINTER, SAVE :: sTime(:), sStep(:), sInterval(:), sSize(:), &
76 ! steadyIt(:),nonlinIt(:),sPrevSizes(:,:),sPeriodic(:)
77 !
78 ! TYPE(Element_t),POINTER :: CurrentElement
79 !
80 ! LOGICAL :: GotIt,Transient,Scanning,LastSaved
81 !
82 ! INTEGER :: TimeIntervals,interval,timestep, &
83 ! TotalTimesteps,SavedSteps,CoupledMaxIter,CoupledMinIter
84 !
85 ! INTEGER, POINTER, SAVE :: Timesteps(:),OutputIntervals(:), ActiveSolvers(:)
86 ! REAL(KIND=dp), POINTER, SAVE :: TimestepSizes(:,:)
87 !
88 ! INTEGER(KIND=AddrInt) :: ControlProcedure
89 !
90 ! LOGICAL :: InitDirichlet, ExecThis
91 !
92 ! TYPE(ElementType_t),POINTER :: elmt
93 !
94 ! TYPE(ParEnv_t), POINTER :: ParallelEnv
95 !
96 ! CHARACTER(LEN=MAX_NAME_LEN) :: ModelName, eq, ExecCommand
97 ! CHARACTER(LEN=MAX_STRING_LEN) :: OutputFile, PostFile, RestartFile, &
98 ! OutputName=' ',PostName=' ', When, OptionString
99 !
100 ! TYPE(Variable_t), POINTER :: Var
101 ! TYPE(Mesh_t), POINTER :: Mesh
102 ! TYPE(Solver_t), POINTER :: Solver
103 !
104 ! REAL(KIND=dp) :: RealTime,CPUTime,CT0,RT0,tt
105 !
106 ! LOGICAL :: FirstLoad = .TRUE., FirstTime=.TRUE., Found
107 ! LOGICAL :: Silent, Version, GotModelName
108 !
109 ! INTEGER :: iargc, NoArgs
110 !
111 ! INTEGER :: ExtrudeLevels
112 ! TYPE(Mesh_t), POINTER :: ExtrudedMesh
113 !
114 ! INTEGER :: omp_get_max_threads
115 !
116 !#ifdef HAVE_TRILINOS
117 !INTERFACE
118 ! SUBROUTINE TrilinosCleanup() BIND(C,name='TrilinosCleanup')
119 ! IMPLICIT NONE
120 ! END SUBROUTINE TrilinosCleanup
121 !END INTERFACE
122 !#endif
123  INTEGER :: runs
124 
125  DO i=1,currentmodel % NumberOfSolvers
126  solver => currentmodel % Solvers(i)
127  IF ( solver % PROCEDURE == 0 ) cycle
128  when = listgetstring( solver % Values, 'Exec Solver', gotit )
129  IF ( gotit ) THEN
130  IF ( when == 'after simulation' .OR. when == 'after all' ) THEN
131  CALL solveractivate( currentmodel,solver,dt,transient )
132  IF (ASSOCIATED(solver % Variable % Values) ) lastsaved = .false.
133  END IF
134  ELSE
135  IF ( solver % SolverExecWhen == solver_exec_after_all ) THEN
136  CALL solveractivate( currentmodel,solver,dt,transient )
137  IF (ASSOCIATED(solver % Variable % Values) ) lastsaved = .false.
138  END IF
139  END IF
140  END DO
141 
142  IF( .NOT. lastsaved ) THEN
143  DO i=1,currentmodel % NumberOfSolvers
144  solver => currentmodel % Solvers(i)
145  IF ( solver % PROCEDURE == 0 ) cycle
146  execthis = ( solver % SolverExecWhen == solver_exec_ahead_save)
147  when = listgetstring( solver % Values, 'Exec Solver', gotit )
148  IF ( gotit ) execthis = ( when == 'before saving')
149  IF( execthis ) CALL solveractivate( currentmodel,solver,dt,transient )
150  END DO
151  END IF
152 
153 
154 !------------------------------------------------------------------------------
155 ! Always save the last step to output
156 !------------------------------------------------------------------------------
157  IF ( .NOT.lastsaved ) THEN
158  DO i=1,currentmodel % NumberOfSolvers
159  solver => currentmodel % Solvers(i)
160  IF ( solver % PROCEDURE == 0 ) cycle
161  execthis = ( solver % SolverExecWhen == solver_exec_ahead_save)
162  when = listgetstring( solver % Values, 'Exec Solver', gotit )
163  IF ( gotit ) execthis = ( when == 'before saving')
164  IF( execthis ) CALL solveractivate( currentmodel,solver,dt,transient )
165  END DO
166 
167  CALL savetopost(0)
168  CALL savecurrent(timestep)
169 
170  DO i=1,currentmodel % NumberOfSolvers
171  solver => currentmodel % Solvers(i)
172  IF ( solver % PROCEDURE == 0 ) cycle
173  execthis = ( solver % SolverExecWhen == solver_exec_after_save)
174  when = listgetstring( solver % Values, 'Exec Solver', gotit )
175  IF ( gotit ) execthis = ( when == 'after saving')
176  IF( execthis ) CALL solveractivate( currentmodel,solver,dt,transient )
177  END DO
178  END IF
179 
180 ! IF ( Initialize >= 2 ) EXIT
181 
182 
183 
184 !------------------------------------------------------------------------------
185 ! THIS IS THE END (...,at last, the end, my friend,...)
186 !------------------------------------------------------------------------------
187  IF ( initialize /= 1 ) CALL info( 'MyElmerSolver', '*** Elmer Solver: ALL DONE ***',level=3 )
188 
189  IF ( initialize <=0 ) CALL freemodel(currentmodel)
190 
191 #ifdef HAVE_TRILINOS
192  CALL trilinoscleanup()
193 #endif
194 
195  IF ( parenv % PEs>1 ) CALL parallelfinalize()
196  CALL info('MyElmerSolver','The end',level=3)
197 
198  runs = 1
199 
200  RETURN
201 
202 
203 !------------------------------------------------------------------------------
204  END SUBROUTINE elmerfinalize
205 !------------------------------------------------------------------------------
206 
subroutine savecurrent(CurrentStep)
Saves current timestep to external files.
subroutine savetopost(CurrentStep)
Saves results file to post processing file of ElmerPost format, if requested.
subroutine elmerfinalize(runs)
ElmerLib Elmer library routines
Definition: Finalize.F90:55
ElmerLib Elmer library routines