Abaqus HETVAL or DFLUX Input Variables : Possible to create heat flux dependent on stresses and strain rate? - subroutine

I'm new to abaqus subroutines and Fortran in general and a bit confused right now. I'm trying to simulate the anelastic heat dissipation during cyclic loading. Because of that I need some way to define a heat flux which is dependent on strain, stress and possibly some damge Parameter. There are different user subroutines like HETVAL or DFLUX which seem to be appropriate for this problem, but in the Documentation it states that none of these can use stresses or strains as input variables.
SUBROUTINE HETVAL(CMNAME,TEMP,TIME,DTIME,STATEV,FLUX,
1 PREDEF,DPRED)
C
INCLUDE 'ABA_PARAM.INC'
C
CHARACTER*80 CMNAME
C
DIMENSION TEMP(2),STATEV(*),PREDEF(*),TIME(2),FLUX(2),
1 DPRED(*)
user coding to define FLUX and update STATEV
RETURN
END
SUBROUTINE DFLUX(FLUX,SOL,KSTEP,KINC,TIME,NOEL,NPT,COORDS,
1 JLTYP,TEMP,PRESS,SNAME)
C
INCLUDE 'ABA_PARAM.INC'
C
DIMENSION FLUX(2), TIME(2), COORDS(3),
CHARACTER*80 SNAME
user coding to define FLUX(1) and FLUX(2)
RETURN
END
As you see neither Hetvall nor DFLUX support Stresses 'S' or Strains 'LE' (logarithmic strain) as input variables.
I already googled extensively but could't find anyone withe the same problem. So i just wanted to ask if someone else managed to teach the HETVAL or DFLUX Subroutine to read solution variables like stresses or strains? Is that even possible at all? My Problem actually shouldn't be that hard the biggest problem is to tell abaqus what to do.
Thank you!:)

It looks like you can access 'S' or 'LE' through state variables which are part of the HETVAL subroutine. You can access and modify the state variables in the USDFLD subroutine, which is called before HETVAL. In your USDFLD subroutine you call the GETVRM utility routine to get 'S' or 'LE' and can then set the corresponding state variable to that value.

Related

Modelica - Is it possible to set name of a submodel as the value of another variable?

I’m quite noob in Modelica language and I’d appreciate any help about this simple issue. I’d like to know if it’s possible to write variables name (that depends on a submodel) as a function of other variable in order to shorten the general code. Here there is an example about what I’d like to do.
I’m considering a top-level model that includes three identical submodels (OpenTank) of the Standard Modelica Library (tank1,tank2 and tank3). I’d like to know if it’s possible to call the variable (“level”) inside the submodels from the top-level model using a loop like this way (example code is attached) or something similar instead of repeating the code three times (I’m really interested in setting this operation in the top-level model)
What would you advise me to do? Thanks in advance!
model threeTanks
Modelica.Fluid.Vessels.OpenTank tank1;
Modelica.Fluid.Vessels.OpenTank tank2;
Modelica.Fluid.Vessels.OpenTank tank3;
equation
for i in 1:3 loop
tank(i).level= /* … */;
end for;
end threeTanks;
You would need a component iterator, which is proposed in Modelica Change Proposal MCP-0021 Component Iterators. But it is not available yet and nothing has changed since 2016 if I read it correct, so don't expect to get that soon.
With the current Modelica language version (specified in Modelica Language Specification 3.5), you must use literal names when you refer to components.
(In Modelica, there is nothing like eval which you might know from other languages.)
So either go for Rene Just Nielsens solution and use vectorized tanks.
This works, but in the graphical view you will have only one tank. The parameter window will then accept vectors and the tank connectors will be vectorized as well.
If you don't want that, you can also instantiate your tanks as you did and manually specify the component names over which you want to iterate:
for item in {tank1, tank2, tank3} loop
item.level= /* … */;
end for;
The question is also what you want to achieve. The tank already has equations to compute the level, so it's unlikely that you want to set it.
Maybe you want to gather all levels at top in one variable. You could do that by adding this line:
Modelica.Units.SI.Length levels[3] = {item.level for item in {tank1, tank2, tank3}};
Similar to the answer to the post (Modelica - Is it possible to set name of a variable as the value of another variable?) you can declare an array of components like this:
model threeTanks
Modelica.Fluid.Vessels.OpenTank[3] tank;
equation
for i in 1:3 loop
tank[i].level= /* … */;
end for;
end threeTanks;

Is there a way for a matlab function to access all variables in a script

I have a script with lots of variables (10-30), and in a for loop I do some processing using basically every variable. I have a helper script so that the interior of the loop looks clean.
main script
a=2;b=5;c=8;d=10;%and many many more
for i=1:1000
helper;
end
I want to turn helper into a function, primarily because this would allow me to have the helper script (now a function) at the bottom of the main file. But I definitely do not want to individually pass every variable and every variable that I have yet to need in this project.
What I really need is a goto, but matlab doesnt have it.
There are many solutions to this. In rinkert's comment you've gotten the only one that is good coding practice: put the variables in a struct, then pass the struct into your function. I highly recommend that you do that. Using nested functions is not a terrible solution either, though it could be a lot more difficult to manage (variable visibility rules are funny in nested functions, I find it confusing at times).
Here I'm going to give you the worst possible solution: evalin. You should not do this, I post this here for educational purposes only.
evalin allows a function to retrieve a variable in the caller's workspace:
a=2;b=5;c=8;d=10;%and many many more
for i=1:1000
helper;
end
function helper
% NEVER DO THIS IN PRACTICE
a = evalin('caller','a');
b = evalin('caller','b');
c = evalin('caller','c');
d = evalin('caller','d');
% do computations....
assignin('caller','result',result);
end
Note that a function result = helper(a,b,c,d) is much more efficient and much easier to maintain because it's clear what is going on. evalin makes for surprising results, and assignin even more so. Do not use this.
There are a few legitimate uses of these functions. For example, I've written a GUI that allows a MATLAB user easier access to a set of functions, but is meant to work in conjunction with the interactive MATLAB command prompt. The GUI would fetch variables from the 'base' workspace, evaluate function calls in the 'base' workspace, and write new variables to the 'base' workspace. Running a function within the GUI is just like running it at the command prompt. There is no other way of accomplishing this other than using evalin and assignin.
although it's not good coding conduct, you could use global variables :
for example :
global a;
a= 5;
function out =test()
global a;
out=2*a;
end

Global CONSTANTS. Any problem using them?

I've been programming for over 6 years now and i've always avoided using global variables because there is always another way around the problems.
Today, i work on a (big) project, we want to use a dictionnary of mathematical CONSTANTS what will never be modified anywhere. The only problem i seem to find with globals on internet is the fact that if someone overwrites one it could bug out the whole project. But as mine are constants this problem doesnt apply.
(as a second security to avoid people creating a variable with the same name as one of the constants i will probably pack them all in a single global struct)
Does anyone know of problems that still happend using global constants?
Thanks for your answers! :)
In MATLAB, your best bet for mathematical constants is to define a class with properties that have the Constant attribute. This is described in the doc here, and here's the leading example from that page:
classdef NamedConst
properties (Constant)
R = pi/180
D = 1/NamedConst.R
AccCode = '0145968740001110202NPQ'
RN = rand(5)
end
end
This way, the values cannot be overridden. (Note that there's something a little perhaps unexpected in this example - the value of the property RN changes each time the class is loaded! I personally wouldn't write code like that...)
The old-fashioned standard way to create a constant in MATLAB is to write a function. For example pi is a function. It could be written as:
function value = pi
value = 3.14159;
end
Of course we can overwrite the value of pi in MATLAB, but it is always a local change, it is not possible to affect another workspace.

Simulink - How to create independent custom blocks using callback functions

I am currently coding a new library with several models in it (I am used to Matlab, but not to Simulink). I am able to create a model with block parameters, let's say parameter 'p', and a callback function (initfct) which uses this parameter to compute specific values used inside my model (let say a simple gain K=K(p)).
My problem is that my parameter 'p' and 'K' are available directly on the workspace, what I don't want to. Moreover, if I use twice or more this model in a system, the two models share always the same 'K', which also I don't want to.
So how I can make these variables 'p' and 'K' independent when I use my custom model several time, and to prevent these variables to be viewed in the workspace ?
Should I use "Reference models", but I am not familiar with this feature ... ?
Thanks for you answer,
Michael
Within a callback, gcb returns the path to the block which currently executes the callback. Having the path, you can use get_param to access the parameters.
Just for demonstation purposes, insert the following to the MoveFcn of a delay block:
set_param(gcb,'DelayLength',num2str(randi(10)))
It will randomly change the delay whenever the block is moved.
I am not sure if my answer explains everything you need. It might be that you also need a Mask. If you think this answer is incomplete, please update your question and include a small example model demonstrating your problem.
Thanks, with your help I was able to solve the problem.
To be more specific if someone else has the same problem : you need in your mask to declare also internal variables used by the callback function. Unchecked the relevant options so that they not appear as standard input parameters of your model.
My problem was also to use num2str instead of mat2str (when the gain was a matrix acting on multiple inputs).

Matlab: How to return output from a function in a set()?

I am now using Matlab GUI and have problem during accessing return values from a function which is set by set().
Situation:
I set the windowMotionFcn as below:
set(gcf,'WindowButtonMotionFcn',#test);
Function 'test' can return 2 variables (named as var1 and var2).But I dont know how to store them...
I have searched in the Internet and could not find any way.
How should I write?
Thank you for your help and kind attention.
I think that what you want to do is to return a value from the callback function. And regarding returning a value from a callback I am not sure that is possible. I found an old article from matlab newsreader. I think your problem could be similar.
However, if you have a matlab GUIDE GUI, there is a way to return a value from a gui. It is described in a matlab tutorial in matlab central: advanced-getting-an-output-from-a-guide-gui. What you must do is to modify your CloseRequestFcn and your OutputFcn.
Another way, which should work is using global variables. A global varable exist in the global workspace. That means that it can be seen and accessed by every function in matlab. Global variables are in most cases not recommended, but if no other solution exists they may be necessary. Just make sure to document them, so that the next person to take over your code knows that they are there. Also make sure to select a good name for the globals, like gblMyVar so there can be no confusion that the variable is global.