Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

extmat in COMSOL

Please login with a confirmed email address before reporting spam

I am trying to use general stress-deformation interface in external material. I want to know what does the input quantity sysT mean? I am trying to print out its values using fprintf function in C code but COSMOL keeps crashing. I guess this is a known issue in reading/writing data to external memory but has anyone been able to do so successfully?


6 Replies Last Post Jun 19, 2023, 3:53 p.m. EDT
Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 10 months ago Jun 18, 2023, 1:31 p.m. EDT

Hi,

I had been using printf() in an external material code for debugging purposes to output data to the screen. This worked but slowed down the whole thing. This was done in MS Visual C. I didn't try fprintf().

Cheers Edgar

-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Hi, I had been using printf() in an external material code for debugging purposes to output data to the screen. This worked but slowed down the whole thing. This was done in MS Visual C. I didn't try fprintf(). Cheers Edgar

Please login with a confirmed email address before reporting spam

Posted: 10 months ago Jun 18, 2023, 5:17 p.m. EDT

Hi, Thanks! But how do I link MS visual C with COMSOL to output data to a screen?

Hi, Thanks! But how do I link MS visual C with COMSOL to output data to a screen?

Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 10 months ago Jun 19, 2023, 3:42 a.m. EDT
Updated: 10 months ago Jun 19, 2023, 3:54 a.m. EDT

The printf() statement is part of the source code for the dll you generate with Visual C. No link of MS Visual C and Comsol needed. Comsol simply calls the dll and executes it.

Here is a code example, adapt it to your needs. Remove the outer commenting: /* */. It ran under Windows 7. Don't close the console manually. This will crash Comsol. It closes when Comsol closes.

/*

//START Debugging Console Window output

//The following code opens a console window for debugging purposes; mainly to check for

//correct reception of submitted fields and parameters

//Handle this with care - it can crash your machine - backup often!

static int counter = 1;

if (counter == 1)

{

AllocConsole();

freopen("CONOUT$", "w", stdout);

printf("COMSOL Multiphysics at work \r\n");

printf("Opened Console after first call to external material routine \r\n\n");

}

if(counter % 10000 == 0)

printf("Call Nr.: %7d Br = %-+5.3f Bphi = %-+5.3f Bz = %-+5.3f\r", counter, B[0], B[1], B[2]);

counter = counter + 1;

//END Debugging Console Window output

*/

Just saw that the forum software messes up the format, so added some linefeeds.

-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
The printf() statement is part of the source code for the dll you generate with Visual C. No link of MS Visual C and Comsol needed. Comsol simply calls the dll and executes it. Here is a code example, adapt it to your needs. Remove the outer commenting: /* */. It ran under Windows 7. Don't close the console manually. This will crash Comsol. It closes when Comsol closes. /* //START Debugging Console Window output //The following code opens a console window for debugging purposes; mainly to check for //correct reception of submitted fields and parameters //Handle this with care - it can crash your machine - backup often! static int counter = 1; if (counter == 1) { AllocConsole(); freopen("CONOUT$", "w", stdout); printf("COMSOL Multiphysics at work \r\n"); printf("Opened Console after first call to external material routine \r\n\n"); } if(counter % 10000 == 0) printf("Call Nr.: %7d Br = %-+5.3f Bphi = %-+5.3f Bz = %-+5.3f\r", counter, B[0], B[1], B[2]); counter = counter + 1; //END Debugging Console Window output */ Just saw that the forum software messes up the format, so added some linefeeds.

Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 10 months ago Jun 19, 2023, 9:29 a.m. EDT

I should add, that you can use any C development system that can generate a dll, it doesn't need to be MS Visual C.

-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
I should add, that you can use any C development system that can generate a dll, it doesn't need to be MS Visual C.

Please login with a confirmed email address before reporting spam

Posted: 10 months ago Jun 19, 2023, 1:27 p.m. EDT

Hi Edgar,

That worked for me! Thanks a lot.

Hi Edgar, That worked for me! Thanks a lot.

Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 10 months ago Jun 19, 2023, 3:53 p.m. EDT

Good to hear. Good luck!

-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Good to hear. Good luck!

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.