Skip to content
Snippets Groups Projects
Commit f14097e8 authored by wenqing's avatar wenqing Committed by Dmitri Naumov
Browse files

[ParameterLib] Moved parseLocalCoordinateSystem to a new file

and renamed to createCoordinateSystem
parent c773a805
No related branches found
No related tags found
No related merge requests found
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h" #include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h"
#include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/readMeshFromFile.h"
#include "ParameterLib/ConstantParameter.h" #include "ParameterLib/ConstantParameter.h"
#include "ParameterLib/CreateCoordinateSystem.h"
#include "ParameterLib/Utils.h" #include "ParameterLib/Utils.h"
#include "ProcessLib/CreateTimeLoop.h" #include "ProcessLib/CreateTimeLoop.h"
#include "ProcessLib/TimeLoop.h" #include "ProcessLib/TimeLoop.h"
...@@ -322,62 +323,6 @@ std::vector<GeoLib::NamedRaster> readRasters( ...@@ -322,62 +323,6 @@ std::vector<GeoLib::NamedRaster> readRasters(
// } // }
//} //}
std::optional<ParameterLib::CoordinateSystem> parseLocalCoordinateSystem(
std::optional<BaseLib::ConfigTree> const& config,
std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
{
if (!config)
{
return {};
}
DBUG("Reading coordinate system configuration.");
//
// Fetch the first basis vector; its length defines the dimension.
//
auto const& basis_vector_0 = ParameterLib::findParameter<double>(
*config,
//! \ogs_file_param_special{prj__local_coordinate_system__basis_vector_0}
"basis_vector_0", parameters, 0 /* any dimension */);
int const dimension = basis_vector_0.getNumberOfGlobalComponents();
// check dimension
if (dimension != 2 && dimension != 3)
{
OGS_FATAL(
"Basis vector parameter '{:s}' must have two or three components, "
"but it has {:d}.",
basis_vector_0.name, dimension);
}
//
// Fetch the second basis vector, which must be of the same dimension as the
// first one.
//
auto const& basis_vector_1 = ParameterLib::findParameter<double>(
*config,
//! \ogs_file_param_special{prj__local_coordinate_system__basis_vector_1}
"basis_vector_1", parameters, dimension);
//
// For two dimensions, we are done; construct coordinate system;
//
if (dimension == 2)
{
return ParameterLib::CoordinateSystem{basis_vector_0, basis_vector_1};
}
//
// Parse the third vector, for three dimensions.
//
auto const& basis_vector_2 = ParameterLib::findParameter<double>(
*config,
//! \ogs_file_param_special{prj__local_coordinate_system__basis_vector_2}
"basis_vector_2", parameters, dimension);
return ParameterLib::CoordinateSystem{basis_vector_0, basis_vector_1,
basis_vector_2};
}
} // namespace } // namespace
ProjectData::ProjectData() = default; ProjectData::ProjectData() = default;
...@@ -432,7 +377,7 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config, ...@@ -432,7 +377,7 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config,
//! \ogs_file_param{prj__parameters} //! \ogs_file_param{prj__parameters}
parseParameters(project_config.getConfigSubtree("parameters")); parseParameters(project_config.getConfigSubtree("parameters"));
_local_coordinate_system = parseLocalCoordinateSystem( _local_coordinate_system = ParameterLib::createCoordinateSystem(
//! \ogs_file_param{prj__local_coordinate_system} //! \ogs_file_param{prj__local_coordinate_system}
project_config.getConfigSubtreeOptional("local_coordinate_system"), project_config.getConfigSubtreeOptional("local_coordinate_system"),
_parameters); _parameters);
......
/**
* \file
* \copyright
* Copyright (c) 2012-2024, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* Created on January 25, 2024, 10:49 AM
*/
#include "CreateCoordinateSystem.h"
#include "BaseLib/ConfigTree.h"
#include "Parameter.h"
#include "Utils.h"
namespace ParameterLib
{
struct ParameterBase;
struct CoordinateSystem;
std::optional<ParameterLib::CoordinateSystem> createCoordinateSystem(
std::optional<BaseLib::ConfigTree> const& config,
std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
{
if (!config)
{
return {};
}
DBUG("Reading coordinate system configuration.");
//
// Fetch the first basis vector; its length defines the dimension.
//
auto const& basis_vector_0 = ParameterLib::findParameter<double>(
*config,
//! \ogs_file_param_special{prj__local_coordinate_system__basis_vector_0}
"basis_vector_0", parameters, 0 /* any dimension */);
int const dimension = basis_vector_0.getNumberOfGlobalComponents();
// check dimension
if (dimension != 2 && dimension != 3)
{
OGS_FATAL(
"Basis vector parameter '{:s}' must have two or three components, "
"but it has {:d}.",
basis_vector_0.name, dimension);
}
//
// Fetch the second basis vector, which must be of the same dimension as the
// first one.
//
auto const& basis_vector_1 = ParameterLib::findParameter<double>(
*config,
//! \ogs_file_param_special{prj__local_coordinate_system__basis_vector_1}
"basis_vector_1", parameters, dimension);
//
// For two dimensions, we are done; construct coordinate system;
//
if (dimension == 2)
{
return ParameterLib::CoordinateSystem{basis_vector_0, basis_vector_1};
}
//
// Parse the third vector, for three dimensions.
//
auto const& basis_vector_2 = ParameterLib::findParameter<double>(
*config,
//! \ogs_file_param_special{prj__local_coordinate_system__basis_vector_2}
"basis_vector_2", parameters, dimension);
return ParameterLib::CoordinateSystem{basis_vector_0, basis_vector_1,
basis_vector_2};
}
} // namespace ParameterLib
/**
* \file
* \copyright
* Copyright (c) 2012-2024, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* Created on January 25, 2024, 10:49 AM
*/
#pragma once
#include <memory>
#include <optional>
#include <vector>
namespace BaseLib
{
class ConfigTree;
}
namespace ParameterLib
{
struct ParameterBase;
struct CoordinateSystem;
std::optional<ParameterLib::CoordinateSystem> createCoordinateSystem(
std::optional<BaseLib::ConfigTree> const& config,
std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const&
parameters);
} // namespace ParameterLib
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment