Hello all,
I would like to introduce an element of randomness into my material density to increase realism. I generated a Gaussian distribution of densities and would like to randomly spread these out across the x-y plane.
I know Elmer can perform linear interpolation for data with one dependence (e.g. density as a function of temperature or x-coordinate), but I would like to have it double interpolate using both the x and y coordinate.
This syntax doesn't work:
Density = Variable Coordinate 1, Coordinate 2
Real
0 0 2500
0 1 2450
1 0 2475
1 1 2460
etc...
End
I also can't model the random densities as a function, so something like
Density = Variable Coordinate 1, Coordinate 2; Real MATC "tx(0) + tx(1)";
won't do.
Any thoughts?
2-D Stochastic Density
-
- Posts: 2293
- Joined: 25 Jan 2019, 01:28
- Antispam: Yes
Re: 2-D Stochastic Density
Most likely would want to look into a user defined function. Elmer allows you to create and compile your own functions and call them from a sif.
See section 18.3 of the solver manual
18.3 Writing a User Function
User functions can be used to provide a pointwise (not element wise!) value for a certain property. They are
used for setting values of material properties inside the domain and/or to set values for certain variables on
boundary conditions at the domain boundary.
The defined interface for a user function looks as follows
FUNCTION myfunction( model, n, var ) RESULT(result)
USE DefUtils
IMPLICIT None
TYPE(Model_t) :: model
INTEGER :: n
REAL(KIND=dp) :: var, result
... contents of the function
leading to a value for variable result ...
END FUNCTION myfunction
See section 18.3 of the solver manual
18.3 Writing a User Function
User functions can be used to provide a pointwise (not element wise!) value for a certain property. They are
used for setting values of material properties inside the domain and/or to set values for certain variables on
boundary conditions at the domain boundary.
The defined interface for a user function looks as follows
FUNCTION myfunction( model, n, var ) RESULT(result)
USE DefUtils
IMPLICIT None
TYPE(Model_t) :: model
INTEGER :: n
REAL(KIND=dp) :: var, result
... contents of the function
leading to a value for variable result ...
END FUNCTION myfunction
-
- Site Admin
- Posts: 4823
- Joined: 22 Aug 2009, 11:57
- Antispam: Yes
- Location: Espoo, Finland
- Contact:
Re: 2-D Stochastic Density
Yes, UDF is the way to go. I would add to Kevin's advice to create a look-up-table for the random numbers the first time, and thereafter pick the right value. If you would do the random thing every time the value would not be constant. So something like (content to Kevin's code),
-Peter
Code: Select all
logical :: Visited = .false.
real(kind=dp), allocatable :: rndvals(:)
save visited, rndvals
if(.not. visited) THEN
allocate(rndvals(model % mesh % numberOfNodes)
CALL RANDOM_NUMBER(rndvals) ! in [0,1]
rndvals = 100+10*rndvals ! in [90,110]
visited = .true.
end if
result = rndvals(n)
-Peter
Re: 2-D Stochastic Density
Thanks for the help. I'll look into the UDFs and see if I can get something going.