Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Özgür Ozan Sen
ogs
Commits
7a385f6c
Commit
7a385f6c
authored
8 years ago
by
Norihiro Watanabe
Committed by
Norihiro Watanabe
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[Mesh] add ConvertToLinearMesh
parent
a26f38ab
No related branches found
No related tags found
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MeshLib/MeshEditing/ConvertToLinearMesh.cpp
+107
-0
107 additions, 0 deletions
MeshLib/MeshEditing/ConvertToLinearMesh.cpp
MeshLib/MeshEditing/ConvertToLinearMesh.h
+25
-0
25 additions, 0 deletions
MeshLib/MeshEditing/ConvertToLinearMesh.h
with
132 additions
and
0 deletions
MeshLib/MeshEditing/ConvertToLinearMesh.cpp
0 → 100644
+
107
−
0
View file @
7a385f6c
/**
* \copyright
* Copyright (c) 2012-2016, 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
"ConvertToLinearMesh.h"
#include
"MeshLib/Elements/Element.h"
#include
"MeshLib/Elements/Line.h"
#include
"MeshLib/Elements/Quad.h"
#include
"MeshLib/Elements/Utils.h"
#include
"MeshLib/Mesh.h"
#include
"MeshLib/MeshEditing/DuplicateMeshComponents.h"
#include
"MeshLib/Node.h"
#include
"MeshLib/Properties.h"
#include
"MeshLib/PropertyVector.h"
namespace
MeshLib
{
namespace
{
template
<
typename
T_ELEMENT
>
T_ELEMENT
*
createLinearElement
(
MeshLib
::
Element
const
*
e
,
std
::
vector
<
MeshLib
::
Node
*>
const
&
vec_new_nodes
)
{
auto
const
n_base_nodes
=
T_ELEMENT
::
n_base_nodes
;
MeshLib
::
Node
**
nodes
=
new
MeshLib
::
Node
*
[
n_base_nodes
];
for
(
unsigned
i
=
0
;
i
<
e
->
getNumberOfBaseNodes
();
i
++
)
nodes
[
i
]
=
const_cast
<
MeshLib
::
Node
*>
(
vec_new_nodes
[
e
->
getNode
(
i
)
->
getID
()]);
return
new
T_ELEMENT
(
nodes
);
}
}
// unnamed namespace
std
::
unique_ptr
<
MeshLib
::
Mesh
>
convertToLinearMesh
(
MeshLib
::
Mesh
const
&
org_mesh
,
std
::
string
const
&
new_mesh_name
)
{
std
::
vector
<
MeshLib
::
Node
*>
vec_new_nodes
=
MeshLib
::
copyNodeVector
(
MeshLib
::
getBaseNodes
(
org_mesh
.
getElements
()));
// create new elements with the quadratic nodes
std
::
vector
<
MeshLib
::
Element
*>
vec_new_eles
;
for
(
MeshLib
::
Element
const
*
e
:
org_mesh
.
getElements
())
{
if
(
e
->
getCellType
()
==
MeshLib
::
CellType
::
LINE3
)
{
vec_new_eles
.
push_back
(
createLinearElement
<
MeshLib
::
Line
>
(
e
,
vec_new_nodes
));
}
else
if
(
e
->
getCellType
()
==
MeshLib
::
CellType
::
QUAD8
)
{
vec_new_eles
.
push_back
(
createLinearElement
<
MeshLib
::
Quad
>
(
e
,
vec_new_nodes
));
}
else
{
OGS_FATAL
(
"Mesh element type %s is not supported"
,
MeshLib
::
CellType2String
(
e
->
getCellType
()).
c_str
());
}
}
std
::
unique_ptr
<
MeshLib
::
Mesh
>
new_mesh
(
new
MeshLib
::
Mesh
(
new_mesh_name
,
vec_new_nodes
,
vec_new_eles
,
org_mesh
.
getProperties
().
excludeCopyProperties
(
std
::
vector
<
MeshLib
::
MeshItemType
>
(
1
,
MeshLib
::
MeshItemType
::
Node
))));
MeshLib
::
Properties
const
&
src_properties
=
org_mesh
.
getProperties
();
for
(
auto
name
:
src_properties
.
getPropertyVectorNames
())
{
auto
const
*
src_prop
=
src_properties
.
getPropertyVector
<
double
>
(
name
);
if
(
!
src_prop
)
continue
;
if
(
src_prop
->
getMeshItemType
()
!=
MeshLib
::
MeshItemType
::
Node
)
continue
;
auto
const
n_src_comp
=
src_prop
->
getNumberOfComponents
();
// convert 2D vector to 3D. Otherwise Paraview Calculator filter does not recognize
// it as a vector
auto
const
n_dest_comp
=
(
n_src_comp
==
2
)
?
3
:
n_src_comp
;
auto
new_prop
=
new_mesh
->
getProperties
().
createNewPropertyVector
<
double
>
(
name
,
MeshLib
::
MeshItemType
::
Node
,
n_dest_comp
);
new_prop
->
resize
(
new_mesh
->
getNumberOfNodes
()
*
n_dest_comp
);
// copy existing
for
(
unsigned
i
=
0
;
i
<
org_mesh
.
getNumberOfBaseNodes
();
i
++
)
{
for
(
unsigned
j
=
0
;
j
<
n_src_comp
;
j
++
)
(
*
new_prop
)[
i
*
n_dest_comp
+
j
]
=
(
*
src_prop
)[
i
*
n_src_comp
+
j
];
// set zero for components not existing in the original
for
(
unsigned
j
=
n_src_comp
;
j
<
n_dest_comp
;
j
++
)
(
*
new_prop
)[
i
*
n_dest_comp
+
j
]
=
0
;
}
}
return
new_mesh
;
}
}
// end namespace MeshLib
This diff is collapsed.
Click to expand it.
MeshLib/MeshEditing/ConvertToLinearMesh.h
0 → 100644
+
25
−
0
View file @
7a385f6c
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef MESHLIB_CONVERRTTOLINEARMESH_H_
#define MESHLIB_CONVERRTTOLINEARMESH_H_
#include
<memory>
#include
<string>
namespace
MeshLib
{
class
Mesh
;
std
::
unique_ptr
<
MeshLib
::
Mesh
>
convertToLinearMesh
(
const
MeshLib
::
Mesh
&
mesh
,
const
std
::
string
&
new_mesh_name
);
}
// end namespace MeshLib
#endif //MESHLIB_CONVERRTTOLINEARMESH_H_
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment