diff --git a/python/lbmpy_walberla/storage_specification.py b/python/lbmpy_walberla/storage_specification.py index c113604381be85e3895e3744285a528d4786f84e..de82603a022bb45c74db8cbadcb35eee724775ff 100644 --- a/python/lbmpy_walberla/storage_specification.py +++ b/python/lbmpy_walberla/storage_specification.py @@ -32,6 +32,7 @@ def generate_lbm_storage_specification(generation_context, class_name: str, default_dtype = config.data_type.default_factory() is_float = True if issubclass(default_dtype.numpy_dtype.type, np.float32) else False + constant_suffix = "f" if is_float else "" cg = PackingKernelsCodegen(stencil, streaming_pattern, class_name, config) kernels = cg.create_uniform_kernel_families() @@ -39,9 +40,6 @@ def generate_lbm_storage_specification(generation_context, class_name: str, if nonuniform: kernels = cg.create_nonuniform_kernel_families(kernels_dict=kernels) - values_per_cell = len(stencil) - dimension = len(stencil[0]) - # Pure storage specification if not stencil_name: raise ValueError("lb_method uses a stencil that is not supported in waLBerla") @@ -56,11 +54,15 @@ def generate_lbm_storage_specification(generation_context, class_name: str, 'namespace': namespace, 'stencil_name': stencil_name, 'communication_stencil_name': communication_stencil_name, + 'stencil_size': stencil.Q, + 'dimension': stencil.D, 'compressible': cqc.compressible, - 'equilibriumAccuracyOrder': equilibrium.order, + 'equilibrium_accuracy_order': equilibrium.order, + 'equilibrium_deviation_only': equilibrium.deviation_only, 'inplace': is_inplace(streaming_pattern), 'zero_centered': cqc.zero_centered_pdfs, - 'eq_deviation_only': equilibrium.deviation_only, + 'weights': ",".join(str(w.evalf()) + constant_suffix for w in method.weights), + 'inverse_weights': ",".join(str((1 / w).evalf()) + constant_suffix for w in method.weights), 'nonuniform': nonuniform, 'target': target.name.lower(), @@ -68,8 +70,6 @@ def generate_lbm_storage_specification(generation_context, class_name: str, 'is_gpu': target == Target.GPU, 'kernels': kernels, 'direction_sizes': cg.get_direction_sizes(), - 'stencil_size': stencil.Q, - 'dimension': stencil.D, 'src_field': cg.src_field, 'dst_field': cg.dst_field diff --git a/python/lbmpy_walberla/templates/LbmStorageSpecification.tmpl.h b/python/lbmpy_walberla/templates/LbmStorageSpecification.tmpl.h index 866119390412a115f40283c7829cbdfc01e5baad..5d5409b6684703666d5066ffa9ea40530a48f07d 100644 --- a/python/lbmpy_walberla/templates/LbmStorageSpecification.tmpl.h +++ b/python/lbmpy_walberla/templates/LbmStorageSpecification.tmpl.h @@ -63,19 +63,20 @@ class {{class_name}} using Stencil = stencil::{{stencil_name}}; // Lattice stencil used for the communication (should be used to define which block directions need to be communicated) using CommunicationStencil = stencil::{{communication_stencil_name}}; - // If false used correction: Lattice Boltzmann Model for the Incompressible Navier–Stokes Equation, He 1997 static const bool compressible = {% if compressible %}true{% else %}false{% endif %}; // Cut off for the lattice Boltzmann equilibrium - static const int equilibriumAccuracyOrder = {{equilibriumAccuracyOrder}}; - + static const int equilibriumAccuracyOrder = {{equilibrium_accuracy_order}}; + // If true the equilibrium is computed in regard to "delta_rho" and not the actual density "rho" + static const bool equilibriumDeviationOnly = {% if equilibrium_deviation_only -%} true {%- else -%} false {%- endif -%}; // If streaming pattern is inplace (esotwist, aa, ...) or not (pull, push) static const bool inplace = {% if inplace -%} true {%- else -%} false {%- endif -%}; - // If true the background deviation (rho_0 = 1) is subtracted for the collision step. static const bool zeroCenteredPDFs = {% if zero_centered -%} true {%- else -%} false {%- endif -%}; - // If true the equilibrium is computed in regard to "delta_rho" and not the actual density "rho" - static const bool deviationOnlyEquilibrium = {% if eq_deviation_only -%} true {%- else -%} false {%- endif -%}; + // Lattice weights + static constexpr {{dtype}} w[{{stencil_size}}] = { {{weights}} }; + // Inverse lattice weights + static constexpr {{dtype}} wInv[{{stencil_size}}] = { {{inverse_weights}} }; // Compute kernels to pack and unpack MPI buffers class PackKernels { diff --git a/src/lbm_generated/storage_specification/D3Q19StorageSpecification.h b/src/lbm_generated/storage_specification/D3Q19StorageSpecification.h index 5f0342741639be847c78026bacd7763e10f07463..7c2fb9e85eb2388361ad3737bb2cc64bcc075aea 100644 --- a/src/lbm_generated/storage_specification/D3Q19StorageSpecification.h +++ b/src/lbm_generated/storage_specification/D3Q19StorageSpecification.h @@ -57,19 +57,20 @@ class D3Q19StorageSpecification using Stencil = stencil::D3Q19; // Lattice stencil used for the communication (should be used to define which block directions need to be communicated) using CommunicationStencil = stencil::D3Q19; - // If false used correction: Lattice Boltzmann Model for the Incompressible Navier–Stokes Equation, He 1997 static const bool compressible = false; // Cut off for the lattice Boltzmann equilibrium static const int equilibriumAccuracyOrder = 2; - + // If true the equilibrium is computed in regard to "delta_rho" and not the actual density "rho" + static const bool equilibriumDeviationOnly = true; // If streaming pattern is inplace (esotwist, aa, ...) or not (pull, push) static const bool inplace = false; - // If true the background deviation (rho_0 = 1) is subtracted for the collision step. static const bool zeroCenteredPDFs = true; - // If true the equilibrium is computed in regard to "delta_rho" and not the actual density "rho" - static const bool deviationOnlyEquilibrium = true; + // Lattice weights + static constexpr double w[19] = { 0.333333333333333,0.0555555555555556,0.0555555555555556,0.0555555555555556,0.0555555555555556,0.0555555555555556,0.0555555555555556,0.0277777777777778,0.0277777777777778,0.0277777777777778,0.0277777777777778,0.0277777777777778,0.0277777777777778,0.0277777777777778,0.0277777777777778,0.0277777777777778,0.0277777777777778,0.0277777777777778,0.0277777777777778 }; + // Inverse lattice weights + static constexpr double wInv[19] = { 3.00000000000000,18.0000000000000,18.0000000000000,18.0000000000000,18.0000000000000,18.0000000000000,18.0000000000000,36.0000000000000,36.0000000000000,36.0000000000000,36.0000000000000,36.0000000000000,36.0000000000000,36.0000000000000,36.0000000000000,36.0000000000000,36.0000000000000,36.0000000000000,36.0000000000000 }; // Compute kernels to pack and unpack MPI buffers class PackKernels { diff --git a/src/lbm_generated/storage_specification/D3Q27StorageSpecification.h b/src/lbm_generated/storage_specification/D3Q27StorageSpecification.h index 49aa692873b51ba5f25590faf9faffd9a018afdc..42599878544c3e4632603b7141074e9196b2153a 100644 --- a/src/lbm_generated/storage_specification/D3Q27StorageSpecification.h +++ b/src/lbm_generated/storage_specification/D3Q27StorageSpecification.h @@ -57,19 +57,20 @@ class D3Q27StorageSpecification using Stencil = stencil::D3Q27; // Lattice stencil used for the communication (should be used to define which block directions need to be communicated) using CommunicationStencil = stencil::D3Q27; - // If false used correction: Lattice Boltzmann Model for the Incompressible Navier–Stokes Equation, He 1997 static const bool compressible = false; // Cut off for the lattice Boltzmann equilibrium static const int equilibriumAccuracyOrder = 2; - + // If true the equilibrium is computed in regard to "delta_rho" and not the actual density "rho" + static const bool equilibriumDeviationOnly = true; // If streaming pattern is inplace (esotwist, aa, ...) or not (pull, push) static const bool inplace = false; - // If true the background deviation (rho_0 = 1) is subtracted for the collision step. static const bool zeroCenteredPDFs = true; - // If true the equilibrium is computed in regard to "delta_rho" and not the actual density "rho" - static const bool deviationOnlyEquilibrium = true; + // Lattice weights + static constexpr double w[27] = { 0.296296296296296,0.0740740740740741,0.0740740740740741,0.0740740740740741,0.0740740740740741,0.0740740740740741,0.0740740740740741,0.0185185185185185,0.0185185185185185,0.0185185185185185,0.0185185185185185,0.0185185185185185,0.0185185185185185,0.0185185185185185,0.0185185185185185,0.0185185185185185,0.0185185185185185,0.0185185185185185,0.0185185185185185,0.00462962962962963,0.00462962962962963,0.00462962962962963,0.00462962962962963,0.00462962962962963,0.00462962962962963,0.00462962962962963,0.00462962962962963 }; + // Inverse lattice weights + static constexpr double wInv[27] = { 3.37500000000000,13.5000000000000,13.5000000000000,13.5000000000000,13.5000000000000,13.5000000000000,13.5000000000000,54.0000000000000,54.0000000000000,54.0000000000000,54.0000000000000,54.0000000000000,54.0000000000000,54.0000000000000,54.0000000000000,54.0000000000000,54.0000000000000,54.0000000000000,54.0000000000000,216.000000000000,216.000000000000,216.000000000000,216.000000000000,216.000000000000,216.000000000000,216.000000000000,216.000000000000 }; // Compute kernels to pack and unpack MPI buffers class PackKernels {