Skip to content
Snippets Groups Projects
Commit fd0e96de authored by Karsten Rink's avatar Karsten Rink Committed by Dmitri Naumov
Browse files

added data structures and read method for fem-conditions in data explorer

parent 8472a483
No related branches found
No related tags found
No related merge requests found
/**
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*
*/
#pragma once
#include "Applications/DataHolderLib/Condition.h"
namespace DataHolderLib
{
class BoundaryCondition : public DataHolderLib::Condition
{
public:
BoundaryCondition(std::string const process_var, std::string const param_name, ConditionType type)
: Condition(process_var, param_name, type)
{}
private:
};
} // namespace
/**
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*
*/
#include "Condition.h"
namespace DataHolderLib
{
Condition::Condition(std::string const process_var, std::string const param_name, ConditionType type)
: _type(type), _process_var(process_var), _param_name(param_name)
{};
Condition::Condition(Condition const& c)
: _base_type(c.getBaseObjType()), _type(c.getType()),
_process_var(c.getProcessVarName()), _param_name(c.getParamName()),
_base_obj_name(c.getBaseObjName()), _obj_name(c.getObjName())
{}
void Condition::setMesh(std::string const mesh_name)
{
_base_type = BaseObjType::MESH;
_base_obj_name = mesh_name;
_obj_name = "";
}
void Condition::setGeoObject(std::string geo_name, std::string obj_name)
{
_base_type = BaseObjType::GEOMETRY;
_base_obj_name = geo_name;
_obj_name = obj_name;
}
ConditionType Condition::convertStringToType(std::string const& str)
{
if ( str == "Dirichlet")
return ConditionType::DIRICHLET;
else if (str == "NonlinearDirichlet")
return ConditionType::NONLINEARDIRICHLET;
else if (str == "Neumann")
return ConditionType::NEUMANN;
else if (str == "NonuniformNeumann")
return ConditionType::NONLINEARNEUMANN;
else if (str == "Robin")
return ConditionType::ROBIN;
return ConditionType::NONE;
}
std::string Condition::convertTypeToString(ConditionType type)
{
if (type == ConditionType::DIRICHLET)
return "Dirichlet";
else if (type == ConditionType::NONLINEARDIRICHLET)
return "NonlinearDirichlet";
else if (type == ConditionType::NEUMANN)
return "Neumann";
else if (type == ConditionType::NONLINEARDIRICHLET)
return "NonlinearNeumann";
else if (type == ConditionType::ROBIN)
return "Robin";
return "";
}
} // namespace
/**
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*
*/
#pragma once
#include <string>
namespace DataHolderLib
{
enum class BaseObjType
{
MESH = 0,
GEOMETRY = 1
};
enum class ConditionType
{
NONE = 0,
DIRICHLET,
NONLINEARDIRICHLET,
NEUMANN,
NONLINEARNEUMANN,
ROBIN
};
enum class ParameterType
{
NONE,
CONSTANT,
FUNCTION
};
class Condition
{
public:
Condition(std::string const process_var, std::string const param_name, ConditionType type);
Condition(Condition const& c);
~Condition() {};
/// Returns the name of the associated process variable
std::string const getProcessVarName() const { return _process_var; }
std::string const getParamName() const { return _param_name; }
/// Is the condition set a geometry or on a mesh
BaseObjType getBaseObjType() const { return _base_type; }
///Returns the name of the base object (i.e. geometry or mesh)
std::string getBaseObjName() const { return _base_obj_name; }
///Returns the name of the geometric object
std::string const getObjName() const { return _obj_name; }
ConditionType getType() const { return _type; }
void setMesh(std::string const mesh_name);
virtual void setGeoObject(std::string geo_name, std::string obj_name);
static std::string convertTypeToString(ConditionType type);
static ConditionType convertStringToType(std::string const& type_str);
private:
BaseObjType _base_type;
ConditionType _type;
std::string _process_var;
std::string _param_name;
std::string _base_obj_name;
std::string _obj_name;
};
} // namespace
/**
* \file
* \author Karsten Rink
* \date 2010-02-04
* \brief Definition of the Color class.
*
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*
*/
#pragma once
#include <array>
#include <map>
#include <string>
namespace DataHolderLib
{
using Color = std::array<unsigned char, 4>;
Color createColor(unsigned char r, unsigned char g, unsigned char b);
Color createColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
/// Returns a random RGB colour.
Color getRandomColor();
/// Uses a color-lookup-table (in form of a map) to return a colour for a specified name. If the name is not
/// in the colortable a new entry is created with the new name and a random colour.
Color const getColor(const std::string &id, std::map<std::string, DataHolderLib::Color> &colors);
/// Convenience function to use the getColor method with numbers as identifiers.
Color const getColor(double id, std::map<std::string, DataHolderLib::Color> &colors);
} // namespace
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#include "MeshLib/Mesh.h" #include "MeshLib/Mesh.h"
#include "Applications/DataHolderLib/BoundaryCondition.h"
#include "Applications/DataHolderLib/SourceTerm.h"
//namespace MeshLib { //namespace MeshLib {
// class Mesh; // class Mesh;
//} //}
...@@ -59,6 +63,14 @@ public: ...@@ -59,6 +63,14 @@ public:
/// false otherwise. /// false otherwise.
bool removeMesh(const std::string &name); bool removeMesh(const std::string &name);
void addBoundaryCondition(BoundaryCondition bc) { _boundary_conditions.push_back(bc); }
std::vector<BoundaryCondition> const getBoundaryConditions() const { return _boundary_conditions; }
void addSourceTerm(SourceTerm bc) { _source_terms.push_back(bc); }
std::vector<SourceTerm> const getSourceTerms() const { return _source_terms; }
private: private:
/// Checks if a mesh with the same name exists and provides a unique name in /// Checks if a mesh with the same name exists and provides a unique name in
/// case of already existing mesh. Returns true if the mesh name is unique. /// case of already existing mesh. Returns true if the mesh name is unique.
...@@ -77,6 +89,10 @@ private: ...@@ -77,6 +89,10 @@ private:
GeoLib::GEOObjects _geoObjects; GeoLib::GEOObjects _geoObjects;
std::vector<std::unique_ptr<MeshLib::Mesh>> _mesh_vec; std::vector<std::unique_ptr<MeshLib::Mesh>> _mesh_vec;
std::vector<BoundaryCondition> _boundary_conditions;
std::vector<SourceTerm> _source_terms;
}; };
} // namespace } // namespace
/**
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*
*/
#pragma once
#include "Applications/DataHolderLib/Condition.h"
namespace DataHolderLib
{
class SourceTerm : public DataHolderLib::Condition
{
public:
SourceTerm(std::string const process_var, std::string const param_name, ConditionType type)
: Condition(process_var, param_name, type)
{}
private:
};
} // namespace
...@@ -2,56 +2,89 @@ ...@@ -2,56 +2,89 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- OpenGeoSysProject schema; initial implementation: Karsten Rink, 2010-08-20 --> <!-- OpenGeoSysProject schema; initial implementation: Karsten Rink, 2010-08-20 -->
<xs:element name="name" type="xs:string" />
<!-- object containing just a source file definition --> <!-- definition of processes -->
<xs:complexType name="projectElement"> <xs:complexType name="processType">
<xs:sequence> <xs:sequence>
<xs:element name="file" type="xs:string" minOccurs="1" maxOccurs="1" /> <xs:element ref="name" minOccurs="1" maxOccurs="1" />
<xs:element name="type" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="integration_order" minOccurs="1" maxOccurs="1" />
<xs:element name="process_variables" minOccurs="1" maxOccurs="1" />
<xs:element name="secondary_variables" minOccurs="0" maxOccurs="1" />
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
<!-- object containing a required reference to a geometry file --> <xs:complexType name="parameterType">
<xs:complexType name="geoElement"> <xs:sequence>
<xs:complexContent> <xs:element ref="name" minOccurs="1" maxOccurs="1" />
<xs:extension base="projectElement"> <xs:element name="type" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:sequence> <xs:element name="value" minOccurs="0" maxOccurs="1" />
<xs:element name="geoReference" type="xs:string"/> <xs:element name="field_name" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:sequence> </xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType> </xs:complexType>
<!-- msh-object with optional geometry- and texture-reference --> <xs:complexType name="conditionType">
<xs:complexType name="mshElement"> <xs:sequence>
<xs:complexContent> <xs:element name="geometrical_set" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:extension base="projectElement"> <xs:element name="geometry" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:sequence> <xs:element name="type" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="geoReference" type="xs:string" minOccurs="0" /> <xs:element name="field_name" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="texture" type="xs:string" minOccurs="0" /> <xs:element name="mesh" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:sequence> <xs:element name="parameter" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:extension> </xs:sequence>
</xs:complexContent>
</xs:complexType> </xs:complexType>
<xs:complexType name="conditionListType">
<xs:sequence>
<xs:element name="boundary_condition" type="conditionType" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="pvariableType">
<xs:sequence>
<xs:element ref="name"/>
<xs:element name="components" type="xs:nonNegativeInteger" minOccurs="1" maxOccurs="1" />
<xs:element name="order" type="xs:nonNegativeInteger" minOccurs="1" maxOccurs="1" />
<xs:element name="initial_condition" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="boundary_conditions" type="conditionListType" minOccurs="0" maxOccurs="1" />
<xs:element name="source_terms" type="conditionListType" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<!-- definition of file content --> <!-- definition of file content -->
<xs:element name="OpenGeoSysProject"> <xs:element name="OpenGeoSysProject">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:all>
<xs:element name="geo" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:element name="mesh" minOccurs="0">
<xs:element name="msh" type="mshElement" minOccurs="0" maxOccurs="unbounded" /> <xs:complexType>
<xs:element name="cnd" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:simpleContent>
<xs:element name="mfp" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:extension base="xs:string">
<xs:element name="mmp" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:attribute name="axially_symmetric" type="xs:boolean"/>
<xs:element name="msp" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> </xs:extension>
<xs:element name="np" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> </xs:simpleContent>
<xs:element name="out" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> </xs:complexType>
<xs:element name="pcs" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> </xs:element>
<xs:element name="sim" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:element name="geometry" type="xs:string" minOccurs="0"/>
<xs:element name="tim" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:element name="processes" minOccurs="0"/> <!--ignore-->
<xs:element name="fct" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:element name="time_loop" minOccurs="0"/> <!--ignore-->
<xs:element name="stn" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:element name="parameters" minOccurs="0">
</xs:sequence> <xs:complexType>
<xs:sequence>
<xs:element name="parameter" type="parameterType" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="process_variables" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="process_variable" type="pvariableType" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="nonlinear_solvers" minOccurs="0"/> <!--ignore-->
<xs:element name="linear_solvers" minOccurs="0"/> <!--ignore-->
</xs:all>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
......
/**
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*
*/
#include <cstdio>
#include "gtest/gtest.h"
#include "BaseLib/BuildInfo.h"
#include "Applications/FileIO/XmlIO/Qt/XmlPrjInterface.h"
#include "Applications/DataHolderLib/Project.h"
#include "Applications/DataHolderLib/BoundaryCondition.h"
#include "Applications/DataHolderLib/SourceTerm.h"
#include "GeoLib/GEOObjects.h"
TEST(TestQtPrjInterface, QtXmlPrjReader)
{
typedef struct
{
std::string const file_name;
std::size_t n_geo;
std::size_t n_mesh;
std::size_t n_bc;
std::size_t n_st;
} TestParams;
std::vector<TestParams> test_files;
std::string name = BaseLib::BuildInfo::data_path + "/Elliptic/nonuniform_bc_Groundwaterflow/neumann_nonuniform.prj";
test_files.push_back({ name, 1, 1, 2, 0 });
name = BaseLib::BuildInfo::data_path + "/Elliptic/nonuniform_bc_Groundwaterflow/neumann_nonuniform.prj";
test_files.push_back({ name, 1, 1, 2, 0 });
for (std::size_t i=0; i<test_files.size(); ++i)
{
DataHolderLib::Project project;
FileIO::XmlPrjInterface xml(project);
int result = xml.readFile(QString::fromStdString(test_files[i].file_name));
EXPECT_EQ(1, result);
std::vector<std::string> geo_names;
project.getGEOObjects().getGeometryNames(geo_names);
EXPECT_EQ(test_files[i].n_geo, geo_names.size());
EXPECT_EQ(test_files[i].n_mesh, project.getMeshObjects().size());
std::vector<DataHolderLib::BoundaryCondition> const bcs = project.getBoundaryConditions();
EXPECT_EQ(test_files[i].n_bc, bcs.size());
for (DataHolderLib::BoundaryCondition bc : bcs)
{
EXPECT_FALSE(bc.getProcessVarName().empty());
EXPECT_FALSE(bc.getParamName().empty());
EXPECT_FALSE(DataHolderLib::ConditionType::NONE == bc.getType());
EXPECT_FALSE(bc.getBaseObjName().empty());
if (bc.getBaseObjType() == DataHolderLib::BaseObjType::GEOMETRY)
EXPECT_FALSE(bc.getObjName().empty());
}
std::vector<DataHolderLib::SourceTerm> const sts = project.getSourceTerms();
EXPECT_EQ(test_files[i].n_st, sts.size());
for (DataHolderLib::SourceTerm st : sts)
{
EXPECT_FALSE(st.getProcessVarName().empty());
EXPECT_FALSE(st.getParamName().empty());
EXPECT_FALSE(DataHolderLib::ConditionType::NONE == st.getType());
EXPECT_FALSE(st.getBaseObjName().empty());
if (st.getBaseObjType() == DataHolderLib::BaseObjType::GEOMETRY)
EXPECT_FALSE(st.getObjName().empty());
}
}
}
...@@ -135,7 +135,8 @@ if(WIN32) ...@@ -135,7 +135,8 @@ if(WIN32)
/wd4267 /wd4996 /bigobj") /wd4267 /wd4996 /bigobj")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} \ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} \
/ZI /Od /Ob0") /ZI /Od /Ob0")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /ignore:4099")
DisableCompilerFlag(DEBUG /RTC1) DisableCompilerFlag(DEBUG /RTC1)
# cygwin # cygwin
else() else()
......
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