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
6f5b1f97
Commit
6f5b1f97
authored
4 years ago
by
Dmitri Naumov
Browse files
Options
Downloads
Patches
Plain Diff
[PL/LIE] Rewrite property conversion loops.
Extend conversion to more property types.
parent
686a68e6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ProcessLib/LIE/Common/PostUtils.cpp
+125
-84
125 additions, 84 deletions
ProcessLib/LIE/Common/PostUtils.cpp
ProcessLib/LIE/Common/PostUtils.h
+5
-2
5 additions, 2 deletions
ProcessLib/LIE/Common/PostUtils.h
with
130 additions
and
86 deletions
ProcessLib/LIE/Common/PostUtils.cpp
+
125
−
84
View file @
6f5b1f97
...
...
@@ -210,113 +210,154 @@ PostProcessTool::PostProcessTool(
// new mesh
_output_mesh
=
std
::
make_unique
<
MeshLib
::
Mesh
>
(
org_mesh
.
getName
(),
new_nodes
,
new_eles
);
createProperties
<
int
>
();
createProperties
<
double
>
();
copyProperties
<
int
>
();
copyProperties
<
double
>
();
calculateTotalDisplacement
(
vec_vec_fracture_nodes
.
size
(),
vec_junction_nodeID_matIDs
.
size
());
}
template
<
typename
T
>
void
PostProcessTool
::
createProperties
()
{
MeshLib
::
Properties
const
&
src_properties
=
_org_mesh
.
getProperties
();
for
(
auto
name
:
src_properties
.
getPropertyVectorNames
())
for
(
auto
[
name
,
property
]
:
_org_mesh
.
getProperties
())
{
if
(
!
src_properties
.
existsPropertyVector
<
T
>
(
name
))
if
(
auto
p
=
dynamic_cast
<
MeshLib
::
PropertyVector
<
double
>*>
(
property
))
{
co
ntinue
;
co
pyPropertyValues
(
*
p
,
createProperty
(
*
p
))
;
}
auto
const
*
src_prop
=
src_properties
.
getPropertyVector
<
T
>
(
name
);
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
=
MeshLib
::
getOrCreateMeshProperty
<
T
>
(
*
_output_mesh
,
name
,
src_prop
->
getMeshItemType
(),
n_dest_comp
);
if
(
src_prop
->
getMeshItemType
()
==
MeshLib
::
MeshItemType
::
Node
)
else
if
(
auto
p
=
dynamic_cast
<
MeshLib
::
PropertyVector
<
float
>*>
(
property
))
{
copyPropertyValues
(
*
p
,
createProperty
(
*
p
));
}
else
if
(
auto
p
=
dynamic_cast
<
MeshLib
::
PropertyVector
<
int
>*>
(
property
))
{
copyPropertyValues
(
*
p
,
createProperty
(
*
p
));
}
else
if
(
auto
p
=
dynamic_cast
<
MeshLib
::
PropertyVector
<
unsigned
>*>
(
property
))
{
copyPropertyValues
(
*
p
,
createProperty
(
*
p
));
}
else
if
(
auto
p
=
dynamic_cast
<
MeshLib
::
PropertyVector
<
long
>*>
(
property
))
{
assert
(
new_prop
->
size
()
==
_output_mesh
->
getNumberOfNodes
()
*
n_dest_comp
);
(
void
)(
new_prop
);
// to avoid compilation warning.
copyPropertyValues
(
*
p
,
createProperty
(
*
p
));
}
else
if
(
src_prop
->
getMeshItemType
()
==
MeshLib
::
MeshItemType
::
Cell
)
else
if
(
auto
p
=
dynamic_cast
<
MeshLib
::
PropertyVector
<
unsigned
long
>*>
(
property
))
{
assert
(
new_prop
->
size
()
==
_output_mesh
->
getNumberOfElements
()
*
n_dest_comp
);
copyPropertyValues
(
*
p
,
createProperty
(
*
p
));
}
else
if
(
auto
p
=
dynamic_cast
<
MeshLib
::
PropertyVector
<
std
::
size_t
>*>
(
property
))
{
copyPropertyValues
(
*
p
,
createProperty
(
*
p
));
}
else
if
(
auto
p
=
dynamic_cast
<
MeshLib
::
PropertyVector
<
char
>*>
(
property
))
{
copyPropertyValues
(
*
p
,
createProperty
(
*
p
));
}
else
{
WARN
(
"Property '{:s}' cannot be created because its mesh item type "
"is "
"not supported."
,
name
);
OGS_FATAL
(
"Mesh property '{:s}' of unhandled data type '{:s}'. Please "
"check the data type of the mesh properties. The available "
"data types are:"
"
\n\t
double,"
"
\n\t
float,"
"
\n\t
int,"
"
\n\t
unsigned,"
"
\n\t
long,"
"
\n\t
unsigned long,"
"
\n\t
char."
,
property
->
getPropertyName
(),
typeid
(
*
property
).
name
());
}
}
calculateTotalDisplacement
(
vec_vec_fracture_nodes
.
size
(),
vec_junction_nodeID_matIDs
.
size
());
}
template
<
typename
T
>
void
PostProcessTool
::
copyProperties
()
MeshLib
::
PropertyVector
<
T
>*
PostProcessTool
::
createProperty
(
MeshLib
::
PropertyVector
<
T
>
const
&
property
)
{
MeshLib
::
Properties
const
&
src_properties
=
_org_mesh
.
getProperties
();
for
(
auto
name
:
src_properties
.
getPropertyVectorNames
())
auto
const
item_type
=
property
.
getMeshItemType
();
auto
const
n_src_comp
=
property
.
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_property
=
MeshLib
::
getOrCreateMeshProperty
<
T
>
(
*
_output_mesh
,
property
.
getPropertyName
(),
item_type
,
n_dest_comp
);
if
(
item_type
==
MeshLib
::
MeshItemType
::
Node
)
{
assert
(
new_property
->
size
()
==
_output_mesh
->
getNumberOfNodes
()
*
n_dest_comp
);
}
else
if
(
item_type
==
MeshLib
::
MeshItemType
::
Cell
)
{
if
(
!
src_properties
.
existsPropertyVector
<
T
>
(
name
))
assert
(
new_property
->
size
()
==
_output_mesh
->
getNumberOfElements
()
*
n_dest_comp
);
}
else
{
WARN
(
"Property '{:s}' cannot be created because its mesh item type "
"'{:s}' is not supported."
,
property
.
getPropertyName
(),
toString
(
item_type
));
_output_mesh
->
getProperties
().
removePropertyVector
(
new_property
->
getPropertyName
());
return
nullptr
;
}
return
new_property
;
}
template
<
typename
T
>
void
PostProcessTool
::
copyPropertyValues
(
MeshLib
::
PropertyVector
<
T
>
const
&
source_property
,
MeshLib
::
PropertyVector
<
T
>*
const
destination_property
)
{
if
(
destination_property
==
nullptr
)
{
// skip the copy, because the destination wasn't created.
return
;
}
auto
const
item_type
=
source_property
.
getMeshItemType
();
if
(
item_type
==
MeshLib
::
MeshItemType
::
Node
)
{
auto
const
n_src_comp
=
source_property
.
getNumberOfComponents
();
auto
const
n_dest_comp
=
destination_property
->
getNumberOfComponents
();
// copy existing
for
(
unsigned
i
=
0
;
i
<
_org_mesh
.
getNumberOfNodes
();
i
++
)
{
continue
;
auto
last
=
std
::
copy_n
(
&
source_property
[
i
*
n_src_comp
],
n_src_comp
,
&
(
*
destination_property
)[
i
*
n_dest_comp
]);
// set zero for components not existing in the original
std
::
fill_n
(
last
,
n_dest_comp
-
n_src_comp
,
0
);
}
auto
const
*
src_prop
=
src_properties
.
getPropertyVector
<
T
>
(
name
);
auto
*
dest_prop
=
_output_mesh
->
getProperties
().
getPropertyVector
<
T
>
(
name
);
if
(
src_prop
->
getMeshItemType
()
==
MeshLib
::
MeshItemType
::
Node
)
// copy duplicated
for
(
auto
itr
:
_map_dup_newNodeIDs
)
{
auto
const
n_src_comp
=
src_prop
->
getNumberOfComponents
();
auto
const
n_dest_comp
=
dest_prop
->
getNumberOfComponents
();
// copy existing
for
(
unsigned
i
=
0
;
i
<
_org_mesh
.
getNumberOfNodes
();
i
++
)
for
(
unsigned
k
=
0
;
k
<
itr
.
second
.
size
();
k
++
)
{
for
(
int
j
=
0
;
j
<
n_src_comp
;
j
++
)
{
(
*
dest_prop
)[
i
*
n_dest_comp
+
j
]
=
(
*
src_prop
)[
i
*
n_src_comp
+
j
];
}
// set zero for components not existing in the original
for
(
int
j
=
n_src_comp
;
j
<
n_dest_comp
;
j
++
)
{
(
*
dest_prop
)[
i
*
n_dest_comp
+
j
]
=
0
;
}
}
// copy duplicated
for
(
auto
itr
:
_map_dup_newNodeIDs
)
{
for
(
int
j
=
0
;
j
<
n_dest_comp
;
j
++
)
{
for
(
unsigned
k
=
0
;
k
<
itr
.
second
.
size
();
k
++
)
{
(
*
dest_prop
)[
itr
.
second
[
k
]
*
n_dest_comp
+
j
]
=
(
*
dest_prop
)[
itr
.
first
*
n_dest_comp
+
j
];
}
}
std
::
copy_n
(
&
(
*
destination_property
)[
itr
.
first
*
n_dest_comp
],
n_dest_comp
,
&
(
*
destination_property
)[
itr
.
second
[
k
]
*
n_dest_comp
]);
}
}
else
if
(
src_prop
->
getMeshItemType
()
==
MeshLib
::
MeshItemType
::
Cell
)
{
std
::
copy
(
src_prop
->
begin
(),
src_prop
->
end
(),
dest_prop
->
begin
());
}
else
{
WARN
(
"Property '{:s}' cannot be created because its mesh item type "
"is "
"not supported."
,
name
);
}
}
else
if
(
item_type
==
MeshLib
::
MeshItemType
::
Cell
)
{
assert
(
source_property
.
size
()
==
destination_property
->
size
());
std
::
copy
(
source_property
.
begin
(),
source_property
.
end
(),
destination_property
->
begin
());
}
else
{
OGS_FATAL
(
"Property '{:s}' values cannot be copied because its mesh item "
"type '{:s}' is not supported. Unexpected error, because the "
"destination property was created."
,
source_property
.
getPropertyName
(),
toString
(
item_type
));
}
}
...
...
This diff is collapsed.
Click to expand it.
ProcessLib/LIE/Common/PostUtils.h
+
5
−
2
View file @
6f5b1f97
...
...
@@ -45,9 +45,12 @@ public:
private
:
template
<
typename
T
>
void
createProperties
();
MeshLib
::
PropertyVector
<
T
>*
createProperty
(
MeshLib
::
PropertyVector
<
T
>
const
&
property
);
template
<
typename
T
>
void
copyProperties
();
void
copyPropertyValues
(
MeshLib
::
PropertyVector
<
T
>
const
&
source_property
,
MeshLib
::
PropertyVector
<
T
>*
const
destination_property
);
void
calculateTotalDisplacement
(
unsigned
const
n_fractures
,
unsigned
const
n_junctions
);
...
...
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