Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
dumux-repositories
dumux
Commits
4a8fa8ed
Commit
4a8fa8ed
authored
2 years ago
by
Timo Koch
Browse files
Options
Downloads
Patches
Plain Diff
[io][subgrid] Add binary mask reader
parent
217078ff
No related branches found
No related tags found
1 merge request
!3630
[io][grid][sub] Binary mask reader
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dumux/io/grid/gridmanager_sub.hh
+51
-1
51 additions, 1 deletion
dumux/io/grid/gridmanager_sub.hh
with
51 additions
and
1 deletion
dumux/io/grid/gridmanager_sub.hh
+
51
−
1
View file @
4a8fa8ed
...
...
@@ -14,6 +14,7 @@
#include
<memory>
#include
<utility>
#include
<algorithm>
#include
<dune/common/shared_ptr.hh>
#include
<dune/common/concept.hh>
...
...
@@ -229,8 +230,57 @@ public:
DUNE_THROW
(
Dune
::
IOError
,
"The SubGridManager doesn't support image files with extension: *."
<<
ext
);
}
else
if
(
hasParamInGroup
(
paramGroup
,
"Grid.BinaryMask"
))
{
const
auto
maskFileName
=
getParamFromGroup
<
std
::
string
>
(
paramGroup
,
"Grid.BinaryMask"
);
std
::
ifstream
mask
(
maskFileName
,
std
::
ios_base
::
binary
);
std
::
vector
<
char
>
buffer
(
std
::
istreambuf_iterator
<
char
>
(
mask
),
std
::
istreambuf_iterator
<
char
>
{});
const
auto
cells
=
getParamFromGroup
<
std
::
array
<
int
,
dim
>>
(
paramGroup
,
"Grid.Cells"
);
if
(
std
::
accumulate
(
cells
.
begin
(),
cells
.
end
(),
1
,
std
::
multiplies
<
int
>
{})
!=
buffer
.
size
())
DUNE_THROW
(
Dune
::
IOError
,
"Grid dimensions doesn't match number of cells specified"
);
using
GlobalPosition
=
typename
ParentType
::
Grid
::
template
Codim
<
0
>
::
Geometry
::
GlobalCoordinate
;
const
auto
lowerLeft
=
GlobalPosition
(
0.0
);
const
auto
upperRight
=
[
&
]{
if
(
hasParamInGroup
(
paramGroup
,
"Grid.PixelDimensions"
))
{
auto
upperRight
=
getParamFromGroup
<
GlobalPosition
>
(
paramGroup
,
"Grid.PixelDimensions"
);
for
(
int
i
=
0
;
i
<
upperRight
.
size
();
++
i
)
upperRight
[
i
]
*=
cells
[
i
];
upperRight
+=
lowerLeft
;
return
upperRight
;
}
else
return
getParamFromGroup
<
GlobalPosition
>
(
paramGroup
,
"Grid.UpperRight"
);
}();
// make sure there is no grid refinement specified
if
(
getParamFromGroup
<
int
>
(
paramGroup
,
"Grid.Refinement"
,
0
)
>
0
)
DUNE_THROW
(
Dune
::
IOError
,
"Binary mask doesn't work together with Grid.Refinement."
<<
" Use grid.globalRefine() after grid construction."
);
// construct the host grid
this
->
initHostGrid_
(
lowerLeft
,
upperRight
,
cells
,
paramGroup
);
// check if the marker is customized, per default
// we use all cells that are encoded as 0
const
char
marker
=
getParamFromGroup
<
char
>
(
paramGroup
,
"Grid.Marker"
,
0
);
const
auto
elementSelector
=
[
&
](
const
auto
&
element
)
{
const
auto
eIdx
=
this
->
hostGrid_
().
leafGridView
().
indexSet
().
index
(
element
);
return
buffer
[
eIdx
]
!=
marker
;
};
// create the grid
this
->
gridPtr
()
=
std
::
make_unique
<
Grid
>
(
this
->
hostGrid_
());
this
->
updateSubGrid_
(
elementSelector
);
this
->
loadBalance
();
}
else
DUNE_THROW
(
Dune
::
IOError
,
"SubGridManager couldn't construct element selector. Specify Grid.Image in the input file!"
);
DUNE_THROW
(
Dune
::
IOError
,
"SubGridManager couldn't construct element selector."
<<
" Specify Grid.Image or Grid.BinaryMask in the input file!"
);
}
private
:
...
...
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