Skip to content

Commit 74f54c1

Browse files
committed
add User1Material for test
1 parent c9c73af commit 74f54c1

File tree

7 files changed

+205
-1
lines changed

7 files changed

+205
-1
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ set(src ${src} src/MateSystem/SmallStrainDiffusionJ2Material.cpp)
524524
###
525525
set(inc ${inc} include/MateSystem/DiffusionACFractureMaterial.h)
526526
set(src ${src} src/MateSystem/DiffusionACFractureMaterial.cpp)
527+
### User-1 material
528+
set(inc ${inc} include/MateSystem/User1Material.h)
529+
set(src ${src} src/MateSystem/User1Material.cpp)
527530
### for material system
528531
set(inc ${inc} include/MateSystem/MateSystem.h)
529532
set(src ${src} src/MateSystem/MateSystem.cpp)

include/MateSystem/BulkMateSystem.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
#include "MateSystem/SmallStrainDiffusionJ2Material.h"
5151
#include "MateSystem/DiffusionACFractureMaterial.h"
5252

53+
/**
54+
* For User-Defined-Material (UMAT)
55+
*/
56+
#include "MateSystem/User1Material.h"
5357

5458
/**
5559
* This class implement the materials calculation for the bulk element in AsFem.
@@ -78,7 +82,9 @@ class BulkMateSystem:public ConstPoissonMaterial,
7882
public MieheFractureMaterial,
7983
public SmallStrainCahnHilliardMaterial,
8084
public SmallStrainDiffusionJ2Material,
81-
public DiffusionACFractureMaterial{
85+
public DiffusionACFractureMaterial,
86+
// for umat
87+
public User1Material{
8288
public:
8389
/**
8490
* constructor

include/MateSystem/User1Material.h

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//****************************************************************
2+
//* This file is part of the AsFem framework
3+
//* A Simple Finite Element Method program (AsFem)
4+
//* All rights reserved, Yang Bai/M3 Group@CopyRight 2020-present
5+
//* https://github.com/M3Group/AsFem
6+
//* Licensed under GNU GPLv3, please see LICENSE for details
7+
//* https://www.gnu.org/licenses/gpl-3.0.en.html
8+
//****************************************************************
9+
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10+
//+++ Author : Yang Bai
11+
//+++ Date : 2023.07.27
12+
//+++ Purpose: Calculate User-1 defined materials
13+
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14+
15+
#pragma once
16+
17+
#include "MateSystem/BulkMaterialBase.h"
18+
19+
/**
20+
* This class calculate the material properties required by user-1
21+
*/
22+
class User1Material:public BulkMaterialBase{
23+
public:
24+
/**
25+
* Constructor
26+
*/
27+
User1Material();
28+
protected:
29+
/**
30+
* Initial the preset material properties, if you don't need the history information of some materials, then you can avoid calling this function
31+
* @param t_inputparams the input material parameters read from the json file
32+
* @param t_elmtinfo the data structure for the local element information
33+
* @param t_elmtsoln the solutions, i.e., U and V of the local element
34+
* @param Mate the materials (container) to be initialized
35+
*/
36+
virtual void initMaterialProperties(const nlohmann::json &t_inputparams,
37+
const LocalElmtInfo &t_elmtinfo,
38+
const LocalElmtSolution &t_elmtsoln,
39+
MaterialsContainer &t_mate) override;
40+
41+
/**
42+
* Compute the material property accroding to your model
43+
* @param t_inputparams the input material parameters read from the input file
44+
* @param t_elmtinfo the data structure for the local element information
45+
* @param t_elmtsoln the solutions, i.e., U and V of the local element
46+
* @param t_mateold the materials from previous step
47+
* @param t_mate the materials to be calculated
48+
*/
49+
virtual void computeMaterialProperties(const nlohmann::json &t_inputparams,
50+
const LocalElmtInfo &t_elmtinfo,
51+
const LocalElmtSolution &t_elmtsoln,
52+
const MaterialsContainer &t_mateold,
53+
MaterialsContainer &t_mate) override;
54+
55+
56+
57+
};

src/MateSystem/InitBulkMateLibs.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ void BulkMateSystem::initBulkMateLibs(const MateType &t_matetype,const nlohmann:
9595
case MateType::DIFFUSIONACFRACTUREMATE:
9696
DiffusionACFractureMaterial::initMaterialProperties(t_params,t_elmtinfo,t_elmtsoln,m_materialcontainer);
9797
break;
98+
//******************************************
99+
//*** for UMAT
100+
//******************************************
101+
case MateType::USER1MATE:
102+
User1Material::initMaterialProperties(t_params,t_elmtinfo,t_elmtsoln,m_materialcontainer);
103+
break;
98104
default:
99105
MessagePrinter::printErrorTxt("Unsupported material type in initBulkMateLibs, please check your code");
100106
MessagePrinter::exitAsFem();

src/MateSystem/RunBulkMateLibs.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ void BulkMateSystem::runBulkMateLibs(const MateType &t_matetype,const nlohmann::
9595
case MateType::DIFFUSIONACFRACTUREMATE:
9696
DiffusionACFractureMaterial::computeMaterialProperties(t_params,t_elmtinfo,t_elmtsoln,m_materialcontainer_old,m_materialcontainer);
9797
break;
98+
//******************************************
99+
//*** for User-Defined-Material (UMAT)
100+
//******************************************
101+
case MateType::USER1MATE:
102+
User1Material::computeMaterialProperties(t_params,t_elmtinfo,t_elmtsoln,m_materialcontainer_old,m_materialcontainer);
103+
break;
98104
default:
99105
MessagePrinter::printErrorTxt("Unsupported material type in runBulkMateLibs, please check your code");
100106
MessagePrinter::exitAsFem();

src/MateSystem/User1Material.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//****************************************************************
2+
//* This file is part of the AsFem framework
3+
//* A Simple Finite Element Method program (AsFem)
4+
//* All rights reserved, Yang Bai/M3 Group@CopyRight 2020-present
5+
//* https://github.com/M3Group/AsFem
6+
//* Licensed under GNU GPLv3, please see LICENSE for details
7+
//* https://www.gnu.org/licenses/gpl-3.0.en.html
8+
//****************************************************************
9+
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10+
//+++ Author : Yang Bai
11+
//+++ Date : 2022.08.26
12+
//+++ Purpose: Calculate the material properties required by diffusion
13+
//+++ element. In this code, we can define:
14+
//+++ 1) D
15+
//+++ 2) dD/dc
16+
//+++ Standard benchmark test for 2d nonlinear diffusion equation
17+
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18+
19+
#include "MateSystem/User1Material.h"
20+
21+
User1Material::User1Material(){
22+
srand(time(00));// for random seed
23+
}
24+
void User1Material::initMaterialProperties(const nlohmann::json &inputparams,
25+
const LocalElmtInfo &elmtinfo,
26+
const LocalElmtSolution &elmtsoln,
27+
MaterialsContainer &mate){
28+
//***************************************************
29+
//*** get rid of unused warning
30+
//***************************************************
31+
if(inputparams.size()||elmtinfo.m_dt||elmtsoln.m_gpU[0]||mate.getScalarMaterialsNum()){}
32+
33+
}
34+
35+
//********************************************************************
36+
void User1Material::computeMaterialProperties(const nlohmann::json &inputparams,
37+
const LocalElmtInfo &elmtinfo,
38+
const LocalElmtSolution &elmtsoln,
39+
const MaterialsContainer &mateold,
40+
MaterialsContainer &mate){
41+
//**************************************************************
42+
//*** get rid of unused warning
43+
//**************************************************************
44+
if(inputparams.size()||elmtinfo.m_dt||elmtsoln.m_gpU[0]||
45+
mateold.getScalarMaterialsNum()||mate.getScalarMaterialsNum()){}
46+
47+
//************************
48+
//*** here the poisson equation is:
49+
//*** div(sigma*grad(phi))=F
50+
mate.ScalarMaterial("sigma")=JsonUtils::getValue(inputparams,"sigma");// sigma
51+
mate.ScalarMaterial("dsigmadu")=0.0;// dsigma/dphi
52+
mate.ScalarMaterial("f")=JsonUtils::getValue(inputparams,"f");// F
53+
mate.ScalarMaterial("dfdu")=0.0;// dF/dphi
54+
mate.VectorMaterial("gradu")=elmtsoln.m_gpGradU[1];// the gradient of u
55+
56+
mate.ScalarMaterial("myx")=1.0*rand()/RAND_MAX;
57+
if(elmtinfo.m_elmtid==elmtinfo.m_elmtsnum){
58+
if(elmtinfo.m_qpointid==elmtinfo.m_qpointsnum){
59+
mate.ScalarMaterial("myx")=1000.0;
60+
}
61+
}
62+
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"mesh":{
3+
"type":"asfem",
4+
"dim":2,
5+
"nx":50,
6+
"ny":50,
7+
"meshtype":"quad4",
8+
"savemesh":true
9+
},
10+
"dofs":{
11+
"names":["phi"]
12+
},
13+
"elements":{
14+
"elmt1":{
15+
"type":"poisson",
16+
"dofs":["phi"],
17+
"domain":["alldomain"],
18+
"material":{
19+
"type":"user1",
20+
"parameters":{
21+
"sigma":1.0,
22+
"f":2.0
23+
}
24+
}
25+
}
26+
},
27+
"projection":{
28+
"type":"default",
29+
"scalarmate":["myx"],
30+
"vectormate":["gradu"]
31+
},
32+
"bcs":{
33+
"fixed":{
34+
"type":"dirichlet",
35+
"dofs":["phi"],
36+
"bcvalue":0.0,
37+
"side":["left","right","bottom","top"]
38+
}
39+
},
40+
"nlsolver":{
41+
"type":"newton",
42+
"solver":"gmres",
43+
"maxiters":50,
44+
"abs-tolerance":5.0e-7,
45+
"rel-tolerance":5.0e-10,
46+
"s-tolerance":0.0,
47+
"preconditioner":"jacobi"
48+
},
49+
"output":{
50+
"type":"vtu",
51+
"interval":1
52+
},
53+
"qpoints":{
54+
"bulk":{
55+
"type":"gauss-legendre",
56+
"order":2
57+
}
58+
},
59+
"job":{
60+
"type":"static",
61+
"print":"dep"
62+
}
63+
}

0 commit comments

Comments
 (0)