Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Periodic BCs #263

Closed
fverdugo opened this issue May 22, 2020 · 6 comments
Closed

Periodic BCs #263

fverdugo opened this issue May 22, 2020 · 6 comments
Assignees

Comments

@fverdugo
Copy link
Member

Draft of the changes in code related with CartesianDescriptor to include periodic BCs

struct CartesianDescriptor{D,T,F<:Function} <: GridapType
  origin::Point{D,T}
  sizes::NTuple{D,T}
  partition::NTuple{D,Int}
  isperiodic::NTuple{D,Bool}
  map::F
  @doc """
      CartesianDescriptor(
        origin::Point{D}, 
        sizes::NTuple{D}, 
        partition,
        map::Function=identity,
        isperiodic::NTuple{D,Bool}=tfill(false,Val{D}())) where D
  `partition` is a 1D indexable collection of arbitrary type.
  """
  function CartesianDescriptor(
        origin::Point{D}, 
        sizes::NTuple{D}, 
        partition,
        map::Function=identity,
        isperiodic::NTuple{D,Bool}=tfill(false,Val{D}())) where D

    T = eltype(sizes)
    F = typeof(map)
    new{D,T,F}(origin,sizes,Tuple(partition),map,isperiodic)
  end

end

function CartesianDescriptor(
        origin::Point{D}, 
        sizes::NTuple{D}, 
        partition;
        map::Function=identity,
        isperiodic::NTuple{D,Bool}=tfill(false,Val{D}())) where D
end


function CartesianGrid(args...;kwargs...)
  desc = CartesianDescriptor(args...;kwargs...)
  CartesianGrid(desc)
end

# Idem for CartesianDiscreteModel


@jesusbonilla
Copy link
Collaborator

We decided to implement two different methods for every constructor of the CartesianDescriptor, one with map and isperiodic as optional arguments and another with them as keyword arguments. If we do so, and you call the function without any optional argument, then it is ambiguous which method should be used. Actually, the following warning is thrown at precompilation time:

WARNING: Method definition (::Type{Gridap.Geometry.CartesianDescriptor{D, T, F} where
F<:Function where T where D})(Gridap.TensorValues.MultiValue{Tuple{D}, T, 1, D} where T, 
Tuple{Vararg{T, D}} where T, Any) where {D} in module Geometry at 
.../src/Geometry/CartesianGrids.jl:37 overwritten at .../src/Geometry/CartesianGrids.jl:68.

  ** incremental compilation may be fatally broken for this module **

To keep backward compatibility only isperiodic should be a keyword argument, but it might be odd to have map as an optional and isperiodic as a keyword argument.

jesusbonilla pushed a commit that referenced this issue May 25, 2020
* Added field isperiodic to cartesian descriptor
* Modified constructors of CartesianDescriptor and CartesianDiscreteModel
* Added new method for _generate_cell_to_vertices_from_grid in
UnstructuredGrids.jl that implements the grid numbering for periodic BC.
* Added test PeriodicBC.jl in Geometry tests to check proper numbering of vefs
with periodic BC.
* Added tests PeriodicDarcy.jl and PeriodicCoupledPoisson.jl to check both
with periodic BC.
@fverdugo
Copy link
Member Author

Yes you are right.

I would do the following:

  1. Make all optional positional arguments mandatory.
  2. Use kw-args when you want optional arguments.
  3. Then, implement specific extra functions where needed to keep backwards compatibility

Does it solve the problem?

@fverdugo
Copy link
Member Author

We can even mark as "Deprecated" functions in step 3 and remove them in the next breaking release.

@santiagobadia
Copy link
Member

As @fverdugo knows, I lobby kwargs for constructors of non-obvious objects that are exposed to the user. They provide extensibility without affecting backward compatibility. I would not use optional arguments in these constructors to be used by users, it is a mess, and it affects backward compatibility when you want extensions.

jesusbonilla pushed a commit that referenced this issue May 26, 2020
* Converted optional arguments of CartesianDescriptor constructors to
key-word arguments.
* Added deprecated signatures for backwards compatibility.
* Uptated tests to use new signatures.
* Updated News.md.
@jesusbonilla
Copy link
Collaborator

Ok, done! Thanks for the tips.

@fverdugo
Copy link
Member Author

closed via PR #266

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants