User defined Casson viscosity model

Numerical methods and mathematical models of Elmer
Post Reply
shubh_shinde
Posts: 19
Joined: 13 Aug 2017, 23:58
Antispam: Yes

User defined Casson viscosity model

Post by shubh_shinde »

Dear all,
I am trying to implement a Casson viscosity model for fluid flow in an artery. The Casson fluid is non-Newtonian in nature and thus depends on the shear rate.
In the material models module I created another case with string casson and compiled the materialmodels.mod file.

Code: Select all

     CASE ('casson')
        c1n = ListGetReal( Material, 'Shear Yield Strength',n,Element % NodeIndexes )
        c1 = SUM( Basis(1:n) * c1n(1:n) )
        c2 = ListGetConstReal( Material, 'M Value',gotIt)
	IF(gotIt) THEN  
	   s= SQRT(ss)
	   mu=  (SQRT(Viscosity)+SQRT(c1/s)*(1-2.718**(-1*SQRT(c2*s))))**2
	END IF
The matrial properties in sif file are given by

Code: Select all

Material 1
  Name = "Material 1"
  Procedure "materialmodels" "EffectiveViscosity"
  Viscosity Model = casson
  M Value = 2
  Viscosity = 0.0035
  Porosity Model = Always saturated
  Shear Yield Strength = 100
End
But I get the following error each time I try to solve the case.

Code: Select all

MAIN: Reading Model: case.sif
LoadInputFile: Scanning input file: case.sif
ERROR:: Model Input: 
ERROR:: Model Input:  Unknown specifier: [viscosity model]
ERROR:: Model Input:  In section: [material 1]
ERROR:: Model Input:  For property name:[procedure materialmodels EffectiveViscosity]
Please suggest if I can append the viscosity models in existing material models in elmer and if so where it is going wrong.
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: User defined Casson viscosity model

Post by annier »

Hi Shubham,
1. The materials models (https://github.com/ElmerCSC/elmerfem/bl ... Models.F90) is a subroutine that consists of several functions that are called from solvers from Solver section of SIF. The non-newtonian material models are called from NavierStokes.F90 subroutine (which is already precompiled with Elmer installation) and so you may not call from Materials block procedure. Also,your calling procedure for user defined subroutines or functions in material block is resembling that of solver section. It should be generally of this structure:

Code: Select all

Material_property_Name = Variable  var-name1, var-name2, var-name3, var-name4, ...,var-namen
Procedure "file name" "function-name"
2. Assuming you want to call the ModifiedMaterialModels.F90 (after it includes Casson viscosity model) from flow solver, you have to use the following fortran files around your SIF.
1. ModifiedFlowSolve.F90 -->> It uses ModifiedNavierStokes.F90
2. ModifiedNavierStokes.F90 -->> It calls the viscosity model from Material Block by asking from ModifiedMaterialModels.F90
3. ModifiedMaterialModel.F90 -->> It includes the Casson viscosity model.

I have used Modifed as a prefix to these files , in order not to make ElmerSolver confuse with the original names of the solvers. Virtually, ModifiedFlowSolve and ModifiedNavierStokes.F90 are same to their original files.
Now, you compile ModifiedFlowSolve.F90 using elmerf90 wrapper and understand how it can communicate with the other two files (in FORTRAN syntax) during solver run. Maybe you need to first compile ModifiedNavierStokes.F90 and ModifiedMaterialModel.F90 step by step to prepare .mod files and enable the ModifiedFlowSolve.f90 to use these mod files while compiling to prepare so file by elmerwrapper. It is a FORTRAN syntax work again.
Then you can use ModifiedFlowSolve in the solver section , that can use the Casson viscosity model.

Another, way is that you can write a user defined function to solve Effective Viscosity and can write viscosity (of the material block or section) as a function of the variable(s) involved.

Yours Sincerely,
Anil Kunwar
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
raback
Site Admin
Posts: 4801
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: User defined Casson viscosity model

Post by raback »

Hi,

Focusing just to the sif this could work:

Code: Select all

Material 1
  Name = "Material 1"
  Viscosity Model = casson
  M Value = Real 2
  Viscosity = 0.0035
  Shear Yield Strength = 100
End
Technically the dependence is as explained by anier.

-Peter
shubh_shinde
Posts: 19
Joined: 13 Aug 2017, 23:58
Antispam: Yes

Re: User defined Casson viscosity model

Post by shubh_shinde »

Dear Anil and Peter,
I understand the procedure now.
I have compiled the ModifiedFlowSolve.F90 using the elmer wrapper command and also the modules using the same command (Is it correct to compile modules in the same way? It does generate the .mod file).
When I run the sif file I get the following error,

Code: Select all

MAIN: =============================================================
MAIN: 
MAIN: 
MAIN: -------------------------------------
MAIN: Reading Model: case.sif
LoadInputFile: Scanning input file: case.sif
LoadInputFile: Loading input file: case.sif
Loading user function library: [FlowSolveTest]...[FlowSolverTest_Init0]
FlowSolveTest: cannot open shared object file: No such file or directory
FlowSolveTest.so: cannot open shared object file: No such file or directory
./FlowSolveTest: cannot open shared object file: No such file or directory
./FlowSolveTest.so: cannot open shared object file: No such file or directory
/usr/share/elmersolver/lib/FlowSolveTest: cannot open shared object file: No such file or directory
/usr/share/elmersolver/lib/FlowSolveTest.so: undefined symbol: __navierstokestest_MOD_vmswalls
Is it because of FlowSolve o NavierStokes module?
Should there be any kind of linking apart from using the module in solver by USE command?

Kindly suggest.
I also apologize for late reply

Sincerely,
Shubham
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: User defined Casson viscosity model

Post by mzenker »

Hi,

I have no experience with self-compiled solvers under Linux (yet).
But I can tell that under Windows, the compilation generates a .dll file which can be placed either in the project directory (where the sif file resides) or in share\elmersolver\lib in the Elmer installation directoy, where all the solver dll's reside. The latter path may be different under Linux, maybe in /usr/share/elmersolver/lib or /usr/lib/elmersolver, and the solver dll's have the extension .so, I think. I don't have my Linux box at hand right now, so I cannot verify.
Anyway, if you copy your .so file into the project directory to start with, ElmerSolver should find it, which would get you one step further.

HTH,
Matthias
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: User defined Casson viscosity model

Post by annier »

Hi Shubham,
Please get some references on compiling hierarchically dependent fortran files (e.g. https://stackoverflow.com/questions/197 ... tine-files), wherein elmerf90 can be utilized in the similar way with gfortran and .so file for .exe.

Links:
1. http://pages.mtu.edu/~shene/COURSES/cs2 ... files.html
2. http://lagrange.mechse.illinois.edu/f90_mod_deps/
3. https://stackoverflow.com/questions/417 ... ubroutines
4. https://stackoverflow.com/questions/586 ... iple-parts

If error persist upon compiling, then you need to look into the fortran files if they have unmet dependencies or need some additional changes inside them.

Matthias,
The preinstalled elmer modules (materials.mod and navierstokes.mod) are in usr/share/elmersolver/include/ folder whereas solver's shared object files (FlowSolve.so) are in usr/share/elmersolver/lib/ directory. However, for files that are to be externally compiled by elmerf90 wrapper, all the dependent modules can be kept within the project directory around the sif and related PATH can be assigned wherever required. Changing the things within /usr/ directory is not recommended unless we know what we are doing. So, basically the major goal ahead would be to find out how the shared object file searches the information from mod files.

Yours Sincerely,
Anil Kunwar
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: User defined Casson viscosity model

Post by annier »

raback wrote: Focusing just to the sif this could work:

Code: Select all

Material 1
  Name = "Material 1"
  Viscosity Model = casson
  M Value = Real 2
  Viscosity = 0.0035
  Shear Yield Strength = 100
End
Peter,
The material model does not include the Viscosity Model "casson". If you could include it in the fresher version, Shubham could be able to use it like other viscosity models .
or,
Shubham,
you can code your casson model in MaterialModels.F90 , in the fork of elmerfem github repository https://github.com/ElmerCSC/elmerfem and push it , so that elmer team can include them in fresher version.

Yours Sincerely,
Anil Kunwar
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
shubh_shinde
Posts: 19
Joined: 13 Aug 2017, 23:58
Antispam: Yes

Re: User defined Casson viscosity model

Post by shubh_shinde »

Hi Anil,
Thank you for valuable suggestions.
I could now solve the issue of linking the modules with main solver. Compiling all the files at once did the trick.
I will definitely put the code for casson viscosity model along with other non-Newtonian viscosity models in github repository once I work with them thoroughly.
Sincerely,
Shubham
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: User defined Casson viscosity model

Post by annier »

Hi Shubham,
Did you make sure that the solver CassonFlowSolve.F90 (only name changed to initial solver) compiled using default MaterialModels.F90 and NavierStokes.F90 or you changed their names too, e.g. ModifiedMaterialModels.F90 and ModifiedNavierStokes.F90? With ElmerSolver's elmerf90 wrapper accessing the modules at /usr/share/elmersolver/include/, the solver may actually be interacting with the default modules.
If CassonFlowSolve.F90 compiled with the default modules of ElmerSolver, then it must issue the following warning , when you run a test case using Casson viscosity model , because it won't find it there.

Code: Select all

...
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
WARNING:: EffectiveViscosity: Unknown material model
FlowSolve: Assembly done
FlowSolve: Dirichlet conditions done
IterSolver: Calling real valued iterative solver
      10 0.5393E-08 0.5393E-08
      20 0.4634E-08 0.4634E-08
      30 0.2656E-08 0.2656E-08
      40 0.8694E-09 0.8694E-09
      50 0.1926E-09 0.1926E-09
      58 0.7236E-10 0.7236E-10
ComputeChange: NS (ITER=5) (NRM,RELC): (  158.04119     0.43690106E-06 ) :: navier-stokes
FlowSolve: iter:    5 Assembly: (s)    0.03    0.14
FlowSolve: iter:    5 Solve:    (s)    0.07    0.30
...
as it is coded in the module MaterialModels.F90

Code: Select all

...
       CASE DEFAULT 
        CALL WARN('EffectiveViscosity','Unknown material model')
...
Please verify it first.

Yours Sincerely,
Anil Kunwar
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
shubh_shinde
Posts: 19
Joined: 13 Aug 2017, 23:58
Antispam: Yes

Re: User defined Casson viscosity model

Post by shubh_shinde »

Hi Anil,
I am compiling using the modified (format --> FileTest.F90) modules i.e. navierstokestest.mod and materialmodelstest.mod. The navierstokestest.mod uses materialmodelstest.mod (where casson viscosity is added)
The problem is when I compile I am now getting following errors,

Code: Select all

FlowSolveTest.F90:1282:52:

          IF ( CompressibilityModel == Incompressible ) THEN
                                                    1
Error: Name ‘incompressible’ at (1) is an ambiguous reference to ‘incompressible’ from module ‘materialmodelstest’
FlowSolveTest.F90:1284:12:

          END IF
            1
Error: Expecting END DO statement at (1)
FlowSolveTest.F90:1297:9:

       END IF
         1
Error: Expecting END DO statement at (1)

There are a lot of syntax errors but the materialmodelstest file is same as default materialmodels. I have no idea why this is happening.

When I compile using only navierstokestest.mod it works fine (in this case I use ModifiedNavierStokes module in FlowSolveTest.F90).
I have tested this by printing some text in code body.
I am not able to understand why it gives errors when I link modifiedmaterialmodels. Kindly suggest.

Compiling as,

Code: Select all

elmerf90 -c NavierStokesTest.F90 MaterialModelsTest.F90 
elmerf90 MaterialModelsTest.o NavierStokesTest.o FlowSolveTest.F90 -o FlowSolveTest.so

Sincerely,
Shubham
Attachments
NavierStokesTest.F90
(58.58 KiB) Downloaded 263 times
MaterialModelsTest.F90
(28.3 KiB) Downloaded 275 times
FlowSolveTest.F90
(101.04 KiB) Downloaded 280 times
Post Reply