# Cylinder generation by using python script in paraview

**URL:** <https://forums.developer.nvidia.com/t/cylinder-generation-by-using-python-script-in-paraview/317174>\
**Category:** Technical Support (PhysicsNeMo Only)\
**Tags:** cuda\
**Created:** [December 17, 2024, 6:43pm UTC](https://forums.developer.nvidia.com/t/cylinder-generation-by-using-python-script-in-paraview/317174 "2024-12-17T18:43:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chungyinpercy](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@chungyinpercy](https://forums.developer.nvidia.com/u/chungyinpercy)\
**Post date:** [December 17, 2024, 6:43pm UTC](https://forums.developer.nvidia.com/t/cylinder-generation-by-using-python-script-in-paraview/317174/1 "2024-12-17T18:43:44Z")

</div>

Hello everyone! now i am doing a simulation about flow past a 2D circular cylinder by input the python script. The problem i facing is the simulation in the Paraview does not work. where i can set the running time for my simulation? I am just a beginner of python and Paraview. Here is the code of the cylinder.

# SPDX-FileCopyrightText: Copyright (c) 2023 - 2024 NVIDIA CORPORATION & AFFILIATES.

# SPDX-FileCopyrightText: All rights reserved.

# SPDX-License-Identifier: Apache-2.0

# 

# Licensed under the Apache License, Version 2.0 (the “License”);

# you may not use this file except in compliance with the License.

# You may obtain a copy of the License at

# 

# [Apache License, Version 2.0 | Apache Software Foundations](http://www.apache.org/licenses/LICENSE-2.0)

# 

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an “AS IS” BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.

import os  
import warnings

import numpy as np  
from sympy import Symbol, Eq

import modulus.sym  
from modulus.sym.hydra import to\_absolute\_path, instantiate\_arch, ModulusConfig  
from [modulus.sym.utils.io](http://modulus.sym.utils.io) import csv\_to\_dict  
from modulus.sym.solver import Solver  
from modulus.sym.domain import Domain  
from modulus.sym.geometry import Bounds  
from modulus.sym.geometry.primitives\_2d import Line, Circle, Channel2D  
from modulus.sym.eq.pdes.navier\_stokes import NavierStokes  
from modulus.sym.eq.pdes.basic import NormalDotVec  
from modulus.sym.domain.constraint import (  
PointwiseBoundaryConstraint,  
PointwiseInteriorConstraint,  
)

from modulus.sym.domain.validator import PointwiseValidator  
from modulus.sym.key import Key  
from modulus.sym import quantity  
from modulus.sym.eq.non\_dim import NonDimensionalizer, Scaler

@modulus.sym.main(config\_path=“conf”, config\_name=“config”)  
def run(cfg: ModulusConfig) → None:  
# physical quantities  
nu = quantity(0.02, “kg/(m\*s)”)  
rho = quantity(1.0, “kg/m^3”)  
inlet\_u = quantity(1.0, “m/s”)  
inlet\_v = quantity(0.0, “m/s”)  
noslip\_u = quantity(0.0, “m/s”)  
noslip\_v = quantity(0.0, “m/s”)  
outlet\_p = quantity(0.0, “pa”)  
velocity\_scale = inlet\_u  
density\_scale = rho  
length\_scale = quantity(20, “m”)  
nd = NonDimensionalizer(  
length\_scale=length\_scale,  
time\_scale=length\_scale / velocity\_scale,  
mass\_scale=density\_scale \* (length\_scale\*\*3),  
)

```
# geometry
channel_length = (quantity(-10, "m"), quantity(30, "m"))
channel_width = (quantity(-10, "m"), quantity(10, "m"))
cylinder_center = (quantity(0, "m"), quantity(0, "m"))
cylinder_radius = quantity(0.5, "m")
channel_length_nd = tuple(map(lambda x: nd.ndim(x), channel_length))
channel_width_nd = tuple(map(lambda x: nd.ndim(x), channel_width))
cylinder_center_nd = tuple(map(lambda x: nd.ndim(x), cylinder_center))
cylinder_radius_nd = nd.ndim(cylinder_radius)

channel = Channel2D(
    (channel_length_nd[0], channel_width_nd[0]),
    (channel_length_nd[1], channel_width_nd[1]),
)
inlet = Line(
    (channel_length_nd[0], channel_width_nd[0]),
    (channel_length_nd[0], channel_width_nd[1]),
    normal=1,
)
outlet = Line(
    (channel_length_nd[1], channel_width_nd[0]),
    (channel_length_nd[1], channel_width_nd[1]),
    normal=1,
)
wall_top = Line(
    (channel_length_nd[1], channel_width_nd[0]),
    (channel_length_nd[1], channel_width_nd[1]),
    normal=1,
)
cylinder = Circle(cylinder_center_nd, cylinder_radius_nd)
volume_geo = channel - cylinder

# make list of nodes to unroll graph on
ns = NavierStokes(nu=nd.ndim(nu), rho=nd.ndim(rho), dim=2, time=False)
normal_dot_vel = NormalDotVec(["u", "v"])
flow_net = instantiate_arch(
    input_keys=[Key("x"), Key("y")],
    output_keys=[Key("u"), Key("v"), Key("p")],
    cfg=cfg.arch.fully_connected,
)
nodes = (
    ns.make_nodes()
    + normal_dot_vel.make_nodes()
    + [flow_net.make_node(name="flow_network")]
    + Scaler(
        ["u", "v", "p"],
        ["u_scaled", "v_scaled", "p_scaled"],
        ["m/s", "m/s", "m^2/s^2"],
        nd,
    ).make_node()
)

# make domain
domain = Domain()
x, y = Symbol("x"), Symbol("y")

# inlet
inlet = PointwiseBoundaryConstraint(
    nodes=nodes,
    geometry=inlet,
    outvar={"u": nd.ndim(inlet_u), "v": nd.ndim(inlet_v)},
    batch_size=cfg.batch_size.inlet,
)
domain.add_constraint(inlet, "inlet")

# outlet
outlet = PointwiseBoundaryConstraint(
    nodes=nodes,
    geometry=outlet,
    outvar={"p": nd.ndim(outlet_p)},
    batch_size=cfg.batch_size.outlet,
)
domain.add_constraint(outlet, "outlet")

# full slip (channel walls)
walls = PointwiseBoundaryConstraint(
    nodes=nodes,
    geometry=channel,
    outvar={"u": nd.ndim(inlet_u), "v": nd.ndim(inlet_v)},
    batch_size=cfg.batch_size.walls,
)
domain.add_constraint(walls, "walls")

# no slip
no_slip = PointwiseBoundaryConstraint(
    nodes=nodes,
    geometry=cylinder,
    outvar={"u": nd.ndim(noslip_u), "v": nd.ndim(noslip_v)},
    batch_size=cfg.batch_size.no_slip,
)
domain.add_constraint(no_slip, "no_slip")

# interior contraints
interior = PointwiseInteriorConstraint(
    nodes=nodes,
    geometry=volume_geo,
    outvar={"continuity": 0, "momentum_x": 0, "momentum_y": 0},
    batch_size=cfg.batch_size.interior,
    bounds=Bounds({x: channel_length_nd, y: channel_width_nd}),
)
domain.add_constraint(interior, "interior")

# Loading validation data from CSV
file_path = "openfoam/cylinder_nu_0.020.csv"
if os.path.exists(to_absolute_path(file_path)):
    mapping = {
        "Points:0": "x",
        "Points:1": "y",
        "U:0": "u_scaled",
        "U:1": "v_scaled",
        "p": "p_scaled",
    }
    openfoam_var = csv_to_dict(to_absolute_path(file_path), mapping)
    openfoam_invar_numpy = {
        key: value / length_scale.magnitude
        for key, value in openfoam_var.items()
        if key in ["x", "y"]
    }
    openfoam_outvar_numpy = {
        key: value
        for key, value in openfoam_var.items()
        if key in ["u_scaled", "v_scaled", "p_scaled"]
    }
    openfoam_validator = PointwiseValidator(
        nodes=nodes, invar=openfoam_invar_numpy, true_outvar=openfoam_outvar_numpy
    )
    domain.add_validator(openfoam_validator)
else:
    warnings.warn(
        f"Directory {file_path} does not exist. Will skip adding validators. Please download the additional files from NGC https://catalog.ngc.nvidia.com/orgs/nvidia/teams/modulus/resources/modulus_sym_examples_supplemental_materials"
    )

# make solver
slv = Solver(cfg, domain)

# start solver
slv.solve()

```

if **name** == “ **main** ”:  
run()

---

<div class="post-metadata">

**Author:** ![chungyinpercy](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@chungyinpercy](https://forums.developer.nvidia.com/u/chungyinpercy)\
**Post date:** [December 17, 2024, 6:45pm UTC](https://forums.developer.nvidia.com/t/cylinder-generation-by-using-python-script-in-paraview/317174/2 "2024-12-17T18:45:58Z")

</div>

Also, my script comes from [modulus-sym/examples/cylinder/cylinder\_2d.py at main · NVIDIA/modulus-sym · GitHub](https://github.com/NVIDIA/modulus-sym/blob/main/examples/cylinder/cylinder_2d.py)
