Skip to content

Commit

Permalink
Make RBC cell insert seed required
Browse files Browse the repository at this point in the history
  • Loading branch information
rupertnash committed Dec 19, 2023
1 parent 3da8423 commit 962976d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 50 deletions.
27 changes: 1 addition & 26 deletions Code/configuration/SimConfigReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <algorithm>
#include <array>
#include <chrono>
#include <concepts>
#include <memory>
#include <optional>
Expand Down Expand Up @@ -577,34 +576,10 @@ namespace hemelb::configuration {
}

// Optional element(s) <insertcell>
PrngSeedType horrible_hack_seed = 0;
for (auto insertEl: ioletEl.Children("insertcell")) {
CellInserterConfig inserterConf;
auto maybeSeed = insertEl.GetChildOrNull("seed").transform(
[](Element const& _) { return _.GetAttributeOrThrow<PrngSeedType>("value"); }
);
if (maybeSeed) {
inserterConf.seed = *maybeSeed;
} else {
// We need to seed each of the RBCInserterWithPerturbation objects consistently across MPI processes
if (horrible_hack_seed == 0) {
PrngSeedType seed = std::chrono::system_clock::now().time_since_epoch().count();
auto comm_world = hemelb::net::MpiCommunicator::World();
comm_world.Broadcast(seed, 0);
std::stringstream message;
message << "RBC insertion random seed: " << std::hex << std::showbase << seed;
log::Logger::Log<log::Info, log::Singleton>(message.str());
horrible_hack_seed = seed;
} else {
horrible_hack_seed += 1;
}
inserterConf.seed = horrible_hack_seed;
}
inserterConf.seed = insertEl.GetChildOrThrow("seed").GetAttributeOrThrow<PrngSeedType>("value");
inserterConf.template_name = insertEl.GetAttributeOrThrow("template");
// if (templateCells.count(templateName) == 0)
// {
// throw Exception() << "Template cell name does not match a known template cell";
// }

// Rotate cell to align z axis with given position, and then z axis with flow
// If phi == 0, then cell symmetry axis is aligned with the flow
Expand Down
35 changes: 17 additions & 18 deletions Code/tests/redblood/CellInserterTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,26 @@ namespace hemelb::tests

auto getDocument = [&](LatticeDistance radius = 1e0, int numInserters = 0) {
std::ostringstream sstr;
sstr << "<hemelbsettings>"
"<inlets><inlet>"
" <condition type=\"pressure\" subtype=\"file\">"
" <path value=\"ignored.dat\" />"
" </condition>"
" <normal units=\"dimensionless\" value=\"(0.0,1.0,1.0)\" />"
" <position units=\"m\" value=\"(0.1,0.2,0.3)\" />"
" <flowextension>"
" <length units=\"m\" value=\"0.5\" />"
" <radius units=\"m\" value=\"" << radius << "\" />"
" <fadelength units=\"m\" value=\"0.4\" />"
" </flowextension>";
sstr << "<hemelbsettings>\n<inlets>\n<inlet>\n"
" <condition type=\"pressure\" subtype=\"file\">\n"
" <path value=\"ignored.dat\" />\n"
" </condition>\n"
" <normal units=\"dimensionless\" value=\"(0.0,1.0,1.0)\" />\n"
" <position units=\"m\" value=\"(0.1,0.2,0.3)\" />\n"
" <flowextension>\n"
" <length units=\"m\" value=\"0.5\" />\n"
" <radius units=\"m\" value=\"" << radius << "\" />\n"
" <fadelength units=\"m\" value=\"0.4\" />\n"
" </flowextension>\n";
for (int i = 0; i < numInserters; ++i)
{
sstr << " <insertcell template=\"joe\">"
" <every units=\"s\" value=\"" << every << "\"/>"
" <offset units=\"s\" value=\"" << offset << "\"/>"
" </insertcell>";
sstr << " <insertcell template=\"joe\">\n"
<< " <every units=\"s\" value=\"" << every << "\"/>\n"
<< " <offset units=\"s\" value=\"" << offset << "\"/>\n"
<< " <seed value=\"854" << i << "\" />\n"
<< " </insertcell>\n";
}
sstr << "</inlet></inlets>"
"</hemelbsettings>";
sstr << "</inlet>\n</inlets>\n</hemelbsettings>\n";
Document doc;
doc.LoadString(sstr.str().c_str());
return doc;
Expand Down
1 change: 1 addition & 0 deletions Code/tests/resources/cyl_l100_r5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<fadelength units="m" value="3e-06" />
</flowextension>
<insertcell template="default">
<seed value="321" />
<every units="s" value="1"/>
<offset units="s" value="1.852e-6"/>
<delta_t units="s" value="0e0"/>
Expand Down
3 changes: 2 additions & 1 deletion Code/tests/resources/fedosov1c.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
<fadelength units="m" value="7e-06" />
</flowextension>
<insertcell template="default">
<every units="s" value="2e-0"/>
<seed value="321" />
<every units="s" value="2e-0"/>
<offset units="s" value="40e-8"/>
<delta_t units="s" value="0e0"/>
<theta units="rad" value="0e0"/>
Expand Down
1 change: 1 addition & 0 deletions Code/tests/resources/large_cylinder_rbc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<fadelength units="m" value="7e-06" />
</flowextension>
<insertcell template="default">
<seed value="321" />
<every units="s" value="2e-0"/>
<offset units="s" value="40e-8"/>
<delta_t units="s" value="0e0"/>
Expand Down
27 changes: 22 additions & 5 deletions doc/user/XmlConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This file is the main input file for a HemeLB simulation. If you use
the geometry tool to generate a .gmy file, it will also create a
minimal XML file that contains the required geometry-related data,
however it is currently (2021) not suitable to run immediately and
however it is currently (2023) not suitable to run immediately and
must be manually edited. Here we describe the file.

All parameters that correspond to a property of the modelled system
Expand All @@ -27,9 +27,14 @@ or:
(since `operator>>` has been overriden to parse such a string into
a `util::Vector3D<float>`).

Floating point values can be given in fixed point, scientific
notation, or hexadecimal floating point. This last can exactly
represent floating point numbers so is used by tooling to avoid loss
of precision.

At the top level there must be the root element: `<hemelbsettings
version="int">`. It MUST have a version attribute, an integer. This is
currently 5.
currently 6.

## Simulation
The `<simulation>` is required and specifies some global properties of
Expand All @@ -45,7 +50,14 @@ It's child elements are:
* Optional: `<checkpoint period="int">` -
save a checkpoint at the given interval (in timesteps) to the
"Checkpoints" directory.

* Optional: `<fluid_density value="float" units="kg/m3" />` - density
of the fluid, default is `DEFAULT_FLUID_DENSITY_Kg_per_m3=1000.0`.
* Optional: `<fluid_viscosity value="float" units="Pa.s" />` - dynamic
viscosity of the fluid, default is `DEFAULT_FLUID_VISCOSITY_Pas =
0.004`.
* Optional: `<reference_pressure value="float" units="mmHg" />` -
pressure from which other pressures are measured - this physical
pressure corresponds to a LB density of 1.0. Default is zero.

## Geometry
The `<geometry>` element is required. It has one, required, child element:
Expand Down Expand Up @@ -148,11 +160,16 @@ Describe what data to extract under the `<properties>` element. Child elements:
+ `type="tangentialprojectiontraction"`
+ `type="mpirank"`

## Cells
Configure the simulation of resolved flexible particles with the IBM
user the `<redbloodcells>` element.

## Changes

### Version 6
Moved checkpoint
- Moved checkpoint.
- Allow hexadecimal floating point
- Basic documentation of RBC elements

### Version 5

Added checkpoint element.

0 comments on commit 962976d

Please sign in to comment.