Solver Configuration

From DWSIM - Chemical Process Simulator
Jump to: navigation, search

As a modern process simulator, DWSIM offers different solver calculation modes to enable efficient usage of the computing power in current PCs, from low to high-end setups.

Introduction

DWSIM offers five different mechanisms to calculate the flowsheet: Main Thread, Background Thread, Background Parallel Threads, Microsoft Azure Service Bus and Network Computer.

These options control the flowsheet solving behavior as a whole and are independent of the Parallel Calculation settings, which are related to how DWSIM calculates each object separately in the flowsheet.

CONF01.png

Calculation Mode

Main Thread

In this mode, the flowsheet is calculated using the main application (UI) thread. You'll get visual feedback as the flowsheet is calculated and the flowsheet area remains clickable. You will be able to see which object is being calculated and the calculation details will be visible to the user.

Since the thread calculating flowsheet data is the same as the UI one, there may be temporary lockups due to a long-running task, as a PS-flash calculation done by a compressor. During this time the entire application will freeze waiting for the calculation to finish.

This mode is similar to the classic solver that was being used by DWSIM up to v3.3.

Background Thread

In this mode, a new thread is created and used to solve the flowsheet in the background. This option can be up to 20-40% faster than the Main Thread option, since there is no user interface interaction or feedback. You won't be able to know which object is being calculated, apart from its color, which will change depending if the calculation was successful or not. The flowsheet remains disabled (can't be edited) until the calculation finishes.

Background Parallel Threads

Is this mode, DWSIM scans the entire flowsheet diagram searching for objects that can be solved in parallel, and creates a new thread to solve each of them at the same time in batches, following the flowsheet sequence. This mode isn't always faster than the Background Thread option because an in-memory copy of the Property Package(s) is done for each flowsheet object in order to avoid a Race condition. If your flowsheet complexity isn't high enough to compensate the time needed to do the in-memory copy, the calculation time will actually be slower than the Background Thread option. So, this mode is only advantageous if your flowsheet is highly parallel (many mixers and splitters and/or recycles) and has a relatively high complexity (many compounds and different/complex property packages).


Backgroundparallel.jpg

Microsoft Azure Service Bus

In this mode, a remote computer (on the local network or a virtual machine in the cloud) is used to solve the flowsheet, communicating and transferring data with your computer through a Microsoft Azure Service Bus. By selecting this option, you'll be able to use a more powerful computer to solve the flowsheet for you, even if it can't be found through a network IP address.

For this mode to work, you'll need access to an Azure Service Bus connection string. The remote computer will be ready to listen for calculation requests once you start the server application AzureServer.exe, located on the main DWSIM installation folder.


Azuresolver.jpg

When the local computer is configured to use the Azure Service Bus for flowsheet calculation and a calculation is requested, you'll see some messages in the log window regarding the communication process. If the server receives the request succesfully, DWSIM will wait for the results until the timeout limit is reached. If the results arrive before that, you'll see a message telling that the calculation was done successfully, or an error message sent by the server if something went wrong.


Azuresolver2.jpg

The server will calculate the flowsheet data sent by using the solver configuration set by the user on the last DWSIM run, or the default options if DWSIM wasn't run yet on the server.

The Azure Service Bus server application runs on Windows machines and supports one client request at a time only, that is, only one computer can be at the other side of the connection receiving data from the server.

Network Computer

Similar to Azure Service Bus mode, the Network Computer solving mode is used when a computer in the local network or in the internet - reachable by a valid IP address - is used to calculate the flowsheet. For this option to work, you'll need to run TCPServer.exe, located in the main DWSIM installation directory. Enter a TCP Port number to listen to calculation requests and leave the application running for as long as you need.

In the client machine, enter the TCP port that the server application is listening to and its IP address.

Networkserver.jpg

When the local computer is configured to use the Network Solver for flowsheet calculation and a calculation is requested, you'll see some messages in the log window regarding the communication process. If the server receives the request succesfully, DWSIM will wait for the results until the timeout limit is reached. If the results arrive before that, you'll see a message telling that the calculation was done successfully, or an error message sent by the server if something went wrong.

The server will calculate the flowsheet data sent by using the solver configuration set by the user on the last DWSIM run, or the default options if DWSIM wasn't run yet on the server.

The network server supports multiple client requests, that is, multiple computers can be at the other end of the connection receiving and sending data from/to the server.

The network server application can be run on any OS supported by DWSIM.

Solver Options

Solver timeout

This controls how many seconds DWSIM will wait for the flowsheet to be calculated completely in the Background Thread and Network/Service Bus solver modes.

Break calculation on exception

If this option is checked, DWSIM will interrupt the flowsheet calculation when an error occurs during the calculation of any object in the flowsheet, otherwise the solver will jump to the next object in the flowsheet and continue the calculations with the results from a previous run, if there's any. If data from a previous calculation isn't available, exceptions will be thrown until the solver reaches the end of the flowsheet.

Store previous solutions

If enabled, DWSIM will store successful calculation results set in-memory. This allows quick restoring of previous solution states and, most importantly, avoids unnecessary flowsheet recalculations when no input parameters are changed. Use the buttons in the flowsheet toolstrip to restore previously saved solutions.

Additional Settings

Background Thread solving modes have additional settings to control the threading behavior.

Task Scheduler

Selects a Task Scheduler to be used by the background thread solvers.

In background threading mode, every calculation is performed by a task object, which is created with the specific purpose of doing the requested calculation and storing the result. Tasks created by the solver calculate an entire object like an unit operation or stream, or do low level calculations like phase equilibria, enthalpy, entropy, fugacities, solve a linear system and so on.

A task scheduler ensures that the work of a task is eventually executed. The default task scheduler is based on the .NET Framework 4 thread pool, which provides work-stealing for load-balancing, thread injection/retirement for maximum throughput, and overall good performance. The default scheduler uses the .NET Framework ThreadPool to queue and execute work. In the .NET Framework 4, the ThreadPool uses the information that is provided by the System.Threading.Tasks.Task type to efficiently support the fine-grained parallelism (short-lived units of work) that parallel tasks and queries often represent.

When using CAPE-OPEN COM Unit Operations, it is possible that you run into lockups when solving the flowsheet with the background solvers. If a CAPE-OPEN COM component is Single-threaded Apartment (STA), it must only be used from an STA thread. However, all of the ThreadPool’s threads are multi-threaded apartment (MTA) threads, and by default Tasks from TPL run on these threads. The STA Task Scheduler then allows you to use Tasks with STA components.

In rare scenarios, you might be able to achieve a performance speedup by using the Limited Concurrency Task Scheduler. It effectively limits the amount of threads created to run the tasks and enables greater control of the solving process.

Maximum Parallel Threads Multiplier

This control how many threads can be used by the solver to calculate the objects. The total number of threads is calculated by multiplying the number input by the number of processor cores. If DWSIM is running in a dual-core CPU and the maximum thread multiplier is set to 8, then 2x8=16 is the maximum number of threads that the solver will use to calculate the flowsheet.

See Also

Parallel calculation options in DWSIM 3