|
| 1 | +! |
| 2 | +! (c) 2019-2020 Guide Star Engineering, LLC |
| 3 | +! This Software was developed for the US Nuclear Regulatory Commission (US NRC) under contract |
| 4 | +! "Multi-Dimensional Physics Implementation into Fuel Analysis under Steady-state and Transients (FAST)", |
| 5 | +! contract # NRC-HQ-60-17-C-0007 |
| 6 | +! |
| 7 | +submodule(units_interface) units_implementation |
| 8 | + use assertions_interface, only : assertions,assert |
| 9 | + implicit none |
| 10 | + |
| 11 | + contains |
| 12 | + |
| 13 | + module procedure set_units |
| 14 | + !! define units exponents |
| 15 | + this%exponents_ = exponents |
| 16 | + this%system= system |
| 17 | + end procedure |
| 18 | + |
| 19 | + module procedure get_system |
| 20 | + system_of_units = this%system |
| 21 | + end procedure |
| 22 | + |
| 23 | + module procedure get_units |
| 24 | + exponents = this%exponents_ |
| 25 | + end procedure |
| 26 | + |
| 27 | + module procedure assign_units |
| 28 | + lhs%exponents_ = rhs%exponents_ |
| 29 | + lhs%system = rhs%system |
| 30 | + end procedure |
| 31 | + |
| 32 | + module procedure is_dimensionless |
| 33 | + nondimensional = all([this%exponents_==0]) .and. this%system==dimensionless |
| 34 | + end procedure |
| 35 | + |
| 36 | + module procedure has_length_units |
| 37 | + length_units = this%exponents_(m)==1 .and. all(this%exponents_([kg,sec,K])==0) |
| 38 | + end procedure |
| 39 | + |
| 40 | + module procedure has_mass_units |
| 41 | + mass_units = this%exponents_(kg)==1 .and. all(this%exponents_([m,sec,K])==0) |
| 42 | + end procedure |
| 43 | + |
| 44 | + module procedure has_time_units |
| 45 | + time_units = this%exponents_(sec)==1 .and. all(this%exponents_([m,kg,K])==0) |
| 46 | + end procedure |
| 47 | + |
| 48 | + module procedure has_temperature_units |
| 49 | + temperature_units = this%exponents_(K)==1 .and. all(this%exponents_([m,kg,sec])==0) |
| 50 | + end procedure |
| 51 | + |
| 52 | + module procedure has_velocity_units |
| 53 | + velocity_units = all(this%exponents_([m,sec])==[1,-1]) .and. all(this%exponents_([kg,K])==0) |
| 54 | + end procedure |
| 55 | + |
| 56 | + module procedure has_energy_units |
| 57 | + energy_units = all(this%exponents_([kg,m,sec])==[1,2,-2]) .and. this%exponents_(K)==0 |
| 58 | + end procedure |
| 59 | + |
| 60 | + module procedure has_density_units |
| 61 | + density_units = all(this%exponents_([kg,m])==[1,-3]) .and. all(this%exponents_([sec,K])==0) |
| 62 | + end procedure |
| 63 | + |
| 64 | + module procedure has_specific_energy_units |
| 65 | + specific_energy_units = all(this%exponents_([m,sec])==[2,-2]) .and. all(this%exponents_([kg,K])==0) |
| 66 | + end procedure |
| 67 | + |
| 68 | + module procedure has_stress_units |
| 69 | + stress_units = all(this%exponents_([kg,m,sec])==[1,-1,-2]) .and. this%exponents_(K)==0 |
| 70 | + end procedure |
| 71 | + |
| 72 | + module procedure has_power_units |
| 73 | + power_units = all(this%exponents_([kg,m,sec])==[1,2,-3]) .and. this%exponents_(K)==0 |
| 74 | + end procedure |
| 75 | + |
| 76 | + module procedure integer_power |
| 77 | + this_raised%system = this%system |
| 78 | + this_raised%exponents_ = exponent_*this%exponents_ |
| 79 | + end procedure |
| 80 | + |
| 81 | + module procedure real_power |
| 82 | + if (assertions) call assert(this%is_dimensionless(), & |
| 83 | + & "units%real_power: an entity raised to a real power must be dimensionless") |
| 84 | + !! Require dimensionless operand => result is default-initialized as dimensionless |
| 85 | + end procedure |
| 86 | + |
| 87 | + module procedure negate |
| 88 | + negative_this%exponents_ = this%exponents_ |
| 89 | + negative_this%system= this%system |
| 90 | + end procedure |
| 91 | + |
| 92 | + module procedure add |
| 93 | + if (assertions) then |
| 94 | + !! Require consistent operand units |
| 95 | + associate(preconditions => [lhs%system==rhs%system, lhs%exponents_==rhs%exponents_] ) |
| 96 | + call assert( all(preconditions), "units%add: consistent operands units") |
| 97 | + end associate |
| 98 | + end if |
| 99 | + total%exponents_ = lhs%exponents_ |
| 100 | + total%system = lhs%system |
| 101 | + end procedure |
| 102 | + |
| 103 | + module procedure subtract |
| 104 | + if (assertions) then |
| 105 | + !! Require consistent operand units |
| 106 | + associate(preconditions => [lhs%system==rhs%system, lhs%exponents_==rhs%exponents_] ) |
| 107 | + call assert( all(preconditions), "units%subtract: consistent operand units") |
| 108 | + end associate |
| 109 | + end if |
| 110 | + difference%exponents_ = lhs%exponents_ |
| 111 | + difference%system = lhs%system |
| 112 | + end procedure |
| 113 | + |
| 114 | + module procedure multiply |
| 115 | + |
| 116 | + if (assertions) call assert( lhs%system==rhs%system, "units%multiply: consistent operand units" ) |
| 117 | + |
| 118 | + product_%exponents_ = lhs%exponents_ + rhs%exponents_ |
| 119 | + product_%system = lhs%system |
| 120 | + end procedure |
| 121 | + |
| 122 | + module procedure divide |
| 123 | + |
| 124 | + if (assertions) call assert( numerator%system==denominator%system, "units%divide: consistent operand units" ) |
| 125 | + |
| 126 | + ratio%exponents_ = numerator%exponents_ - denominator%exponents_ |
| 127 | + ratio%system = merge(numerator%system,dimensionless,any(ratio%exponents_/=0)) |
| 128 | + end procedure |
| 129 | + |
| 130 | +end submodule units_implementation |
0 commit comments