Skip to content

Commit

Permalink
Merge branch 'develop' into add-tests-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
MakisH committed Mar 13, 2024
2 parents 9db6146 + a353484 commit e59d9e7
Show file tree
Hide file tree
Showing 28 changed files with 535 additions and 50 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
6 changes: 3 additions & 3 deletions .github/workflows/build-custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
echo "Run tutorial partitioned-pipe: ${{ github.event.inputs.runTutorialPartitionedPipe }}"
echo "Tutorials branch: ${{ github.event.inputs.branchTutorials }}"
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.refAdapter }}
- name: Install OpenFOAM (no cache)
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
wait $PIDfluid
fi
- name: Archive logs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: logs
path: |
Expand All @@ -234,7 +234,7 @@ jobs:
tutorials/partitioned-pipe/fluid1-openfoam-pimplefoam/fluid1-openfoam-pimplefoam.log
tutorials/partitioned-pipe/fluid2-openfoam-pimplefoam/fluid2-openfoam-pimplefoam.log
- name: Archive case files
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: case-files
path: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup caches
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-id
with:
path: ${{ runner.temp }}/cache-directory
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
name: Check formatting (clang-format)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Run clang-format style check for C/C++ programs.
uses: jidicula/clang-format-action@main
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Check links in markdown files (markdown-link-check)
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/check-markdown.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/check-shell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Lint shell scripts (shellcheck)
uses: ludeeus/action-shellcheck@master
31 changes: 31 additions & 0 deletions .github/workflows/check-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Check code style
on:
push:
branches:
- main
- develop
pull_request:
branches:
- "*"

jobs:
formatting:
runs-on: ubuntu-latest
steps:
- name: Checkout preCICE
uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.10'
check-latest: true
- name: Install pre-commit
run: pip install pre-commit
- name: Run checks
run: pre-commit run -a -v
- name: Git status
if: always()
run: git status
- name: Full diff
if: always()
run: git diff
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
# Official repo for default hooks
- repo: https://github.com/precice/precice-pre-commit-hooks
rev: 'v3.3'
hooks:
- id: format-precice-config
- id: check-image-prefix
args: [ --prefix=docs-adapter-openfoam- ]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.30.0
hooks:
- id: markdownlint
files: "^docs/.*.md"
- id: markdownlint-fix
files: "^docs/.*.md"
28 changes: 15 additions & 13 deletions Adapter.C
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ void preciceAdapter::Adapter::initialize()

DEBUG(adapterInfo("Initializing preCICE data..."));
precice_->initialize();
timestepPrecice_ = precice_->getMaxTimeStepSize();
preciceInitialized_ = true;
ACCUMULATE_TIMER(timeInInitialize_);

Expand Down Expand Up @@ -587,7 +586,6 @@ void preciceAdapter::Adapter::advance()

SETUP_TIMER();
precice_->advance(timestepSolver_);
timestepPrecice_ = precice_->getMaxTimeStepSize();
ACCUMULATE_TIMER(timeInAdvance_);

return;
Expand Down Expand Up @@ -651,8 +649,8 @@ void preciceAdapter::Adapter::adjustSolverTimeStepAndReadData()
If the solver tries to use a bigger timestep, then it needs to use
the same timestep as the one determined by preCICE.
*/

if (timestepSolverDetermined < timestepPrecice_)
double tolerance = 1e-14;
if (precice_->getMaxTimeStepSize() - timestepSolverDetermined > tolerance)
{
// Add a bool 'subCycling = true' which is checked in the storeMeshPoints() function.
adapterInfo(
Expand All @@ -668,20 +666,24 @@ void preciceAdapter::Adapter::adjustSolverTimeStepAndReadData()
"warning");
}
}
else if (timestepSolverDetermined > timestepPrecice_)
else if (timestepSolverDetermined - precice_->getMaxTimeStepSize() > tolerance)
{
adapterInfo(
"The solver's timestep cannot be larger than the coupling timestep."
" Adjusting from "
+ std::to_string(timestepSolverDetermined) + " to " + std::to_string(timestepPrecice_),
"warning");
timestepSolver_ = timestepPrecice_;
// In the last time-step, we adjust to dt = 0, but we don't need to trigger the warning here
if (precice_->isCouplingOngoing())
{
adapterInfo(
"The solver's timestep cannot be larger than the coupling timestep."
" Adjusting from "
+ std::to_string(timestepSolverDetermined) + " to " + std::to_string(precice_->getMaxTimeStepSize()),
"warning");
}
timestepSolver_ = precice_->getMaxTimeStepSize();
}
else
{
DEBUG(adapterInfo("The solver's timestep is the same as the "
"coupling timestep."));
timestepSolver_ = timestepPrecice_;
timestepSolver_ = precice_->getMaxTimeStepSize();
}

// Update the solver's timestep (but don't trigger the adjustDeltaT(),
Expand Down Expand Up @@ -1663,7 +1665,7 @@ preciceAdapter::Adapter::~Adapter()
Info << " (I) advance(): " << timeInAdvance_.str() << nl;
Info << " (I) finalize(): " << timeInFinalize_.str() << nl;
Info << " These times include time waiting for other participants." << nl;
Info << " See also precice-<participant>-events-summary.log." << nl;
Info << " See also precice-profiling on the website https://precice.org/tooling-performance-analysis.html." << nl;
Info << "-------------------------------------------------------------------------------------" << nl;)

return;
Expand Down
3 changes: 0 additions & 3 deletions Adapter.H
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ private:

// Timesteps

//- Timestep dictated by preCICE
double timestepPrecice_;

//- Timestep used by the solver
double timestepSolver_;

Expand Down
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ merge conflicts and we will merge these files at the time we release a new versi

## Code formatting

You can format all files with clang-format 11 by running `./tools/format-code.sh`.
We use [pre-commit](https://pre-commit.com/) to ensure consistent formatting.
Please install `pre-commit` and then install the hook in this repository with `pre-commit install`.
This ensures correct formatting for future commits.
Run `pre-commit run -va` to apply formatting retrospectively.

## Automatic checks

Expand Down
116 changes: 116 additions & 0 deletions FF/Alpha.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "Alpha.H"

using namespace Foam;

preciceAdapter::FF::Alpha::Alpha(
const Foam::fvMesh& mesh,
const std::string nameAlpha)
: Alpha_(
const_cast<volScalarField*>(
&mesh.lookupObject<volScalarField>(nameAlpha)))
{
dataType_ = scalar;
}

std::size_t preciceAdapter::FF::Alpha::write(double* buffer, bool meshConnectivity, const unsigned int dim)
{
int bufferIndex = 0;

if (this->locationType_ == LocationType::volumeCenters)
{
if (cellSetNames_.empty())
{
for (const auto& cell : Alpha_->internalField())
{
buffer[bufferIndex++] = cell;
}
}
else
{
for (const auto& cellSetName : cellSetNames_)
{
cellSet overlapRegion(Alpha_->mesh(), cellSetName);
const labelList& cells = overlapRegion.toc();

for (const auto& currentCell : cells)
{
// Copy the alpha valus into the buffer
buffer[bufferIndex++] = Alpha_->internalField()[currentCell];
}
}
}
}

// For every boundary patch of the interface
for (uint j = 0; j < patchIDs_.size(); j++)
{
int patchID = patchIDs_.at(j);

// For every cell of the patch
forAll(Alpha_->boundaryFieldRef()[patchID], i)
{
// Copy the Alpha into the buffer
buffer[bufferIndex++] =
Alpha_->boundaryFieldRef()[patchID][i];
}
}
return bufferIndex;
}

void preciceAdapter::FF::Alpha::read(double* buffer, const unsigned int dim)
{
int bufferIndex = 0;

if (this->locationType_ == LocationType::volumeCenters)
{
if (cellSetNames_.empty())
{
for (auto& cell : Alpha_->ref())
{
cell = buffer[bufferIndex++];
}
}
else
{
for (const auto& cellSetName : cellSetNames_)
{
cellSet overlapRegion(Alpha_->mesh(), cellSetName);
const labelList& cells = overlapRegion.toc();

for (const auto& currentCell : cells)
{
// Copy the pressure into the buffer
Alpha_->ref()[currentCell] = buffer[bufferIndex++];
}
}
}
}

// For every boundary patch of the interface
for (uint j = 0; j < patchIDs_.size(); j++)
{
int patchID = patchIDs_.at(j);
// For every cell of the patch
forAll(Alpha_->boundaryFieldRef()[patchID], i)
{
Alpha_->boundaryFieldRef()[patchID][i] = buffer[bufferIndex++];
}
}
}

bool preciceAdapter::FF::Alpha::isLocationTypeSupported(const bool meshConnectivity) const
{
if (meshConnectivity)
{
return (this->locationType_ == LocationType::faceCenters);
}
else
{
return (this->locationType_ == LocationType::faceCenters || this->locationType_ == LocationType::volumeCenters);
}
}

std::string preciceAdapter::FF::Alpha::getDataName() const
{
return "Alpha";
}
43 changes: 43 additions & 0 deletions FF/Alpha.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef FF_ALPHA_H
#define FF_ALPHA_H

#include "CouplingDataUser.H"

#include "fvCFD.H"
#include "cellSet.H"

namespace preciceAdapter
{
namespace FF
{

//- Class that writes and reads Alpha
class Alpha : public CouplingDataUser
{

private:
//- Alpha field
Foam::volScalarField* Alpha_;

public:
//- Constructor
Alpha(
const Foam::fvMesh& mesh,
const std::string nameAlpha);

//- Write the Alpha values into the buffer
std::size_t write(double* buffer, bool meshConnectivity, const unsigned int dim);

//- Read the Alpha values from the buffer
void read(double* buffer, const unsigned int dim);

bool isLocationTypeSupported(const bool meshConnectivity) const override;

//- Get the name of the current data field
std::string getDataName() const override;
};

}
}

#endif
Loading

0 comments on commit e59d9e7

Please sign in to comment.