Anisotropic material with StatCurrentSolver

Numerical methods and mathematical models of Elmer
Post Reply
m_nadimii
Posts: 14
Joined: 07 Mar 2023, 17:03
Antispam: Yes

Anisotropic material with StatCurrentSolver

Post by m_nadimii »

Hello,
I want to use anisotropic material for each node, and get potential at each node based on laplace equation.
now I'm using StatCurrentSolver for this aim. but got this error:

"Program received signal SIGSEGV: Segmentation fault - invalid memory reference."

The user defined function that I'm using :

Code: Select all

FUNCTION anisotropy(Model, n, f) RESULT(g)
	USE DefUtils
	TYPE(Nodes_t) :: ElementNodes
	TYPE(Model_t) :: Model

	integer :: stat, n

	LOGICAL, SAVE :: Visited = .FALSE.
	REAL(KIND=dp), dimension(:), ALLOCATABLE :: g
	REAL(KIND=dp), ALLOCATABLE, SAVE :: gall(:,:)
	  IF(.NOT. Visited) THEN
	    ! populate some table "gall"
	    m = Model % Mesh % NumberOfNodes
	    ALLOCATE(gall(m,9))
	    OPEN(newunit=io1, file="data.dat", status="old", action="read")
	    READ(io1, *,iostat=stat) gall(1:m,:)
	    allocate(g(9))

	    CLOSE(io1)
	    Visited = .TRUE.
	  END IF
	    g = gall(n,:)
		print *, g
END FUNCTION anisotropy
and this is how I read it in .sif file

Code: Select all

  Electric Conductivity(9) = Variable Potential
  Real Procedure "anisotropy" "anisotropy"  
I was wondering whether the function has some errors or this solver doesn't support anisotropic material?
raback
Site Admin
Posts: 4832
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Anisotropic material with StatCurrentSolver

Post by raback »

Hi

These test cases work:

Code: Select all

elmeruser@elmeruser-VirtualBox:~/elmerfem/fem/tests$ ls | grep Uniso
HeatUniso
HeatUnisoMATC
HeatUnisoTable
HeatUnisoUDF
In you F90 I fear that you cannot allocate the argument (g) inside the UDF. The caller knows by the size declaration of the keyword what is the size of the vector to be returned and it is allocated for.

-Peter
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: Anisotropic material with StatCurrentSolver

Post by annier »

Hi m_nadimii,
Yes the electric conductivity materials properties can be a tensor (please refer the following snippet at https://github.com/ElmerCSC/elmerfem/bl ... tSolve.F90) . So, anisotropy can be directly supplied via sif.

Code: Select all

IF( .NOT. GetCondAtIp ) THEN

           k = ListGetInteger( Model % Bodies(CurrentElement % BodyId) % &
               Values, 'Material', minv=1, maxv=Model % NumberOfMaterials )

           !------------------------------------------------------------------------------
           !      Read conductivity values (might be a tensor)
           !------------------------------------------------------------------------------
           
           CALL ListGetRealArray( Model % Materials(k) % Values, &
               'Electric Conductivity', Cwrk, n, NodeIndexes )

           Conductivity = 0.0d0
           IF ( SIZE(Cwrk,1) == 1 ) THEN
             DO i=1,3
               Conductivity( i,i,1:n ) = Cwrk( 1,1,1:n )
             END DO
           ELSE IF ( SIZE(Cwrk,2) == 1 ) THEN
             DO i=1,MIN(3,SIZE(Cwrk,1))
               Conductivity(i,i,1:n) = Cwrk(i,1,1:n)
             END DO
           ELSE
             DO i=1,MIN(3,SIZE(Cwrk,1))
               DO j=1,MIN(3,SIZE(Cwrk,2))
                 Conductivity( i,j,1:n ) = Cwrk(i,j,1:n)
               END DO
             END DO
           END IF
         END IF


The tensor values can be directly supplied in the sif in the Material 1 block as

Code: Select all

! For 3D constant diagonal conductivity
 Electric Conductivity(3) = 5 10 0
!  Electric Conductivity(3,3) = 5 0 0 0 10 0 0 0 0

! For 2D coordinate system
!  Electric Conductivity(2) = 5 10
!  Electric Conductivity(2,2) = 5 0 0 10 
Also, these values can be entered via Table or matc expressions.

An example of using user defined function for anisotropic material property is available at
https://github.com/anilkunwar/elmerfem/ ... oKthml.sif
https://github.com/anilkunwar/elmerfem/ ... Tensor.F90

Best Regards,
Anil
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
Post Reply