Define material on mesh nodes

Numerical methods and mathematical models of Elmer
Post Reply
m_nadimi
Posts: 6
Joined: 27 Jan 2023, 15:41
Antispam: Yes

Define material on mesh nodes

Post by m_nadimi »

Hi,
I would like to assign different material on every nodes of my mesh since my model is heterogeneous. and then solve the laplace equation to get electric potential.
Materials are saved in an external .dat file.
I want to see whether it is possible to assign this values to nodes in user defined functions.
there would be around.
Thanks for your attention.

********************************
Material 2
include data.dat
Name = "brain"
Electric Conductivity = Variable Potential
Real Procedure "siff" "heterogeneity"
End
*******************************
FUNCTION heterogeneity(Model, n, f) RESULT(g)
USE DefUtils
TYPE(Model_t) :: Model
TYPE(ValueList_t), POINTER :: material
REAL(KIND=dp) :: x, y, z
x = Model % Nodes % x(n)
y = Model % Nodes % y(n)
z = Model % Nodes % z(n)
print*, x,y,z,n
END FUNCTION heterogeneity
raback
Site Admin
Posts: 4823
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Define material on mesh nodes

Post by raback »

Hi

No problem. Have you stored the data on the mesh points, or on some other points?

If you already have on mesh points read in the data when 1st calling your function and then take g from the table. To perform only once use a construct like:

Code: Select all

  ...
  LOGICAL, SAVE :: Visited = .FALSE.
  REAL(KIND=dp), ALLOCATABLE, SAVE :: gall(:)
  INTEGER :: m, io
  IF(.NOT. Visited) THEN
    ! populate some table "gall"
    m = Model % Mesh % NumberOfNodes
    ALLOCATE(Gall(m))
    OPEN(newunit=io, file="data.dat", status="old", action="read")
    READ(io, *) gall(1:m)
    CLOSE(io)
    Visited = .TRUE.
  END IF
  g = gall(n)
  ...
-Peter
m_nadimi
Posts: 6
Joined: 27 Jan 2023, 15:41
Antispam: Yes

Re: Define material on mesh nodes

Post by m_nadimi »

Thank you very much. It helped me a lot.
My other question is that I have saved the conductivities in a .dat file with size (m,4) which the first 3 columns are coordinates and the fourth is conductivity. now here I'm not sure how I should assign the correct value to each node.
raback
Site Admin
Posts: 4823
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Define material on mesh nodes

Post by raback »

Hi

Perform dummy N^2 search, or sort the entries by some coorinates for quicker finding. Or maybe they are not even the same nodes...

There is "DataToFieldSolver" that takes nodes and performs Galerkin fit to them. Perhaps use that if you need a generic approach.

-Peter
m_nadimi
Posts: 6
Joined: 27 Jan 2023, 15:41
Antispam: Yes

Re: Define material on mesh nodes

Post by m_nadimi »

Thanks for your answer. by using mesh.nodes I could access to the exact mesh nodes.
but now I'm not sure if this part is correct. since my result are not as expected and somehow infinity.

Code: Select all

Electric Conductivity = Variable Potential
Real Procedure "siff" "heterogeneity"
Potential is aimed to be solved by laplace equation. but I'm not sure it should be used here as variable?

Code: Select all

Solver 1
  Equation = Electrostatics
  Variable = Potential
  Calculate Electric Field = True
  Procedure = "StatCurrentSolve" "StatCurrentSolver"
  Calculate Electric Flux = True
  Calculate Electric Energy = True
  Constant Weights = True
  Exec Solver = Always
  Stabilize = True
  Optimize Bandwidth = True
  Steady State Convergence Tolerance = 1.0e-5
  Nonlinear System Convergence Tolerance = 1.0e-7
  Nonlinear System Max Iterations = 2
  Nonlinear System Newton After Iterations = 3
  Nonlinear System Newton After Tolerance = 1.0e-3
  Nonlinear System Relaxation Factor =1
  Linear System Solver = Direct
  Linear System Direct Method = umfpack
  Linear System Max Iterations = 500
  Linear System Convergence Tolerance = 1.0e-10
  BiCGstabl polynomial degree = 2
  Linear System Preconditioning = ILU0
  Linear System ILUT Tolerance = 1.0e-3
  Linear System Abort Not Converged = True
  Linear System Residual Output = 10
  Linear System Precondition Recompute = 1
End
m_nadimi
Posts: 6
Joined: 27 Jan 2023, 15:41
Antispam: Yes

Re: Define material on mesh nodes

Post by m_nadimi »

when solving the problem it shows:

Code: Select all

StatCurrentSolve:  Assembly (s)          :   4.7505990000000002
ComputeChange: NS (ITER=1) (NRM,RELC): (       Infinity            NaN ) :: electrostatics
StatCurrentSolve:  Solve (s)             :   80.878566000000006

raback
Site Admin
Posts: 4823
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Define material on mesh nodes

Post by raback »

Hi, There really isn't enough material to locate the issue. A complete case would help. -Peter
m_nadimi
Posts: 6
Joined: 27 Jan 2023, 15:41
Antispam: Yes

Re: Define material on mesh nodes

Post by m_nadimi »

Thanks for your reply.
The problem was defining g as double precision.
and now it is computing what I want.

Code: Select all

	REAL(KIND=dp) :: g
raback
Site Admin
Posts: 4823
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Define material on mesh nodes

Post by raback »

Yeh, "IMPLICIT NONE" was missing... Such a remnant from history to give implicit variable types but maintained for backward compability of legacy codes. -Peter
Post Reply