V3FIT
combination.f
Go to the documentation of this file.
1 !*******************************************************************************
4 !
5 ! Note separating the Doxygen comment block here so detailed decription is
6 ! found in the Module not the file.
7 !
12 !*******************************************************************************
13  MODULE combination
14  USE stel_kinds, only: rprec
15  USE data_parameters
16  USE signal
17 
18 !*******************************************************************************
19 ! combination module parameters
20 !*******************************************************************************
22  INTEGER, PARAMETER :: combination_type_length = 4
23 
25  INTEGER, PARAMETER :: combination_none = -1
27  INTEGER, PARAMETER :: combination_sum = 0
29  INTEGER, PARAMETER :: combination_max = 1
31  INTEGER, PARAMETER :: combination_min = 2
33  INTEGER, PARAMETER :: combination_wavg = 3
34 
35 !-------------------------------------------------------------------------------
39 !-------------------------------------------------------------------------------
40  TYPE, EXTENDS(signal_class) :: combination_class
47  INTEGER :: type = combination_none
49  TYPE (signal_pointer), DIMENSION(:), POINTER :: signals
51  REAL(rprec), DIMENSION(:), POINTER :: a
53  INTEGER :: wgt_index
54  CONTAINS
55  PROCEDURE :: &
56  & set_signal => combination_set_signal
57  PROCEDURE :: &
58  & set_weight => combination_set_weight
59  PROCEDURE :: &
60  & get_modeled_signal_last => combination_get_modeled_signal
61  PROCEDURE :: &
62  & get_type => combination_get_type
63  PROCEDURE :: &
64  & get_header => combination_get_header
65  PROCEDURE :: &
66  & write_auxiliary => combination_write_auxiliary
67  final :: &
69  END TYPE combination_class
70 
71 !*******************************************************************************
72 ! INTERFACE BLOCKS
73 !*******************************************************************************
74 !-------------------------------------------------------------------------------
76 !-------------------------------------------------------------------------------
77  INTERFACE combination_class
78  MODULE PROCEDURE combination_construct
79  END INTERFACE
80 
81  CONTAINS
82 !*******************************************************************************
83 ! CONSTRUCTION SUBROUTINES
84 !*******************************************************************************
85 !-------------------------------------------------------------------------------
99 !-------------------------------------------------------------------------------
100  FUNCTION combination_construct(n_signals, combination_type, &
101  & wgt_index)
102 
103  IMPLICIT NONE
104 
105 ! Declare Arguments
106  TYPE (combination_class), POINTER :: combination_construct
107  INTEGER, INTENT(in) :: n_signals
108  CHARACTER (len=combination_type_length), INTENT(in) :: &
109  & combination_type
110  INTEGER, INTENT(IN) :: wgt_index
111 
112 ! Local Variables
113  REAL (rprec) :: start_time
114 
115 ! Start of executable code
116  start_time = profiler_get_start_time()
117 
118  ALLOCATE(combination_construct)
119 
120  ALLOCATE(combination_construct%signals(n_signals))
121  ALLOCATE(combination_construct%a(n_signals))
122 
123  combination_construct%wgt_index = wgt_index
124 
125  SELECT CASE (combination_type)
126  CASE ('sum')
128 
129  CASE ('max')
131 
132  CASE ('min')
134 
135  CASE ('wavg')
137  IF (n_signals .gt. 2) THEN
138  WRITE (*,1000)
139  END IF
140 
141  END SELECT
142 
143  CALL profiler_set_stop_time('combination_construct', start_time)
144 
145 1000 FORMAT('More than two signals specified for weighted average. &
146  & Only using the first two.')
147 
148  END FUNCTION
149 
150 !*******************************************************************************
151 ! DESTRUCTION SUBROUTINES
152 !*******************************************************************************
153 !-------------------------------------------------------------------------------
161 !-------------------------------------------------------------------------------
162  SUBROUTINE combination_destruct(this)
163 
164  IMPLICIT NONE
165 
166 ! Declare Arguments
167  TYPE (combination_class), INTENT(inout) :: this
168 
169 ! Local Variables
170  INTEGER :: i
171 
172 ! Start of executable code
173 
174 ! Null all pointers in the signals array. Do not deallocate the signals in the
175 ! array since this object is not the owner.
176  IF (ASSOCIATED(this%signals)) THEN
177  DO i = 1, SIZE(this%signals)
178  this%signals(i)%p => null()
179  END DO
180  this%signals => null()
181  END IF
182  IF (ASSOCIATED(this%a)) THEN
183  DEALLOCATE(this%a)
184  this%a => null()
185  END IF
186 
187  this%type = combination_none
188 
189  END SUBROUTINE
190 
191 !*******************************************************************************
192 ! SETTER SUBROUTINES
193 !*******************************************************************************
194 !-------------------------------------------------------------------------------
204 !-------------------------------------------------------------------------------
205  SUBROUTINE combination_set_signal(this, signal, a, index)
206 
207  IMPLICIT NONE
208 
209 ! Declare Arguments
210  class(combination_class), INTENT(inout) :: this
211  class(signal_class), POINTER :: signal
212  INTEGER, INTENT(in) :: index
213  REAL (rprec), INTENT(in) :: a
214 
215 ! local Variables
216  REAL (rprec) :: start_time
217 
218 ! Start of executable code
219  start_time = profiler_get_start_time()
220 
221  this%a(index) = a
222  this%signals(index)%p => signal
223 
224  CALL profiler_set_stop_time('combination_set_signal', start_time)
225 
226  END SUBROUTINE
227 
228 !-------------------------------------------------------------------------------
236 !-------------------------------------------------------------------------------
237  SUBROUTINE combination_set_weight(this, a_model)
238  USE model
239 
240  IMPLICIT NONE
241 
242 ! Declare Arguments
243  class(combination_class), INTENT(inout) :: this
244  TYPE (model_class), INTENT(in) :: a_model
245 
246 ! local Variables
247  REAL (rprec) :: start_time
248 
249  this%a(1) = a_model%coosig_wgts(this%wgt_index)
250  this%a(2) = 1.0 - this%a(1)
251 
252  CALL profiler_set_stop_time('combination_set_signal', start_time)
253 
254  END SUBROUTINE
255 
256 !*******************************************************************************
257 ! GETTER SUBROUTINES
258 !*******************************************************************************
259 !-------------------------------------------------------------------------------
270 !-------------------------------------------------------------------------------
271  FUNCTION combination_get_modeled_signal(this, a_model, sigma, &
272  & last_value)
273  USE model
274 
275  IMPLICIT NONE
276 
277 ! Declare Arguments
278  REAL (rprec), DIMENSION(4) :: combination_get_modeled_signal
279  CLASS (combination_class), INTENT(inout) :: this
280  TYPE (model_class), POINTER :: a_model
281  REAL (rprec), DIMENSION(4), INTENT(out) :: sigma
282  REAL (rprec), DIMENSION(4), INTENT(in) :: last_value
283 
284 ! Local Variables
285  class(signal_class), POINTER :: temp_signal
286  INTEGER :: i
287  REAL (rprec), DIMENSION(4) :: sigma_local
288  REAL (rprec) :: start_time
289 
290 ! Start of executable code
291  start_time = profiler_get_start_time()
292 
293 ! NOTE: Using the syntax, this%signals(i)%p%get_modeled_signal(...) Causes an
294 ! internal compiler error in gfortran. Use the explicit version.
295  temp_signal => this%signals(1)%p
296 
297  combination_get_modeled_signal = this%a(1)* &
298  & temp_signal%get_modeled_signal(a_model, sigma, .true., &
299  & last_value)
300 
301  SELECT CASE(this%type)
302  CASE (combination_sum)
303  DO i = 2, SIZE(this%signals)
304  temp_signal => this%signals(i)%p
307  & temp_signal%get_modeled_signal(a_model, &
308  & sigma_local, &
309  & .true., &
310  & last_value) * &
311  & this%a(i)
312  sigma = sigma + sigma_local
313  END DO
314 
315  CASE (combination_max)
316  DO i = 2, SIZE(this%signals)
317  temp_signal => this%signals(i)%p
320  & temp_signal%get_modeled_signal(a_model, sigma_local, &
321  & .true., last_value) * &
322  & this%a(i))
323  sigma = max(sigma, sigma_local)
324  END DO
325 
326  CASE (combination_min)
327  DO i = 2, SIZE(this%signals)
328  temp_signal => this%signals(i)%p
331  & temp_signal%get_modeled_signal(a_model, sigma_local, &
332  & .true., sigma_local) * &
333  & this%a(i))
334  sigma = min(sigma, sigma_local)
335  END DO
336 
337 ! ECH I assume that the combination wavg is composed of only two signals and
338 ! the there is only 1 coosig wgt. Second do I need to account for the
339 ! uncertainity in the wgt_ids when calculaing the sigma value.
340  CASE (combination_wavg)
341  CALL combination_set_weight(this, a_model)
342  temp_signal => this%signals(2)%p
345  & temp_signal%get_modeled_signal(a_model, sigma_local, &
346  & .true., last_value) * &
347  & this%a(2)
348 
349  sigma = sigma + this%a(2)*sigma_local
350 
351 ! It doesn't always make sense to average the values in model signal 2-4.
353 
354  END SELECT
355 
356  CALL this%scale_and_offset(a_model, &
358 
359  CALL profiler_set_stop_time('combination_get_modeled_signal', &
360  & start_time)
361 
362  END FUNCTION
363 
364 !-------------------------------------------------------------------------------
372 !-------------------------------------------------------------------------------
373  FUNCTION combination_get_type(this)
374 
375  IMPLICIT NONE
376 
377 ! Declare Arguments
378  CHARACTER (len=data_name_length) :: combination_get_type
379  CLASS (combination_class), INTENT(in) :: this
380 
381 ! local variables
382  REAL (rprec) :: start_time
383 
384 ! Start of executable code
385  start_time = profiler_get_start_time()
386 
387  SELECT CASE (this%type)
388  CASE (combination_sum)
389  combination_get_type = 'coosig sum'
390 
391  CASE (combination_max)
392  combination_get_type = 'coosig max'
393 
394  CASE (combination_min)
395  combination_get_type = 'coosig min'
396 
397  CASE (combination_wavg)
398  combination_get_type = 'coosig wavg'
399 
400  END SELECT
401 
402  CALL profiler_set_stop_time('combination_get_type', start_time)
403 
404  END FUNCTION
405 
406 !-------------------------------------------------------------------------------
416 !-------------------------------------------------------------------------------
417  SUBROUTINE combination_get_header(this, header)
418 
419  IMPLICIT NONE
420 
421 ! Declare Arguments
422  class(combination_class), INTENT(in) :: this
423  CHARACTER (len=data_name_length), DIMENSION(7), INTENT(inout) :: &
424  & header
425 
426 ! local variables
427  REAL (rprec) :: start_time
428 
429 ! Start of executable code
430  start_time = profiler_get_start_time()
431 
432  header(1) = 'model(2)'
433  header(2) = 'model(3)'
434  header(3) = 'model(4)'
435  header(4) = 'model_sig(1)'
436  header(5) = 'model_sig(2)'
437  header(6) = 'model_sig(3)'
438  header(7) = 'model_sig(4)'
439 
440  CALL profiler_set_stop_time('combination_get_header', start_time)
441 
442  END SUBROUTINE
443 
444 !*******************************************************************************
445 ! UTILITY SUBROUTINES
446 !*******************************************************************************
447 !-------------------------------------------------------------------------------
456 !-------------------------------------------------------------------------------
457  SUBROUTINE combination_write_auxiliary(this, iou, index, a_model)
458 
459  IMPLICIT NONE
460 
461 ! Declare Arguments
462  class(combination_class), INTENT(in) :: this
463  INTEGER, INTENT(in) :: iou
464  INTEGER, INTENT(in) :: index
465  TYPE (model_class), INTENT(in) :: a_model
466 
467 ! local variables
468  INTEGER :: i
469  REAL (rprec) :: start_time
470 
471 ! Start of executable code
472  start_time = profiler_get_start_time()
473 
474  WRITE (iou,*)
475  WRITE (iou,1000) index, this%get_type()
476  IF (this%type .eq. combination_wavg) THEN
477  WRITE (iou,1001) this%wgt_index
478  END IF
479  WRITE (iou,1002)
480 
481  DO i = 1, SIZE(this%signals)
482  WRITE (iou,1003) i, this%signals(i)%p%s_name, this%a(i)
483  END DO
484 
485  CALL profiler_set_stop_time('combination_write_auxiliary', &
486  & start_time)
487 
488 1000 FORMAT('Signal',1x,i4,1x, &
489  & 'is a combination of other signals, type: ',a)
490 1001 FORMAT('Weighted Average Index: ',i4)
491 1002 FORMAT('term #',2x,'s_name',16x,'Coefficient')
492 1003 FORMAT(2x,i4,2x,a20,2x,es12.5)
493 
494  END SUBROUTINE
495  END MODULE
combination
Defines the base class of the type combination_class.
Definition: combination.f:13
combination::combination_sum
integer, parameter combination_sum
Type descriptor for combination type sum.
Definition: combination.f:27
model
Defines the base class of the type model_class. The model contains information not specific to the eq...
Definition: model.f:59
combination::combination_set_weight
subroutine combination_set_weight(this, a_model)
Sets the weight factors from from the weight index.
Definition: combination.f:238
combination::combination_wavg
integer, parameter combination_wavg
Type descriptor for combination type weighted average.
Definition: combination.f:33
combination::combination_type_length
integer, parameter combination_type_length
Maximum length of the combination type descritpion string.
Definition: combination.f:22
combination::combination_get_header
subroutine combination_get_header(this, header)
Gets a discription of the model and model sigma array indices.
Definition: combination.f:418
combination::combination_write_auxiliary
subroutine combination_write_auxiliary(this, iou, index, a_model)
Write out auxiliary signal information to an output file.
Definition: combination.f:458
combination::combination_max
integer, parameter combination_max
Type descriptor for combination type max.
Definition: combination.f:29
combination::combination_get_type
character(len=data_name_length) function combination_get_type(this)
Gets a discription of the combination type.
Definition: combination.f:374
combination::combination_none
integer, parameter combination_none
Type descriptor for combination type no type.
Definition: combination.f:25
combination::combination_class
Base class representing a combination signal.
Definition: combination.f:40
model::model_class
Base class representing a model.
Definition: model.f:141
combination::combination_get_modeled_signal
real(rprec) function, dimension(4) combination_get_modeled_signal(this, a_model, sigma, last_value)
Calculates the modeled signal.
Definition: combination.f:273
combination::combination_set_signal
subroutine combination_set_signal(this, signal, a, index)
Set the object and coefficient for an index.
Definition: combination.f:206
data_parameters
This modules contains parameters used by equilibrium models.
Definition: data_parameters.f:10
signal::signal_pointer
Pointer to a signal object. Used for creating arrays of signal pointers. This is needed because fortr...
Definition: signal.f:100
combination::combination_min
integer, parameter combination_min
Type descriptor for combination type min.
Definition: combination.f:31
signal::signal_class
Base class representing a signal.
Definition: signal.f:33
combination::combination_destruct
subroutine combination_destruct(this)
Deconstruct a combination_class object.
Definition: combination.f:163
combination::combination_construct
type(combination_class) function, pointer combination_construct(n_signals, combination_type, wgt_index)
Construct a combination_class.
Definition: combination.f:102
signal
Defines the base class of the type signal_class.
Definition: signal.f:14