diff --git a/configure.ac b/configure.ac index d80a2ff4..6a3c034d 100644 --- a/configure.ac +++ b/configure.ac @@ -145,7 +145,6 @@ AC_CONFIG_FILES([Makefile modulesrc/include/Makefile modulesrc/geocoords/Makefile modulesrc/spatialdb/Makefile - modulesrc/units/Makefile modulesrc/utils/Makefile spatialdata/Makefile tests/Makefile @@ -160,7 +159,6 @@ AC_CONFIG_FILES([Makefile tests/pytests/geocoords/Makefile tests/pytests/spatialdb/Makefile tests/pytests/spatialdb/data/Makefile - tests/pytests/units/Makefile tests/pytests/utils/Makefile templates/Makefile docs/Makefile]) diff --git a/docs/Makefile.am b/docs/Makefile.am index 253db72e..375fe53d 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -44,10 +44,10 @@ dist_noinst_DATA = \ user/components/geocoords/index.md \ user/components/geocoords/CSCart.md \ user/components/geocoords/CoordSys.md \ - user/components/units/NondimElasticQuasistatic.md \ + user/components/units/QuasistaticElasticity.md \ user/components/units/index.md \ - user/components/units/NondimElasticDynamic.md \ - user/components/units/Nondimensional.md \ + user/components/units/DynamicElasticity.md \ + user/components/units/Scales.md \ user/components/spatialdb/SimpleGridDB.md \ user/components/spatialdb/CompositeDB.md \ user/components/spatialdb/SimpleDB.md \ @@ -65,7 +65,6 @@ dist_noinst_DATA = \ user/components/spatialdb/SCECCVMH.md \ user/components/spatialdb/UniformDB.md \ user/components/spatialdb/SimpleIOAscii.md \ - user/nondimensionalization.md \ user/spatialdb/simplegriddb.md \ user/spatialdb/overview.md \ user/spatialdb/compositedb.md \ diff --git a/docs/user/components/implementations.md b/docs/user/components/implementations.md index 8cf7a39c..84b39e57 100644 --- a/docs/user/components/implementations.md +++ b/docs/user/components/implementations.md @@ -39,10 +39,3 @@ [`TimeHistory`](spatialdb/TimeHistory.md) : User-specified time history using a file. -## Nondimensionalization - -[`NondimElasticQuasistatic`](units/NondimElasticQuasistatic.md) -: Nondimensional length scales in terms of quasistatic parameters. - -[`NondimElasticDynamic`](units/NondimElasticDynamic.md) -: Nondimensional length scales in terms of dynamic parameters. diff --git a/docs/user/components/units/NondimElasticDynamic.md b/docs/user/components/units/DynamicElasticity.md similarity index 78% rename from docs/user/components/units/NondimElasticDynamic.md rename to docs/user/components/units/DynamicElasticity.md index 5539cfbd..0d92bbaa 100644 --- a/docs/user/components/units/NondimElasticDynamic.md +++ b/docs/user/components/units/DynamicElasticity.md @@ -1,12 +1,12 @@ -# NondimElasticDynamic +# DynamicElasticity % WARNING: Do not edit; this is a generated file! -:Full name: `spatialdata.units.NondimElasticDynamic` -:Journal name: `nondimelasticdynamic` +:Full name: `spatialdata.units.DynamicElasticity` +:Journal name: `DynamicElasticity` Convenience object for nondimensionalizing dynamic elasticity problems. -Implements `Nondimensional`. +Implements `Scales`. ## Pyre Properties @@ -25,7 +25,7 @@ Implements `Nondimensional`. ## Example -Example of setting `NondimElasticDynamic` Pyre properties and facilities in a parameter file. +Example of setting `DynamicElasticity` Pyre properties and facilities in a parameter file. :::{code-block} cfg [normalizer] diff --git a/docs/user/components/units/NondimElasticQuasistatic.md b/docs/user/components/units/QuasistaticElasticity.md similarity index 78% rename from docs/user/components/units/NondimElasticQuasistatic.md rename to docs/user/components/units/QuasistaticElasticity.md index 918139d4..572fc595 100644 --- a/docs/user/components/units/NondimElasticQuasistatic.md +++ b/docs/user/components/units/QuasistaticElasticity.md @@ -1,12 +1,12 @@ -# NondimElasticQuasistatic +# QuasistaticElasticity % WARNING: Do not edit; this is a generated file! -:Full name: `spatialdata.units.NondimElasticQuasistatic` -:Journal name: `nondimelasticquasistatic` +:Full name: `spatialdata.units.QuasistaticElasticity` +:Journal name: `QuasistaticElasticity` Convenience object for nondimensionalizing quasi-static elasticity problems. -Implements `Nondimensional`. +Implements `Scales`. ## Pyre Properties @@ -25,7 +25,7 @@ Implements `Nondimensional`. ## Example -Example of setting `NondimElasticQuasistatic` Pyre properties and facilities in a parameter file. +Example of setting `QuasistaticElasticity` Pyre properties and facilities in a parameter file. :::{code-block} cfg [normalizer] diff --git a/docs/user/components/units/Nondimensional.md b/docs/user/components/units/Scales.md similarity index 52% rename from docs/user/components/units/Nondimensional.md rename to docs/user/components/units/Scales.md index 95b4373a..f32388a5 100644 --- a/docs/user/components/units/Nondimensional.md +++ b/docs/user/components/units/Scales.md @@ -1,8 +1,8 @@ -# Nondimensional +# Scales % WARNING: Do not edit; this is a generated file! -:Full name: `spatialdata.units.Nondimensional` -:Journal name: `nondimensional` +:Full name: `spatialdata.units.Scales` +:Journal name: `Scales` Abstract base class for nondimensionalizing problems. diff --git a/docs/user/components/units/index.md b/docs/user/components/units/index.md index 5811fdc0..3b1a1773 100644 --- a/docs/user/components/units/index.md +++ b/docs/user/components/units/index.md @@ -6,7 +6,7 @@ --- maxdepth: 1 --- -NondimElasticDynamic.md -NondimElasticQuasistatic.md -Nondimensional.md +DynamicElasticity.md +QuasistaticElasticity.md +Scales.md ::: diff --git a/docs/user/index.md b/docs/user/index.md index dc2f0464..05c09c5e 100644 --- a/docs/user/index.md +++ b/docs/user/index.md @@ -1,7 +1,6 @@ # User Guide :::{toctree} -nondimensionalization.md coordsys.md spatialdb/index.md timedb/index.md diff --git a/docs/user/nondimensionalization.md b/docs/user/nondimensionalization.md deleted file mode 100644 index 1dac4ad1..00000000 --- a/docs/user/nondimensionalization.md +++ /dev/null @@ -1,65 +0,0 @@ -# Nondimensionalization - -Nondimensionalization allows solving a system equations across a vast range of scales. -We primary use SpatialData for elasticity boundary value problems, so we define length, prssure, time, density, and temperature scales. - -## Nondimensional - -The `Nondimensional` object sets scales used to nondimensionalize values. -The density scale is not independent of the length, pressure, and time scales. -In most cases it is computed from those scales. -For wave propagation boundary values problems it is more convenient to specify the velocity, time, and density scales, and compute the length and pressure scales. - -In the following discussion, we will use $S_\mathit{scale}$ to denote the scale, where scale can be length, pressure, time, density, or temperature. -\begin{gather} -S_\mathit{density} = \frac{S_\mathit{pressure} S_\mathit{time}^2}{S_\mathit{length}^2} \\ -S_\mathit{pressure} = \frac{S_\mathit{density} S_\mathit{length}^2}{S_\mathit{time}^2} -\end{gather} - -:::{tip} -The default nondimensionalization is reasonable for many problems; however, it may be necessary to change the default values in some cases. -When doing so, keep in mind that the nondimensionalization generally applies to the minimum values -encountered for a problem. -For example, in a quasistatic elaticity boundary value problem, the `length_scale` should be on the order of the minimum cell size. -Similarly, the `relaxation_time` should be on the order of the minimum relaxation time or time scale associated with time-dependent boundary and interface conditions. -::: - -## NondimensionalQuasistatic - -`NondimensionalQuasistatic` provides convenient scales for nondimensionalizing quasistatic elasticity boundary values problems. -The scales are specified in terms of the length scale of deformation, shear modulus, and relaxation time. - -:::{note} -The density scale will be very large in quasistatic problems, consistent with inertia not being important. -::: - -```{table} Nondimensional scales for quasistatic elasticity boundary value problems. -:name: tab:nondimensional:quasistatic:scales -| Scale | Name | Default Value | -| :---: | :--: | :-----------: | -| length | length_scale | 1.0 km | -| pressure | shear_modulus | 30 GPa | -| time | relaxation_time | 100 years | -``` - -:::{admonition} Pyre User Interface -See [NondimElasticQuasistatic component](components/units/NondimElasticQuasistatic.md). -::: - -## NondimensionalDynamic - -`NondimensionalDynamic` provides convenient scales for nondimensionalizing quasistatic elasticity boundary values problems. -The scales are specified in terms of the minimum shear wave speed, minimum density, and minimum wave period. - -```{table} Nondimensional scales for dynamic elasticity boundary value problems. -:name: tab:nondimensional:dynamic:scales -| Scale | Name | Default Value | -| :---: | :--: | :-----------: | -| velocity | shear_wave_speed | 3.0 km/s | -| density | mass_density | 3000 kg/m$^3$ | -| time | wave_period | 1.0 s | -``` - -:::{admonition} Pyre User Interface -See [NondimElasticDynamic component](components/units/NondimElasticDynamic.md). -::: diff --git a/libsrc/spatialdata/Makefile.am b/libsrc/spatialdata/Makefile.am index 08f41f98..ef659956 100644 --- a/libsrc/spatialdata/Makefile.am +++ b/libsrc/spatialdata/Makefile.am @@ -42,7 +42,6 @@ libspatialdata_la_SOURCES = \ spatialdb/UniformDB.cc \ spatialdb/UserFunctionDB.cc \ spatialdb/cspatialdb.cc \ - units/Nondimensional.cc \ units/Parser.cc \ utils/LineParser.cc \ utils/PointsStream.cc \ diff --git a/libsrc/spatialdata/units/Makefile.am b/libsrc/spatialdata/units/Makefile.am index 5cddb6b1..fda89c4a 100644 --- a/libsrc/spatialdata/units/Makefile.am +++ b/libsrc/spatialdata/units/Makefile.am @@ -12,8 +12,6 @@ subpackage = units include $(top_srcdir)/subpackage.am subpkginclude_HEADERS = \ - Nondimensional.hh \ - Nondimensional.icc \ Parser.hh \ unitsfwd.hh diff --git a/libsrc/spatialdata/units/Nondimensional.cc b/libsrc/spatialdata/units/Nondimensional.cc deleted file mode 100644 index aeada92a..00000000 --- a/libsrc/spatialdata/units/Nondimensional.cc +++ /dev/null @@ -1,143 +0,0 @@ -// ================================================================================================= -// This code is part of SpatialData, developed through the Computational Infrastructure -// for Geodynamics (https://github.com/geodynamics/spatialdata). -// -// Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -// All rights reserved. -// -// See https://mit-license.org/ and LICENSE.md and for license information. -// ================================================================================================= - -#include - -#include "Nondimensional.hh" // implementation of class methods - -#include // USES std::ostringstream -#include // USES std::runtime_error -#include // USES assert() - -// ---------------------------------------------------------------------- -// Default constructor -spatialdata::units::Nondimensional::Nondimensional(void) : - _length(1.0), - _pressure(1.0), - _time(1.0), - _density(1.0), - _temperature(1.0) {} - - -// ---------------------------------------------------------------------- -// Default destructor -spatialdata::units::Nondimensional::~Nondimensional(void) {} - - -// ---------------------------------------------------------------------- -// Copy constructor. -spatialdata::units::Nondimensional::Nondimensional(const Nondimensional& dim) : - _length(dim._length), - _pressure(dim._pressure), - _time(dim._time), - _density(dim._density), - _temperature(dim._temperature) {} - - -// ---------------------------------------------------------------------- -// Assignment operator. -const spatialdata::units::Nondimensional& -spatialdata::units::Nondimensional::operator=(const Nondimensional& dim) { - if (this != &dim) { - _length = dim._length; - _pressure = dim._pressure; - _time = dim._time; - _density = dim._density; - _temperature = dim._temperature; - } // if - - return *this; -} // operator= - - -// ---------------------------------------------------------------------- -// Set value to nondimensionalize length scale in meters (SI units). -void -spatialdata::units::Nondimensional::setLengthScale(const double value) { - if (value <= 0.0) { - std::ostringstream msg; - msg << "Length scale (" << value << ") must be positive."; - throw std::invalid_argument(msg.str()); - } // if - _length = value; -} // setLengthScale - - -// ---------------------------------------------------------------------- -// Set value to nondimensionalize pressure scale in Pascals (SI units). -void -spatialdata::units::Nondimensional::setPressureScale(const double value) { - if (value <= 0.0) { - std::ostringstream msg; - msg << "Pressure scale (" << value << ") must be positive."; - throw std::invalid_argument(msg.str()); - } // if - _pressure = value; -} // setPressureScale - - -// ---------------------------------------------------------------------- -// Set value to nondimensionalize time scale in seconds (SI units). -void -spatialdata::units::Nondimensional::setTimeScale(const double value) { - if (value <= 0.0) { - std::ostringstream msg; - msg << "Time scale (" << value << ") must be positive."; - throw std::invalid_argument(msg.str()); - } // if - _time = value; -} // setTimeScale - - -// ---------------------------------------------------------------------- -// Set value to nondimensionalize density scale in kg/m^3 (SI units). -void -spatialdata::units::Nondimensional::setDensityScale(const double value) { - if (value <= 0.0) { - std::ostringstream msg; - msg << "Density scale (" << value << ") must be positive."; - throw std::invalid_argument(msg.str()); - } // if - _density = value; -} // setDensityScale - - -// ---------------------------------------------------------------------- -// Set value to nondimensionalize temperature scale in Kelvin (SI units). -void -spatialdata::units::Nondimensional::setTemperatureScale(const double value) { - if (value <= 0.0) { - std::ostringstream msg; - msg << "Temperature scale (" << value << ") must be positive."; - throw std::invalid_argument(msg.str()); - } // if - _temperature = value; -} // setTemperatureScale - - -// ---------------------------------------------------------------------- -// Set density scale from length, time, and pressure scales. -void -spatialdata::units::Nondimensional::computeDensityScale(void) { - const double velocityScale = _length / _time; - _density = _pressure / (velocityScale * velocityScale); -} // computeDensityScale - - -// ---------------------------------------------------------------------- -// Compute pressure scale from length, time, and density scales. -void -spatialdata::units::Nondimensional::computePressureScale(void) { - const double velocityScale = _length / _time; - _pressure = _density * velocityScale * velocityScale; -} // computePressureScale - - -// End of file diff --git a/libsrc/spatialdata/units/Nondimensional.hh b/libsrc/spatialdata/units/Nondimensional.hh deleted file mode 100644 index 590fcad8..00000000 --- a/libsrc/spatialdata/units/Nondimensional.hh +++ /dev/null @@ -1,187 +0,0 @@ -// ================================================================================================= -// This code is part of SpatialData, developed through the Computational Infrastructure -// for Geodynamics (https://github.com/geodynamics/spatialdata). -// -// Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -// All rights reserved. -// -// See https://mit-license.org/ and LICENSE.md and for license information. -// ================================================================================================= -#pragma once - -#include "unitsfwd.hh" - -#include // USES size_t - -/// C++ object for managing parameters defining a coordinate system -class spatialdata::units::Nondimensional { // class Nondimensional - friend class TestNondimensional; // Unit testing - -public: - - // PUBLIC METHODS ///////////////////////////////////////////////////// - - /// Default constructor - Nondimensional(void); - - /// Default destructor - ~Nondimensional(void); - - /** Copy constructor. - * - * @param dim Object to copy. - */ - Nondimensional(const Nondimensional& dim); - - /** Assignment operator. - * - * @param dim Object to copy. - * @returns Copy of this. - */ - const Nondimensional& operator=(const Nondimensional& dim); - - /** Set value to nondimensionalize length scale in meters (SI units). - * - * @param value Length scale in meters (SI units). - */ - void setLengthScale(const double value); - - /** Get value to nondimensionalize length scale in meters (SI units). - * - * @returns Length scale in meters (SI units). - */ - double getLengthScale(void) const; - - /** Set value to nondimensionalize pressure scale in Pascals (SI units). - * - * @param value Pressure scale in Pascals (SI units). - */ - void setPressureScale(const double value); - - /** Get value to nondimensionalize pressure scale in Pascals (SI units). - * - * @returns Pressure scale in Pascals (SI units). - */ - double getPressureScale(void) const; - - /** Set value to nondimensionalize time scale in seconds (SI units). - * - * @param value Time scale in seconds (SI units). - */ - void setTimeScale(const double value); - - /** Get value to nondimensionalize time scale in seconds (SI units). - * - * @returns Time scale in seconds (SI units). - */ - double getTimeScale(void) const; - - /** Set value to nondimensionalize density scale in kg/m^3 (SI units). - * - * @param value Density scale in kg/m^3 (SI units). - */ - void setDensityScale(const double value); - - /** Get value to nondimensionalize density scale in kg/m^3 (SI units). - * - * @returns Density scale in kg/m^3 (SI units). - */ - double getDensityScale(void) const; - - /** Set value to nondimensionalize temperature scale in Kelvin (SI units). - * - * @param value Temperature scale in Kelvin (SI units). - */ - void setTemperatureScale(const double value); - - /** Get value to nondimensionalize temperature scale in Kelvin (SI units). - * - * @returns Temperature scale in Kelvin (SI units). - */ - double getTemperatureScale(void) const; - - /** Set density scale from length, time, and pressure scales. - * - * D = P * (T / L)**2 - */ - void computeDensityScale(void); - - /** Compute pressure scale from length, time, and density scales. - * - * P = D * (L / T)**2 - */ - void computePressureScale(void); - - /** Make value dimensionless. - * - * @param value Value with dimensions in SI units. - * @param scale Scale used to nondimensionalize value. - * @returns Dimensionless value. - */ - double nondimensionalize(const double value, - const double scale) const; - - /** Make value dimensionless. - * - * @param value Dimensionless value. - * @param value Value with dimensions in SI units. - * @returns Scale used to nondimensionalize value. - */ - double dimensionalize(const double value, - const double scale) const; - - /** Make values dimensionless. - * - * @param values Array of values with dimensions in SI units. - * @param nvalues Number of values. - * @param scale Scale used to nondimensionalize value. - */ - void nondimensionalize(double* const values, - const size_t nvalues, - const double scale) const; - - /** Make values dimensionless. - * - * @param values Array of values with dimensions in SI units. - * @param nvalues Number of values. - * @param scale Scale used to nondimensionalize value. - */ - void nondimensionalize(float* const values, - const size_t nvalues, - const double scale) const; - - /** Make value dimensionless. - * - * @param values Array of dimensionless values. - * @param nvalues Number of values. - * @param scale Scale used to nondimensionalize value. - */ - void dimensionalize(double* const values, - const size_t nvalues, - const double scale) const; - - /** Make value dimensionless. - * - * @param values Array of dimensionless values. - * @param nvalues Number of values. - * @param scale Scale used to nondimensionalize value. - */ - void dimensionalize(float* const values, - const size_t nvalues, - const double scale) const; - -private: - - // PRIVATE MEMBERS //////////////////////////////////////////////////// - - double _length; ///< Length scale - double _pressure; ///< Pressure scale - double _time; ///< Time scale - double _density; ///< Density scale - double _temperature; ///< Temperature scale - -}; // class Nondimensional - -#include "Nondimensional.icc" // inline methods - -// End of file diff --git a/libsrc/spatialdata/units/Nondimensional.icc b/libsrc/spatialdata/units/Nondimensional.icc deleted file mode 100644 index 7c62aba6..00000000 --- a/libsrc/spatialdata/units/Nondimensional.icc +++ /dev/null @@ -1,132 +0,0 @@ -// ================================================================================================= -// This code is part of SpatialData, developed through the Computational Infrastructure -// for Geodynamics (https://github.com/geodynamics/spatialdata). -// -// Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -// All rights reserved. -// -// See https://mit-license.org/ and LICENSE.md and for license information. -// ================================================================================================= -#pragma once - -#include // USES assert() - -// Get value to nondimensionalize length scale in meters (SI units). -inline -double -spatialdata::units::Nondimensional::getLengthScale(void) const { - return _length; -} - - -// Get value to nondimensionalize pressure scale in Pascals (SI units). -inline -double -spatialdata::units::Nondimensional::getPressureScale(void) const { - return _pressure; -} - - -// Get value to nondimensionalize time scale in seconds (SI units). -inline -double -spatialdata::units::Nondimensional::getTimeScale(void) const { - return _time; -} - - -// Get value to nondimensionalize density scale in kg/m^3 (SI units). -inline -double -spatialdata::units::Nondimensional::getDensityScale(void) const { - return _density; -} - - -// Get value to nondimensionalize temperature scale in Kelvin (SI units). -inline -double -spatialdata::units::Nondimensional::getTemperatureScale(void) const { - return _temperature; -} - - -// Make value dimensionless. -inline -double -spatialdata::units::Nondimensional::nondimensionalize(const double value, - const double scale) const { - return value / scale; -} - - -// Make values dimensionless. -inline -void -spatialdata::units::Nondimensional::nondimensionalize(double* const values, - const size_t nvalues, - const double scale) const { // nondimensionalize - assert( (0 < nvalues && values) || - (0 == nvalues && !values) ); - - for (size_t i = 0; i < nvalues; ++i) { - values[i] /= scale; - } -} // nondimensionalize - - -// Make values dimensionless. -inline -void -spatialdata::units::Nondimensional::nondimensionalize(float* const values, - const size_t nvalues, - const double scale) const { // nondimensionalize - assert( (0 < nvalues && values) || - (0 == nvalues && !values) ); - - for (size_t i = 0; i < nvalues; ++i) { - values[i] /= scale; - } -} // nondimensionalize - - -// Make value dimensionless. -inline -double -spatialdata::units::Nondimensional::dimensionalize(const double value, - const double scale) const { - return value * scale; -} - - -// Make value dimensionless. -inline -void -spatialdata::units::Nondimensional::dimensionalize(double* const values, - const size_t nvalues, - const double scale) const { // dimensionalize - assert( (0 < nvalues && values) || - (0 == nvalues && !values) ); - - for (size_t i = 0; i < nvalues; ++i) { - values[i] *= scale; - } -} // dimensionalize - - -// Make value dimensionless. -inline -void -spatialdata::units::Nondimensional::dimensionalize(float* const values, - const size_t nvalues, - const double scale) const { // dimensionalize - assert( (0 < nvalues && values) || - (0 == nvalues && !values) ); - - for (size_t i = 0; i < nvalues; ++i) { - values[i] *= scale; - } -} // dimensionalize - - -// End of file diff --git a/libsrc/spatialdata/units/unitsfwd.hh b/libsrc/spatialdata/units/unitsfwd.hh index 81d960a3..98bd194c 100644 --- a/libsrc/spatialdata/units/unitsfwd.hh +++ b/libsrc/spatialdata/units/unitsfwd.hh @@ -11,7 +11,6 @@ namespace spatialdata { namespace units { - class Nondimensional; class Parser; } // units } // spatialdata diff --git a/modulesrc/Makefile.am b/modulesrc/Makefile.am index 83970584..80068147 100644 --- a/modulesrc/Makefile.am +++ b/modulesrc/Makefile.am @@ -12,7 +12,6 @@ SUBDIRS = \ include \ geocoords \ spatialdb \ - units \ utils diff --git a/modulesrc/units/Makefile.am b/modulesrc/units/Makefile.am deleted file mode 100644 index 346945ca..00000000 --- a/modulesrc/units/Makefile.am +++ /dev/null @@ -1,49 +0,0 @@ -# ================================================================================================= -# This code is part of SpatialData, developed through the Computational Infrastructure -# for Geodynamics (https://github.com/geodynamics/spatialdata). -# -# Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -# All rights reserved. -# -# See https://mit-license.org/ and LICENSE.md and for license information. -# ================================================================================================= - -subpackage = units -include $(top_srcdir)/subpackage.am -include $(top_srcdir)/modulesrc/module.am - -subpkgpython_LTLIBRARIES = _units.la -subpkgpython_PYTHON = units.py - -swig_sources = \ - units.i \ - Nondimensional.i - -swig_generated = \ - units_wrap.cxx \ - units.py - -_units_la_LDFLAGS = -module -avoid-version \ - $(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS) - -dist__units_la_SOURCES = $(swig_sources) $(swig_generated) - -_units_la_LIBADD = \ - $(top_builddir)/libsrc/spatialdata/libspatialdata.la \ - $(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS) - -if ENABLE_SWIG -$(srcdir)/units_wrap.cxx $(srcdir)/units.py: $(swig_sources) - $(SWIG) -Wall -c++ -python $< -else -$(srcdir)/units_wrap.cxx $(srcdir)/units.py: - $(error Missing SWIG generated files. Make sure SWIG is installed and reconfigure with --enable-swig) -endif - - -MAINTAINERCLEANFILES = \ - $(srcdir)/units_wrap.cxx \ - $(srcdir)/units.py - - -# End of file diff --git a/modulesrc/units/Nondimensional.i b/modulesrc/units/Nondimensional.i deleted file mode 100644 index 94945392..00000000 --- a/modulesrc/units/Nondimensional.i +++ /dev/null @@ -1,153 +0,0 @@ -// ================================================================================================= -// This code is part of SpatialData, developed through the Computational Infrastructure -// for Geodynamics (https://github.com/geodynamics/spatialdata). -// -// Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -// All rights reserved. -// -// See https://mit-license.org/ and LICENSE.md and for license information. -// ================================================================================================= - -/** @file modulesrc/units/Nondimensional.i - * - * @brief SWIG interface for C++ Nondimensional object. - */ - -namespace spatialdata { - namespace units { - class Nondimensional - { // class Nondimensional -public: - - // PUBLIC METHODS ///////////////////////////////////////////////// - - /// Default constructor - Nondimensional(void); - - /// Default destructor - ~Nondimensional(void); - - /** Set value to nondimensionalize length scale in meters (SI - * units). - * - * @param value Length scale in meters (SI units). - */ - void setLengthScale(const double value); - - /** Get value to nondimensionalize length scale in meters (SI - * units). - * - * @returns Length scale in meters (SI units). - */ - double getLengthScale(void) const; - - /** Set value to nondimensionalize pressure scale in Pascals (SI - * units). - * - * @param value Pressure scale in Pascals (SI units). - */ - void setPressureScale(const double value); - - /** Get value to nondimensionalize pressure scale in Pascals (SI - * units). - * - * @returns Pressure scale in Pascals (SI units). - */ - double getPressureScale(void) const; - - /** Set value to nondimensionalize time scale in seconds (SI - * units). - * - * @param value Time scale in seconds (SI units). - */ - void setTimeScale(const double value); - - /** Get value to nondimensionalize time scale in seconds (SI - * units). - * - * @returns Time scale in seconds (SI units). - */ - double getTimeScale(void) const; - - /** Set value to nondimensionalize density scale in kg/m^3 (SI - * units). - * - * @param value Density scale in kg/m^3 (SI units). - */ - void setDensityScale(const double value); - - /** Get value to nondimensionalize density scale in kg/m^3 (SI - * units). - * - * @returns Density scale in kg/m^3 (SI units). - */ - double getDensityScale(void) const; - - /** Set value to nondimensionalize temperature scale in Kelvin (SI units). - * - * @param value Temperature scale in Kelvin (SI units). - */ - void setTemperatureScale(const double value); - - /** Get value to nondimensionalize temperature scale in Kelvin (SI units). - * - * @returns Temperature scale in Kelvin (SI units). - */ - double getTemperatureScale(void) const; - - /** Set density scale from length, time, and pressure scales. - * - * D = P * (T / L)**2 - */ - void computeDensityScale(void); - - /** Compute pressure scale from length, time, and density scales. - * - * P = D * (L / T)**2 - */ - void computePressureScale(void); - - /** Make value dimensionless. - * - * @param value Value with dimensions in SI units. - * @param scale Scale used to nondimensionalize value. - * @returns Dimensionless value. - */ - double nondimensionalize(const double value, - const double scale) const; - - /** Make value dimensionless. - * - * @param value Dimensionless value. - * @param value Value with dimensions in SI units. - * @returns Scale used to nondimensionalize value. - */ - double dimensionalize(const double value, - const double scale) const; - - /** Make values dimensionless. - * - * @param values Array of values with dimensions in SI units. - * @param nvalues Number of values. - * @param scale Scale used to nondimensionalize value. - */ - void nondimensionalize(double* const values, - const size_t nvalues, - const double scale) const; - - /** Make value dimensionless. - * - * @param values Array of dimensionless values. - * @param nvalues Number of values. - * @param scale Scale used to nondimensionalize value. - */ - void dimensionalize(double* const values, - const size_t nvalues, - const double scale) const; - - }; // class Nondimensional - - } // units -} // spatialdata - -// End of file diff --git a/modulesrc/units/units.i b/modulesrc/units/units.i deleted file mode 100644 index e8a946c7..00000000 --- a/modulesrc/units/units.i +++ /dev/null @@ -1,30 +0,0 @@ -// ================================================================================================= -// This code is part of SpatialData, developed through the Computational Infrastructure -// for Geodynamics (https://github.com/geodynamics/spatialdata). -// -// Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -// All rights reserved. -// -// See https://mit-license.org/ and LICENSE.md and for license information. -// ================================================================================================= -// SWIG interface -%module units - -// Header files for module C++ code -%{ -#include "spatialdata/units/Nondimensional.hh" -%} - -%include "exception.i" -%exception { - try { - $action - } catch (const std::exception& err) { - SWIG_exception(SWIG_RuntimeError, err.what()); - } // try/catch -} // exception - -%include "Nondimensional.i" - - -// End of file diff --git a/spatialdata/Makefile.am b/spatialdata/Makefile.am index 6ce794c6..f444fd61 100644 --- a/spatialdata/Makefile.am +++ b/spatialdata/Makefile.am @@ -45,10 +45,6 @@ EXTRA_DIST = \ testing/__init__.py \ testing/UnitTestApp.py \ testing/TestCases.py \ - units/NondimElasticDynamic.py \ - units/NondimElasticQuasistatic.py \ - units/Nondimensional.py \ - units/__init__.py \ utils/PointsStream.py \ utils/__init__.py diff --git a/spatialdata/__init__.py b/spatialdata/__init__.py index 701f7c44..af7a14ad 100644 --- a/spatialdata/__init__.py +++ b/spatialdata/__init__.py @@ -12,10 +12,10 @@ # @brief Python top-level SpatialData module initialization try: - from pkg_resources import get_distribution - version = get_distribution("spatialdata").version + import importlib.metadata + version = importlib.metadata.version("spatialdata") except: - version = "Could not get version information via pkg_resources." + version = "Could not get version information via importlib.metadata." __version__ = version diff --git a/spatialdata/units/NondimElasticDynamic.py b/spatialdata/units/NondimElasticDynamic.py deleted file mode 100644 index 5ed6439c..00000000 --- a/spatialdata/units/NondimElasticDynamic.py +++ /dev/null @@ -1,79 +0,0 @@ -# ================================================================================================= -# This code is part of SpatialData, developed through the Computational Infrastructure -# for Geodynamics (https://github.com/geodynamics/spatialdata). -# -# Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -# All rights reserved. -# -# See https://mit-license.org/ and LICENSE.md and for license information. -# ================================================================================================= - -from .Nondimensional import Nondimensional - - -class NondimElasticDynamic(Nondimensional): - """ - Convenience object for nondimensionalizing dynamic elasticity problems. - - Implements `Nondimensional`. - """ - DOC_CONFIG = { - "cfg": """ - [normalizer] - shear_wave_speed = 3.0*km/s - mass_density = 3.0*kg/m**3 - wave_period = 2.0*s - """, - } - - import pythia.pyre.inventory - - from pythia.pyre.units.length import meter - from pythia.pyre.units.time import second - from pythia.pyre.units.mass import kg - shearWaveSpeed = pythia.pyre.inventory.dimensional("shear_wave_speed", default=3.0e+3 * meter / second) - shearWaveSpeed.validator = pythia.pyre.inventory.greater(0.0 * meter / second) - shearWaveSpeed.meta['tip'] = "Shear wave speed to nondimensionalize problem." - - massDensity = pythia.pyre.inventory.dimensional("mass_density", default=3.0e+3 * kg / meter**3) - massDensity.validator = pythia.pyre.inventory.greater(0.0 * kg / meter**3) - massDensity.meta['tip'] = "Mass density to nondimensionalize problem" - - wavePeriod = pythia.pyre.inventory.dimensional("wave_period", default=1.0 * second) - wavePeriod.validator = pythia.pyre.inventory.greater(0.0 * second) - wavePeriod.meta['tip'] = "Period of wave to nondimensionalize problem." - - # PUBLIC METHODS ///////////////////////////////////////////////////// - - def __init__(self, name="nondimelasticdynamic"): - """ - Constructor. - """ - Nondimensional.__init__(self, name) - - # PRIVATE METHODS //////////////////////////////////////////////////// - - def _configure(self): - """ - Setup members using inventory. - """ - Nondimensional._configure(self) - vs = self.inventory.shearWaveSpeed - period = self.inventory.wavePeriod - density = self.inventory.massDensity - self.setLengthScale(vs * period) - self.setTimeScale(period) - self.setDensityScale(density) - self.computePressureScale() - - -# FACTORIES //////////////////////////////////////////////////////////// - -def nondimensional(): - """ - Factory associated with NondimElasticDynamic. - """ - return NondimElasticDynamic() - - -# End of file diff --git a/spatialdata/units/NondimElasticQuasistatic.py b/spatialdata/units/NondimElasticQuasistatic.py deleted file mode 100644 index 8bafd50c..00000000 --- a/spatialdata/units/NondimElasticQuasistatic.py +++ /dev/null @@ -1,76 +0,0 @@ -# ================================================================================================= -# This code is part of SpatialData, developed through the Computational Infrastructure -# for Geodynamics (https://github.com/geodynamics/spatialdata). -# -# Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -# All rights reserved. -# -# See https://mit-license.org/ and LICENSE.md and for license information. -# ================================================================================================= - -from .Nondimensional import Nondimensional - - -class NondimElasticQuasistatic(Nondimensional): - """ - Convenience object for nondimensionalizing quasi-static elasticity problems. - - Implements `Nondimensional`. - """ - DOC_CONFIG = { - "cfg": """ - [normalizer] - length_scale = 5.0*km - shear_modulus = 30.0*GPa - relaxation_time = 200.0*year - """, - } - - import pythia.pyre.inventory - - from pythia.pyre.units.length import meter - lengthScale = pythia.pyre.inventory.dimensional("length_scale", default=1.0e+3 * meter) - lengthScale.validator = pythia.pyre.inventory.greater(0.0 * meter) - lengthScale.meta['tip'] = "Value to nondimensionalize length scale." - - from pythia.pyre.units.pressure import pascal - shearModulus = pythia.pyre.inventory.dimensional("shear_modulus", default=3.0e+10 * pascal) - shearModulus.validator = pythia.pyre.inventory.greater(0.0 * pascal) - shearModulus.meta['tip'] = "Shear modulus to nondimensionalize pressure." - - from pythia.pyre.units.time import year - relaxationTime = pythia.pyre.inventory.dimensional("relaxation_time", default=100.0 * year) - relaxationTime.validator = pythia.pyre.inventory.greater(0.0 * year) - relaxationTime.meta['tip'] = "Relaxation time to nondimensionalize time." - - # PUBLIC METHODS ///////////////////////////////////////////////////// - - def __init__(self, name="nondimelasticquasistatic"): - """ - Constructor. - """ - Nondimensional.__init__(self, name) - - # PRIVATE METHODS //////////////////////////////////////////////////// - - def _configure(self): - """ - Setup members using inventory. - """ - Nondimensional._configure(self) - self.setLengthScale(self.inventory.lengthScale) - self.setPressureScale(self.inventory.shearModulus) - self.setTimeScale(self.inventory.relaxationTime) - self.computeDensityScale() - - -# FACTORIES //////////////////////////////////////////////////////////// - -def nondimensional(): - """ - Factory associated with NondimElasticQuasistatic. - """ - return NondimElasticQuasistatic() - - -# End of file diff --git a/spatialdata/units/Nondimensional.py b/spatialdata/units/Nondimensional.py deleted file mode 100644 index 66016da8..00000000 --- a/spatialdata/units/Nondimensional.py +++ /dev/null @@ -1,128 +0,0 @@ -# ================================================================================================= -# This code is part of SpatialData, developed through the Computational Infrastructure -# for Geodynamics (https://github.com/geodynamics/spatialdata). -# -# Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -# All rights reserved. -# -# See https://mit-license.org/ and LICENSE.md and for license information. -# ================================================================================================= - -from pythia.pyre.components.Component import Component -from .units import Nondimensional as ModuleNondimensional - - -class Nondimensional(Component, ModuleNondimensional): - """ - Abstract base class for nondimensionalizing problems. - """ - - # PUBLIC METHODS ///////////////////////////////////////////////////// - - def __init__(self, name="nondimensional"): - """ - Constructor. - """ - Component.__init__(self, name, facility="nondimensional") - - def _configure(self): - Component._configure(self) - self._createModuleObj() - - def setLengthScale(self, value): - """ - Get length scale. - """ - return ModuleNondimensional.setLengthScale(self, value.value) - - def getLengthScale(self): - """ - Get length scale. - """ - from pythia.pyre.units.length import meter - return ModuleNondimensional.getLengthScale(self) * meter - - def setPressureScale(self, value): - """ - Get length scale. - """ - return ModuleNondimensional.setPressureScale(self, value.value) - - def getPressureScale(self): - """ - Get pressure scale. - """ - from pythia.pyre.units.pressure import pascal - return ModuleNondimensional.getPressureScale(self) * pascal - - def setTimeScale(self, value): - """ - Get time scale. - """ - return ModuleNondimensional.setTimeScale(self, value.value) - - def getTimeScale(self): - """ - Get time scale. - """ - from pythia.pyre.units.time import second - return ModuleNondimensional.getTimeScale(self) * second - - def setDensityScale(self, value): - """ - Get density scale. - """ - return ModuleNondimensional.setDensityScale(self, value.value) - - def getDensityScale(self): - """ - Get density scale. - """ - from pythia.pyre.units.length import meter - from pythia.pyre.units.mass import kilogram - return ModuleNondimensional.getDensityScale(self) * kilogram / meter**3 - - def setTemperatureScale(self, value): - """ - Get temperature scale. - """ - return ModuleNondimensional.setTemperatureScale(self, value.value) - - def getTemperatureScale(self): - """ - Get temperature scale. - """ - from pythia.pyre.units.temperature import kelvin - return ModuleNondimensional.getTemperatureScale(self) * kelvin - - def nondimensionalize(self, value, scale): - """ - Make value dimensionless. - """ - return value / scale - - def dimensionalize(self, value, scale): - """ - Make value dimensional. - """ - return value * scale - - # PRIVATE METHODS //////////////////////////////////////////////////// - - def _createModuleObj(self): - """ - Create Python module object. - """ - ModuleNondimensional.__init__(self) - - -# FACTORIES //////////////////////////////////////////////////////////// - -def nondimensional(): - """ - Factory associated with Nondimensional. - """ - return Nondimensional() - - -# End of file diff --git a/spatialdata/units/__init__.py b/spatialdata/units/__init__.py deleted file mode 100644 index 2ddc7d24..00000000 --- a/spatialdata/units/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# ================================================================================================= -# This code is part of SpatialData, developed through the Computational Infrastructure -# for Geodynamics (https://github.com/geodynamics/spatialdata). -# -# Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -# All rights reserved. -# -# See https://mit-license.org/ and LICENSE.md and for license information. -# ================================================================================================= -# -# @file spatialdata/units/__init__.py -# -# @brief Python spatialdata units module initialization. - -__all__ = [ - "Nondimensional", - "NondimElasticQuasistatic", - "NondimElasticDynamic", - ] - - -# End of file diff --git a/tests/libtests/spatialdb/TestSimpleGridDB.cc b/tests/libtests/spatialdb/TestSimpleGridDB.cc index 20aaea1c..37825c34 100644 --- a/tests/libtests/spatialdb/TestSimpleGridDB.cc +++ b/tests/libtests/spatialdb/TestSimpleGridDB.cc @@ -341,11 +341,11 @@ spatialdata::spatialdb::TestSimpleGridDB::_checkQuery(SimpleGridDB& db, assert(numValues); // reverse order of vals in queries - const char* valNames[numValues]; + std::vectorvalueNames(numValues); for (size_t i = 0; i < numValues; ++i) { - valNames[numValues-i-1] = names[i]; + valueNames[numValues-i-1] = names[i]; } - db.setQueryValues(valNames, numValues); + db.setQueryValues(valueNames.data(), numValues); double* vals = (0 < numValues) ? new double[numValues] : NULL; const double tolerance = 1.0e-06; diff --git a/tests/libtests/units/Makefile.am b/tests/libtests/units/Makefile.am index d38e17ef..af62c9e6 100644 --- a/tests/libtests/units/Makefile.am +++ b/tests/libtests/units/Makefile.am @@ -15,7 +15,6 @@ TESTS = libtest_units check_PROGRAMS = libtest_units libtest_units_SOURCES = \ - TestNondimensional.cc \ TestParser.cc \ $(top_srcdir)/tests/src/driver_catch2.cc diff --git a/tests/libtests/units/TestNondimensional.cc b/tests/libtests/units/TestNondimensional.cc deleted file mode 100644 index 7bd87c6a..00000000 --- a/tests/libtests/units/TestNondimensional.cc +++ /dev/null @@ -1,257 +0,0 @@ -// ================================================================================================= -// This code is part of SpatialData, developed through the Computational Infrastructure -// for Geodynamics (https://github.com/geodynamics/spatialdata). -// -// Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -// All rights reserved. -// -// See https://mit-license.org/ and LICENSE.md and for license information. -// ================================================================================================= - -#include - -#include "spatialdata/units/Nondimensional.hh" // USES Nondimensional - -#include "catch2/catch_test_macros.hpp" -#include "catch2/matchers/catch_matchers_floating_point.hpp" - -#include // USES fabs() -#include // USES std::valarray - -// ------------------------------------------------------------------------------------------------ -namespace spatialdata { - namespace units { - class TestNondimensional; - } // units -} // spatialdata - -class spatialdata::units::TestNondimensional { - // PUBLIC METHODS ///////////////////////////////////////////////////////////////////////////// -public: - - /// Test constructors. - static - void testConstructors(void); - - /// Test accessors. - static - void testAccessors(void); - - /// Test computeDensityScale. - static - void testComputeDensityScale(void); - - /// Test computePressureScale. - static - void testComputePressureScale(void); - - /// Test nondimensionalize() and dimensionalize(). - static - void testNondimensionalize(void); - - /// Test nondimensionalie() and dimensionalize() with arrays. - static - void testNondimensionalizeArray(void); - -}; // class TestNondimensional - -// ------------------------------------------------------------------------------------------------ -TEST_CASE("TestNondimensional::testConstructors", "[TestNondimensional]") { - spatialdata::units::TestNondimensional::testConstructors(); -} -TEST_CASE("TestNondimensional::testAccessors", "[TestNondimensional]") { - spatialdata::units::TestNondimensional::testAccessors(); -} -TEST_CASE("TestNondimensional::testComputeDensityScale", "[TestNondimensional]") { - spatialdata::units::TestNondimensional::testComputeDensityScale(); -} -TEST_CASE("TestNondimensional::testComputePressureScale", "[TestNondimensional]") { - spatialdata::units::TestNondimensional::testComputePressureScale(); -} -TEST_CASE("TestNondimensional::testNondimensionalize", "[TestNondimensional]") { - spatialdata::units::TestNondimensional::testNondimensionalize(); -} -TEST_CASE("TestNondimensional::testNondimensionalizeArray", "[TestNondimensional]") { - spatialdata::units::TestNondimensional::testNondimensionalizeArray(); -} - -// ------------------------------------------------------------------------------------------------ -// Test constructor. -void -spatialdata::units::TestNondimensional::testConstructors(void) { - const double defaultLength(1.0); - const double defaultPressure(1.0); - const double defaultTime(1.0); - const double defaultDensity(1.0); - const double defaultTemperature(1.0); - - Nondimensional dim; - CHECK(defaultLength == dim._length); - CHECK(defaultPressure == dim._pressure); - CHECK(defaultTime == dim._time); - CHECK(defaultDensity == dim._density); - CHECK(defaultTemperature == dim._temperature); - - dim._length = 2.0; - dim._pressure = 3.0; - dim._time = 4.0; - dim._density = 5.0; - dim._temperature = 6.0; - Nondimensional dimCopy(dim); - CHECK(dim._length == dimCopy._length); - CHECK(dim._pressure == dimCopy._pressure); - CHECK(dim._time == dimCopy._time); - CHECK(dim._density == dimCopy._density); - CHECK(dim._temperature == dimCopy._temperature); - - Nondimensional dimAssign; - dimAssign = dim; - CHECK(dim._length == dimAssign._length); - CHECK(dim._pressure == dimAssign._pressure); - CHECK(dim._time == dimAssign._time); - CHECK(dim._density == dimAssign._density); - CHECK(dim._temperature == dimAssign._temperature); -} // testConstructors - - -// ------------------------------------------------------------------------------------------------ -// Test accessors. -void -spatialdata::units::TestNondimensional::testAccessors(void) { - const double length(4.0); - const double pressure(5.0); - const double time(6.0); - const double density(7.0); - const double temperature(8.0); - - Nondimensional dim; - - // Length scale - INFO("Testing setting length scale."); - dim.setLengthScale(length); - CHECK(length == dim.getLengthScale()); - CHECK(1.0 == dim.getPressureScale()); - CHECK(1.0 == dim.getTimeScale()); - CHECK(1.0 == dim.getDensityScale()); - CHECK(1.0 == dim.getTemperatureScale()); - - // Pressure scale - INFO("Testing setting pressure scale."); - dim.setPressureScale(pressure); - CHECK(length == dim.getLengthScale()); - CHECK(pressure == dim.getPressureScale()); - CHECK(1.0 == dim.getTimeScale()); - CHECK(1.0 == dim.getDensityScale()); - CHECK(1.0 == dim.getTemperatureScale()); - - // Time scale - INFO("Testing setting time scale."); - dim.setTimeScale(time); - CHECK(length == dim.getLengthScale()); - CHECK(pressure == dim.getPressureScale()); - CHECK(time == dim.getTimeScale()); - CHECK(1.0 == dim.getDensityScale()); - CHECK(1.0 == dim.getTemperatureScale()); - - // Density scale - INFO("Testing setting density scale."); - dim.setDensityScale(density); - CHECK(length == dim.getLengthScale()); - CHECK(pressure == dim.getPressureScale()); - CHECK(time == dim.getTimeScale()); - CHECK(density == dim.getDensityScale()); - CHECK(1.0 == dim.getTemperatureScale()); - - // Temperature scale - INFO("Testing setting temperature scale."); - dim.setTemperatureScale(temperature); - CHECK(length == dim.getLengthScale()); - CHECK(pressure == dim.getPressureScale()); - CHECK(time == dim.getTimeScale()); - CHECK(density == dim.getDensityScale()); - CHECK(temperature == dim.getTemperatureScale()); -} // testAccessors - - -// ------------------------------------------------------------------------------------------------ -// Test computePressureScale(). -void -spatialdata::units::TestNondimensional::testComputePressureScale(void) { - const double timeScale = 2.0; - const double densityScale = 3.0; - const double lengthScale = 7.0; - - const double velocityScale = lengthScale / timeScale; - const double pressureScale = densityScale * velocityScale * velocityScale; - - Nondimensional dim; - dim.setTimeScale(timeScale); - dim.setDensityScale(densityScale); - dim.setLengthScale(lengthScale); - dim.computePressureScale(); - CHECK_THAT(dim.getPressureScale(), Catch::Matchers::WithinAbs(pressureScale, pressureScale*1.0e-6)); -} // testComputePressureScale - - -// ------------------------------------------------------------------------------------------------ -// Test computeDensityScale(). -void -spatialdata::units::TestNondimensional::testComputeDensityScale(void) { - const double timeScale = 2.0; - const double pressureScale = 3.0; - const double lengthScale = 7.0; - - const double velocityScale = lengthScale / timeScale; - const double densityScale = pressureScale / (velocityScale * velocityScale); - - Nondimensional dim; - dim.setTimeScale(timeScale); - dim.setPressureScale(pressureScale); - dim.setLengthScale(lengthScale); - dim.computeDensityScale(); - CHECK_THAT(dim.getDensityScale(), Catch::Matchers::WithinAbs(densityScale, densityScale*1.0e-6)); -} // testComputeDensityScale - - -// ------------------------------------------------------------------------------------------------ -// Test nondimensionalize() and dimensionalize(). -void -spatialdata::units::TestNondimensional::testNondimensionalize(void) { - const double scale = 4.0; - const double value = 3.0; - const double valueE = 0.75; - - Nondimensional dim; - const double tolerance = 1.0e-6; - CHECK_THAT(dim.nondimensionalize(value, scale), Catch::Matchers::WithinAbs(valueE, tolerance)); - CHECK_THAT(dim.dimensionalize(valueE, scale), Catch::Matchers::WithinAbs(value, tolerance)); -} // testNondimensionalize - - -// ------------------------------------------------------------------------------------------------ -// Test nondimensionalize() and dimensionalize() with arrays. -void -spatialdata::units::TestNondimensional::testNondimensionalizeArray(void) { - const double scale = 10.0; - const size_t nvalues = 3; - const double values[nvalues] = { 2.0, 5.0, 7.0 }; - const double valuesE[nvalues] = { 0.2, 0.5, 0.7 }; - - Nondimensional dim; - - std::valarray v(values, nvalues); - dim.nondimensionalize(&v[0], nvalues, scale); - const double tolerance = 1.0e-6; - for (size_t i = 0; i < nvalues; ++i) { - CHECK_THAT(v[i], Catch::Matchers::WithinAbs(valuesE[i], tolerance)); - } // for - - v = std::valarray(valuesE, nvalues); - dim.dimensionalize(&v[0], nvalues, scale); - for (size_t i = 0; i < nvalues; ++i) { - CHECK_THAT(v[i], Catch::Matchers::WithinAbs(values[i], tolerance)); - } // for -} // testNondimensionalizeArray - - -// End of file diff --git a/tests/pytests/Makefile.am b/tests/pytests/Makefile.am index 0537d28f..7486b997 100644 --- a/tests/pytests/Makefile.am +++ b/tests/pytests/Makefile.am @@ -11,7 +11,6 @@ SUBDIRS = \ geocoords \ spatialdb \ - units \ utils diff --git a/tests/pytests/units/Makefile.am b/tests/pytests/units/Makefile.am deleted file mode 100644 index 00a8a302..00000000 --- a/tests/pytests/units/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -# ================================================================================================= -# This code is part of SpatialData, developed through the Computational Infrastructure -# for Geodynamics (https://github.com/geodynamics/spatialdata). -# -# Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -# All rights reserved. -# -# See https://mit-license.org/ and LICENSE.md and for license information. -# ================================================================================================= - -include $(top_srcdir)/tests/check.am - -TESTS = test_units.py -dist_check_SCRIPTS = test_units.py - -noinst_PYTHON = \ - TestNondimensional.py \ - TestNondimElasticQuasistatic.py \ - TestNondimElasticDynamic.py - - -# End of file diff --git a/tests/pytests/units/TestNondimElasticDynamic.py b/tests/pytests/units/TestNondimElasticDynamic.py deleted file mode 100644 index 2003cb12..00000000 --- a/tests/pytests/units/TestNondimElasticDynamic.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env nemesis -# -# ================================================================================================= -# This code is part of SpatialData, developed through the Computational Infrastructure -# for Geodynamics (https://github.com/geodynamics/spatialdata). -# -# Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -# All rights reserved. -# -# See https://mit-license.org/ and LICENSE.md and for license information. -# ================================================================================================= - -import unittest - -from spatialdata.testing.TestCases import make_suite -from spatialdata.units.NondimElasticDynamic import NondimElasticDynamic - -from pythia.pyre.units.length import meter -from pythia.pyre.units.pressure import pascal -from pythia.pyre.units.time import second -from pythia.pyre.units.mass import kilogram - - -class TestNondimElasticDynamic(unittest.TestCase): - - def test_constructor(self): - dim = NondimElasticDynamic() - dim._configure() - - # Default values - velocityScale = 3.0e+3 * meter / second - densityScale = 3.0e+3 * kilogram / meter**3 - timeScale = 1.0 * second - - lengthScale = velocityScale * timeScale - pressureScale = densityScale * velocityScale**2 - - # Check defaults - self.assertEqual(lengthScale, dim.getLengthScale()) - self.assertEqual(pressureScale, dim.getPressureScale()) - self.assertEqual(timeScale, dim.getTimeScale()) - self.assertEqual(densityScale, dim.getDensityScale()) - - -def load_tests(loader, tests, pattern): - TEST_CLASSES = [TestNondimElasticDynamic] - return make_suite(test_classes=TEST_CLASSES, loader=loader) - - -if __name__ == "__main__": - unittest.main(verbosity=2) - - -# End of file diff --git a/tests/pytests/units/TestNondimElasticQuasistatic.py b/tests/pytests/units/TestNondimElasticQuasistatic.py deleted file mode 100644 index 52312eb5..00000000 --- a/tests/pytests/units/TestNondimElasticQuasistatic.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env nemesis -# -# ================================================================================================= -# This code is part of SpatialData, developed through the Computational Infrastructure -# for Geodynamics (https://github.com/geodynamics/spatialdata). -# -# Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -# All rights reserved. -# -# See https://mit-license.org/ and LICENSE.md and for license information. -# ================================================================================================= - -import unittest - -from spatialdata.testing.TestCases import make_suite -from spatialdata.units.NondimElasticQuasistatic import NondimElasticQuasistatic - -from pythia.pyre.units.length import meter -from pythia.pyre.units.pressure import pascal -from pythia.pyre.units.time import year -from pythia.pyre.units.mass import kilogram - - -class TestNondimElasticQuasistatic(unittest.TestCase): - - def test_constructor(self): - dim = NondimElasticQuasistatic() - dim._configure() - - # Default values - lengthScale = 1.0e+3 * meter - pressureScale = 3.0e+10 * pascal - timeScale = 1.0e+2 * year - - # Check defaults - self.assertEqual(lengthScale, dim.getLengthScale()) - self.assertEqual(pressureScale, dim.getPressureScale()) - self.assertEqual(timeScale, dim.getTimeScale()) - - velocityScale = lengthScale / timeScale - densityScale = pressureScale / velocityScale**2 - self.assertEqual(densityScale, dim.getDensityScale()) - - -def load_tests(loader, tests, pattern): - TEST_CLASSES = [TestNondimElasticQuasistatic] - return make_suite(test_classes=TEST_CLASSES, loader=loader) - - -if __name__ == "__main__": - unittest.main(verbosity=2) - - -# End of file diff --git a/tests/pytests/units/TestNondimensional.py b/tests/pytests/units/TestNondimensional.py deleted file mode 100644 index 3dc8410d..00000000 --- a/tests/pytests/units/TestNondimensional.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env nemesis -# -# ================================================================================================= -# This code is part of SpatialData, developed through the Computational Infrastructure -# for Geodynamics (https://github.com/geodynamics/spatialdata). -# -# Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -# All rights reserved. -# -# See https://mit-license.org/ and LICENSE.md and for license information. -# ================================================================================================= - -import unittest - -from spatialdata.testing.TestCases import make_suite -from spatialdata.units.Nondimensional import Nondimensional - -from pythia.pyre.units.length import meter -from pythia.pyre.units.pressure import pascal -from pythia.pyre.units.time import second -from pythia.pyre.units.mass import kilogram -from pythia.pyre.units.temperature import kelvin - - -class TestNondimensional(unittest.TestCase): - - def test_constructor(self): - dim = Nondimensional() - dim._configure() - - self.assertEqual(1.0 * meter, dim.getLengthScale()) - self.assertEqual(1.0 * pascal, dim.getPressureScale()) - self.assertEqual(1.0 * second, dim.getTimeScale()) - self.assertEqual(1.0 * kilogram / meter**3, dim.getDensityScale()) - self.assertEqual(1.0 * kelvin, dim.getTemperatureScale()) - - def test_lengthScale(self): - dim = Nondimensional() - dim._configure() - dim.setLengthScale(2.0 * meter) - - self.assertEqual(2.0 * meter, dim.getLengthScale()) - self.assertEqual(1.0 * pascal, dim.getPressureScale()) - self.assertEqual(1.0 * second, dim.getTimeScale()) - self.assertEqual(1.0 * kilogram / meter**3, dim.getDensityScale()) - - def test_pressureScale(self): - dim = Nondimensional() - dim._configure() - dim.setPressureScale(2.0 * pascal) - - self.assertEqual(1.0 * meter, dim.getLengthScale()) - self.assertEqual(2.0 * pascal, dim.getPressureScale()) - self.assertEqual(1.0 * second, dim.getTimeScale()) - self.assertEqual(1.0 * kilogram / meter**3, dim.getDensityScale()) - - def test_timeScale(self): - dim = Nondimensional() - dim._configure() - dim.setTimeScale(2.0 * second) - - self.assertEqual(1.0 * meter, dim.getLengthScale()) - self.assertEqual(1.0 * pascal, dim.getPressureScale()) - self.assertEqual(2.0 * second, dim.getTimeScale()) - self.assertEqual(1.0 * kilogram / meter**3, dim.getDensityScale()) - - def test_densityScale(self): - dim = Nondimensional() - dim._configure() - dim.setDensityScale(2.0 * kilogram / meter**3) - - self.assertEqual(1.0 * meter, dim.getLengthScale()) - self.assertEqual(1.0 * pascal, dim.getPressureScale()) - self.assertEqual(1.0 * second, dim.getTimeScale()) - self.assertEqual(2.0 * kilogram / meter**3, dim.getDensityScale()) - - def test_temperatureScale(self): - dim = Nondimensional() - dim._configure() - dim.setTemperatureScale(2.0 * kelvin) - - self.assertEqual(1.0 * meter, dim.getLengthScale()) - self.assertEqual(1.0 * pascal, dim.getPressureScale()) - self.assertEqual(1.0 * second, dim.getTimeScale()) - self.assertEqual(2.0 * kelvin, dim.getTemperatureScale()) - - def test_nondimensionalize(self): - dim = Nondimensional() - dim._configure() - - scale = 8.0 * meter - value = 2.0 * meter - valueE = 0.25 - - self.assertEqual(valueE, dim.nondimensionalize(value, scale)) - - def test_dimensionalize(self): - dim = Nondimensional() - dim._configure() - - scale = 8.0 * meter - value = 0.25 - valueE = 2.0 * meter - - self.assertEqual(valueE, dim.dimensionalize(value, scale)) - - -def load_tests(loader, tests, pattern): - TEST_CLASSES = [TestNondimensional] - return make_suite(test_classes=TEST_CLASSES, loader=loader) - - -if __name__ == "__main__": - unittest.main(verbosity=2) - - -# End of file diff --git a/tests/pytests/units/test_units.py b/tests/pytests/units/test_units.py deleted file mode 100755 index b92deacd..00000000 --- a/tests/pytests/units/test_units.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env nemesis -# ================================================================================================= -# This code is part of SpatialData, developed through the Computational Infrastructure -# for Geodynamics (https://github.com/geodynamics/spatialdata). -# -# Copyright (c) 2010-2025, University of California, Davis and the SpatialData Development Team. -# All rights reserved. -# -# See https://mit-license.org/ and LICENSE.md and for license information. -# ================================================================================================= - -from spatialdata.testing.UnitTestApp import UnitTestApp - - -import TestNondimensional -import TestNondimElasticQuasistatic -import TestNondimElasticDynamic - - -TEST_MODULES = [ - TestNondimensional, - TestNondimElasticQuasistatic, - TestNondimElasticDynamic -] - - -if __name__ == '__main__': - app = UnitTestApp(test_modules=TEST_MODULES, src_dirs=["spatialdata.units"]) - app.run() - - -# End of file