Skip to content

Commit

Permalink
refactor code (mSize). now works with vertex and edge (#21)
Browse files Browse the repository at this point in the history
* refactor code (mSize). now works with vertex and edge

* fix cube

* Refactor lists

* Fix unreachable warning

* Make cast explicit

* address review

* fix example

Co-authored-by: Thomas-Ulrich <thomas.ulrich@geophysik.uni-muenchen.de>
Co-authored-by: Sebastian Wolf <wolf.sebastian@in.tum.de>
  • Loading branch information
3 people committed Nov 17, 2020
1 parent efd3979 commit 498ab01
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 56 deletions.
2 changes: 2 additions & 0 deletions XmlExample/meshAttributes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<boundaryCondition tag="7">7</boundaryCondition>
<boundaryCondition tag="8">8,9</boundaryCondition>
<globalMSize value="100e3"/>
<vertexMSize value="1000">1,2</vertexMSize>
<edgeMSize value="500">4,8</edgeMSize>
<surfaceMSize value="20e3">1,2</surfaceMSize>
<surfaceMSize value="10e3">3,4</surfaceMSize>
<regionMSize value="15e3">1</regionMSize>
Expand Down
57 changes: 47 additions & 10 deletions src/input/MeshAttributes.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "MeshAttributes.h"


MeshAttributes::MeshAttributes():
lpair_lVertexId_MSize(), lpair_lEdgeId_MSize(), lpair_lFaceId_MSize(), lpair_lRegionId_MSize() {
}

MeshAttributes::MeshAttributes(const char* xmlFilename) {
init(xmlFilename);
}
Expand All @@ -10,6 +15,8 @@ void MeshAttributes::init(const char* xmlFilename) {
set_SurfaceMeshingAttributes();
set_VolumeMeshingAttributes();
set_UseDiscreteMesh();
set_vertexMSize();
set_edgeMSize();
set_surfaceMSize();
set_MeshSizePropagation();
set_regionMSize();
Expand All @@ -23,16 +30,16 @@ void MeshAttributes::readXmlFile(const char* xmlFilename) {
}

void MeshAttributes::set_MeshRefinementZoneCube() {
std::string xyz = "xyz";
for (auto child = doc.FirstChildElement("MeshRefinementZoneCube"); child; child = child->NextSiblingElement("MeshRefinementZoneCube"))
{
Cube mycube;
mycube.CubeMSize = std::atof(child->Attribute("value"));
for (std::string::size_type i = 0; i < xyz.size(); i++) {
update_attribute_from_xml(*child, "Center", &xyz[i], mycube.CubeCenter[i]);
update_attribute_from_xml(*child, "Width", &xyz[i], mycube.CubeWidth[i]);
update_attribute_from_xml(*child, "Height", &xyz[i], mycube.CubeHeight[i]);
update_attribute_from_xml(*child, "Depth", &xyz[i], mycube.CubeDepth[i]);
for (char i = 0; i < 3; i++) {
char xyz[] = {static_cast<char>('x' + i), '\0'};
update_attribute_from_xml(*child, "Center", xyz, mycube.CubeCenter[i]);
update_attribute_from_xml(*child, "Width", xyz, mycube.CubeWidth[i]);
update_attribute_from_xml(*child, "Height", xyz, mycube.CubeHeight[i]);
update_attribute_from_xml(*child, "Depth", xyz, mycube.CubeDepth[i]);
}
lCube.push_back(mycube);
}
Expand Down Expand Up @@ -81,12 +88,24 @@ void MeshAttributes::set_UseDiscreteMesh() {
}
}

void MeshAttributes::set_vertexMSize() {
for (auto child = doc.FirstChildElement("vertexMSize"); child; child = child->NextSiblingElement("vertexMSize"))
{
lpair_lVertexId_MSize.push_back(std::make_pair(fill_list_using_parsed_string(child-> GetText()), std::atof(child->Attribute("value"))));
}
}

void MeshAttributes::set_edgeMSize() {
for (auto child = doc.FirstChildElement("edgeMSize"); child; child = child->NextSiblingElement("edgeMSize"))
{
lpair_lEdgeId_MSize.push_back(std::make_pair(fill_list_using_parsed_string(child-> GetText()), std::atof(child->Attribute("value"))));
}
}

void MeshAttributes::set_surfaceMSize() {
for (auto child = doc.FirstChildElement("surfaceMSize"); child; child = child->NextSiblingElement("surfaceMSize"))
{
lsurfaceMSize.push_back( std::atof(child->Attribute("value")));
llsurfaceMSizeFaceId.push_back(fill_list_using_parsed_string(child-> GetText()));
lpair_lFaceId_MSize.push_back(std::make_pair(fill_list_using_parsed_string(child-> GetText()), std::atof(child->Attribute("value"))));
}
}

Expand All @@ -103,8 +122,7 @@ void MeshAttributes::set_MeshSizePropagation() {
void MeshAttributes::set_regionMSize() {
for (auto child = doc.FirstChildElement("regionMSize"); child; child = child->NextSiblingElement("regionMSize"))
{
lregionMSize.push_back( std::atof(child->Attribute("value")));
llregionMSizeRegionId.push_back(fill_list_using_parsed_string(child-> GetText()));
lpair_lRegionId_MSize.push_back(std::make_pair(fill_list_using_parsed_string(child-> GetText()), std::atof(child->Attribute("value"))));
}
}

Expand All @@ -117,6 +135,25 @@ void MeshAttributes::set_global_mesh_attributes() {

}

const std::list<std::pair<std::list<int>, double>>& MeshAttributes::getMSizeList(ElementType type) {
switch(type) {
case ElementType::vertex:
return lpair_lVertexId_MSize;
break;
case ElementType::edge:
return lpair_lEdgeId_MSize;
break;
case ElementType::face:
return lpair_lFaceId_MSize;
break;
case ElementType::region:
return lpair_lRegionId_MSize;
break;
default:
__builtin_unreachable();
break;
}
}

void MeshAttributes::update_attribute_from_xml(XMLNode& element, const char* sElementName, const char* sAttributeName, double& MeshAttributesMember) {
if (auto child = element.FirstChildElement(sElementName)) {
Expand Down
22 changes: 17 additions & 5 deletions src/input/MeshAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ struct Cube {
double CubeMSize=0,CubeCenter[3],CubeWidth[3],CubeHeight[3],CubeDepth[3];
};

enum class ElementType {
vertex = 0,
edge = 1,
face = 2,
region = 3
};


using namespace tinyxml2;
class MeshAttributes {
Expand All @@ -32,16 +39,19 @@ class MeshAttributes {
SmoothingType volumeSmoothingType = SmoothingType::Gradient;
int VolumeMesherOptimization=1;
double globalMSize=0., faultMSize=0., gradation=0., vol_AspectRatio=0., area_AspectRatio=0.;
std::list<double> lsurfaceMSize;
std::list <std::list<int>> llsurfaceMSizeFaceId;
std::list<double> lregionMSize;
std::list <std::list<int>> llregionMSizeRegionId;
const std::list<std::pair<std::list<int>, double>>& getMSizeList(ElementType type);

std::list <std::pair <std::list<int>, double>> lpair_lVertexId_MSize;
std::list <std::pair <std::list<int>, double>> lpair_lEdgeId_MSize;
std::list <std::pair <std::list<int>, double>> lpair_lFaceId_MSize;
std::list <std::pair <std::list<int>, double>> lpair_lRegionId_MSize;

std::list<Cube> lCube;
std::list<int> lFaceIdMeshSizePropagation;
std::list<int> lFaceIdUseDiscreteMesh;
int UseDiscreteMesh_noModification;
double MeshSizePropagationScalingFactor,MeshSizePropagationDistance=0.0;
MeshAttributes() {};
MeshAttributes();
MeshAttributes(const char*);
void init(const char*);

Expand All @@ -52,6 +62,8 @@ class MeshAttributes {
void set_SurfaceMeshingAttributes();
void set_VolumeMeshingAttributes();
void set_UseDiscreteMesh();
void set_vertexMSize();
void set_edgeMSize();
void set_surfaceMSize();
void set_MeshSizePropagation();
void set_regionMSize();
Expand Down
70 changes: 29 additions & 41 deletions src/input/SimModSuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,32 @@ struct get_second : public std::unary_function<MyMap::value_type, int>
}
};


void setMeshSize(pGModel model, pACase &meshCase, MeshAttributes &MeshAtt) {
// Set mesh size on vertices, edges, surfaces and regions
const char *element_name[4] = { "vertex", "edge", "face", "region" };
const ElementType element_type[4] = { ElementType::vertex, ElementType::edge, ElementType::face, ElementType::region };

for (int element_type_id = 0; element_type_id < 4; element_type_id ++)
{
std::list <std::pair <std::list<int>, double>> lpair_lId_MSize = MeshAtt.getMSizeList(element_type[element_type_id]);
for (const auto& pair_lId_MSize : lpair_lId_MSize) {
double MSize = pair_lId_MSize.second;
std::list<int> lElements = pair_lId_MSize.first;
for (const auto& element_id : lElements) {
pGEntity entity = GM_entityByTag(model, element_type_id, element_id);
if (entity == NULL) {
logError() << element_name[element_type_id] << "id:" << element_id << "not found in model.";
} else {
MS_setMeshSize(meshCase, entity, 1, MSize, NULL);
logInfo(PMU_rank()) << element_name[element_type_id] << "id:"<<element_id <<", MSize =" << MSize;
}
}
}
}
}


void setCases(pGModel model, pACase &meshCase, pACase &analysisCase, MeshAttributes &MeshAtt, AnalysisAttributes &AnalysisAtt) {

logInfo(PMU_rank()) << "Setting cases";
Expand Down Expand Up @@ -432,48 +458,10 @@ void setCases(pGModel model, pACase &meshCase, pACase &analysisCase, MeshAttribu
// ( <meshing case>, <entity>, <1=absolute, 2=relative>, <size>, <size expression> )
MS_setMeshSize(meshCase, modelDomain, 1, MeshAtt.globalMSize, NULL);
}

// Set mesh size on surfaces
std::list< std::list<int>>::iterator itr;
std::list<double>::iterator itMeshSize;
itMeshSize = MeshAtt.lsurfaceMSize.begin();
for (itr=MeshAtt.llsurfaceMSizeFaceId.begin(); itr != MeshAtt.llsurfaceMSizeFaceId.end(); itr++)
{
double surfaceMSize = *itMeshSize;
std::list<int>tl=*itr;
std::list<int>::iterator it;
for (it=tl.begin(); it != tl.end(); it++)
{
pGEntity face = GM_entityByTag(model, 2, *it);
if (face == NULL) {
logError() << "faceid:"<<*it <<"not found in model.";
} else {
MS_setMeshSize(meshCase, face, 1, surfaceMSize, NULL);
logInfo(PMU_rank()) << "faceid:"<<*it <<", surfaceMSize =" << surfaceMSize;
}
}
itMeshSize++;
}

// Set mesh size on region
itMeshSize = MeshAtt.lregionMSize.begin();
for (itr=MeshAtt.llregionMSizeRegionId.begin(); itr != MeshAtt.llregionMSizeRegionId.end(); itr++)
{
double regionMSize = *itMeshSize;
std::list<int>tl=*itr;
std::list<int>::iterator it;
for (it=tl.begin(); it != tl.end(); it++)
{
pGRegion region = (pGRegion) GM_entityByTag(model, 3, *it);
if (region == NULL) {
logError() << "regionid:"<<*it <<"not found in model.";
} else {
MS_setMeshSize(meshCase, region, 1, regionMSize, NULL);
logInfo(PMU_rank()) << "regionid:"<<*it <<", regionMSize =" << regionMSize;
}
}
itMeshSize++;
}
// Set mesh size on vertices, edges, surfaces and regions
setMeshSize(model, meshCase, MeshAtt);

if (MeshAtt.gradation>0) {
// Set gradation relative
logInfo(PMU_rank()) << "Gradation rate =" << MeshAtt.gradation;
Expand Down

0 comments on commit 498ab01

Please sign in to comment.