AttitudePhysicalPropertiesWriter.java

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

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

  18. import java.io.IOException;

  19. import org.hipparchus.linear.RealMatrix;
  20. import org.orekit.files.ccsds.definitions.Units;
  21. import org.orekit.files.ccsds.section.AbstractWriter;
  22. import org.orekit.files.ccsds.utils.generation.Generator;
  23. import org.orekit.utils.units.Unit;

  24. /** Writer for physical properties data.
  25.  * @author Luc Maisonobe
  26.  * @since 12.0
  27.  */
  28. class AttitudePhysicalPropertiesWriter extends AbstractWriter {

  29.     /** Physical properties block. */
  30.     private final AttitudePhysicalProperties phys;

  31.     /** Create a writer.
  32.      * @param phys physical properties to write
  33.      */
  34.     AttitudePhysicalPropertiesWriter(final AttitudePhysicalProperties phys) {
  35.         super(AcmDataSubStructureKey.phys.name(), AcmDataSubStructureKey.PHYS.name());
  36.         this.phys = phys;
  37.     }

  38.     /** {@inheritDoc} */
  39.     @Override
  40.     protected void writeContent(final Generator generator) throws IOException {

  41.         // physical properties block
  42.         generator.writeComments(phys.getComments());

  43.         // drag
  44.         generator.writeEntry(AttitudePhysicalPropertiesKey.DRAG_COEFF.name(), phys.getDragCoefficient(), Unit.ONE,     false);

  45.         // mass
  46.         generator.writeEntry(AttitudePhysicalPropertiesKey.WET_MASS.name(),   phys.getWetMass(), Unit.KILOGRAM,        false);
  47.         generator.writeEntry(AttitudePhysicalPropertiesKey.DRY_MASS.name(),   phys.getDryMass(), Unit.KILOGRAM,        false);

  48.         // center of pressure
  49.         if (phys.getCenterOfPressureReferenceFrame() != null) {
  50.             generator.writeEntry(AttitudePhysicalPropertiesKey.CP_REF_FRAME.name(), phys.getCenterOfPressureReferenceFrame().getName(), null, false);
  51.         }
  52.         if (phys.getCenterOfPressure() != null) {
  53.             final StringBuilder cp = new StringBuilder();
  54.             cp.append(generator.doubleToString(Unit.METRE.fromSI(phys.getCenterOfPressure().getX())));
  55.             cp.append(' ');
  56.             cp.append(generator.doubleToString(Unit.METRE.fromSI(phys.getCenterOfPressure().getY())));
  57.             cp.append(' ');
  58.             cp.append(generator.doubleToString(Unit.METRE.fromSI(phys.getCenterOfPressure().getZ())));
  59.             generator.writeEntry(AttitudePhysicalPropertiesKey.CP.name(), cp.toString(), Unit.METRE, false);
  60.         }

  61.         // inertia
  62.         if (phys.getInertiaReferenceFrame() != null) {
  63.             generator.writeEntry(AttitudePhysicalPropertiesKey.INERTIA_REF_FRAME.name(), phys.getInertiaReferenceFrame().getName(), null, false);
  64.         }
  65.         final RealMatrix inertia = phys.getInertiaMatrix();
  66.         if (inertia != null) {
  67.             generator.writeEntry(AttitudePhysicalPropertiesKey.IXX.name(), inertia.getEntry(0, 0), Units.KG_M2, true);
  68.             generator.writeEntry(AttitudePhysicalPropertiesKey.IYY.name(), inertia.getEntry(1, 1), Units.KG_M2, true);
  69.             generator.writeEntry(AttitudePhysicalPropertiesKey.IZZ.name(), inertia.getEntry(2, 2), Units.KG_M2, true);
  70.             generator.writeEntry(AttitudePhysicalPropertiesKey.IXY.name(), inertia.getEntry(0, 1), Units.KG_M2, true);
  71.             generator.writeEntry(AttitudePhysicalPropertiesKey.IXZ.name(), inertia.getEntry(0, 2), Units.KG_M2, true);
  72.             generator.writeEntry(AttitudePhysicalPropertiesKey.IYZ.name(), inertia.getEntry(1, 2), Units.KG_M2, true);
  73.         }

  74.     }

  75. }