Skip to content

Commit

Permalink
Minor fix for circuits when extruding internally.
Browse files Browse the repository at this point in the history
  • Loading branch information
raback committed Oct 25, 2024
1 parent 3da4fb1 commit d0ec43b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
42 changes: 29 additions & 13 deletions fem/src/CircuitUtils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ SUBROUTINE ReadComponents(CId)
INTEGER :: ExtMaster

CALL Info('ReadComponents','Reading component: '//I2S(Cid),Level=20)

Circuit => CurrentModel % Circuits(CId)

Circuit % CvarDofs = 0
Expand Down Expand Up @@ -775,25 +775,34 @@ SUBROUTINE ReadComponents(CId)
IF (.NOT. Found) Comp % VoltageFactor = 1._dp

Comp % ElBoundaries => ListGetIntegerArray(CompParams, 'Electrode Boundaries', Found)

! This is a feature intended to make it easier to extruded meshes internally with
! ElmerSolver. The idea is that the code knows which are the BCs that were created
! from extruding this 2D body.
ExtMaster = 0
IF(.NOT. Found ) THEN
IF( ListGetLogical( CurrentModel % Solver % Values,'Extruded Child BC Electrode', Found ) ) THEN
IF( ListGetLogical( CurrentModel % Solver % Values,'Extruded Child BC Electrode', Found ) ) THEN

IF( ListGetLogical( CurrentModel % Simulation,"Extruded BCs Collect",Found ) ) THEN
CALL Fatal('Circuits_init',&
'Conflicting keywords: "Extruded Child BC Electrode" vs. "Extruded BCs Collect"')
END IF

CALL Info('Circuits_init','Setting "Extruded Child BCs"',Level=10)
BLOCK
INTEGER :: body_id
INTEGER, POINTER :: pIntArray(:) => NULL()
pIntArray => ListGetIntegerArray(CompParams, 'Master Bodies', Found )
pIntArray => ListGetIntegerArray(CompParams, 'Body', Found )
IF(.NOT. Found) pIntArray => ListGetIntegerArray(CompParams, 'Master Bodies', Found )
IF( Found ) THEN
IF(SIZE(pIntArray)==1) THEN
body_id = pIntArray(1)
NULLIFY(pIntArray)
pIntArray => ListGetIntegerArray(CurrentModel % Bodies(body_id) % Values,&
'Extruded Child BCs',Found )
IF(Found) THEN
CALL Info('Circuits_int','Associating "Electrode Boundaries" to extruded bcs!',Level=10)
CALL Info('Circuits_init','Setting Component '//I2S(CompInd)//' "Electrode Boundaries" to '&
//I2S(pIntArray(1))//' '//I2S(pIntArray(2)),Level=10)
Comp % ElBoundaries => pIntArray
ExtMaster = body_id
END IF
Expand All @@ -816,8 +825,12 @@ SUBROUTINE ReadComponents(CId)
IF (.NOT. Found) CALL Fatal('Circuits_Init','Number of Turns not found!')

Comp % ElArea = GetConstReal(CompParams, 'Electrode Area', Found)
IF (.NOT. Found) CALL ComputeElectrodeArea(Comp, CompParams, ExtMaster )

IF (.NOT. Found) THEN
CALL ComputeElectrodeArea(Comp, CompParams, ExtMaster )
WRITE(Message,'(A,ES12.5)') 'Component '//I2S(CompInd)//' "Electrode Area" is ',Comp % ElArea
CALL Info('Circuits_Init',Message,Level=10)
END IF

Comp % CoilThickness = GetConstReal(CompParams, 'Coil Thickness', Found)
IF (.NOT. Found) Comp % CoilThickness = 1._dp

Expand Down Expand Up @@ -870,8 +883,12 @@ SUBROUTINE ReadComponents(CId)
IF (.NOT. Found) CALL Fatal('Circuits_Init','Number of Turns not found!')

Comp % ElArea = GetConstReal(CompParams, 'Electrode Area', Found)
IF (.NOT. Found) CALL ComputeElectrodeArea(Comp, CompParams)

IF (.NOT. Found) THEN
CALL ComputeElectrodeArea(Comp, CompParams )
WRITE(Message,'(A,ES12.5)') 'Component '//I2S(CompInd)//' "Electrode Area" is ',Comp % ElArea
CALL Info('Circuits_Init',Message,Level=10)
END IF

Comp % N_j = Comp % nofturns / Comp % ElArea
END SELECT
END IF
Expand Down Expand Up @@ -942,8 +959,9 @@ SUBROUTINE ComputeElectrodeArea(Comp, CompParams, ExtMaster )
IF (.NOT. ASSOCIATED(Comp % ElBoundaries)) &
CALL Fatal('ComputeElectrodeArea','Electrode Boundaries not found')
BCid = Comp % ElBoundaries(1)
IF( BCid > CurrentModel % NumberOfBCs ) &
IF( BCid < 1 .OR. BCid > CurrentModel % NumberOfBCs ) &
CALL Fatal('ComputeElectrodeArea', 'BCid is beyond range: '//I2S(BCid))

BC => CurrentModel % BCs(BCid) % Values
IF (.NOT. ASSOCIATED(BC) ) CALL Fatal('ComputeElectrodeArea', 'Boundary not found!')
Comp % ElArea = GetConstReal(BC, 'Area', Found)
Expand Down Expand Up @@ -2321,11 +2339,9 @@ SUBROUTINE Circuits_MatrixInit()
CALL CreateBasicCircuitEquations(Rows, Cols, Cnts)
CALL CreateComponentEquations(Rows, Cols, Cnts, Done, dofsdone)


IF (n /= SUM(Cnts)) THEN
print *, "Counted Cnts:", n, "Applied Cnts:", SUM(Cnts)
CALL Fatal('Circuits_MatrixInit', &
'There were different amount of matrix elements than was counted')
'Inconsistent number of matrix elements: '//I2S(n)//' vs. '//I2S(SUM(CNTs)))
END IF

DEALLOCATE( Cnts, Done )
Expand Down
5 changes: 3 additions & 2 deletions fem/src/MeshUtils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18861,8 +18861,9 @@ FUNCTION MeshExtrudeSlices(Mesh_in, Vlist) RESULT(Mesh_out)
TmpPair(2) = ChildBCs(2*i)
CALL ListAddIntegerArray(vList,'Extruded Child BCs',2,TmpPair)

IF( InfoActive(20) ) THEN
PRINT *,'Extruded Child BCs for body:',i,TmpPair
IF( InfoActive(10) ) THEN
CALL Info(Caller,'Setting Body '//I2S(i)//' "Extruded Child BCs" to '&
//I2S(TmpPair(1))//' '//I2S(TmpPair(2)))
END IF
NULLIFY(TmpPair)
END IF
Expand Down
16 changes: 6 additions & 10 deletions fem/src/modules/CircuitsAndDynamics.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2702,13 +2702,12 @@ SUBROUTINE CircuitsOutput(Model,Solver,dt,Transient)

IF (Cvar % pdofs /= 0 ) THEN
DO jj = 1, Cvar % pdofs
write (dofnumber, "(I2)") jj
CALL SimListAddAndOutputConstReal(&
TRIM(Circuits(p) % names(i))&
//'re dof '//TRIM(dofnumber), crt(Cvar % ValueId + ReIndex(jj)), Level=10)
//'re dof '//I2S(jj), crt(Cvar % ValueId + ReIndex(jj)), Level=10)
CALL SimListAddAndOutputConstReal(&
TRIM(Circuits(p) % names(i))&
//'im dof '//TRIM(dofnumber), crt(Cvar % ValueId + ImIndex(jj)), Level=10)
//'im dof '//I2S(jj), crt(Cvar % ValueId + ImIndex(jj)), Level=10)
END DO
END IF
ELSE
Expand All @@ -2717,10 +2716,9 @@ SUBROUTINE CircuitsOutput(Model,Solver,dt,Transient)

IF (Cvar % pdofs /= 0 ) THEN
DO jj = 1, Cvar % pdofs
write (dofnumber, "(I2)") jj
CALL SimListAddAndOutputConstReal(&
TRIM(Circuits(p) % names(i))&
//'dof '//TRIM(dofnumber), crt(Cvar % ValueId + jj), Level=10)
//'dof '//I2S(jj), crt(Cvar % ValueId + jj), Level=10)
END DO
END IF
END IF
Expand Down Expand Up @@ -2782,11 +2780,9 @@ SUBROUTINE SimListAddAndOutputConstReal(VariableName, VariableValue, Level)
INTEGER :: LevelVal = 3

IF (PRESENT(Level)) LevelVal = Level

WRITE(VarVal,'(ES15.4)') VariableValue
CALL Info(Caller, TRIM(VariableName)//' '//&
TRIM(VarVal), Level=LevelVal)

WRITE(Message,'(A,T20,ES15.4)') TRIM(VariableName),VariableValue
CALL Info(Caller,Message,Level=LevelVal)

CALL ListAddConstReal(GetSimulation(),TRIM(CktPrefix)//' '//TRIM(VariableName), VariableValue)
!-------------------------------------------------------------------
END SUBROUTINE SimListAddAndOutputConstReal
Expand Down

0 comments on commit d0ec43b

Please sign in to comment.