Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ namespace geode
"Write the transferable attributes on the Block meshes of the "
"BRep: each unique vertex on the closest BRep unique vertex "
"(on all its Block vertices), each cell barycenter on the "
"Block polyhedron with the closest barycenter. Raise an error "
"if a point is farther than the tolerance (GLOBAL_EPSILON "
"relative to the largest coordinate when larger than 1) from "
"its closest Block element, if several points match the same "
"Block element, or if a point is within the tolerance of "
"several Block elements" );
"Block polyhedron with the closest barycenter. The "
"simulation may cover only some Blocks: a Block is "
"represented in the cell barycenters when one of its "
"polyhedra is matched, in the unique vertices when one of its "
"matched vertices belongs to no other Block. Every element of "
"a represented Block must be matched with a point, the other "
"Blocks are left untouched. Several points matched with the "
"same element are accepted with an error log (the closest one "
"is kept). A point set without transferable attribute is not "
"matched. The tolerance bounds the single precision rounding "
"of the largest absolute coordinates of the points (as "
"simulators often store them). Raise an error, leaving the "
"model unchanged, if a point is farther than the tolerance "
"from its closest Block element, if a point is within the "
"tolerance of several Block elements, or if an element of a "
"represented Block is matched with no point" );
}
} // namespace geode
87 changes: 67 additions & 20 deletions bindings/python/tests/model/test-py-external-time-series.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def pressure(unique_vertex, time):
return unique_vertex + time


# Polyhedra are numbered over all the Blocks, in brep.blocks() order
def velocity(polyhedron):
return [float(polyhedron), 1.0, 2.0]

Expand Down Expand Up @@ -70,10 +71,9 @@ def create_unique_vertices(brep):
return vertices


def create_cell_barycenters(brep, block_id, translation):
def create_cell_barycenters(brep, translation):
barycenters = mesh.PointSet3D.create()
builder = mesh.PointSetBuilder3D.create(barycenters)
block_mesh = brep.block(block_id).mesh()
manager = barycenters.vertex_attribute_manager()
values = basic.AttributeValuesArrayDouble3()
values.default_value = [0.0, 0.0, 0.0]
Expand All @@ -82,20 +82,20 @@ def create_cell_barycenters(brep, block_id, translation):
VELOCITY, TIMES[1], values, basic.AttributeProperties()
)
attribute = manager.find_attribute_variable_arraydouble3(attribute_id)
for polyhedron in range(block_mesh.nb_polyhedra()):
point = builder.create_point(
block_mesh.polyhedron_barycenter(polyhedron) + translation
)
attribute.set_value(point, velocity(polyhedron))
for block in brep.blocks():
block_mesh = block.mesh()
for polyhedron in range(block_mesh.nb_polyhedra()):
point = builder.create_point(
block_mesh.polyhedron_barycenter(polyhedron) + translation
)
attribute.set_value(point, velocity(point))
return barycenters


def create_time_series(brep, block_id, translation=geometry.Point3D()):
def create_time_series(brep, translation=geometry.Point3D()):
time_series = model.ExternalTimeSeries()
time_series.set_unique_vertices(create_unique_vertices(brep))
time_series.set_cell_barycenters(
create_cell_barycenters(brep, block_id, translation)
)
time_series.set_cell_barycenters(create_cell_barycenters(brep, translation))
return time_series


Expand All @@ -118,16 +118,61 @@ def check_pressures(brep):
raise ValueError("[Test] Wrong pressure on vertex")


def check_velocities(brep, block_id):
block_mesh = brep.block(block_id).mesh()
def check_velocities(brep):
model_polyhedron = 0
for block in brep.blocks():
block_mesh = block.mesh()
series = basic.AttributeTimeSeriesArrayDouble3(
block_mesh.polyhedron_attribute_manager(), VELOCITY
)
if series.nb_time_steps() != 1 or series.time(0) != TIMES[1]:
raise ValueError("[Test] Wrong velocity time steps")
for polyhedron in range(block_mesh.nb_polyhedra()):
if series.value(0, polyhedron) != velocity(model_polyhedron):
raise ValueError("[Test] Wrong velocity on polyhedron")
model_polyhedron += 1


# Barycenters of the first Block only (e.g. a simulation of some regions)
def create_first_block_time_series(brep, nb_missing_polyhedra):
barycenters = create_cell_barycenters(brep, geometry.Point3D())
nb_kept = next(iter(brep.blocks())).mesh().nb_polyhedra() - nb_missing_polyhedra
to_delete = [point >= nb_kept for point in range(barycenters.nb_vertices())]
mesh.PointSetBuilder3D.create(barycenters).delete_vertices(to_delete)
time_series = model.ExternalTimeSeries()
time_series.set_cell_barycenters(barycenters)
return time_series


# The Blocks absent from the simulation are left untouched
def check_single_block(filename):
brep = opengeode.load_one(model.load_brep(filename), filename)
create_first_block_time_series(brep, 0).apply_to(brep)
blocks = list(brep.blocks())
block_mesh = blocks[0].mesh()
series = basic.AttributeTimeSeriesArrayDouble3(
block_mesh.polyhedron_attribute_manager(), VELOCITY
)
if series.nb_time_steps() != 1 or series.time(0) != TIMES[1]:
raise ValueError("[Test] Wrong velocity time steps")
for polyhedron in range(block_mesh.nb_polyhedra()):
if series.value(0, polyhedron) != velocity(polyhedron):
raise ValueError("[Test] Wrong velocity on polyhedron")
raise ValueError("[Test] Wrong velocity on the first Block")
for block in blocks[1:]:
if block.mesh().polyhedron_attribute_manager().time_steps(VELOCITY):
raise ValueError("[Test] The other Blocks should be left untouched")


# A Block represented in the simulation must have all its polyhedra matched
def check_single_block_unmatched(filename):
brep = opengeode.load_one(model.load_brep(filename), filename)
try:
create_first_block_time_series(brep, 1).apply_to(brep)
except basic.OpenGeodeDataError:
pass
else:
raise ValueError("[Test] A partially matched Block should be rejected")
for block in brep.blocks():
if block.mesh().polyhedron_attribute_manager().time_steps(VELOCITY):
raise ValueError("[Test] A rejected matching should write no value")


if __name__ == "__main__":
Expand All @@ -136,24 +181,26 @@ def check_velocities(brep, block_id):
data_dir = os.path.abspath(os.path.join(test_dir, "../../../../tests/data"))
filename = os.path.join(data_dir, "test_mesh3.og_brep")
brep = opengeode.load_one(model.load_brep(filename), filename)
block_id = next(iter(brep.blocks())).id()
time_series = create_time_series(brep, block_id)
time_series = create_time_series(brep)
output = "python_time_series." + model.ExternalTimeSeries.native_extension_static()
model.save_external_time_series(time_series, output)
model.load_external_time_series(output).apply_to(brep)
check_pressures(brep)
check_velocities(brep, block_id)
check_velocities(brep)

other = opengeode.load_one(model.load_brep(filename), filename)
model.load_brep_time_series(other, output)
check_pressures(other)

wrong = create_time_series(
brep, block_id, geometry.Point3D([100 * basic.GLOBAL_EPSILON, 0.0, 0.0])
brep, geometry.Point3D([100 * basic.GLOBAL_EPSILON, 0.0, 0.0])
)
try:
wrong.apply_to(opengeode.load_one(model.load_brep(filename), filename))
except Exception:
pass
else:
raise ValueError("[Test] Translated barycenters should be rejected")

check_single_block(filename)
check_single_block_unmatched(filename)
26 changes: 18 additions & 8 deletions include/geode/model/representation/core/external_time_series.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,28 @@ namespace geode
* Write the transferable attributes on the Block meshes of the model:
* each unique vertex on the closest model unique vertex (on all its
* Block vertices), each cell barycenter on the Block polyhedron with
* the closest barycenter. Block elements matched with no point keep
* no value, Blocks matched with no point are left untouched.
* the closest barycenter. The simulation may cover only some Blocks:
* a Block is represented in the cell barycenters when one of its
* polyhedra is matched, in the unique vertices when one of its
* matched vertices belongs to no other Block. Every element of a
* represented Block must be matched with a point, the other Blocks
* are left untouched. Several points matched with the same element
* are accepted with an error log: the closest one is kept. Both
* point sets are matched before any value is written.
* Attribute ids and properties (time steps included) are kept. A
* Block time step with the same name and time as an applied one is
* replaced.
* The matching tolerance is GLOBAL_EPSILON relative to the largest
* absolute coordinate of the points (when larger than 1), to accept
* points rounded by the simulator (e.g. stored in single precision).
* A point set without transferable attribute is not matched.
* The matching tolerance bounds the rounding of the points to single
* precision (as simulators often store them), computed from their
* largest absolute coordinates. Points computed in double precision
* from rounded coordinates (e.g. barycenters) are accepted, points
* rounded twice may not be.
* @exception OpenGeodeException if a point is farther than the
* tolerance from its closest Block element, if several points are
* matched with the same Block element, or if a point is within the
* tolerance of several Block elements
* tolerance from its closest Block element, if a point is within the
* tolerance of several Block elements, or if an element of a
* represented Block is matched with no point. The model is then
* unchanged.
*/
void apply_to( BRep& model ) const;

Expand Down
Loading
Loading