AttitudePhysicalProperties.java

/* Copyright 2022-2026 Luc Maisonobe
 * Licensed to CS GROUP (CS) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * CS licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.orekit.files.ccsds.ndm.adm.acm;

import java.util.Optional;

import org.hipparchus.geometry.euclidean.threed.Vector3D;
import org.hipparchus.linear.MatrixUtils;
import org.hipparchus.linear.RealMatrix;
import org.orekit.annotation.Nullable;
import org.orekit.files.ccsds.definitions.FrameFacade;
import org.orekit.files.ccsds.section.CommentsContainer;

/** Spacecraft physical properties.
 * <p>
 * Beware that the Orekit getters and setters all rely on SI units. The parsers
 * and writers take care of converting these SI units into CCSDS mandatory units.
 * The {@link org.orekit.utils.units.Unit Unit} class provides useful
 * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
 * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
 * already use CCSDS units instead of the API SI units. The general-purpose
 * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
 * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
 * (with an 's') also provide some predefined units. These predefined units and the
 * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
 * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
 * what the parsers and writers use for the conversions.
 * </p>
 * @author Luc Maisonobe
 * @since 12.0
 */
public class AttitudePhysicalProperties extends CommentsContainer {

    /** Drag coefficient. */
    @Nullable
    private Double dragCoefficient;

    /** Total mass at T₀. */
    @Nullable
    private Double wetMass;

    /** Mass without propellant. */
    @Nullable
    private Double dryMass;

    /** Reference frame for center of pressure. */
    @Nullable
    private FrameFacade centerOfPressureReferenceFrame;

    /** Location of center of pressure. */
    @Nullable
    private Vector3D centerOfPressure;

    /** Reference frame for inertia. */
    @Nullable
    private FrameFacade inertiaReferenceFrame;

    /** Inertia matrix. */
    @Nullable
    private RealMatrix inertiaMatrix;

    /**
     * Simple constructor.
     */
    public AttitudePhysicalProperties() {
    }

    /** {@inheritDoc} */
    @Override
    public void validate(final double version) {
        super.validate(version);
        if (centerOfPressureReferenceFrame != null) {
            checkNotNull(centerOfPressure, AttitudePhysicalPropertiesKey.CP.name());
        }
    }

    /** Get the drag coefficient.
     * @return the drag coefficient
     */
    public Optional<Double> getDragCoefficient() {
        return Optional.ofNullable(dragCoefficient);
    }

    /** Set the the drag coefficient.
     * @param dragCoefficient the drag coefficient
     */
    public void setDragCoefficient(final double dragCoefficient) {
        refuseFurtherComments();
        this.dragCoefficient = dragCoefficient;
    }

    /** Get the total mass at T₀.
     * @return total mass at T₀
     */
    public Optional<Double> getWetMass() {
        return Optional.ofNullable(wetMass);
    }

    /** Set the total mass at T₀.
     * @param wetMass total mass at T₀
     */
    public void setWetMass(final double wetMass) {
        refuseFurtherComments();
        this.wetMass = wetMass;
    }

    /** Get the mass without propellant.
     * @return mass without propellant
     */
    public Optional<Double> getDryMass() {
        return Optional.ofNullable(dryMass);
    }

    /** Set the mass without propellant.
     * @param dryMass mass without propellant
     */
    public void setDryMass(final double dryMass) {
        refuseFurtherComments();
        this.dryMass = dryMass;
    }

    /** Get reference frame for center of pressure.
     * @return reference frame for center of pressure
     */
    public Optional<FrameFacade> getCenterOfPressureReferenceFrame() {
        return Optional.ofNullable(centerOfPressureReferenceFrame);
    }

    /** Set reference frame for center of pressure.
     * @param centerOfPressureReferenceFrame reference frame for center of pressure
     */
    public void setCenterOfPressureReferenceFrame(final FrameFacade centerOfPressureReferenceFrame) {
        this.centerOfPressureReferenceFrame = centerOfPressureReferenceFrame;
    }

    /** Get the location of center of pressure.
     * @return location of center of pressure
     */
    public Optional<Vector3D> getCenterOfPressure() {
        return Optional.ofNullable(centerOfPressure);
    }

    /** Set the location of center of pressure.
     * @param centerOfPressure location of center of pressure
     */
    public void setCenterOfPressure(final Vector3D centerOfPressure) {
        this.centerOfPressure = centerOfPressure;
    }

    /** Get reference frame for inertia.
     * @return reference frame for inertia
     */
    public Optional<FrameFacade> getInertiaReferenceFrame() {
        return Optional.ofNullable(inertiaReferenceFrame);
    }

    /** Set reference frame for inertia.
     * @param inertiaReferenceFrame reference frame for inertia
     */
    public void setInertiaReferenceFrame(final FrameFacade inertiaReferenceFrame) {
        this.inertiaReferenceFrame = inertiaReferenceFrame;
    }

    /** Get the inertia matrix.
     * @return the inertia matrix
     */
    public Optional<RealMatrix> getInertiaMatrix() {
        return Optional.ofNullable(inertiaMatrix);
    }

    /** Set an entry in the inertia matrix.
     * <p>
     * Both I(j, k) and I(k, j) are set.
     * </p>
     * @param j row index (must be between 0 and 3 (inclusive)
     * @param k column index (must be between 0 and 3 (inclusive)
     * @param entry value of the matrix entry
     */
    public void setInertiaMatrixEntry(final int j, final int k, final double entry) {
        refuseFurtherComments();
        if (inertiaMatrix == null) {
            inertiaMatrix = MatrixUtils.createRealMatrix(3, 3);
        }
        inertiaMatrix.setEntry(j, k, entry);
        inertiaMatrix.setEntry(k, j, entry);
    }

}