1 package org.djunits.quantity;
2
3 import org.djunits.quantity.def.Quantity;
4 import org.djunits.unit.AbstractUnit;
5 import org.djunits.unit.UnitRuntimeException;
6 import org.djunits.unit.Unitless;
7 import org.djunits.unit.scale.LinearScale;
8 import org.djunits.unit.scale.Scale;
9 import org.djunits.unit.si.SIUnit;
10 import org.djunits.unit.system.UnitSystem;
11
12 /**
13 * Absorbed dose is the energy deposited by ionizing radiation per unit mass, measured in grays (Gy).
14 * <p>
15 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
16 * for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
17 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
18 * @author Alexander Verbraeck
19 */
20 public class AbsorbedDose extends Quantity<AbsorbedDose>
21 {
22 /** Constant with value zero. */
23 public static final AbsorbedDose ZERO = ofSi(0.0);
24
25 /** Constant with value one. */
26 public static final AbsorbedDose ONE = ofSi(1.0);
27
28 /** Constant with value NaN. */
29 @SuppressWarnings("checkstyle:constantname")
30 public static final AbsorbedDose NaN = ofSi(Double.NaN);
31
32 /** Constant with value POSITIVE_INFINITY. */
33 public static final AbsorbedDose POSITIVE_INFINITY = ofSi(Double.POSITIVE_INFINITY);
34
35 /** Constant with value NEGATIVE_INFINITY. */
36 public static final AbsorbedDose NEGATIVE_INFINITY = ofSi(Double.NEGATIVE_INFINITY);
37
38 /** Constant with value MAX_VALUE. */
39 public static final AbsorbedDose POS_MAXVALUE = ofSi(Double.MAX_VALUE);
40
41 /** Constant with value -MAX_VALUE. */
42 public static final AbsorbedDose NEG_MAXVALUE = ofSi(-Double.MAX_VALUE);
43
44 /** */
45 private static final long serialVersionUID = 600L;
46
47 /**
48 * Instantiate a AbsorbedDose quantity with a unit.
49 * @param valueInUnit the value, expressed in the unit
50 * @param unit the unit in which the value is expressed
51 */
52 public AbsorbedDose(final double valueInUnit, final AbsorbedDose.Unit unit)
53 {
54 super(valueInUnit, unit);
55 }
56
57 /**
58 * Return a AbsorbedDose instance based on an SI value.
59 * @param si the si value
60 * @return the AbsorbedDose instance based on an SI value
61 */
62 public static AbsorbedDose ofSi(final double si)
63 {
64 return new AbsorbedDose(si, AbsorbedDose.Unit.SI);
65 }
66
67 @Override
68 public AbsorbedDose instantiateSi(final double si)
69 {
70 return ofSi(si);
71 }
72
73 @Override
74 public SIUnit siUnit()
75 {
76 return AbsorbedDose.Unit.SI_UNIT;
77 }
78
79 /**
80 * Returns a AbsorbedDose representation of a textual representation of a value with a unit. The String representation that
81 * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
82 * allowed, but not required, between the value and the unit.
83 * @param text the textual representation to parse into a AbsorbedDose
84 * @return the Scalar representation of the value in its unit
85 * @throws IllegalArgumentException when the text cannot be parsed
86 * @throws NullPointerException when the text argument is null
87 */
88 public static AbsorbedDose valueOf(final String text)
89 {
90 return Quantity.valueOf(text, ZERO);
91 }
92
93 /**
94 * Returns a AbsorbedDose based on a value and the textual representation of the unit, which can be localized.
95 * @param valueInUnit the value, expressed in the unit as given by unitString
96 * @param unitString the textual representation of the unit
97 * @return the Scalar representation of the value in its unit
98 * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
99 * @throws NullPointerException when the unitString argument is null
100 */
101 public static AbsorbedDose of(final double valueInUnit, final String unitString)
102 {
103 return Quantity.of(valueInUnit, unitString, ZERO);
104 }
105
106 @Override
107 public AbsorbedDose.Unit getDisplayUnit()
108 {
109 return (AbsorbedDose.Unit) super.getDisplayUnit();
110 }
111
112 /**
113 * Calculate the division of AbsorbedDose and AbsorbedDose, which results in a Dimensionless quantity.
114 * @param v quantity
115 * @return quantity as a division of AbsorbedDose and AbsorbedDose
116 */
117 public final Dimensionless divide(final AbsorbedDose v)
118 {
119 return new Dimensionless(this.si() / v.si(), Unitless.BASE);
120 }
121
122 /******************************************************************************************************/
123 /********************************************** UNIT CLASS ********************************************/
124 /******************************************************************************************************/
125
126 /**
127 * AbsorbedDose.Unit encodes the units of absorbed dose (of ionizing radiation).
128 * <p>
129 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.
130 * See for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
131 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
132 * @author Alexander Verbraeck
133 */
134 @SuppressWarnings("checkstyle:constantname")
135 public static class Unit extends AbstractUnit<AbsorbedDose.Unit, AbsorbedDose>
136 {
137 /** The dimensions of the absorbed dose: m2/s2. */
138 public static final SIUnit SI_UNIT = SIUnit.of("m2/s2");
139
140 /** Gray. */
141 public static final AbsorbedDose.Unit Gy = new AbsorbedDose.Unit("Gy", "gray", 1.0, UnitSystem.SI_DERIVED);
142
143 /** The SI or BASE unit. */
144 public static final AbsorbedDose.Unit SI = Gy;
145
146 /** mGy. */
147 public static final AbsorbedDose.Unit mGy =
148 new AbsorbedDose.Unit("mGy", "milligray", 1.0E-3, UnitSystem.SI_DERIVED).setSiPrefix("m");
149
150 /** µGy. */
151 public static final AbsorbedDose.Unit muGy =
152 new AbsorbedDose.Unit("muGy", "\u03BCGy", "microgray", new LinearScale(1.0E-6), UnitSystem.SI_DERIVED)
153 .setSiPrefix("mu");
154
155 /** erg/g. */
156 public static final AbsorbedDose.Unit erg_g = new AbsorbedDose.Unit("erg/g", "erg per gram", 1.0E-4, UnitSystem.CGS);
157
158 /** rad. */
159 public static final AbsorbedDose.Unit rad = new AbsorbedDose.Unit("rad", "rad", 1.0E-2, UnitSystem.CGS);
160
161 /**
162 * Create a new AbsorbedDose unit.
163 * @param id the id or main abbreviation of the unit
164 * @param name the full name of the unit
165 * @param scaleFactorToBaseUnit the scale factor of the unit to convert it TO the base (SI) unit
166 * @param unitSystem the unit system such as SI or IMPERIAL
167 */
168 public Unit(final String id, final String name, final double scaleFactorToBaseUnit, final UnitSystem unitSystem)
169 {
170 super(id, name, new LinearScale(scaleFactorToBaseUnit), unitSystem);
171 }
172
173 /**
174 * Return a derived unit for this unit, with textual abbreviation(s) and a display abbreviation.
175 * @param textualAbbreviation the textual abbreviation of the unit, which doubles as the id
176 * @param displayAbbreviation the display abbreviation of the unit
177 * @param name the full name of the unit
178 * @param scale the scale to use to convert between this unit and the standard (e.g., SI, BASE) unit
179 * @param unitSystem unit system, e.g. SI or Imperial
180 */
181 public Unit(final String textualAbbreviation, final String displayAbbreviation, final String name, final Scale scale,
182 final UnitSystem unitSystem)
183 {
184 super(textualAbbreviation, displayAbbreviation, name, scale, unitSystem);
185 }
186
187 @Override
188 public SIUnit siUnit()
189 {
190 return SI_UNIT;
191 }
192
193 @Override
194 public Unit getBaseUnit()
195 {
196 return SI;
197 }
198
199 @Override
200 public AbsorbedDose ofSi(final double si)
201 {
202 return AbsorbedDose.ofSi(si);
203 }
204
205 @Override
206 public Unit deriveUnit(final String textualAbbreviation, final String displayAbbreviation, final String name,
207 final double scaleFactor, final UnitSystem unitSystem)
208 {
209 if (getScale() instanceof LinearScale ls)
210 {
211 return new AbsorbedDose.Unit(textualAbbreviation, displayAbbreviation, name,
212 new LinearScale(ls.getScaleFactorToBaseUnit() * scaleFactor), unitSystem);
213 }
214 throw new UnitRuntimeException("Only possible to derive a unit from a unit with a linear scale");
215 }
216
217 }
218 }