Skip to content

Commit

Permalink
Merge pull request #3 from FEniCS/master
Browse files Browse the repository at this point in the history
Update with upstream
  • Loading branch information
iitrabhi authored Jun 24, 2019
2 parents 301bbba + d4da3a5 commit 2e500b3
Show file tree
Hide file tree
Showing 102 changed files with 804 additions and 2,451 deletions.
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ install-python-components: &install-python-components
command: |
pip3 install git+https://bitbucket.org/fenics-project/fiat.git --upgrade
pip3 install git+https://bitbucket.org/fenics-project/ufl.git --upgrade
pip3 install git+https://bitbucket.org/fenics-project/dijitso.git --upgrade
pip3 install git+https://github.com/FEniCS/ffcx.git --upgrade
rm -rf /usr/local/include/dolfin /usr/local/include/dolfin.h
Expand Down
34 changes: 19 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
# docker run -p 8888:8888 -v "$(pwd)":/tmp quay.io/fenicsproject/dolfinx:notebook
#

ARG GMSH_VERSION=4.2.2
ARG PYBIND11_VERSION=2.2.4
ARG PETSC_VERSION=3.11.1
ARG SLEPC_VERSION=3.11.0
ARG GMSH_VERSION=4.3.0
ARG PYBIND11_VERSION=2.3.0
ARG PETSC_VERSION=3.11.2
ARG SLEPC_VERSION=3.11.1
ARG PETSC4PY_VERSION=3.11.0
ARG SLEPC4PY_VERSION=3.11.0
ARG TINI_VERSION=v0.18.0
Expand All @@ -48,10 +48,12 @@ ENV OPENBLAS_NUM_THREADS=1 \
OPENBLAS_VERBOSE=0

# Install dependencies available via apt-get.
# First set of packages are required to build and run FEniCS.
# Second set of packages are recommended and/or required to build documentation or tests.
# Third set of packages are optional, but required to run gmsh pre-built binaries.
# Fourth set of packages are optional, required for meshio.
# - First set of packages are required to build and run FEniCS.
# - Second set of packages are recommended and/or required to build
# documentation or tests.
# - Third set of packages are optional, but required to run gmsh
# pre-built binaries.
# - Fourth set of packages are optional, required for meshio.
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get -qq update && \
apt-get -yq --with-new-pkgs -o Dpkg::Options::="--force-confold" upgrade && \
Expand Down Expand Up @@ -103,9 +105,11 @@ RUN cd /usr/local && \
ENV PATH=/usr/local/gmsh-${GMSH_VERSION}-Linux64/bin:$PATH

# Install Python packages (via pip)
# First set of packages are required to build and run FEniCS.
# Second set of packages are recommended and/or required to build documentation or run tests.
# Third set of packages are optional but required for pygmsh/meshio/DOLFIN mesh pipeline.
# - First set of packages are required to build and run FEniCS.
# - Second set of packages are recommended and/or required to build
# documentation or run tests.
# - Third set of packages are optional but required for
# pygmsh/meshio/DOLFIN mesh pipeline.
RUN pip3 install --no-cache-dir mpi4py numba && \
pip3 install --no-cache-dir cffi decorator flake8 pytest pytest-xdist sphinx sphinx_rtd_theme && \
export HDF5_MPI="ON" && \
Expand Down Expand Up @@ -256,11 +260,11 @@ ARG MAKEFLAGS

WORKDIR /tmp

# Install ipython (optional), FIAT, UFL, dijitso and ffcX (development versions, master branch)
# Install ipython (optional), FIAT, UFL and ffcX (development
# versions, master branch)
RUN pip3 install --no-cache-dir ipython && \
pip3 install --no-cache-dir git+https://bitbucket.org/fenics-project/fiat.git && \
pip3 install --no-cache-dir git+https://bitbucket.org/fenics-project/ufl.git && \
pip3 install --no-cache-dir git+https://bitbucket.org/fenics-project/dijitso.git && \
pip3 install --no-cache-dir git+https://github.com/fenics/ffcX

# Install dolfinx
Expand All @@ -285,11 +289,11 @@ ARG MAKEFLAGS

WORKDIR /tmp

# Install ipython (optional), FIAT, UFL, dijitso and ffcX (development versions, master branch)
# Install ipython (optional), FIAT, UFL and ffcX (development versions,
# master branch)
RUN pip3 install --no-cache-dir ipython && \
pip3 install --no-cache-dir git+https://bitbucket.org/fenics-project/fiat.git && \
pip3 install --no-cache-dir git+https://bitbucket.org/fenics-project/ufl.git && \
pip3 install --no-cache-dir git+https://bitbucket.org/fenics-project/dijitso.git && \
pip3 install --no-cache-dir git+https://github.com/fenics/ffcX

# Install dolfinx
Expand Down
83 changes: 24 additions & 59 deletions cpp/demo/hyperelasticity/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,60 +33,6 @@ class Right : public mesh::SubDomain
}
};

// Dirichlet boundary condition for clamp at left end
class Clamp : public function::Expression
{
public:
Clamp() : function::Expression({3}) {}

void eval(Eigen::Ref<Eigen::Array<PetscScalar, Eigen::Dynamic, Eigen::Dynamic,
Eigen::RowMajor>>
values,
Eigen::Ref<const EigenRowArrayXXd> x) const
{
for (int i = 0; i < x.rows(); ++i)
{
values(i, 0) = 0.0;
values(i, 1) = 0.0;
values(i, 2) = 0.0;
}
}
};

// Dirichlet boundary condition for rotation at right end
class Rotation : public function::Expression
{
public:
Rotation() : function::Expression({3}) {}

void eval(Eigen::Ref<Eigen::Array<PetscScalar, Eigen::Dynamic, Eigen::Dynamic,
Eigen::RowMajor>>
values,
Eigen::Ref<const EigenRowArrayXXd> x) const
{
const double scale = 0.005;

// Center of rotation
const double y0 = 0.5;
const double z0 = 0.5;

// Large angle of rotation (60 degrees)
double theta = 1.04719755;

for (int i = 0; i < x.rows(); ++i)
{
// New coordinates
double y = y0 + (x(1, 1) - y0) * cos(theta) - (x(i, 2) - z0) * sin(theta);
double z = z0 + (x(i, 1) - y0) * sin(theta) + (x(i, 2) - z0) * cos(theta);

// Rotate at right end
values(i, 0) = 0.0;
values(i, 1) = scale * (y - x(i, 1));
values(i, 2) = scale * (z - x(i, 2));
}
}
};

// Next:
//
// .. code-block:: cpp
Expand Down Expand Up @@ -207,13 +153,32 @@ int main(int argc, char* argv[])
auto cmap = a->coordinate_mapping();
mesh->geometry().coord_mapping = cmap;

Rotation rotation;
Clamp clamp;

auto u_rotation = std::make_shared<function::Function>(V);
u_rotation->interpolate(rotation);
u_rotation->interpolate([](auto values, auto x) {
const double scale = 0.005;

// Center of rotation
const double y0 = 0.5;
const double z0 = 0.5;

// Large angle of rotation (60 degrees)
double theta = 1.04719755;

for (int i = 0; i < x.rows(); ++i)
{
// New coordinates
double y = y0 + (x(1, 1) - y0) * cos(theta) - (x(i, 2) - z0) * sin(theta);
double z = z0 + (x(i, 1) - y0) * sin(theta) + (x(i, 2) - z0) * cos(theta);

// Rotate at right end
values(i, 0) = 0.0;
values(i, 1) = scale * (y - x(i, 1));
values(i, 2) = scale * (z - x(i, 2));
}
});

auto u_clamp = std::make_shared<function::Function>(V);
u_clamp->interpolate(clamp);
u_clamp->interpolate([](auto values, auto x) { values = 0.0; });

L->set_coefficients({{"u", u}});
a->set_coefficients({{"u", u}});
Expand Down
56 changes: 10 additions & 46 deletions cpp/demo/poisson/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,42 +101,6 @@ using namespace dolfin;
//
// .. code-block:: cpp

// Source term (right-hand side)
class Source : public function::Expression
{
public:
Source() : function::Expression({}) {}

void eval(Eigen::Ref<Eigen::Array<PetscScalar, Eigen::Dynamic, Eigen::Dynamic,
Eigen::RowMajor>>
values,
Eigen::Ref<const EigenRowArrayXXd> x) const
{
for (unsigned int i = 0; i != x.rows(); ++i)
{
double dx = x(i, 0) - 0.5;
double dy = x(i, 1) - 0.5;
values(i, 0) = 10 * exp(-(dx * dx + dy * dy) / 0.02);
}
}
};

// Normal derivative (Neumann boundary condition)
class dUdN : public function::Expression
{
public:
dUdN() : function::Expression({}) {}

void eval(Eigen::Ref<Eigen::Array<PetscScalar, Eigen::Dynamic, Eigen::Dynamic,
Eigen::RowMajor>>
values,
Eigen::Ref<const EigenRowArrayXXd> x) const
{
for (unsigned int i = 0; i != x.rows(); ++i)
values(i, 0) = sin(5 * x(i, 0));
}
};

// The ``DirichletBoundary`` is derived from the :cpp:class:`SubDomain`
// class and defines the part of the boundary to which the Dirichlet
// boundary condition should be applied.
Expand All @@ -149,10 +113,7 @@ class DirichletBoundary : public mesh::SubDomain
EigenArrayXb inside(Eigen::Ref<const EigenRowArrayXXd> x,
bool on_boundary) const
{
EigenArrayXb result(x.rows());
for (unsigned int i = 0; i != x.rows(); ++i)
result[i] = (x(i, 0) < DBL_EPSILON or x(i, 0) > 1.0 - DBL_EPSILON);
return result;
return (x.col(0) < DBL_EPSILON or x.col(0) > 1.0 - DBL_EPSILON);
}
};

Expand Down Expand Up @@ -232,18 +193,21 @@ int main(int argc, char* argv[])
std::initializer_list<std::shared_ptr<const function::FunctionSpace>>{V});
std::free(linear_form);

auto f_expr = Source();
auto g_expr = dUdN();

auto f = std::make_shared<function::Function>(V);
auto g = std::make_shared<function::Function>(V);

// Attach 'coordinate mapping' to mesh
auto cmap = a->coordinate_mapping();
mesh->geometry().coord_mapping = cmap;

f->interpolate(f_expr);
g->interpolate(g_expr);
// auto dx = Eigen::square(x - 0.5);
// values = 10.0 * Eigen::exp(-(dx.col(0) + dx.col(1)) / 0.02);
f->interpolate([](auto values, auto x) {
auto dx = Eigen::square(x - 0.5);
values = 10.0 * Eigen::exp(-(dx.col(0) + dx.col(1)) / 0.02);
});
g->interpolate(
[](auto values, auto x) { values = Eigen::sin(5 * x.col(0)); });
L->set_coefficients({{"f", f}, {"g", g}});

// Now, we have specified the variational forms and can consider the
Expand Down Expand Up @@ -290,7 +254,7 @@ int main(int argc, char* argv[])
// .. code-block:: cpp

// Save solution in VTK format
io::VTKFile file("poisson.pvd");
io::VTKFile file("u.pvd");
file.write(u);

return 0;
Expand Down
2 changes: 0 additions & 2 deletions cpp/dolfin/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ set(HEADERS
types.h
UniqueIdGenerator.h
utils.h
Variable.h
PARENT_SCOPE)

set(SOURCES
Expand All @@ -34,5 +33,4 @@ set(SOURCES
timing.cpp
UniqueIdGenerator.cpp
utils.cpp
Variable.cpp
PARENT_SCOPE)
4 changes: 2 additions & 2 deletions cpp/dolfin/common/MPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ dolfin::Table dolfin::MPI::all_reduce(const MPI_Comm comm,
const dolfin::Table& table,
const MPI_Op op)
{
const std::string new_title = "[" + operation_map[op] + "] " + table.name();
const std::string new_title = "[" + operation_map[op] + "] " + table.name;

// Handle trivial reduction
if (MPI::size(comm) == 1)
{
Table table_all(table);
table_all.rename(new_title);
table_all.name = new_title;
return table_all;
}

Expand Down
6 changes: 3 additions & 3 deletions cpp/dolfin/common/SubSystemsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void SubSystemsManager::init_petsc()
{
// Dummy command-line arguments
int argc = 0;
char** argv = NULL;
char** argv = nullptr;

// Initialize PETSc
init_petsc(argc, argv);
Expand All @@ -106,10 +106,10 @@ void SubSystemsManager::init_petsc(int argc, char* argv[])
PetscBool is_initialized;
PetscInitialized(&is_initialized);
if (!is_initialized)
PetscInitialize(&argc, &argv, NULL, NULL);
PetscInitialize(&argc, &argv, nullptr, nullptr);

#ifdef HAS_SLEPC
SlepcInitialize(&argc, &argv, NULL, NULL);
SlepcInitialize(&argc, &argv, nullptr, nullptr);
#endif

// Remember that PETSc has been initialized
Expand Down
Loading

0 comments on commit 2e500b3

Please sign in to comment.