Commit 2c3ca968 authored by Martin Bauer's avatar Martin Bauer
Browse files

Fix: compressible models are now generated correctly

parent 913d2040
Pipeline #16231 passed with stage
in 1 minute and 52 seconds
...@@ -100,7 +100,7 @@ public: ...@@ -100,7 +100,7 @@ public:
static const real_t w[{{Q}}]; static const real_t w[{{Q}}];
static const real_t wInv[{{Q}}]; static const real_t wInv[{{Q}}];
static const bool compressible = {{compressible}}; static const bool compressible = {% if compressible %}true{% else %}false{% endif %};
static const int equilibriumAccuracyOrder = {{equilibrium_order}}; static const int equilibriumAccuracyOrder = {{equilibrium_order}};
class Sweep class Sweep
...@@ -211,7 +211,7 @@ public: ...@@ -211,7 +211,7 @@ public:
const Vector3< real_t > & u = Vector3< real_t >( real_t(0.0) ), const Vector3< real_t > & u = Vector3< real_t >( real_t(0.0) ),
real_t rho = real_t(1.0) ) real_t rho = real_t(1.0) )
{ {
{% if compressible == 'false' %} {% if not compressible %}
rho -= real_t(1.0); rho -= real_t(1.0);
{% endif %} {% endif %}
{{equilibrium_from_direction}} {{equilibrium_from_direction}}
...@@ -221,7 +221,7 @@ public: ...@@ -221,7 +221,7 @@ public:
const Vector3<real_t> & u = Vector3< real_t >(real_t(0.0)), const Vector3<real_t> & u = Vector3< real_t >(real_t(0.0)),
real_t rho = real_t(1.0) ) real_t rho = real_t(1.0) )
{ {
{% if compressible == 'false' %} {% if not compressible %}
rho -= real_t(1.0); rho -= real_t(1.0);
{% endif %} {% endif %}
{{symmetric_equilibrium_from_direction}} {{symmetric_equilibrium_from_direction}}
...@@ -231,7 +231,7 @@ public: ...@@ -231,7 +231,7 @@ public:
const Vector3< real_t > & u = Vector3<real_t>( real_t(0.0) ), const Vector3< real_t > & u = Vector3<real_t>( real_t(0.0) ),
real_t rho = real_t(1.0) ) real_t rho = real_t(1.0) )
{ {
{% if compressible == 'false' %} {% if not compressible %}
rho -= real_t(1.0); rho -= real_t(1.0);
{% endif %} {% endif %}
{{asymmetric_equilibrium_from_direction}} {{asymmetric_equilibrium_from_direction}}
...@@ -240,7 +240,7 @@ public: ...@@ -240,7 +240,7 @@ public:
static std::vector< real_t > get( const Vector3< real_t > & u = Vector3<real_t>( real_t(0.0) ), static std::vector< real_t > get( const Vector3< real_t > & u = Vector3<real_t>( real_t(0.0) ),
real_t rho = real_t(1.0) ) real_t rho = real_t(1.0) )
{ {
{% if compressible == 'false' %} {% if not compressible %}
rho -= real_t(1.0); rho -= real_t(1.0);
{% endif %} {% endif %}
...@@ -296,7 +296,7 @@ struct Equilibrium< {{class_name}}, void > ...@@ -296,7 +296,7 @@ struct Equilibrium< {{class_name}}, void >
static void set( FieldPtrOrIterator & it, static void set( FieldPtrOrIterator & it,
const Vector3< real_t > & u = Vector3< real_t >( real_t(0.0) ), real_t rho = real_t(1.0) ) const Vector3< real_t > & u = Vector3< real_t >( real_t(0.0) ), real_t rho = real_t(1.0) )
{ {
{%if compressible == 'false' %} {%if not compressible %}
rho -= real_t(1.0); rho -= real_t(1.0);
{%endif %} {%endif %}
...@@ -309,7 +309,7 @@ struct Equilibrium< {{class_name}}, void > ...@@ -309,7 +309,7 @@ struct Equilibrium< {{class_name}}, void >
static void set( PdfField_T & pdf, const cell_idx_t x, const cell_idx_t y, const cell_idx_t z, static void set( PdfField_T & pdf, const cell_idx_t x, const cell_idx_t y, const cell_idx_t z,
const Vector3< real_t > & u = Vector3< real_t >( real_t(0.0) ), real_t rho = real_t(1.0) ) const Vector3< real_t > & u = Vector3< real_t >( real_t(0.0) ), real_t rho = real_t(1.0) )
{ {
{%if compressible == 'false' %} {%if not compressible %}
rho -= real_t(1.0); rho -= real_t(1.0);
{%endif %} {%endif %}
...@@ -364,7 +364,7 @@ struct DensityAndVelocity<{{class_name}}> ...@@ -364,7 +364,7 @@ struct DensityAndVelocity<{{class_name}}>
const real_t u_2(0.0); const real_t u_2(0.0);
{% endif %} {% endif %}
Equilibrium<{{class_name}}>::set(it, Vector3<real_t>(u_0, u_1, u_2), rho{%if compressible %} + real_t(1) {%endif%}); Equilibrium<{{class_name}}>::set(it, Vector3<real_t>(u_0, u_1, u_2), rho{%if not compressible %} + real_t(1) {%endif%});
} }
template< typename PdfField_T > template< typename PdfField_T >
...@@ -376,7 +376,7 @@ struct DensityAndVelocity<{{class_name}}> ...@@ -376,7 +376,7 @@ struct DensityAndVelocity<{{class_name}}>
const real_t u_2(0.0); const real_t u_2(0.0);
{% endif %} {% endif %}
Equilibrium<{{class_name}}>::set(pdf, x, y, z, Vector3<real_t>(u_0, u_1, u_2), rho {%if compressible %} + real_t(1) {%endif%}); Equilibrium<{{class_name}}>::set(pdf, x, y, z, Vector3<real_t>(u_0, u_1, u_2), rho {%if not compressible %} + real_t(1) {%endif%});
} }
}; };
...@@ -398,7 +398,7 @@ struct DensityAndVelocityRange<{{class_name}}, FieldIteratorXYZ> ...@@ -398,7 +398,7 @@ struct DensityAndVelocityRange<{{class_name}}, FieldIteratorXYZ>
const real_t u_2(0.0); const real_t u_2(0.0);
{% endif %} {% endif %}
Equilibrium<{{class_name}}>::set(cellIt, Vector3<real_t>(u_0, u_1, u_2), rho{%if compressible %} + real_t(1) {%endif%}); Equilibrium<{{class_name}}>::set(cellIt, Vector3<real_t>(u_0, u_1, u_2), rho{%if not compressible %} + real_t(1) {%endif%});
} }
} }
}; };
......
...@@ -100,7 +100,7 @@ def generate_lattice_model(generation_context, class_name, lb_method, refinement ...@@ -100,7 +100,7 @@ def generate_lattice_model(generation_context, class_name, lb_method, refinement
'stencil_name': stencil_name, 'stencil_name': stencil_name,
'D': lb_method.dim, 'D': lb_method.dim,
'Q': len(lb_method.stencil), 'Q': len(lb_method.stencil),
'compressible': 'true' if params['compressible'] else 'false', 'compressible': lb_method.conserved_quantity_computation.compressible,
'weights': ",".join(str(w.evalf()) + constant_suffix for w in lb_method.weights), 'weights': ",".join(str(w.evalf()) + constant_suffix for w in lb_method.weights),
'inverse_weights': ",".join(str((1/w).evalf()) + constant_suffix for w in lb_method.weights), 'inverse_weights': ",".join(str((1/w).evalf()) + constant_suffix for w in lb_method.weights),
......
...@@ -17,16 +17,18 @@ class WalberlaLbmpyCodegenTest(unittest.TestCase): ...@@ -17,16 +17,18 @@ class WalberlaLbmpyCodegenTest(unittest.TestCase):
force_field = ps.fields("force(3): [3D]", layout='fzyx') force_field = ps.fields("force(3): [3D]", layout='fzyx')
omega = sp.Symbol("omega") omega = sp.Symbol("omega")
lb_method = create_lb_method(stencil='D3Q19', method='srt', relaxation_rates=[omega], lb_method = create_lb_method(stencil='D3Q19', method='srt', relaxation_rates=[omega], compressible=True,
force_model='guo', force=force_field.center_vector) force_model='guo', force=force_field.center_vector)
scaling = RefinementScaling() scaling = RefinementScaling()
scaling.add_standard_relaxation_rate_scaling(omega) scaling.add_standard_relaxation_rate_scaling(omega)
scaling.add_force_scaling(force_field) scaling.add_force_scaling(force_field)
generate_lattice_model(ctx, 'SrtWithForceFieldModel', lb_method, refinement_scaling=scaling) generate_lattice_model(ctx, 'SrtWithForceFieldModel', lb_method, refinement_scaling=scaling,
update_rule_params={'compressible': True})
generate_boundary(ctx, 'MyUBB', UBB([0.05, 0, 0]), lb_method) generate_boundary(ctx, 'MyUBB', UBB([0.05, 0, 0]), lb_method)
generate_boundary(ctx, 'MyNoSlip', NoSlip(), lb_method) generate_boundary(ctx, 'MyNoSlip', NoSlip(), lb_method)
assert 'static const bool compressible = true;' in ctx.files['SrtWithForceFieldModel.h']
@staticmethod @staticmethod
def test_sparse(): def test_sparse():
...@@ -48,3 +50,12 @@ class WalberlaLbmpyCodegenTest(unittest.TestCase): ...@@ -48,3 +50,12 @@ class WalberlaLbmpyCodegenTest(unittest.TestCase):
lb_assignments = create_lb_update_rule(stencil='D3Q19', method='srt').main_assignments lb_assignments = create_lb_update_rule(stencil='D3Q19', method='srt').main_assignments
generate_pack_info_from_kernel(ctx, 'MyPackInfo2', lb_assignments) generate_pack_info_from_kernel(ctx, 'MyPackInfo2', lb_assignments)
@staticmethod
def test_incompressible():
with ManualCodeGenerationContext() as ctx:
omega = sp.Symbol("omega")
lb_method = create_lb_method(stencil='D3Q19', method='srt', relaxation_rates=[omega], compressible=False)
generate_lattice_model(ctx, 'Model', lb_method, update_rule_params={'compressible': False})
assert 'static const bool compressible = false;' in ctx.files['Model.h']
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment