uw-comphys / openccm

OpenCCM is a CFD-based compartment modelling software package. It is primarily intended for convection dominated reactive flows which feature a weak or one-way coupling between the reactive species and the carrier fluid, i.e. the reaction does not substantially influence the fluid flow over the course of the simulation.
https://uw-comphys.github.io/openccm/
GNU Lesser General Public License v2.1
0 stars 3 forks source link

Errors running pipe_with_recirc_2d example #39

Closed speth closed 2 days ago

speth commented 3 weeks ago

I was not able to run the pipe_with_recirc_2d example.

The first step, run_opencmp.py seems to work. But executing analysis.py fails with the following output:

/Users/speth/src/openccm/openccm/postprocessing/vtu_output.py:30: SyntaxWarning: invalid escape sequence '\*'
  OPENFOAM_SCALAR_HEADER = """/*--------------------------------*- C++ -*----------------------------------*\\
Using the default value of 5 for SETUP, num_cores.
Using the default value of False for SETUP, DEBUG.
Using the default value of ./ for SETUP, working_directory.
Using the default value of output_ccm/ for SETUP, output_folder_path.
Using the default value of cache/ for SETUP, tmp_folder_path.
Using the default value of log/ for SETUP, log_folder_path.
Using the default value of 5 for COMPARTMENTALIZATION, angle_threshold.
Using the default value of 45 for COMPARTMENTALIZATION, flow_threshold.
Using the default value of 1e-15 for COMPARTMENT MODELLING, flow_threshold.
Using the default value of 1e-15 for COMPARTMENT MODELLING, flow_threshold_facet.
Using the default value of 0.05 for COMPARTMENT MODELLING, dist_threshold.
Using the default value of 0.01 for COMPARTMENT MODELLING, atol_opt.
Using the default value of 0.0001 for SIMULATION, first_timestep.
Using the default value of LSODA for SIMULATION, solver.
Using the default value of None for SIMULATION, reactions_file_path.
Using the default value of 1e-06 for SIMULATION, rtol.
Using the default value of 1e-06 for SIMULATION, atol.
Using the default value of all for SIMULATION, t_eval.
Using the default value of True for POST-PROCESSING, save_to_file.
Using the default value of False for POST-PROCESSING, network_diagram.
Using the default value of 0 for POST-PROCESSING, subdivisions.
Using the default value of 1 for POST-PROCESSING, interpolant_order.
Using the default value of compartment_pfr_vtu/ for POST-PROCESSING, vtu_dir.
Start LOAD
WARNING: Physical groups detected - Be sure to define them for every geometrical entity.
WARNING: Physical groups detected - Be sure to define them for every geometrical entity.
End LOAD
Converting Mesh
Done converting Mesh
Calculating compartments
/Users/speth/src/openccm/openccm/compartmentalize/unidirectional.py:623: RuntimeWarning: invalid value encountered in arccos
  angle_result = np.arccos(director_neighbours.dot(director_seed)) * 180/np.pi
WARNING: A large number of compartments were created, tolerances may have been misspecified. 2246 on a mesh with 12776 elements.
Done calculating compartments
Creating compartment network
Merging compartments
No downstream compartments for 735, merging upstream.
No downstream compartments for 2041, merging upstream.
No downstream compartments for 2045, merging upstream.
No downstream compartments for 948, merging upstream.
No downstream compartments for 949, merging upstream.
No downstream compartments for 2034, merging upstream.
No downstream compartments for 2038, merging upstream.
No downstream compartments for 123, merging upstream.
No downstream compartments for 257, merging upstream.
No downstream compartments for 2035, merging upstream.
No downstream compartments for 330, merging upstream.
No downstream compartments for 542, merging upstream.
No downstream compartments for 354, merging upstream.
No downstream compartments for 492, merging upstream.
No downstream compartments for 849, merging upstream.
No downstream compartments for 852, merging upstream.
No downstream compartments for 2043, merging upstream.
No downstream compartments for 493, merging upstream.
Merged 2211 compartments
WARNING: Merged 98.4855% compartments. Compartmentalization and/or merging tolerances may have been misspecified.
Done merging compartments
Renumbering compartments
Done renumbering compartments
Done creating compartment network
End COMPARTMENTALIZE
Creating CSTR network
BEFORE: MAX abs error: 1.0078e-02
BEFORE: AVG abs error: 1.3247e-03
AFTER:  MAX abs error: 4.9024e-19
AFTER:  AVG abs error: 1.5996e-20
Done creating CSTR network
Solving simulation
Traceback (most recent call last):
  File "/Users/speth/src/openccm/examples/OpenCMP/pipe_with_recirc_2d/analysis.py", line 218, in <module>
    data_pfr, data_cstr  = rtd_cm()
                           ^^^^^^^^
  File "/Users/speth/src/openccm/examples/OpenCMP/pipe_with_recirc_2d/analysis.py", line 159, in rtd_cm
    run(config_parser)
  File "/Users/speth/src/openccm/openccm/run.py", line 181, in run
    system_results = solve_system(model, model_network, config_parser, c_mesh.grouped_bcs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/speth/src/openccm/openccm/system_solvers/__init__.py", line 40, in solve_system
    return solve_cstr(model_network, config_parser, grouped_bc)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/speth/src/openccm/openccm/system_solvers/cstr_system.py", line 125, in solve_system
    reactions, bcs, c0 = load_and_prepare_bc_ic_and_rxn(config_parser,
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/speth/src/openccm/openccm/system_solvers/__init__.py", line 101, in load_and_prepare_bc_ic_and_rxn
    import bc_code_gen
  File "/Users/speth/src/openccm/examples/OpenCMP/pipe_with_recirc_2d/bc_code_gen.py", line 8, in <module>
    Q_weights_inlet = array([np.float64(0.030493674190635964), np.float64(0.00978672891217256), np.float64(0.018874324088688093), np.float64(0.022962262863139446), np.float64(0.3171842947510168), np.float64(0.37618063047588735)])
                             ^^
NameError: name 'np' is not defined

Besides the fatal error regarding the missing NumPy import, the multiple warnings from OpenCCM seem a bit surprising to see in the example.

I also noticed that running analysis.py again fails, as it seems to move or delete some of its own input data. On subsequent runs, I get the error:

Traceback (most recent call last):
  File "/Users/speth/src/openccm/examples/OpenCMP/pipe_with_recirc_2d/analysis.py", line 218, in <module>
    data_pfr, data_cstr  = rtd_cm()
                           ^^^^^^^^
  File "/Users/speth/src/openccm/examples/OpenCMP/pipe_with_recirc_2d/analysis.py", line 169, in rtd_cm
    raise FileNotFoundError("PFR data not found")
FileNotFoundError: PFR data not found

This was found in the context of the review for JOSS (https://github.com/openjournals/joss-reviews/issues/6963).

Here is a list of the package versions I have installed in my Conda environment: env.txt

Alex-Vasile commented 3 weeks ago

Hi @speth, thanks for the thorough message. I will have a PR to address these issues up shortly, in the meantime I shall comment on them here:

Alex-Vasile commented 3 weeks ago

Hi @speth, please let me know if #44 addresses your issues.

speth commented 2 weeks ago

With a new checkout of commit 51fe6ab, I now get the following error while trying to run analysis.py in this example:

Using the default value of 5 for SETUP, num_cores.
Using the default value of False for SETUP, DEBUG.
Using the default value of ./ for SETUP, working_directory.
Using the default value of output_ccm/ for SETUP, output_folder_path.
Using the default value of cache/ for SETUP, tmp_folder_path.
Using the default value of log/ for SETUP, log_folder_path.
Using the default value of 1e-15 for COMPARTMENT MODELLING, flow_threshold.
Using the default value of 1e-15 for COMPARTMENT MODELLING, flow_threshold_facet.
Using the default value of 0.05 for COMPARTMENT MODELLING, dist_threshold.
Using the default value of 0.01 for COMPARTMENT MODELLING, atol_opt.
Using the default value of 0.0001 for SIMULATION, first_timestep.
Using the default value of LSODA for SIMULATION, solver.
Using the default value of None for SIMULATION, reactions_file_path.
Using the default value of 1e-06 for SIMULATION, rtol.
Using the default value of 1e-06 for SIMULATION, atol.
Using the default value of all for SIMULATION, t_eval.
Using the default value of True for POST-PROCESSING, save_to_file.
Using the default value of False for POST-PROCESSING, network_diagram.
Using the default value of 0 for POST-PROCESSING, subdivisions.
Using the default value of 1 for POST-PROCESSING, interpolant_order.
Using the default value of compartment_pfr_vtu/ for POST-PROCESSING, vtu_dir.
End COMPARTMENTALIZE
Creating CSTR network
Traceback (most recent call last):
  File "/Users/speth/src/openccm/examples/OpenCMP/pipe_with_recirc_2d/analysis.py", line 202, in <module>
    data_pfr, data_cstr  = rtd_cm()
                           ^^^^^^^^
  File "/Users/speth/src/openccm/examples/OpenCMP/pipe_with_recirc_2d/analysis.py", line 150, in rtd_cm
    run(config_parser)
  File "/Users/speth/src/openccm/openccm/run.py", line 169, in run
    model_network = create_model_network(model, compartments_post, compartment_network, c_mesh, dir_vec, flows_and_upwind, config_parser)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/speth/src/openccm/openccm/compartment_models/__init__.py", line 43, in create_model_network
    return create_cstr_network(compartments, compartment_network, mesh, flows_and_upwind, dir_vec, config_parser)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/speth/src/openccm/openccm/compartment_models/cstr.py", line 224, in create_cstr_network
    assert len(outlets) > 0
           ^^^^^^^^^^^^^^^^
AssertionError
Alex-Vasile commented 2 weeks ago

I just retried it and it's working on two of my machines, let's see if we can figure out what's different.

Based on the output, it looks like it's using the cache. Can you try deleting cache/ and output_ccm/ before re-running analysis.py.

speth commented 2 days ago

The example is working for me now.