-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from sintefmath/dev
Coarsening features, lower default report level
- Loading branch information
Showing
12 changed files
with
421 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
abstract type AbstractCoarseningFunction end | ||
|
||
struct CoarsenByVolumeAverage <: AbstractCoarseningFunction end | ||
|
||
function inner_apply_coarsening_function(finevals, fine_indices, op::CoarsenByVolumeAverage, coarse, fine, row, name, entity) | ||
subvols = fine[:volumes][fine_indices] | ||
return sum(finevals.*subvols)/sum(subvols) | ||
end | ||
|
||
struct CoarsenByHarmonicAverage <: AbstractCoarseningFunction end | ||
|
||
function inner_apply_coarsening_function(finevals, fine_indices, op::CoarsenByHarmonicAverage, coarse, fine, row, name, entity) | ||
invvals = 1.0./finevals | ||
return length(invvals)/sum(invvals) | ||
end | ||
|
||
struct CoarsenByArithemticAverage <: AbstractCoarseningFunction end | ||
|
||
function inner_apply_coarsening_function(finevals, fine_indices, op::CoarsenByArithemticAverage, coarse, fine, row, name, entity) | ||
return sum(finevals)/length(finevals) | ||
end | ||
|
||
struct CoarsenByFirstValue <: AbstractCoarseningFunction end | ||
|
||
function inner_apply_coarsening_function(finevals, fine_indices, op::CoarsenByFirstValue, coarse, fine, row, name, entity) | ||
return finevals[1] | ||
end | ||
|
||
function apply_coarsening_function!(coarsevals, finevals, op, coarse::DataDomain, fine::DataDomain, name, entity::Union{Cells, Faces}) | ||
CG = physical_representation(coarse) | ||
function block_indices(CG, block, ::Cells) | ||
return findall(isequal(block), CG.partition) | ||
end | ||
function block_indices(CG, block, ::Faces) | ||
return CG.coarse_faces_to_fine[block] | ||
end | ||
function block_indices(CG, block, ::BoundaryFaces) | ||
return CG.coarse_boundary_to_fine[block] | ||
end | ||
ncoarse = count_entities(coarse, entity) | ||
if finevals isa AbstractVector | ||
for block in 1:ncoarse | ||
ix = block_indices(CG, block, entity) | ||
coarsevals[block] = inner_apply_coarsening_function(view(finevals, ix), ix, op, coarse, fine, 1, name, entity) | ||
end | ||
else | ||
for block in 1:ncoarse | ||
ix = block_indices(CG, block, entity) | ||
for j in axes(coarsevals, 1) | ||
coarsevals[j, block] = inner_apply_coarsening_function(view(finevals, j, ix), ix, op, coarse, fine, j, name, entity) | ||
end | ||
end | ||
end | ||
return coarsevals | ||
end | ||
|
||
function coarsen_data_domain(D::DataDomain, partition; | ||
functions = Dict(), | ||
default = CoarsenByArithemticAverage(), | ||
default_other = CoarsenByFirstValue(), | ||
kwarg... | ||
) | ||
for (k, v) in pairs(kwarg) | ||
functions[k] = v | ||
end | ||
g = physical_representation(D) | ||
cg = CoarseMesh(g, partition) | ||
cD = DataDomain(cg) | ||
for name in keys(D) | ||
if !haskey(cD, name) | ||
val = D[name] | ||
e = Jutul.associated_entity(D, name) | ||
Te = eltype(val) | ||
if !(e in (Cells(), Faces(), BoundaryFaces(), nothing)) | ||
# Other entities are not supported yet. | ||
continue | ||
end | ||
if isnothing(e) | ||
# No idea about coarse dims, just copy | ||
coarseval = deepcopy(val) | ||
elseif val isa AbstractVecOrMat | ||
ne = count_entities(cg, e) | ||
if val isa AbstractVector | ||
coarseval = zeros(Te, ne) | ||
else | ||
coarseval = zeros(Te, size(val, 1), ne) | ||
end | ||
if eltype(Te)<:AbstractFloat | ||
f = get(functions, name, default) | ||
else | ||
f = get(functions, name, default_other) | ||
end | ||
coarseval = apply_coarsening_function!(coarseval, val, f, cD, D, name, e) | ||
else | ||
# Don't know what's going on | ||
coarseval = deepcopy(val) | ||
end | ||
cD[name, e] = coarseval | ||
end | ||
end | ||
return cD | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
07c7486
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
07c7486
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/117273
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: