|
| 1 | +!< Abstract base object, the ancestor of all. |
| 2 | +module wenoof_base_object |
| 3 | +!< Abstract base object, the ancestor of all. |
| 4 | +!< |
| 5 | +!< Define a minimal, base, object that is used as ancestor of all objects, e.g. smoothness indicator, optimal weights, etc... |
| 6 | + |
| 7 | +use penf |
| 8 | + |
| 9 | +implicit none |
| 10 | +private |
| 11 | +public :: base_object |
| 12 | +public :: base_object_constructor |
| 13 | + |
| 14 | +real(R_P), parameter :: EPS_DEF=10._R_P**(-6) !< Small epsilon to avoid division by zero, default value. |
| 15 | + |
| 16 | +type :: base_object_constructor |
| 17 | + !< Abstract base object constructor. |
| 18 | + integer(I_P) :: S=0_I_P !< Stencils dimension. |
| 19 | + logical :: face_left=.true. !< Activate left-face interpolation computation. |
| 20 | + logical :: face_right=.true. !< Activate right-face interpolation computation. |
| 21 | + real(R_P) :: eps=EPS_DEF !< Small epsilon to avoid division by zero. |
| 22 | +endtype base_object_constructor |
| 23 | + |
| 24 | +type, abstract :: base_object |
| 25 | + !< Abstract base object, the ancestor of all. |
| 26 | + !< |
| 27 | + !< Define a minimal, base, object that is used as ancestor of all objects, e.g. smoothness indicator, optimal weights, etc... |
| 28 | + integer(I_P) :: S=0_I_P !< Stencils dimension. |
| 29 | + integer(I_P) :: f1=1_I_P !< Lower bound of faces index. |
| 30 | + integer(I_P) :: f2=2_I_P !< Upper bound of faces index. |
| 31 | + integer(I_P) :: ff=0_I_P !< Offset (step) of faces index. |
| 32 | + real(R_P) :: eps=EPS_DEF !< Small epsilon to avoid division by zero. |
| 33 | + contains |
| 34 | + ! public deferred methods |
| 35 | + procedure(create_interface), pass(self), deferred :: create !< Create object. |
| 36 | + procedure(description_interface), pass(self), deferred :: description !< Return object string-description. |
| 37 | + procedure(destroy_interface), pass(self), deferred :: destroy !< Destroy object. |
| 38 | + ! public non overridable methods |
| 39 | + procedure, pass(self), non_overridable :: create_ !< Create object. |
| 40 | + procedure, pass(self), non_overridable :: destroy_ !< Destroy object. |
| 41 | +endtype base_object |
| 42 | + |
| 43 | +abstract interface |
| 44 | + !< Abstract interfaces of [[base_object]]. |
| 45 | + subroutine create_interface(self, constructor) |
| 46 | + !< Create object. |
| 47 | + !< |
| 48 | + !< @note Before call this method a concrete constructor must be instantiated. |
| 49 | + import :: base_object, base_object_constructor |
| 50 | + class(base_object), intent(inout) :: self !< Object. |
| 51 | + class(base_object_constructor), intent(in) :: constructor !< Object constructor. |
| 52 | + endsubroutine create_interface |
| 53 | + |
| 54 | + pure function description_interface(self) result(string) |
| 55 | + !< Return object string-description. |
| 56 | + import :: base_object |
| 57 | + class(base_object), intent(in) :: self !< Object. |
| 58 | + character(len=:), allocatable :: string !< String-description. |
| 59 | + endfunction description_interface |
| 60 | + |
| 61 | + elemental subroutine destroy_interface(self) |
| 62 | + !< Destroy object. |
| 63 | + import :: base_object |
| 64 | + class(base_object), intent(inout) :: self !< Object. |
| 65 | + endsubroutine destroy_interface |
| 66 | +endinterface |
| 67 | + |
| 68 | +contains |
| 69 | + ! public non overridable methods |
| 70 | + subroutine create_(self, constructor) |
| 71 | + !< Create object. |
| 72 | + class(base_object), intent(inout) :: self !< Object. |
| 73 | + class(base_object_constructor), intent(in) :: constructor !< Object constructor. |
| 74 | + |
| 75 | + call self%destroy_ |
| 76 | + select type(constructor) |
| 77 | + class is(base_object_constructor) |
| 78 | + self%S = constructor%S |
| 79 | + if (constructor%face_left.and.constructor%face_right) then |
| 80 | + self%f1 = 1_I_P; self%f2 = 2_I_P; self%ff = 0_I_P |
| 81 | + elseif (constructor%face_left) then |
| 82 | + self%f1 = 1_I_P; self%f2 = 1_I_P; self%ff = 0_I_P |
| 83 | + elseif (constructor%face_right) then |
| 84 | + self%f1 = 2_I_P; self%f2 = 2_I_P; self%ff = -1_I_P |
| 85 | + endif |
| 86 | + self%eps = constructor%eps |
| 87 | + endselect |
| 88 | + endsubroutine create_ |
| 89 | + |
| 90 | + elemental subroutine destroy_(self) |
| 91 | + !< Destroy object. |
| 92 | + class(base_object), intent(inout) :: self !< Object. |
| 93 | + |
| 94 | + self%S = 0_I_P |
| 95 | + self%f1 = 1_I_P |
| 96 | + self%f2 = 2_I_P |
| 97 | + self%ff = 0_I_P |
| 98 | + self%eps = EPS_DEF |
| 99 | + endsubroutine destroy_ |
| 100 | +endmodule wenoof_base_object |
0 commit comments