Skip to content

Commit

Permalink
Merge pull request #50 from precice/bundle_solver
Browse files Browse the repository at this point in the history
Bundle solver into a single executable
  • Loading branch information
davidscn authored Mar 23, 2021
2 parents f9c2c65 + 0edace1 commit ce6484d
Show file tree
Hide file tree
Showing 25 changed files with 1,090 additions and 1,496 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/building.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ jobs:
cd dealii-adapter && \
git fetch origin ${{ github.ref }} && \
git checkout FETCH_HEAD && \
cd linear_elasticity && \
cmake . && \
make && \
cd ../nonlinear_elasticity && \
cmake . && \
make";
Expand Down
76 changes: 76 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)

FIND_PACKAGE(deal.II 9.1 QUIET
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)
IF(NOT ${deal.II_FOUND})
MESSAGE(FATAL_ERROR "\n"
"*** Could not locate deal.II. ***\n\n"
"You may want to either pass a flag -DDEAL_II_DIR=/path/to/deal.II to cmake\n"
"or set an environment variable \"DEAL_II_DIR\" that contains this path."
)
ENDIF()

# Enable a switchable dimension choice
IF (NOT DEFINED DIM)
SET(DIM 2)
ENDIF()
ADD_DEFINITIONS(-DDIM=${DIM})

# Set the target and the target source
SET( TARGET "elasticity" )
SET( TARGET_SRC ${TARGET}.cc include/adapter/parameters.cc)

DEAL_II_INITIALIZE_CACHED_VARIABLES()

IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "RELEASE")
MESSAGE(STATUS "No build type specified. Building in ${CMAKE_BUILD_TYPE} mode.")
ENDIF()

# Set the include directory and the name of the project
PROJECT(${TARGET})
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)

# Set the executable
ADD_EXECUTABLE(${TARGET} ${TARGET_SRC})

# Use deal.II macros for setting up the target
DEAL_II_SETUP_TARGET(${TARGET})
DEAL_II_INITIALIZE_CACHED_VARIABLES()

# Query the git information and set it in the source
DEAL_II_QUERY_GIT_INFORMATION()
SET_PROPERTY(TARGET ${TARGET} APPEND PROPERTY COMPILE_DEFINITIONS
GIT_BRANCH="${GIT_BRANCH}"
GIT_REVISION="${GIT_REVISION}"
GIT_SHORTREV="${GIT_SHORTREV}")


FIND_PACKAGE(precice REQUIRED
HINTS ${PRECICE_DIR} $ENV{precice_DIR})
TARGET_LINK_LIBRARIES(${TARGET} precice::precice)

MESSAGE(STATUS "Using the preCICE version found at ${precice_CONFIG}")

# add the individual solver
ADD_SUBDIRECTORY(source)

# ...and link them
TARGET_LINK_LIBRARIES(${TARGET} nonlinear_elasticity linear_elasticity)


#
# Custom "debug" and "release" make targets:
#
ADD_CUSTOM_TARGET(debug
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
COMMENT "Switch CMAKE_BUILD_TYPE to Debug"
)

ADD_CUSTOM_TARGET(release
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
COMMENT "Switch CMAKE_BUILD_TYPE to Release"
)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

Coupled structural solvers written with the C++ finite element library deal.II:

- `linear_elasticity` contains a linear-elastic solver based on the [step-8 tutorial program](https://www.dealii.org/developer/doxygen/deal.II/step_8.html) of deal.II
- `nonlinear_elasticity` contains a nonlinear elastic solver, which builds on previous work of Jean-Paul Pelteret and Andrew McBride in their deal.II code gallery program '[Quasi-Static Finite-Strain Compressible Elasticity](https://www.dealii.org/developer/doxygen/deal.II/code_gallery_Quasi_static_Finite_strain_Compressible_Elasticity.html).' This solver supports shared-memory parallelization.
- `source/linear_elasticity` contains a linear-elastic solver based on the [step-8 tutorial program](https://www.dealii.org/developer/doxygen/deal.II/step_8.html) of deal.II
- `source/nonlinear_elasticity` contains a nonlinear elastic solver, which builds on previous work of Jean-Paul Pelteret and Andrew McBride in their deal.II code gallery program '[Quasi-Static Finite-Strain Compressible Elasticity](https://www.dealii.org/developer/doxygen/deal.II/code_gallery_Quasi_static_Finite_strain_Compressible_Elasticity.html).' This solver supports shared-memory parallelization.

Applied coupling functionalities have been separated and can be found in the `adapter` directory.
Applied coupling functionalities have been separated and can be found in the `include/adapter` directory.

## Start here
Our [wiki](https://www.precice.org/adapter-dealii-overview.html) will help you start. If you are missing something, [let us know](https://www.precice.org/resources/#contact).
Expand Down
101 changes: 101 additions & 0 deletions elasticity.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include <adapter/parameters.h>

#include "source/linear_elasticity/include/linear_elasticity.h"
#include "source/nonlinear_elasticity/include/nonlinear_elasticity.h"

int
main(int argc, char **argv)
{
using namespace dealii;

#ifdef DEAL_II_WITH_MPI
Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv);
#endif

try
{
deallog.depth_console(0);
static const unsigned int n_threads = MultithreadInfo::n_threads();

// Query adapter and deal.II info
const std::string adapter_info =
GIT_SHORTREV == std::string("") ?
"unknown" :
(GIT_SHORTREV + std::string(" on branch ") + GIT_BRANCH);
const std::string dealii_info =
DEAL_II_GIT_SHORTREV == std::string("") ?
"unknown" :
(DEAL_II_GIT_SHORTREV + std::string(" on branch ") +
DEAL_II_GIT_BRANCH);

std::cout
<< "-----------------------------------------------------------------------------"
<< std::endl
<< "-- . running with " << n_threads << " thread"
<< (n_threads == 1 ? "" : "s") << std::endl;

std::cout << "-- . adapter revision " << adapter_info << std::endl;
std::cout << "-- . deal.II " << DEAL_II_PACKAGE_VERSION
<< " (revision " << dealii_info << ")" << std::endl;
std::cout
<< "-----------------------------------------------------------------------------"
<< std::endl
<< std::endl;

// Store the name of the parameter file
const std::string parameter_file = argc > 1 ? argv[1] : "parameters.prm";

// Extract case path for the output directory
size_t pos = parameter_file.find_last_of("/");
std::string case_path =
std::string::npos == pos ? "" : parameter_file.substr(0, pos + 1);

// Query solver type from the parameter file
ParameterHandler prm;
Parameters::Solver solver;
solver.add_output_parameters(prm);
prm.parse_input(parameter_file, "", true);

if (solver.model == "neo-Hookean") // nonlinear
{
Nonlinear_Elasticity::Solid<DIM> solid(case_path, parameter_file);
solid.run();
}
else if (solver.model == "linear") // linear
{
Linear_Elasticity::ElastoDynamics<DIM> elastic_solver(case_path,
parameter_file);
elastic_solver.run();
}
else
AssertThrow(false, ExcNotImplemented())
}
catch (std::exception &exc)
{
std::cerr << std::endl
<< std::endl
<< "----------------------------------------------------"
<< std::endl;
std::cerr << "Exception on processing: " << std::endl
<< exc.what() << std::endl
<< "Aborting!" << std::endl
<< "----------------------------------------------------"
<< std::endl;

return 1;
}
catch (...)
{
std::cerr << std::endl
<< std::endl
<< "----------------------------------------------------"
<< std::endl;
std::cerr << "Unknown exception!" << std::endl
<< "Aborting!" << std::endl
<< "----------------------------------------------------"
<< std::endl;
return 1;
}

return 0;
}
4 changes: 2 additions & 2 deletions adapter/adapter.h → include/adapter/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include <deal.II/fe/fe.h>
#include <deal.II/fe/mapping_q1.h>

#include <adapter/dof_tools_extension.h>
#include <adapter/time_handler.h>
#include <precice/SolverInterface.hpp>

#include "dof_tools_extension.h"
#include "time.h"

namespace Adapter
{
Expand Down
File renamed without changes.
Loading

0 comments on commit ce6484d

Please sign in to comment.