Group Abstract Group Abstract

Message Boards Message Boards

Modeling jump conditions in interphase mass transfer

Posted 6 years ago
POSTED BY: Tim Laska
19 Replies
Anonymous User
Anonymous User
Posted 6 years ago

Thank you very much Tim Laska. I shouldn't have asked the question I want to retract it.

My book says a PDE is used when solving a formula containing only partial differentials (not total differentials) which I should have remembered. The discussion of conversion from one to another isn't one I meant to begin.

Perhaps I was wondering when it was that lab measurement taking pushes one into a partial derivative formula rather than total: but I shouldn't start that discussion either :) It would include discussion of derivatives and integrals of several variables which aren't ... any easier discussed than pde per say.

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 6 years ago

(in short i asked if this PDE could be solved as an ODE, but wish to retract question)

POSTED BY: Anonymous User

Hi John,

Here is an attempt to answer your questions.

Generally, one has some variable of interest (e.g., temperature) that DEPENDS on INDEPENDENT variables of space (x, y, z) and time (t). The equations to describe this dependence usually derive from conservation laws (e.g., energy balance, momentum balance, species balance, etc) that are only valid for differential elements of space and time. If your system depends on more than one independent variable or if you are unsure of how many independent variables it depends on, then you are in the realm of PDEs.

As to your second question, if the problem could be represented as an ODE, then the numerical solution would have revealed it in the plots (e.g., families of characteristic contour curves would be identifiable). So, the answer is no, this system can not be represented by an ODE. For an example where I was able to convert a PDE into a simpler ODE based on characteristic lines I observed in the numerical solution of the fully coupled PDE, look here.

Almost all ODEs, PDEs, or systems thereof, cannot be solved analytically. In contrast, with the advent of fast computers and improved algorithms, a much larger class of ODE/PDE can be solved at reasonable speeds. Further, if you start off with the numerical solution, it can give insights on reasonable assumptions for a potential analytical solution.

POSTED BY: Tim Laska
Anonymous User
Anonymous User
Posted 6 years ago

The strength of MMA is ______.

packages often don't share their math code and the code isn't "good" it does the job.

you can publish you mm code so mm have it, or keep it private for use in a pro product :)

POSTED BY: Anonymous User

Thank you for the nice FEM program. The mass transfer is important in chemistry, but in other fields as well. I have to look more concisely to the analytical formulation of the mas transfer problem as trying to solve some mass transfer problems linked to peritoneal dialysis. Ladislav Lukas

POSTED BY: Ladislav Lukas

Sorry for the late reply. I hope that you may find some additional use for this post.

For the dialysis case, you could have two jump conditions on either side of the membrane as shown below.

Two Jumps Across a Membrane

So, you probably need to model the membrane and add an "interphase" region to both sides for a total of 5 regions. If the model grows too large due to meshing three relatively thin regions, then maybe a structured quad mesh is in order.

POSTED BY: Tim Laska

enter image description here - Congratulations! This post is now a Staff Pick as distinguished by a badge on your profile! Thank you, keep it coming, and consider contributing your work to the The Notebook Archive!

POSTED BY: EDITORIAL BOARD
Posted 6 years ago

Nice to see a simulation done by MMA! I always wants to learn fem in MMA. Sadly there wasn't many detailed tutorials around.

This may not be on topic but would you mind telling did you model the same problem in comsol? I'm also a comsol user myself so I recognize the icon immediately.

POSTED BY: Ox Clouding

Yes, I did model in both COMSOL and MMA. I generally don't mention other codes because I don't want to appear as though I am promoting possible competition. I am, however, a firm believer in validation versus other standards whenever possible.

Thank you for the comment!

POSTED BY: Tim Laska
Posted 6 years ago

I see. From your experience, what advantages MMA have over other codes like comsol? I always wonder if MMA solvers are superior in terms of speed or accuracy.

POSTED BY: Ox Clouding

To be honest, I am rather new at the FEM in the Wolfram Language, so I have not optimized my approaches or explored parallelizing. For these small 2D models that I have been creating to demonstrate principles, the solve times are short and the results are similar (let's presume that they are accurate) for both solvers. I really have not had to tune the solvers to match results. To see separation in performance (speed, memory, accuracy, robustness, etc.), I would have to start looking at bigger models.

I believe that one needs many tools in the toolbox and that you need to know the strengths and weaknesses of the tools and play to those strengths and avoid those weaknesses. It is likely that one will need to transition between multiple tools as weaknesses are discovered. Since MMA can do algebra, it is ideal to develop equations and map them between the different solver implementations. My current view (subject to change) is that I would use MMA or COMSOL to determine the dominating physics on a geometrically simple model and apply those simplified physics to a geometrically complex model (i.e., large 3D CAD assembly) in another code.

This is actually a complex question with many dimensions, but I hope this helps.

POSTED BY: Tim Laska
Posted 6 years ago

Thanks.

The strength of MMA is its symbolic abilities. But to do fem modeling in MMA is still a hassle - not because its solvers, but the lack of features compared with other FEM softwares:

  1. Ability to show solving progress, i.e. current time, error plots and plot of latest step solution.

  2. Preset equation models. While heat or diffusion equations are easy to write, models like solid mechanics or N-S equations will take more time and prone to bugs.

  3. Somehow exporting animation is much slower on my computer than comsol.

I wish to see MMA improve in these areas in the future.

POSTED BY: Ox Clouding

I agree with your assessment and the assessment in the Mathematica StackExchange link provided by Kuba. I also agree with Alexi’s comment that it is an And proposition versus an Either Or proposition. For me personally, it is also an And plus a bunch of other tools proposition. I generally have more success integrating a bunch of best in class tools to create a simulation workflow than I do using an integrated tool that does everything. Much of what I do is the simulation of highly non-Newtonian fluid flow. My preference is to use Mathematica and COMSOL to study smaller scale phenomena and other CFD packages to study industrial sized models. If you can reduce the complexity of the physics for the large-scale model with Mathematica or COMSOL, you can dramatically increase your probability of a successful simulation.

Generally, I use COMSOL and Mathematica in complementary fashions. As time marches on, there is a blurring of some of the lines between the tools. For example, Mathematica is expanding their PDE capability, while COMSOL is expanding the portability capability with the COMSOL compiler. The computable document format and Wolfram Cloud did set Mathematica apart with its ability to deploy to a broad audience.

COMSOL is definitely a more mature physics modeling platform. As such, it has some convenience features that I will add in addition to yours.

  • Material library
  • Boundary layer meshing for CFD/non-conformal meshes/multiple reference frames
  • Solving steps
  • An application library of over a thousand worked examples
    • Validation and verification examples

Generally, when I am approached to do new modeling project, I state that I need 3 classes of inputs to begin. Namely, I need a description of the geometry, material properties, and operating conditions. Having a material library allows one to help specify the required inputs or potentially use a proxy material if the client cannot provide the inputs.

For highly shear thinning fluids, it is necessary to create a boundary layer mesh on surfaces otherwise the shear stresses will be overestimated. It is unclear to me that this capability exists in the Wolfram language or if the FEM implementation maintains accuracy with high aspect ratio tetrahedra.

Although COMSOL touts its fully coupled multiphysics capability, it is usually much faster and more robust if you can decouple the physics into a series of solution steps. For example, if you want to study heat transfer in a mixing vessel, you could naïvely conduct a fully coupled transient simulation starting from rest. However, experience shows that you can speed up the process over 100x by first solving the flow field with the steady-state frozen rotor approximation without heat transfer, then fix the flow field and solve the transient heat equation only in the next step and get about 90 to 95% of the correct answer. COMSOL makes it relatively easy to create this sequence of study steps (toggling checkboxes and pointing to a solution to initialize from). It should be noted that most solvers can use this strategy to reduce simulation time. It is not clear to me that this capability exists in the Wolfram language in a straightforward way, but if CFD capability is in the development plan, you need the capability to break the simulation and into a series of steps otherwise simulation times will be slow.

To be an effective modeler, it is likely that you will need to create a workflow consisting of multiple steps with different solver settings. The options space is combinatorially complex. Starting from a good initial guess that you can modify to suit your purpose is much simpler than trying to discover the optimal path from the ground up. This is where an extensive application library of solving workflows can be very beneficial. As the Mathematica modeling capability matures, perhaps they could use their curating ability to create a model lookup function similar to their formula lookup function. For example, ModelLookup[“non-isothermal flow”] would return several types of nonisothermal flow workflows (model data objects similar to formula data objects) to choose from.

Synergy

What I like to do is integrate multiple tools together into a productive workflow. What is usually more interesting to me is not how the tools compete, but rather how I can get them to cooperate to produce something they cannot do alone.

Flight Simulators.

One of the most successful applications of simulation has been that of a flight simulator, which have been commercially available since 1929 (Link Trainer). The main purpose of a flight simulator is to train the neural nets of the prospective pilot to the real time (i.e. interactive) dynamics of multiple controls in multiple environments. We probably can agree that a flight simulator that allowed the pilot to select the aircraft, one throttle, aileron, rudder, elevator, and flap setting and returned a picture of the aircraft flying into a mountain is essentially useless. Yet that is precisely what is being asked when a client asks for the one-off simulation.

So now, we might ask is it possible to make an interactive tool for the “pilots” (your customers potentially down to the operator level) to explore the effects of multiple controls using Mathematica and another slow tool? Here is one possible idea.

Slider Model with Mathematica

Interactivity

When I think of an interactive slider model, Mathematica’s manipulate is one of the first tools that comes to mind.

"Baking" the Physics

Since CFD simulations are generally quite slow, I am used to postprocessing the simulation in batch mode. So, let us try to make a multidimensional flipbook using MMA in another code. Let us create a series of GIF animations varying the liquid velocity at several gas velocities while fixing the equilibrium constant in the diffusion coefficient (in Mathematica this could take a few hours as I have not optimized the process so you may want to do this overnight). When the simulation is complete, we will import the list of GIF animations.

mDic = meshfn[config -> "Co"];
basename = "varyliquid_";
filenames = 
  Table[basename <> IntegerString[i, 10, 3] <> "." <> "gif", {i, 1, 
    20}];
Table[Export[filenames[[i]],
   Monitor[
    Table[
     modelfn[md -> mDic, k -> 0.5, dratio -> 0.5, 
       pel -> yy[1, 20, 0, 50, j] // N, 
       peg -> yy[1, 20, 0, 50, i] // N, title -> "Co-Flow"][[3]], {j, 
      1, 20}
     ],
    Grid[
     {{"Total progress:", 
       ProgressIndicator[
        Dynamic[f[j, 1, 20, 1]]]}, {"j=", {Dynamic@j}}}]
    ],
   "AnimationRepetitions" -> \[Infinity]], {i, 1, 20}];
files = FileNames["vary*.gif", NotebookDirectory[]];
gifs = Import[#] & /@ files;

It is quite easy to create a flipbook using manipulate so that we can view the effects along the liquid velocity and gas velocity dimensions.

m = Manipulate[
  Show[gifs[[i, j]]], {j, 1, 20, 1}, {i, 1, Length[gifs], 1}]

Co Flow Slider MMA

Just a word of warning. When I used the SaveDefinitions->True option, MMA ballooned up to over 15GB of RAM and took a while. There probably is a more optimal approach.

Likewise, we can conduct a similar process in COMSOL to create a series of GIF animations that can be imported and displayed in manipulate.

COMSOL Slider

What I like about this approach is that almost all solvers can produce a GIF animation, but few or none that I am aware of can create a flipbook along multiple dimensions. Additionally, there could be other clever tricks that one could play with Mathematica using interpolation functions on a sampled mesh, image processing, or machine learning that could be incorporated into manipulate, but I have yet to experiment with those approaches. Now, we have a pathway to distill potentially terabytes of information into a model that an operator can interact with. I find that pretty interesting.

POSTED BY: Tim Laska
Posted 6 years ago

Sorry for not seeing your reply earlier. That is very interesting comparison of the two software.

I mostly do data analysis directly in COMSOL but if there is a easy way to transfer results into MMA that would be nice. (Or even better, transfer equations, geometry and parameters from MMA to COMSOL! )

Currently COMSOL is more integrated with MATLAB. The only code linking MMA and comsol I found is "mathematica-comsol" on Github. Maybe you will be interested to try it.

POSTED BY: Ox Clouding

Thank you for the github link. I will investigate when I have free moment.

In the StackExchange link provided by Kuba above, Alexi does provide a procedure to export COMSOL data so that it can be can be read into Mathematica. I used it successfully to compare Mathematica to COMSOL from my very first answer to an adsorption problem to the Wolfram Community here.

tbl = Import[
   "C:\\Users\\Tim\\Dropbox\\WolframCommunity\\BreakThrough\\comsol_\
data_export.csv"];
conc = tbl[[All, Range[2, 302, 2]]];
ListPlot3D[Transpose@conc, DataRange -> {{0, 2}, {0, 1.5}}, 
 PlotRange -> {{0, 1}, {0, 1.5}}, 
 ColorFunction -> (ColorData["DarkBands"][#3] &), 
 MeshFunctions -> {#2 &}, Mesh -> 20, AxesLabel -> Automatic, 
 MeshStyle -> {Black, Thick}, ImageSize -> Large]

Comsol Solution

Perhaps, one could try to automate the workflow in java on the COMSOL end to facilitate the transfer.

With regard to the mesh, it looks like one might be able to use pyNastran to help bridge the gap between COMSOL and Mathematica. I have used pyNastran in the past to extract nodes and connectivity from an optiStruct model (Nastran format) and it looks as though COMSOL will export a Nastran mesh. GUIs do help facilitate meshing operations.

Parsing a parameter file should be easy, but parsing how all the parameters are used throughout the model would be difficult and prone to errors.

POSTED BY: Tim Laska

Take a look at the extensive documentation “Advanced Solutions to Numerical Differential Equations“ and for NDSolve. There are methods to track solutions (combinations of EvaluationMonitor, StepMonitor, and Dynamic.

There are also good examples of doing solid mechanics.

POSTED BY: W. Craig Carter
Posted 6 years ago

Thanks for the reply. I am aware of MMA capabilities of manually track solutions with code. But I still wish they could make it simpler by adding a simple built-in function like TrackSolving[NDSolve[...]] instead of having us to implement it.

Just like in the past we have to write our own neural network but now we have NetTrain. Why not improve more fundamental functions like NDSolve?

POSTED BY: Ox Clouding

You may find this thread interesting: https://mathematica.stackexchange.com/q/154254/5478

POSTED BY: Kuba Podkalicki

@TimLaska, It is perfectly reasonable to mention use of other languages/programs in any of several situations.

(1) Validation of results.

(2) Asking about discrepancies in behavior between the two. (If the Wolfram Language is showing obviously buggy behavior, it is good also to report that directly. Also we do not take well to having the same issue reported repeatedly. But that tends to be an uncommon problem in any forum.)

(3) Discussion about linking to/from other programs.

(4) Speed comparison, when we are faster (just kidding-- if it is an apples-to-apples comparison and WL falls short, that's good for us and others to know about).

(5) Questions to the effect "Does the Wolfram Language have something similar or equivalent to the built-in function XXX from program YYY?"

I'm probably missing a few other valid reasons. In any case, it would be fine for you to add discussion of othe rprograms in this setting.

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard